From 3ea899c9a6117d722acc936d2659fd68c4f83eeb Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 3 Jan 2018 22:24:57 -0500 Subject: [PATCH] LU-9019 osc: migrate to 64 bit time Change od_contention_time from int to time64_t to make it clear this field is in units of seconds. Change the *_contention_time fields from jiffies to ktime_t to make it clear we are dealing with time and ktime_t is consistent on any platform unlike jiffies. Change-Id: Ieb240e40cc4d56050607314db057004db00aae13 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/30607 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Andreas Dilger Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 30 ++++++++++++++++++++++++++++++ libcfs/include/libcfs/linux/linux-time.h | 8 ++++++++ lustre/include/lustre_osc.h | 8 ++++---- lustre/mdc/lproc_mdc.c | 2 +- lustre/osc/lproc_osc.c | 2 +- lustre/osc/osc_cache.c | 4 ++-- lustre/osc/osc_object.c | 29 ++++++++++++++--------------- lustre/osc/osc_page.c | 12 ++++++------ 8 files changed, 66 insertions(+), 29 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 2ba0471..df1bfcb 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -301,6 +301,7 @@ AS_IF([test "x$enable_crc32c_crypto" = xyes], [ AC_DEFUN([LIBCFS_KTIME_GET_TS64],[ LB_CHECK_COMPILE([does function 'ktime_get_ts64' exist], ktime_get_ts64, [ + #include #include ],[ struct timespec64 *ts = NULL; @@ -335,6 +336,7 @@ kernel_param_ops, [ AC_DEFUN([LIBCFS_KTIME_ADD],[ LB_CHECK_COMPILE([does function 'ktime_add' exist], ktime_add, [ + #include #include ],[ ktime_t start = ktime_set(0, 0); @@ -354,6 +356,7 @@ ktime_add, [ AC_DEFUN([LIBCFS_KTIME_AFTER],[ LB_CHECK_COMPILE([does function 'ktime_after' exist], ktime_after, [ + #include #include ],[ ktime_t start = ktime_set(0, 0); @@ -373,6 +376,7 @@ ktime_after, [ AC_DEFUN([LIBCFS_KTIME_BEFORE],[ LB_CHECK_COMPILE([does function 'ktime_before' exist], ktime_before, [ + #include #include ],[ ktime_t start = ktime_set(0, 0); @@ -391,6 +395,7 @@ ktime_before, [ AC_DEFUN([LIBCFS_KTIME_COMPARE],[ LB_CHECK_COMPILE([does function 'ktime_compare' exist], ktime_compare, [ + #include #include ],[ ktime_t start = ktime_set(0, 0); @@ -476,6 +481,7 @@ ktime_get_real_ts64, [ AC_DEFUN([LIBCFS_KTIME_GET_REAL_SECONDS],[ LB_CHECK_COMPILE([does function 'ktime_get_real_seconds' exist], ktime_get_real_seconds, [ + #include #include ],[ time64_t now; @@ -493,6 +499,7 @@ ktime_get_real_seconds, [ AC_DEFUN([LIBCFS_KTIME_GET_NS],[ LB_CHECK_COMPILE([does function 'ktime_get_ns' exist], ktime_get_ns, [ + #include #include ],[ u64 nanoseconds; @@ -510,6 +517,7 @@ ktime_get_ns, [ AC_DEFUN([LIBCFS_KTIME_GET_REAL_NS],[ LB_CHECK_COMPILE([does function 'ktime_get_real_ns' exist], ktime_get_real_ns, [ + #include #include ],[ u64 nanoseconds; @@ -527,6 +535,7 @@ ktime_get_real_ns, [ AC_DEFUN([LIBCFS_KTIME_TO_TIMESPEC64],[ LB_CHECK_COMPILE([does function 'ktime_to_timespec64' exist], ktime_to_timespec64, [ + #include #include ],[ struct timespec64 ts; @@ -613,6 +622,25 @@ cpumap_print_to_pagebuf, [ ]) # LIBCFS_HAVE_CPUMASK_PRINT_TO_PAGEBUF # +# Kernel version 4.0 commit 41fbf3b39d5eca01527338b4d0ee15ee1ae1023c +# introduced the helper function ktime_ms_delta. +# +AC_DEFUN([LIBCFS_KTIME_MS_DELTA],[ +LB_CHECK_COMPILE([does function 'ktime_ms_delta' exist], +ktime_ms_delta, [ + #include +],[ + ktime_t start = ktime_set(0, 0); + ktime_t end = start; + + ktime_ms_delta(start, end); +],[ + AC_DEFINE(HAVE_KTIME_MS_DELTA, 1, + ['ktime_ms_delta' is available]) +]) +]) # LIBCFS_KTIME_MS_DELTA + +# # Kernel version 4.1 commit b51d23e4e9fea6f264d39535c2a62d1f51e7ccc3 # create per module locks which added kernel_param_[un]lock(). Older # kernels you have to use __kernel_param_[un]lock(). In that case its @@ -846,6 +874,8 @@ LIBCFS_TIMESPEC64_TO_KTIME # 3.19 LIBCFS_KTIME_GET_SECONDS LIBCFS_HAVE_CPUMASK_PRINT_TO_PAGEBUF +# 4.0 +LIBCFS_KTIME_MS_DELTA # 4.1 LIBCFS_KERNEL_PARAM_LOCK # 4.2 diff --git a/libcfs/include/libcfs/linux/linux-time.h b/libcfs/include/libcfs/linux/linux-time.h index 3855d27..055b166 100644 --- a/libcfs/include/libcfs/linux/linux-time.h +++ b/libcfs/include/libcfs/linux/linux-time.h @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -185,6 +186,13 @@ static inline u64 ktime_get_real_ns(void) } #endif /* NEED_KTIME_GET_REAL_NS */ +#ifndef HAVE_KTIME_MS_DELTA +static inline s64 ktime_ms_delta(const ktime_t later, const ktime_t earlier) +{ + return ktime_to_ms(ktime_sub(later, earlier)); +} +#endif /* HAVE_KTIME_MS_DELTA */ + #ifndef HAVE_KTIME_TO_TIMESPEC64 static inline struct timespec64 ktime_to_timespec64(ktime_t kt) { diff --git a/lustre/include/lustre_osc.h b/lustre/include/lustre_osc.h index 331e02f..21f1764 100644 --- a/lustre/include/lustre_osc.h +++ b/lustre/include/lustre_osc.h @@ -120,7 +120,7 @@ struct osc_device { } od_stats; /* configuration item(s) */ - int od_contention_time; + time64_t od_contention_time; int od_lockless_truncate; }; @@ -256,7 +256,7 @@ struct osc_object { * True if locking against this stripe got -EUSERS. */ int oo_contended; - cfs_time_t oo_contention_time; + ktime_t oo_contention_time; #ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK /** * IO context used for invariant checks in osc_lock_has_pages(). @@ -358,7 +358,7 @@ static inline int osc_object_is_locked(struct osc_object *obj) static inline void osc_object_set_contended(struct osc_object *obj) { - obj->oo_contention_time = cfs_time_current(); + obj->oo_contention_time = ktime_get(); /* mb(); */ obj->oo_contended = 1; } @@ -541,7 +541,7 @@ struct osc_page { /** * Submit time - the time when the page is starting RPC. For debugging. */ - cfs_time_t ops_submit_time; + ktime_t ops_submit_time; }; struct osc_brw_async_args { diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index 1b39a8e..8bd9285 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -190,7 +190,7 @@ static int mdc_contention_seconds_seq_show(struct seq_file *m, void *v) struct obd_device *obd = m->private; struct osc_device *od = obd2osc_dev(obd); - seq_printf(m, "%u\n", od->od_contention_time); + seq_printf(m, "%lld\n", od->od_contention_time); return 0; } diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index 2ea2015..3eaba3e 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -508,7 +508,7 @@ static int osc_contention_seconds_seq_show(struct seq_file *m, void *v) struct obd_device *obd = m->private; struct osc_device *od = obd2osc_dev(obd); - seq_printf(m, "%u\n", od->od_contention_time); + seq_printf(m, "%lld\n", od->od_contention_time); return 0; } diff --git a/lustre/osc/osc_cache.c b/lustre/osc/osc_cache.c index 5652c4d..b9112ef 100644 --- a/lustre/osc/osc_cache.c +++ b/lustre/osc/osc_cache.c @@ -1286,7 +1286,7 @@ static int osc_make_ready(const struct lu_env *env, struct osc_async_page *oap, ENTRY; result = cl_page_make_ready(env, page, CRT_WRITE); if (result == 0) - opg->ops_submit_time = cfs_time_current(); + opg->ops_submit_time = ktime_get(); RETURN(result); } @@ -1342,7 +1342,7 @@ static int osc_completion(const struct lu_env *env, struct osc_async_page *oap, /* Clear opg->ops_transfer_pinned before VM lock is released. */ opg->ops_transfer_pinned = 0; - opg->ops_submit_time = 0; + opg->ops_submit_time = ktime_set(0, 0); srvlock = oap->oap_brw_flags & OBD_BRW_SRVLOCK; /* statistic */ diff --git a/lustre/osc/osc_object.c b/lustre/osc/osc_object.c index 8f95765..6b44d63 100644 --- a/lustre/osc/osc_object.c +++ b/lustre/osc/osc_object.c @@ -308,10 +308,9 @@ drop_lock: int osc_object_is_contended(struct osc_object *obj) { - struct osc_device *dev = lu2osc_dev(obj->oo_cl.co_lu.lo_dev); - int osc_contention_time = dev->od_contention_time; - cfs_time_t cur_time = cfs_time_current(); - cfs_time_t retry_time; + struct osc_device *dev = lu2osc_dev(obj->oo_cl.co_lu.lo_dev); + time64_t osc_contention_time = dev->od_contention_time; + ktime_t retry_time; if (OBD_FAIL_CHECK(OBD_FAIL_OSC_OBJECT_CONTENTION)) return 1; @@ -319,17 +318,17 @@ int osc_object_is_contended(struct osc_object *obj) if (!obj->oo_contended) return 0; - /* - * I like copy-paste. the code is copied from - * ll_file_is_contended. - */ - retry_time = cfs_time_add(obj->oo_contention_time, - cfs_time_seconds(osc_contention_time)); - if (cfs_time_after(cur_time, retry_time)) { - osc_object_clear_contended(obj); - return 0; - } - return 1; + /* + * I like copy-paste. the code is copied from + * ll_file_is_contended. + */ + retry_time = ktime_add_ns(obj->oo_contention_time, + osc_contention_time * NSEC_PER_SEC); + if (ktime_after(ktime_get(), retry_time)) { + osc_object_clear_contended(obj); + return 0; + } + return 1; } EXPORT_SYMBOL(osc_object_is_contended); diff --git a/lustre/osc/osc_page.c b/lustre/osc/osc_page.c index 5762af2..eae7a92 100644 --- a/lustre/osc/osc_page.c +++ b/lustre/osc/osc_page.c @@ -119,12 +119,12 @@ static const char *osc_list(struct list_head *head) return list_empty(head) ? "-" : "+"; } -static inline cfs_time_t osc_submit_duration(struct osc_page *opg) +static inline s64 osc_submit_duration(struct osc_page *opg) { - if (opg->ops_submit_time == 0) - return 0; + if (ktime_to_ns(opg->ops_submit_time) == 0) + return 0; - return (cfs_time_current() - opg->ops_submit_time); + return ktime_ms_delta(ktime_get(), opg->ops_submit_time); } static int osc_page_print(const struct lu_env *env, @@ -139,7 +139,7 @@ static int osc_page_print(const struct lu_env *env, return (*printer)(env, cookie, LUSTRE_OSC_NAME"-page@%p %lu: " "1< %#x %d %u %s %s > " "2< %lld %u %u %#x %#x | %p %p %p > " - "3< %d %lu %d > " + "3< %d %lld %d > " "4< %d %d %d %lu %s | %s %s %s %s > " "5< %s %s %s %s | %d %s | %d %s %s>\n", opg, osc_index(opg), @@ -327,7 +327,7 @@ void osc_page_submit(const struct lu_env *env, struct osc_page *opg, oap->oap_cmd |= OBD_BRW_NOQUOTA; } - opg->ops_submit_time = cfs_time_current(); + opg->ops_submit_time = ktime_get(); osc_page_transfer_get(opg, "transfer\0imm"); osc_page_transfer_add(env, opg, crt); } -- 1.8.3.1