[ovs-dev] [PATCH] tc: Correct convert ticks to msecs on parsing tc TM

Simon Horman simon.horman at netronome.com
Thu Jul 27 08:00:46 UTC 2017


On Thu, Jul 27, 2017 at 09:14:00AM +0300, Roi Dayan wrote:
> From: Paul Blakey <paulb at mellanox.com>
> 
> 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.
> 
> Signed-off-by: Paul Blakey <paulb at mellanox.com>
> Reviewed-by: Roi Dayan <roid at mellanox.com>

This looks good to me. I'm happy to apply this if someone could provide
an Acked-by tag. Or alternatively for someone to apply it with:

Acked-by: Simon Horman <simon.horman at netronome.com>

> ---
>  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
> 


More information about the dev mailing list