Skip to content

Commit 3b15d09

Browse files
lrq-maxummakynes
authored andcommitted
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 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]>
1 parent ed514fc commit 3b15d09

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

include/linux/jiffies.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static inline u64 jiffies_to_nsecs(const unsigned long j)
297297
}
298298

299299
extern u64 jiffies64_to_nsecs(u64 j);
300+
extern u64 jiffies64_to_msecs(u64 j);
300301

301302
extern unsigned long __msecs_to_jiffies(const unsigned int m);
302303
#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)

kernel/time/time.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,16 @@ u64 jiffies64_to_nsecs(u64 j)
783783
}
784784
EXPORT_SYMBOL(jiffies64_to_nsecs);
785785

786+
u64 jiffies64_to_msecs(const u64 j)
787+
{
788+
#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
789+
return (MSEC_PER_SEC / HZ) * j;
790+
#else
791+
return div_u64(j * HZ_TO_MSEC_NUM, HZ_TO_MSEC_DEN);
792+
#endif
793+
}
794+
EXPORT_SYMBOL(jiffies64_to_msecs);
795+
786796
/**
787797
* nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64
788798
*

net/netfilter/nf_tables_api.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,9 +3193,7 @@ static int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result)
31933193

31943194
static __be64 nf_jiffies64_to_msecs(u64 input)
31953195
{
3196-
u64 ms = jiffies64_to_nsecs(input);
3197-
3198-
return cpu_to_be64(div_u64(ms, NSEC_PER_MSEC));
3196+
return cpu_to_be64(jiffies64_to_msecs(input));
31993197
}
32003198

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

0 commit comments

Comments
 (0)