From: James Simmons Date: Mon, 11 Dec 2017 18:18:42 +0000 (-0500) Subject: LU-9019 libcfs: add ktime_compare for platforms lacking it. X-Git-Tag: 2.10.57~77 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=4bbc835dc87cf947e87bd687553602781381fc81 LU-9019 libcfs: add ktime_compare for platforms lacking it. The function ktime_compare() was added to the linux kernel starting with verison 3.19. Add to libcfs support for older platforms lacking this function. Test-Parameters: trivial Change-Id: I7826b8e78d0dc2c633490a2949210176a0003d9a Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/30475 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Dmitry Eremin --- diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 10d98a6..2ba0471 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -386,6 +386,24 @@ ktime_before, [ ]) # LIBCFS_KTIME_BEFORE # +# Kernel version 3.12 introduced ktime_compare +# +AC_DEFUN([LIBCFS_KTIME_COMPARE],[ +LB_CHECK_COMPILE([does function 'ktime_compare' exist], +ktime_compare, [ + #include +],[ + ktime_t start = ktime_set(0, 0); + ktime_t end = start; + + ktime_compare(start, end); +],[ + AC_DEFINE(HAVE_KTIME_COMPARE, 1, + [ktime_compare is available]) +]) +]) # LIBCFS_KTIME_COMPARE + +# # FC19 3.12 kernel struct shrinker change # AC_DEFUN([LIBCFS_SHRINKER_COUNT],[ @@ -813,6 +831,7 @@ LIBCFS_KERNEL_PARAM_OPS LIBCFS_KTIME_ADD LIBCFS_KTIME_AFTER LIBCFS_KTIME_BEFORE +LIBCFS_KTIME_COMPARE LIBCFS_SHRINKER_COUNT # 3.17 LIBCFS_HLIST_ADD_AFTER diff --git a/libcfs/include/libcfs/linux/linux-time.h b/libcfs/include/libcfs/linux/linux-time.h index ec7f3e3..3855d27 100644 --- a/libcfs/include/libcfs/linux/linux-time.h +++ b/libcfs/include/libcfs/linux/linux-time.h @@ -144,6 +144,17 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) } #endif /* !HAVE_KTIME_BEFORE */ +#ifndef HAVE_KTIME_COMPARE +static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2) +{ + if (cmp1.tv64 < cmp2.tv64) + return -1; + if (cmp1.tv64 > cmp2.tv64) + return 1; + return 0; +} +#endif /* !HAVE_KTIME_COMPARE */ + #ifndef HAVE_KTIME_GET_TS64 void ktime_get_ts64(struct timespec64 *ts); #endif /* HAVE_KTIME_GET_TS */