time: Introduce jiffies64_to_nsecs()
authorFrederic Weisbecker <fweisbec@gmail.com>
Tue, 31 Jan 2017 03:09:17 +0000 (04:09 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Oct 2018 06:53:18 +0000 (08:53 +0200)
commit 07e5f5e353aaa61696c8353d87050994a0c4648a upstream.

This will be needed for the cputime_t to nsec conversion.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Link: http://lkml.kernel.org/r/1485832191-26889-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Ivan Delalande <colona@arista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/jiffies.h
kernel/time/time.c
kernel/time/timeconst.bc

index c2a0f0072274329f1966df12b2c3275b537befe1..734377ad42e9f0e4719edc4750b57245fa2d3f17 100644 (file)
@@ -292,6 +292,8 @@ static inline u64 jiffies_to_nsecs(const unsigned long j)
        return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
 }
 
+extern u64 jiffies64_to_nsecs(u64 j);
+
 extern unsigned long __msecs_to_jiffies(const unsigned int m);
 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
 /*
index 39468651a064a859447af176eae0fa882c9d3797..a5b6d98ea7b1ccaf244ec4146888221f37f09b73 100644 (file)
@@ -704,6 +704,16 @@ u64 nsec_to_clock_t(u64 x)
 #endif
 }
 
+u64 jiffies64_to_nsecs(u64 j)
+{
+#if !(NSEC_PER_SEC % HZ)
+       return (NSEC_PER_SEC / HZ) * j;
+# else
+       return div_u64(j * HZ_TO_NSEC_NUM, HZ_TO_NSEC_DEN);
+#endif
+}
+EXPORT_SYMBOL(jiffies64_to_nsecs);
+
 /**
  * nsecs_to_jiffies64 - Convert nsecs in u64 to jiffies64
  *
index c48688904f9fec9dc033239e28c0bdcbc761e59d..f83bbb81600b01c489249bcd2cccad233b6d95ae 100644 (file)
@@ -98,6 +98,12 @@ define timeconst(hz) {
                print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "\n"
                print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "\n"
                print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "\n"
+
+               cd=gcd(hz,1000000000)
+               print "#define HZ_TO_NSEC_NUM\t\t", 1000000000/cd, "\n"
+               print "#define HZ_TO_NSEC_DEN\t\t", hz/cd, "\n"
+               print "#define NSEC_TO_HZ_NUM\t\t", hz/cd, "\n"
+               print "#define NSEC_TO_HZ_DEN\t\t", 1000000000/cd, "\n"
                print "\n"
 
                print "#endif /* KERNEL_TIMECONST_H */\n"