[ovs-dev] [PATCH 3/8] timeval: Factor out cycles_counter().

Pravin B Shelar pshelar at nicira.com
Mon Jan 11 07:18:09 UTC 2016


Used by STT tunnel.

Signed-off-by: Pravin B Shelar <pshelar at nicira.com>
---
 lib/dpif-netdev.c | 10 ----------
 lib/timeval.h     | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index cd72e62..c746cc2 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -2464,16 +2464,6 @@ dp_netdev_actions_free(struct dp_netdev_actions *actions)
     free(actions);
 }
 
-static inline unsigned long long
-cycles_counter(void)
-{
-#ifdef DPDK_NETDEV
-    return rte_get_tsc_cycles();
-#else
-    return 0;
-#endif
-}
-
 /* Fake mutex to make sure that the calls to cycles_count_* are balanced */
 extern struct ovs_mutex cycles_counter_fake_mutex;
 
diff --git a/lib/timeval.h b/lib/timeval.h
index 96b5d08..199bb03 100644
--- a/lib/timeval.h
+++ b/lib/timeval.h
@@ -76,6 +76,28 @@ long long int time_boot_msec(void);
 
 void timewarp_run(void);
 
+#ifdef DPDK_NETDEV
+#define OVS_HZ rte_get_tsc_hz()
+#else
+#define OVS_HZ 1000000000L
+#endif
+
+static inline unsigned long long
+cycles_counter(void)
+{
+#ifdef DPDK_NETDEV
+    return rte_get_tsc_cycles();
+#else
+    struct timespec tm;
+
+    if (clock_gettime(CLOCK_REALTIME, &tm) == -1 ) {
+        return 0;
+    }
+    return tm.tv_sec * OVS_HZ + tm.tv_nsec;
+#endif
+}
+
+#define time_before(a, b)  ((long)((a) - (b)) < 0)
 #ifdef  __cplusplus
 }
 #endif
-- 
1.8.3.1




More information about the dev mailing list