diff options
author | Paul Blakey <paulb@mellanox.com> | 2017-07-30 08:01:52 +0300 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-08-03 12:53:48 -0700 |
commit | 8c1e74d1c8e3aeb74b676da45ff0b04021083c35 (patch) | |
tree | 414384520da2a3b3e2c41fbe5b189f525e4aadd4 /lib | |
parent | 08fa0266b6632111407f00de9bc6e118522204d6 (diff) | |
download | openvswitch-8c1e74d1c8e3aeb74b676da45ff0b04021083c35.tar.gz |
tc: Correct convert ticks to msecs on parsing tc TM
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 <paulb@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Joe Stringer <joe@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tc.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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" @@ -414,12 +415,24 @@ 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 |