From 21c6bb547d0d46a6ce36b7e1026b62548c6acfc1 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 12 Jun 2019 15:05:50 +0200 Subject: global: switch to coarse ktime Coarse ktime is broken until [1] in 5.2 and kernels without the backport, so we use fallback code there. The fallback code has also been improved significantly. It now only uses slower clocks on kernels < 3.17, at the expense of some accuracy we're not overly concerned about. [1] https://lore.kernel.org/lkml/tip-e3ff9c3678b4d80e22d2557b68726174578eaf52@git.kernel.org/ Suggested-by: Arnd Bergmann --- src/compat/compat.h | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/compat') diff --git a/src/compat/compat.h b/src/compat/compat.h index acf18e7..19f51a9 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -388,25 +388,38 @@ static inline int get_random_bytes_wait(void *buf, int nbytes) #define system_power_efficient_wq system_unbound_wq #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) && !defined(ISRHEL7) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 3, 0) +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) #include -static inline u64 ktime_get_boot_ns(void) +#ifndef ktime_get_real_ts64 +#define timespec64 timespec +#define ktime_get_real_ts64 ktime_get_real_ts +#endif +#else +#include +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) +static inline u64 __compat_jiffies64_to_nsecs(u64 j) { - return ktime_to_ns(ktime_get_boottime()); +#if !(NSEC_PER_SEC % HZ) + return (NSEC_PER_SEC / HZ) * j; +# else + return div_u64(j * HZ_TO_USEC_NUM, HZ_TO_USEC_DEN) * 1000; +#endif } +#define jiffies64_to_nsecs __compat_jiffies64_to_nsecs #endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) +static inline u64 ktime_get_coarse_boottime_ns(void) +{ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) -#include + return ktime_to_ns(ktime_get_boottime()); +#elif (LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 12) && LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)) || LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 53) + return ktime_to_ns(ktime_mono_to_any(ns_to_ktime(jiffies64_to_nsecs(get_jiffies_64())), TK_OFFS_BOOT)); #else -#include + return ktime_to_ns(ktime_get_coarse_boottime()); #endif -static inline u64 __compat_ktime_get_boot_fast_ns(void) -{ - return ktime_get_boot_ns(); } -#define ktime_get_boot_fast_ns __compat_ktime_get_boot_fast_ns #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) @@ -646,11 +659,6 @@ struct __compat_dummy_container { char dev; }; #define COMPAT_CANNOT_USE_AVX512 #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) -#define timespec64 timespec -#define ktime_get_real_ts64 ktime_get_real_ts -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0) #include #define genl_dump_check_consistent(a, b) genl_dump_check_consistent(a, b, &genl_family) -- cgit v1.2.3-59-g8ed1b