time: Introduce jiffies64_to_msecs()
authorLi RongQing <lirongqing@baidu.com>
Thu, 28 Feb 2019 05:13:26 +0000 (13:13 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 8 Apr 2019 20:56:14 +0000 (22:56 +0200)
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 <zhangyu31@baidu.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
Acked-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/linux/jiffies.h
kernel/time/time.c
net/netfilter/nf_tables_api.c

index fa928242567db30769839ac8738be5dc58e372ab..1b6d31da7cbc3dd885e43a0c430b8cac890b13dd 100644 (file)
@@ -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)
index c3f756f8534bba606b1fcee479bfcb0e05829502..9e3f79d4f5a850475763eeffb0d0bf8d8c8527c7 100644 (file)
@@ -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
  *
index 90e6b09ef2af652e3615749a350c7a165d18eedd..ee1b0d1445aa99765494c2fc565fa67944d50e7e 100644 (file)
@@ -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,