diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-12 15:05:50 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-25 16:42:42 +0200 |
commit | 868bdd798190a689ddebf1fff7c41509e73c7cc0 (patch) | |
tree | eda7b6e3f06ea2e5ae20c175944a433231681b4c /src/compat | |
parent | 07b71d592d4c172f3311e91a36b65e98cae68198 (diff) |
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 <arnd@arndb.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/compat')
-rw-r--r-- | src/compat/compat.h | 40 |
1 files changed, 24 insertions, 16 deletions
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 <linux/ktime.h> +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) #include <linux/hrtimer.h> -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 <linux/timekeeping.h> +#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 <linux/hrtimer.h> + 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 <linux/timekeeping.h> + 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 <net/genetlink.h> #define genl_dump_check_consistent(a, b) genl_dump_check_consistent(a, b, &genl_family) |