From: Paul Blakey <[email protected]>

Use sysconf(_SC_CLK_TCK) to read run time "number of clock ticks per
second" and use that to convert ticks to msecs.
This is how iproute does the conversion when parsing tc filters.
The system call is done only once.

Signed-off-by: Paul Blakey <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
---
 lib/tc.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/tc.c b/lib/tc.c
index 401690e..b3fe52f 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -27,6 +27,7 @@
 #include <linux/tc_act/tc_vlan.h>
 #include <linux/gen_stats.h>
 #include <net/if.h>
+#include <unistd.h>
 
 #include "byte-order.h"
 #include "netlink-socket.h"
@@ -399,12 +400,23 @@ static const struct nl_policy gact_policy[] = {
                       .optional = false, },
 };
 
-#define JIFFIES_TO_MS(x) (x * 10)
+static int
+get_user_hz(void) {
+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+    static int user_hz = 100;
+
+    if (ovsthread_once_start(&once)) {
+        user_hz = sysconf(_SC_CLK_TCK);
+        ovsthread_once_done(&once);
+    }
+
+    return user_hz;
+}
 
 static void
 nl_parse_tcf(const struct tcf_t *tm, struct tc_flower *flower)
 {
-    flower->lastused = time_msec() - JIFFIES_TO_MS(tm->lastuse);
+    flower->lastused = time_msec() - (tm->lastuse * 1000 / get_user_hz());
 }
 
 static int
-- 
2.7.4

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to