From eef4e499042792c0f16e12d0674d50c4e53f9f72 Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Mon, 8 Feb 2021 10:16:25 +0100 Subject: [PATCH] Use time since epoch instead of jiffies If time is counted in jiffies, machine reboot brokes `dirty for` statistic for caches loaded at boot. The counter overflows and `dirty for` shows some huge values. Cast ticks to unsigned long. Add necessary header. Move `env_msleep` to `TIME` subgroup of header. Move `env_time_after` below time converting functions. Signed-off-by: Slawomir Jankowski --- modules/cas_cache/linux_kernel_version.h | 1 + modules/cas_cache/ocf_env.h | 45 ++++++++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/modules/cas_cache/linux_kernel_version.h b/modules/cas_cache/linux_kernel_version.h index 4520e43..8e59b88 100644 --- a/modules/cas_cache/linux_kernel_version.h +++ b/modules/cas_cache/linux_kernel_version.h @@ -39,6 +39,7 @@ #include #include #include +#include #include "generated_defines.h" diff --git a/modules/cas_cache/ocf_env.h b/modules/cas_cache/ocf_env.h index 46721d2..60a130d 100644 --- a/modules/cas_cache/ocf_env.h +++ b/modules/cas_cache/ocf_env.h @@ -539,17 +539,34 @@ static inline int env_in_interrupt(void) /* *** TIME *** */ static inline uint64_t env_get_tick_count(void) { - return jiffies; -} - -static inline uint64_t env_ticks_to_msecs(uint64_t j) -{ - return jiffies_to_msecs(j); + struct timespec ts; + getnstimeofday(&ts); + return ts.tv_sec * 1000000000UL + ts.tv_nsec; } static inline uint64_t env_ticks_to_nsecs(uint64_t j) { - return jiffies_to_usecs(j) * NSEC_PER_USEC; + return j; +} + +static inline uint64_t env_ticks_to_usecs(uint64_t j) +{ + return j / 1000UL; +} + +static inline uint64_t env_ticks_to_msecs(uint64_t j) +{ + return j / 1000000UL; +} + +static inline uint64_t env_ticks_to_secs(uint64_t j) +{ + return j / 1000000000UL; +} + +static inline uint64_t env_secs_to_ticks(uint64_t j) +{ + return j * 1000000000UL; } static inline bool env_time_after(uint64_t a, uint64_t b) @@ -557,14 +574,9 @@ static inline bool env_time_after(uint64_t a, uint64_t b) return time_after64(a,b); } -static inline uint64_t env_ticks_to_secs(uint64_t j) +static inline void env_msleep(uint64_t n) { - return j >> SHIFT_HZ; -} - -static inline uint64_t env_secs_to_ticks(uint64_t j) -{ - return j << SHIFT_HZ; + msleep(n); } /* *** BIT OPERATIONS *** */ @@ -584,11 +596,6 @@ static inline int env_bit_test(int nr, const void *addr) return test_bit(nr, addr); } -static inline void env_msleep(uint64_t n) -{ - msleep(n); -} - /* *** STRING OPERATIONS *** */