diff mbox series

[v6,05/10] app/testpmd: add clock_gettime_monotonic

Message ID 1618874400-26819-6-git-send-email-jizh@linux.microsoft.com (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers show
Series app/testpmd: enable testpmd on Windows | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Zhou April 19, 2021, 11:19 p.m. UTC
Add clock_gettime_monotonic for testpmd on Windows

Signed-off-by: Jie Zhou <jizh@microsoft.com>
Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
---
 app/test-pmd/config.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Konstantin Ananyev April 20, 2021, 9:09 a.m. UTC | #1
> 
> Add clock_gettime_monotonic for testpmd on Windows
> 
> Signed-off-by: Jie Zhou <jizh@microsoft.com>
> Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> ---
>  app/test-pmd/config.c | 33 ++++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index ef0b9784d..a5f8fec5b 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -63,6 +63,12 @@
> 
>  #define NS_PER_SEC 1E9
> 
> +#ifdef RTE_EXEC_ENV_WINDOWS
> +#define _clock_gettime_monotonic(cur_time) clock_gettime_monotonic(&cur_time)
> +#else
> +#define _clock_gettime_monotonic(cur_time) clock_gettime(CLOCK_TYPE_ID, &cur_time)
> +#endif
> +
>  static char *flowtype_to_str(uint16_t flow_type);
> 
>  static const struct {
> @@ -170,6 +176,27 @@ print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
>  	printf("%s%s", name, buf);
>  }
> 
> +#ifdef RTE_EXEC_ENV_WINDOWS

Do we really need to pollute testpmd code with all these ifdefs?
Might be better to move it into a separate .h?

> +static int
> +clock_gettime_monotonic(struct timespec *tp)
> +{
> +	LARGE_INTEGER pf, pc;
> +	LONGLONG nsec;
> +
> +	if (QueryPerformanceFrequency(&pf) == 0)
> +		return -1;
> +
> +	if (QueryPerformanceCounter(&pc) == 0)
> +		return -1;
> +
> +	nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
> +	tp->tv_sec = nsec / NS_PER_SEC;
> +	tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
> +
> +	return 0;
> +}
> +#endif
> +
Jie Zhou April 22, 2021, 9:54 p.m. UTC | #2
On Tue, Apr 20, 2021 at 09:09:52AM +0000, Ananyev, Konstantin wrote:
> 
> 
> > 
> > Add clock_gettime_monotonic for testpmd on Windows
> > 
> > Signed-off-by: Jie Zhou <jizh@microsoft.com>
> > Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> > ---
> >  app/test-pmd/config.c | 33 ++++++++++++++++++++++++++++++++-
> >  1 file changed, 32 insertions(+), 1 deletion(-)
> > 
> > diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> > index ef0b9784d..a5f8fec5b 100644
> > --- a/app/test-pmd/config.c
> > +++ b/app/test-pmd/config.c
> > @@ -63,6 +63,12 @@
> > 
> >  #define NS_PER_SEC 1E9
> > 
> > +#ifdef RTE_EXEC_ENV_WINDOWS
> > +#define _clock_gettime_monotonic(cur_time) clock_gettime_monotonic(&cur_time)
> > +#else
> > +#define _clock_gettime_monotonic(cur_time) clock_gettime(CLOCK_TYPE_ID, &cur_time)
> > +#endif
> > +
> >  static char *flowtype_to_str(uint16_t flow_type);
> > 
> >  static const struct {
> > @@ -170,6 +176,27 @@ print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
> >  	printf("%s%s", name, buf);
> >  }
> > 
> > +#ifdef RTE_EXEC_ENV_WINDOWS
> 
> Do we really need to pollute testpmd code with all these ifdefs?
> Might be better to move it into a separate .h?

Thanks Konstantin for the suggestion. In V7 move this into config.h, together with the NS_PER_SEC def etc.

> 
> > +static int
> > +clock_gettime_monotonic(struct timespec *tp)
> > +{
> > +	LARGE_INTEGER pf, pc;
> > +	LONGLONG nsec;
> > +
> > +	if (QueryPerformanceFrequency(&pf) == 0)
> > +		return -1;
> > +
> > +	if (QueryPerformanceCounter(&pc) == 0)
> > +		return -1;
> > +
> > +	nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
> > +	tp->tv_sec = nsec / NS_PER_SEC;
> > +	tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
> > +
> > +	return 0;
> > +}
> > +#endif
> > +
diff mbox series

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index ef0b9784d..a5f8fec5b 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -63,6 +63,12 @@ 
 
 #define NS_PER_SEC 1E9
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define _clock_gettime_monotonic(cur_time) clock_gettime_monotonic(&cur_time)
+#else
+#define _clock_gettime_monotonic(cur_time) clock_gettime(CLOCK_TYPE_ID, &cur_time)
+#endif
+
 static char *flowtype_to_str(uint16_t flow_type);
 
 static const struct {
@@ -170,6 +176,27 @@  print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
 	printf("%s%s", name, buf);
 }
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+static int
+clock_gettime_monotonic(struct timespec *tp)
+{
+	LARGE_INTEGER pf, pc;
+	LONGLONG nsec;
+
+	if (QueryPerformanceFrequency(&pf) == 0)
+		return -1;
+
+	if (QueryPerformanceCounter(&pc) == 0)
+		return -1;
+
+	nsec = pc.QuadPart * NS_PER_SEC / pf.QuadPart;
+	tp->tv_sec = nsec / NS_PER_SEC;
+	tp->tv_nsec = nsec - tp->tv_sec * NS_PER_SEC;
+
+	return 0;
+}
+#endif
+
 void
 nic_stats_display(portid_t port_id)
 {
@@ -186,6 +213,8 @@  nic_stats_display(portid_t port_id)
 
 	static const char *nic_stats_border = "########################";
 
+	int ret;
+
 	if (port_id_is_invalid(port_id, ENABLED_WARN)) {
 		print_valid_ports();
 		return;
@@ -202,7 +231,9 @@  nic_stats_display(portid_t port_id)
 	       "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
 
 	diff_ns = 0;
-	if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
+
+	ret = _clock_gettime_monotonic(cur_time);
+	if (ret == 0) {
 		uint64_t ns;
 
 		ns = cur_time.tv_sec * NS_PER_SEC;