time: Introduce jiffies64_to_msecs()
PATCH v2 1/1 time: Introduce jiffies64_to_msecs()
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
---
v1-->v2: using jiffies64_to_msecs in nf_tables_api.c
include/linux/jiffies.h | 1 + kernel/time/time.c | 10 ++++++++++ net/netfilter/nf_tables_api.c | 4 +--- 3 files changed, 12 insertions(+), 3 deletions(-)
include/linux/jiffies.h +1 -0
@@ -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 )
kernel/time/time.c +10 -0
@@ -719,6 +719,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 *
net/netfilter/nf_tables_api.c +1 -3
@@ -3184,9 +3184,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,
Signature · 1 line
2.16.2
Quoted 6 lines · Li RongQing
there is a similar helper in
net/netfilter/nf_tables_api.c, this maybe become a common request someday, so move it totime.cSigned-off-by Zhang Yu <[email protected]>Signed-off-by Li RongQing <[email protected]>
This is touching kernel/time.c bits, which is far from my realm.
What should I do with this? I can just place it in nf-next.git if I get an ACK to do so. Otherwise, please just take this if this looks good to you.
Thanks!
Quoted 59 lines
---
v1-->v2: usingjiffies64_to_msecsinnf_tables_api.cinclude/linux/jiffies.h | 1 + kernel/time/time.c | 10 ++++++++++ net/netfilter/nf_tables_api.c | 4 +--- 3 files changed, 12 insertions(+), 3 deletions(-)include/linux/jiffies.h +1
-0@@ -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 )kernel/time/time.c +10
-0@@ -719,6 +719,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 * net/netfilter/nf_tables_api.c +1
-3@@ -3184,9 +3184,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,Signature · 1 line
2.16.2
John Stultz
Acked-byQuoted 9 lines · Pablo Neira Ayuso
Quoted 6 lines · Li RongQing
there is a similar helper in
net/netfilter/nf_tables_api.c, this maybe become a common request someday, so move it totime.cSigned-off-by Zhang Yu <[email protected]>Signed-off-by Li RongQing <[email protected]>
Quoted 7 lines
This is touching
kernel/time.cbits, which is far from my realm.What should I do with this? I can just place it in nf-next.git if I get an ACK to do so. Otherwise, please just take this if this looks good to you.
Pablo Neira Ayuso
maintainerQuoted 12 lines · John Stultz
Quoted 11 lines · Pablo Neira Ayuso
Quoted 6 lines · Li RongQing
there is a similar helper in
net/netfilter/nf_tables_api.c, this maybe become a common request someday, so move it totime.cSigned-off-by Zhang Yu <[email protected]>Signed-off-by Li RongQing <[email protected]>
Quoted 7 lines
Quoted 5 lines
This is touching
kernel/time.cbits, which is far from my realm.What should I do with this? I can just place it in nf-next.git if I get an ACK to do so. Otherwise, please just take this if this looks good to you.
Acked-by John Stultz <[email protected]>
Thanks. Now applied.