diff mbox series

[v9,04/10] eal/Windows: add clock_gettime on Windows

Message ID 1619805162-10684-5-git-send-email-jizh@linux.microsoft.com (mailing list archive)
State Superseded, archived
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 30, 2021, 5:52 p.m. UTC
Add clock_gettime on Windows in rte_os_shim.h

Signed-off-by: Jie Zhou <jizh@microsoft.com>
Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
---
 app/test-pmd/config.c                 |  1 +
 lib/eal/windows/include/rte_os_shim.h | 38 +++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

Comments

Tal Shnaiderman May 3, 2021, 5:37 p.m. UTC | #1
> Subject: [PATCH v9 04/10] eal/Windows: add clock_gettime on Windows
> 
> External email: Use caution opening links or attachments
> 
> 
> Add clock_gettime on Windows in rte_os_shim.h
> 
> Signed-off-by: Jie Zhou <jizh@microsoft.com>
> Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>
> ---
>  app/test-pmd/config.c                 |  1 +

Unneeded change

>  lib/eal/windows/include/rte_os_shim.h | 38
> +++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index
> e189062ef..0e86ed02f 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -205,6 +205,7 @@ 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) {
>                 uint64_t ns;
> 
> diff --git a/lib/eal/windows/include/rte_os_shim.h
> b/lib/eal/windows/include/rte_os_shim.h
> index e60f27400..ec1087290 100644
> --- a/lib/eal/windows/include/rte_os_shim.h
> +++ b/lib/eal/windows/include/rte_os_shim.h
> @@ -75,4 +75,42 @@ rte_timespec_get(struct timespec *now, int base)
> 
>  #endif /* RTE_TOOLCHAIN_GCC */
> 
> +/* Identifier for system-wide realtime clock. */
> +#define CLOCK_REALTIME                  0
> +/* Monotonic system-wide clock. */
> +#define CLOCK_MONOTONIC                 1
> +/* High-resolution timer from the CPU. */
> +#define CLOCK_PROCESS_CPUTIME_ID        2
> +/* Thread-specific CPU-time clock. */
> +#define CLOCK_THREAD_CPUTIME_ID         3
> +
> +#define NS_PER_SEC 1E9
> +
> +typedef int clockid_t;
> +
> +static inline int
> +rte_clock_gettime(clockid_t clock_id, struct timespec *tp) {
> +       LARGE_INTEGER pf, pc;
> +       LONGLONG nsec;
> +       switch (clock_id) {
> +       case CLOCK_REALTIME:
> +               if (timespec_get(tp, TIME_UTC) != TIME_UTC)
> +                       return -1;
> +               return 0;
> +       case CLOCK_MONOTONIC:
> +               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;
> +       default:
> +               return -1;
> +       }
> +}
> +#define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp)
> +
>  #endif /* _RTE_OS_SHIM_ */
> --
> 2.30.0.vfs.0.2
diff mbox series

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index e189062ef..0e86ed02f 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -205,6 +205,7 @@  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) {
 		uint64_t ns;
 
diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index e60f27400..ec1087290 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -75,4 +75,42 @@  rte_timespec_get(struct timespec *now, int base)
 
 #endif /* RTE_TOOLCHAIN_GCC */
 
+/* Identifier for system-wide realtime clock. */
+#define CLOCK_REALTIME                  0
+/* Monotonic system-wide clock. */
+#define CLOCK_MONOTONIC                 1
+/* High-resolution timer from the CPU. */
+#define CLOCK_PROCESS_CPUTIME_ID        2
+/* Thread-specific CPU-time clock. */
+#define CLOCK_THREAD_CPUTIME_ID         3
+
+#define NS_PER_SEC 1E9
+
+typedef int clockid_t;
+
+static inline int
+rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+	LARGE_INTEGER pf, pc;
+	LONGLONG nsec;
+	switch (clock_id) {
+	case CLOCK_REALTIME:
+		if (timespec_get(tp, TIME_UTC) != TIME_UTC)
+			return -1;
+		return 0;
+	case CLOCK_MONOTONIC:
+		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;
+	default:
+		return -1;
+	}
+}
+#define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp)
+
 #endif /* _RTE_OS_SHIM_ */