Whamcloud - gitweb
LU-9019 libcfs: add ktime_compare for platforms lacking it. 75/30475/2
authorJames Simmons <uja.ornl@yahoo.com>
Mon, 11 Dec 2017 18:18:42 +0000 (13:18 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 22 Dec 2017 06:48:54 +0000 (06:48 +0000)
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 <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/30475
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/linux/linux-time.h

index 10d98a6..2ba0471 100644 (file)
@@ -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 <linux/ktime.h>
+],[
+       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
index ec7f3e3..3855d27 100644 (file)
@@ -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 */