Skip to content

Commit

Permalink
time: Introduce jiffies64_to_msecs()
Browse files Browse the repository at this point in the history
there is a similar helper in net/netfilter/nf_tables_api.c,
this maybe become a common request someday, so move it to
time.c

Signed-off-by: Zhang Yu <[email protected]>
Signed-off-by: Li RongQing <[email protected]>
Acked-by: John Stultz <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
lrq-max authored and ummakynes committed Apr 8, 2019
1 parent ed514fc commit 3b15d09
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/linux/jiffies.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ static inline u64 jiffies_to_nsecs(const unsigned long j)
}

extern u64 jiffies64_to_nsecs(u64 j);
extern u64 jiffies64_to_msecs(u64 j);

extern unsigned long __msecs_to_jiffies(const unsigned int m);
#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
Expand Down
10 changes: 10 additions & 0 deletions kernel/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,16 @@ u64 jiffies64_to_nsecs(u64 j)
}
EXPORT_SYMBOL(jiffies64_to_nsecs);

u64 jiffies64_to_msecs(const u64 j)
{
#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
return (MSEC_PER_SEC / HZ) * j;
#else
return div_u64(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN);
#endif
}
EXPORT_SYMBOL(jiffies64_to_msecs);

/**
* nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64
*
Expand Down
4 changes: 1 addition & 3 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3193,9 +3193,7 @@ static int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result)

static __be64 nf_jiffies64_to_msecs(u64 input)
{
u64 ms = jiffies64_to_nsecs(input);

return cpu_to_be64(div_u64(ms, NSEC_PER_MSEC));
return cpu_to_be64(jiffies64_to_msecs(input));
}

static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
Expand Down

0 comments on commit 3b15d09

Please sign in to comment.