DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Tyler Retzlaff <roretzla@microsoft.com>,
	Mike Wells <mike.wells@telchemy.com>,
	Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
	Dmitry Malloy <dmitrym@microsoft.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>,
	Ray Kinsella <mdr@ashroe.eu>, Neil Horman <nhorman@tuxdriver.com>
Subject: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
Date: Sun, 14 Feb 2021 05:16:11 +0300	[thread overview]
Message-ID: <20210214021616.26970-2-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20210214021616.26970-1-dmitry.kozliuk@gmail.com>

Many PMDs use POSIX gettimeofday(). Add rte_time_get_us() function
to obtain current time with microsecond precision on all platforms.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/include/rte_time.h    | 17 +++++++++++++++++
 lib/librte_eal/rte_eal_exports.def   |  1 +
 lib/librte_eal/unix/eal_unix_timer.c | 13 +++++++++++++
 lib/librte_eal/version.map           |  1 +
 lib/librte_eal/windows/eal_timer.c   | 21 ++++++++++++++++++++-
 5 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/include/rte_time.h b/lib/librte_eal/include/rte_time.h
index 5ad7c8841..50fa4f889 100644
--- a/lib/librte_eal/include/rte_time.h
+++ b/lib/librte_eal/include/rte_time.h
@@ -8,6 +8,8 @@
 #include <stdint.h>
 #include <time.h>
 
+#include <rte_compat.h>
+
 #define NSEC_PER_SEC             1000000000L
 
 /**
@@ -98,4 +100,19 @@ rte_ns_to_timespec(uint64_t nsec)
 	return ts;
 }
 
+/* Point of time with microsecond precision. */
+struct rte_time_us {
+	int64_t sec;  /**< Number of whole seconds. */
+	int64_t usec; /**< Fractional part of second in [0, 999999]. */
+};
+
+/**
+ * Get current system time.
+ *
+ * @param now
+ *  Receives current system time.
+ */
+__rte_internal
+void rte_time_get_us(struct rte_time_us *now);
+
 #endif /* _RTE_TIME_H_ */
diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
index 474cf123f..cb691f7bc 100644
--- a/lib/librte_eal/rte_eal_exports.def
+++ b/lib/librte_eal/rte_eal_exports.def
@@ -334,3 +334,4 @@ EXPORTS
 	rte_mem_map
 	rte_mem_page_size
 	rte_mem_unmap
+	rte_time_get_us
diff --git a/lib/librte_eal/unix/eal_unix_timer.c b/lib/librte_eal/unix/eal_unix_timer.c
index cc5015910..5612fdebe 100644
--- a/lib/librte_eal/unix/eal_unix_timer.c
+++ b/lib/librte_eal/unix/eal_unix_timer.c
@@ -4,7 +4,10 @@
 
 #include <time.h>
 
+#include <sys/time.h>
+
 #include <rte_cycles.h>
+#include <rte_time.h>
 
 void
 rte_delay_us_sleep(unsigned int us)
@@ -27,3 +30,13 @@ rte_delay_us_sleep(unsigned int us)
 		ind = 1 - ind;
 	}
 }
+
+void
+rte_time_get_us(struct rte_time_us *now)
+{
+	struct timeval sys;
+
+	gettimeofday(&sys, NULL);
+	now->sec = sys.tv_sec;
+	now->usec = sys.tv_usec;
+}
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112..405bed766 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -421,4 +421,5 @@ INTERNAL {
 	rte_mem_map;
 	rte_mem_page_size;
 	rte_mem_unmap;
+	rte_time_get_us;
 };
diff --git a/lib/librte_eal/windows/eal_timer.c b/lib/librte_eal/windows/eal_timer.c
index b070cb775..a5c42106a 100644
--- a/lib/librte_eal/windows/eal_timer.c
+++ b/lib/librte_eal/windows/eal_timer.c
@@ -9,6 +9,7 @@
 #include <rte_cycles.h>
 #include <rte_eal.h>
 #include <rte_errno.h>
+#include <rte_time.h>
 #include "eal_private.h"
 
 #define US_PER_SEC 1E6
@@ -85,10 +86,28 @@ get_tsc_freq(void)
 	return RTE_ALIGN_MUL_NEAR(tsc_hz, CYC_PER_10MHZ);
 }
 
-
 int
 rte_eal_timer_init(void)
 {
 	set_tsc_freq();
 	return 0;
 }
+
+void
+rte_time_get_us(struct rte_time_us *now)
+{
+	/* 100ns ticks from 1601-01-01 to 1970-01-01 */
+	static const uint64_t EPOCH = 116444736000000000ULL;
+	static const uint64_t TICKS_PER_USEC = 10;
+	static const uint64_t USEC_PER_SEC = 1000000;
+
+	FILETIME ft;
+	uint64_t ticks, sec;
+
+	GetSystemTimePreciseAsFileTime(&ft);
+	ticks = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
+	ticks -= EPOCH;
+	sec = ticks / (TICKS_PER_USEC * USEC_PER_SEC);
+	now->sec = sec;
+	now->usec = ticks / TICKS_PER_USEC - sec * USEC_PER_SEC;
+}
-- 
2.29.2


  reply	other threads:[~2021-02-14  2:16 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14  1:20 [dpdk-dev] [PATCH 0/6] net/pcap: build on Windows Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 1/6] eal: add internal API for current time Dmitry Kozlyuk
2021-03-01 22:31   ` Nick Connolly
2021-03-01 22:36     ` Nick Connolly
2021-02-14  1:20 ` [dpdk-dev] [PATCH 2/6] net/pcap: fix format string Dmitry Kozlyuk
2021-03-01 22:33   ` Nick Connolly
2021-02-14  1:20 ` [dpdk-dev] [PATCH 3/6] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 4/6] net/pcap: add libpcap wrappers Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 5/6] config: discover libpcap on Windows Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 6/6] net/pcap: build " Dmitry Kozlyuk
2021-02-14  2:16 ` [dpdk-dev] [PATCH v2 0/6] " Dmitry Kozlyuk
2021-02-14  2:16   ` Dmitry Kozlyuk [this message]
2021-03-01 22:39     ` [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time Nick Connolly
2021-03-05 17:50     ` Jie Zhou
2021-03-16  9:18     ` Thomas Monjalon
2021-03-16 18:59     ` Stephen Hemminger
2021-03-16 20:07       ` Dmitry Kozlyuk
2021-03-17  9:50         ` Morten Brørup
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 2/6] net/pcap: fix format string Dmitry Kozlyuk
2021-02-25 14:45     ` Ferruh Yigit
2021-03-02 11:48       ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 3/6] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-02-25 14:51     ` Ferruh Yigit
2021-02-25 16:05       ` Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers Dmitry Kozlyuk
2021-02-25 14:59     ` Ferruh Yigit
2021-02-25 19:04       ` Dmitry Kozlyuk
2021-02-25 20:31         ` Nick Connolly
2021-02-25 23:10           ` Dmitry Kozlyuk
2021-03-01 21:43             ` Nick Connolly
2021-03-01 23:05               ` Dmitry Kozlyuk
2021-03-01 23:23                 ` Dmitry Kozlyuk
2021-03-02 11:22                 ` Nick Connolly
2021-03-03 16:32                   ` Dmitry Kozlyuk
2021-03-03 16:47                     ` Ferruh Yigit
2021-03-03 18:19                       ` Dmitry Kozlyuk
2021-03-03 19:30                         ` Ferruh Yigit
2021-03-03 23:03                           ` Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows Dmitry Kozlyuk
2021-02-25 15:02     ` Ferruh Yigit
2021-02-25 16:04       ` Dmitry Kozlyuk
2021-02-25 16:33         ` Bruce Richardson
2021-02-25 17:42           ` Dmitry Kozlyuk
2021-03-16  9:16             ` Thomas Monjalon
2021-03-16  9:37               ` Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 6/6] net/pcap: build " Dmitry Kozlyuk
2021-03-24  0:50   ` [dpdk-dev] [PATCH v3 0/3] " Dmitry Kozlyuk
2021-03-24  0:50     ` [dpdk-dev] [PATCH v3 1/3] eal/windows: add timespec_get shim for MinGW Dmitry Kozlyuk
2021-03-24  0:50     ` [dpdk-dev] [PATCH v3 2/3] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-03-24  0:50     ` [dpdk-dev] [PATCH v3 3/3] net/pcap: build on Windows Dmitry Kozlyuk
2021-04-09 10:51     ` [dpdk-dev] [PATCH v3 0/3] " Ferruh Yigit
2021-04-09 11:03       ` Dmitry Kozlyuk
2021-04-09 11:24         ` Ferruh Yigit
2021-04-15 22:10     ` [dpdk-dev] [PATCH v4 " Dmitry Kozlyuk
2021-04-15 22:10       ` [dpdk-dev] [PATCH v4 1/3] eal/windows: add timespec_get shim for MinGW Dmitry Kozlyuk
2021-04-15 22:10       ` [dpdk-dev] [PATCH v4 2/3] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-04-15 22:10       ` [dpdk-dev] [PATCH v4 3/3] net/pcap: build on Windows Dmitry Kozlyuk
2021-04-19 21:05         ` Tyler Retzlaff
2021-04-16 17:22       ` [dpdk-dev] [PATCH v4 0/3] " Ferruh Yigit
2021-04-20 22:20       ` Thomas Monjalon
2021-04-21 14:53         ` Dmitry Kozlyuk
2021-04-21 18:12           ` Thomas Monjalon
2021-04-21 19:33       ` [dpdk-dev] [PATCH v5 " Dmitry Kozlyuk
2021-04-21 19:33         ` [dpdk-dev] [PATCH v5 1/3] eal: add timespec_get shim Dmitry Kozlyuk
2021-04-21 19:33         ` [dpdk-dev] [PATCH v5 2/3] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-04-21 19:33         ` [dpdk-dev] [PATCH v5 3/3] net/pcap: build on Windows Dmitry Kozlyuk
2021-04-21 21:54         ` [dpdk-dev] [PATCH v5 0/3] " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210214021616.26970-2-dmitry.kozliuk@gmail.com \
    --to=dmitry.kozliuk@gmail.com \
    --cc=dev@dpdk.org \
    --cc=dmitrym@microsoft.com \
    --cc=mdr@ashroe.eu \
    --cc=mike.wells@telchemy.com \
    --cc=navasile@linux.microsoft.com \
    --cc=nhorman@tuxdriver.com \
    --cc=pallavi.kadam@intel.com \
    --cc=roretzla@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).