]> granicus.if.org Git - zfs/commitdiff
Simplify the time compatibility wrappers
authorBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 30 Sep 2014 22:48:25 +0000 (18:48 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 17 Oct 2014 22:11:50 +0000 (15:11 -0700)
Many of the time functions had grown overly complex in order to
handle kernel compatibility issues.  However, as of Linux 2.6.26
all the required functionality is available.  This allows us to
retire numerous configure checks and greatly simplify the time
compatibility wrappers.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
config/spl-build.m4
include/linux/Makefile.am
include/linux/time_compat.h [deleted file]
include/sys/time.h
include/sys/types.h
module/spl/Makefile.in
module/spl/spl-time.c [deleted file]

index fbe88083683ec22d77297897af66f068815884d5..109c653c132a365eef7181d9812d0bd84f2df246 100644 (file)
@@ -30,12 +30,8 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
        SPL_AC_CTL_NAME
        SPL_AC_VMALLOC_INFO
        SPL_AC_PDE_DATA
-       SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT
-       SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE
-       SPL_AC_TIMESPEC_SUB
        SPL_AC_UACCESS_HEADER
        SPL_AC_KMALLOC_NODE
-       SPL_AC_MONOTONIC_CLOCK
        SPL_AC_INODE_I_MUTEX
        SPL_AC_MUTEX_OWNER
        SPL_AC_MUTEX_OWNER_TASK_STRUCT
@@ -992,66 +988,6 @@ AC_DEFUN([SPL_AC_CTL_NAME], [
        ])
 ])
 
-dnl #
-dnl # 2.6.26 API change, set_normalized_timespec() is exported.
-dnl #
-AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_EXPORT],
-       [AC_MSG_CHECKING([whether set_normalized_timespec() is available as export])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/time.h>
-       ], [
-               set_normalized_timespec(NULL, 0, 0);
-       ], [set_normalized_timespec], [kernel/time.c], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT, 1,
-                         [set_normalized_timespec() is available as export])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
-dnl #
-dnl # 2.6.16 API change, set_normalize_timespec() moved to time.c
-dnl # previously it was available in time.h as an inline.
-dnl #
-AC_DEFUN([SPL_AC_SET_NORMALIZED_TIMESPEC_INLINE], [
-       AC_MSG_CHECKING([whether set_normalized_timespec() is an inline])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/time.h>
-               void set_normalized_timespec(struct timespec *ts,
-                                            time_t sec, long nsec) { }
-       ],
-       [],
-       [
-               AC_MSG_RESULT(no)
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_SET_NORMALIZED_TIMESPEC_INLINE, 1,
-                         [set_normalized_timespec() is available as inline])
-       ])
-])
-
-dnl #
-dnl # 2.6.18 API change,
-dnl # timespec_sub() inline function available in linux/time.h
-dnl #
-AC_DEFUN([SPL_AC_TIMESPEC_SUB], [
-       AC_MSG_CHECKING([whether timespec_sub() is available])
-       SPL_LINUX_TRY_COMPILE([
-               #include <linux/time.h>
-       ],[
-               struct timespec a = { 0 };
-               struct timespec b = { 0 };
-               struct timespec c __attribute__ ((unused));
-               c = timespec_sub(a, b);
-       ],[
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_TIMESPEC_SUB, 1, [timespec_sub() is available])
-       ],[
-               AC_MSG_RESULT(no)
-       ])
-])
-
 dnl #
 dnl # 2.6.18 API change,
 dnl # added linux/uaccess.h
@@ -1079,26 +1015,6 @@ AC_DEFUN([SPL_AC_KMALLOC_NODE], [
        ])
 ])
 
-dnl #
-dnl # 2.6.9 API change,
-dnl # check whether 'monotonic_clock()' is available it may
-dnl # be available for some archs but not others.
-dnl #
-AC_DEFUN([SPL_AC_MONOTONIC_CLOCK],
-       [AC_MSG_CHECKING([whether monotonic_clock() is available])
-       SPL_LINUX_TRY_COMPILE_SYMBOL([
-               #include <linux/timex.h>
-       ], [
-               monotonic_clock();
-       ], [monotonic_clock], [], [
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1,
-                         [monotonic_clock() is available])
-       ], [
-               AC_MSG_RESULT(no)
-       ])
-])
-
 dnl #
 dnl # 2.6.16 API change,
 dnl # check whether 'struct inode' has i_mutex
index ec7023d150adae5e3da10ac19aaf7a7a6ccc2af0..c921cc5763530e1c303356b753597adb21d505bf 100644 (file)
@@ -15,7 +15,6 @@ KERNEL_H = \
        $(top_srcdir)/include/linux/rwsem_compat.h \
        $(top_srcdir)/include/linux/smp_compat.h \
        $(top_srcdir)/include/linux/sysctl_compat.h \
-       $(top_srcdir)/include/linux/time_compat.h \
        $(top_srcdir)/include/linux/uaccess_compat.h \
        $(top_srcdir)/include/linux/wait_compat.h \
        $(top_srcdir)/include/linux/zlib_compat.h
diff --git a/include/linux/time_compat.h b/include/linux/time_compat.h
deleted file mode 100644 (file)
index efa0232..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*****************************************************************************\
- *  Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
- *  Copyright (C) 2007 The Regents of the University of California.
- *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
- *  Written by Brian Behlendorf <behlendorf1@llnl.gov>.
- *  UCRL-CODE-235197
- *
- *  This file is part of the SPL, Solaris Porting Layer.
- *  For details, see <http://zfsonlinux.org/>.
- *
- *  The SPL is free software; you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License as published by the
- *  Free Software Foundation; either version 2 of the License, or (at your
- *  option) any later version.
- *
- *  The SPL is distributed in the hope that it will be useful, but WITHOUT
- *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- *  for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
-\*****************************************************************************/
-
-#ifndef _SPL_TIME_COMPAT_H
-#define _SPL_TIME_COMPAT_H
-
-#include <linux/time.h>
-
-/* timespec_sub() API changes
- * 2.6.18  - 2.6.x: Inline function provided by linux/time.h
- */
-#ifndef HAVE_TIMESPEC_SUB
-static inline struct timespec
-timespec_sub(struct timespec lhs, struct timespec rhs)
-{
-        struct timespec ts_delta;
-        set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec,
-                                lhs.tv_nsec - rhs.tv_nsec);
-        return ts_delta;
-}
-#endif /* HAVE_TIMESPEC_SUB */
-
-#endif /* _SPL_TIME_COMPAT_H */
-
index d8e81c9a76ab52f2ce3a13a4a8172346c0aadc0f..b9826d2b7aaff1049ba61ed1f37e41cd99703f06 100644 (file)
 \*****************************************************************************/
 
 #ifndef _SPL_TIME_H
-#define _SPL_TIME_H
+#define        _SPL_TIME_H
 
-/*
- * Structure returned by gettimeofday(2) system call,
- * and used in other calls.
- */
 #include <linux/module.h>
 #include <linux/time.h>
 #include <sys/types.h>
 #include <sys/timer.h>
 
 #if defined(CONFIG_64BIT)
-#define TIME_MAX                       INT64_MAX
-#define TIME_MIN                       INT64_MIN
+#define        TIME_MAX                        INT64_MAX
+#define        TIME_MIN                        INT64_MIN
 #else
-#define TIME_MAX                       INT32_MAX
-#define TIME_MIN                       INT32_MIN
+#define        TIME_MAX                        INT32_MAX
+#define        TIME_MIN                        INT32_MIN
 #endif
 
-#define SEC                            1
-#define MILLISEC                       1000
-#define MICROSEC                       1000000
-#define NANOSEC                                1000000000
+#define        SEC                             1
+#define        MILLISEC                        1000
+#define        MICROSEC                        1000000
+#define        NANOSEC                         1000000000
 
 #define        MSEC2NSEC(m)    ((hrtime_t)(m) * (NANOSEC / MILLISEC))
 #define        NSEC2MSEC(n)    ((n) / (NANOSEC / MILLISEC))
 
-/* Already defined in include/linux/time.h */
-#undef CLOCK_THREAD_CPUTIME_ID
-#undef CLOCK_REALTIME
-#undef CLOCK_MONOTONIC
-#undef CLOCK_PROCESS_CPUTIME_ID
+#define        hz                              HZ
 
-typedef enum clock_type {
-       __CLOCK_REALTIME0 =             0,      /* obsolete; same as CLOCK_REALTIME */
-       CLOCK_VIRTUAL =                 1,      /* thread's user-level CPU clock */
-       CLOCK_THREAD_CPUTIME_ID =       2,      /* thread's user+system CPU clock */
-       CLOCK_REALTIME =                3,      /* wall clock */
-       CLOCK_MONOTONIC =               4,      /* high resolution monotonic clock */
-       CLOCK_PROCESS_CPUTIME_ID =      5,      /* process's user+system CPU clock */
-       CLOCK_HIGHRES =                 CLOCK_MONOTONIC,        /* alternate name */
-       CLOCK_PROF =                    CLOCK_THREAD_CPUTIME_ID,/* alternate name */
-} clock_type_t;
-
-#define hz                                     \
-({                                             \
-        ASSERT(HZ >= 100 && HZ <= MICROSEC);   \
-        HZ;                                    \
-})
-
-extern void __gethrestime(timestruc_t *);
-extern int __clock_gettime(clock_type_t, timespec_t *);
-extern hrtime_t __gethrtime(void);
+#define        TIMESPEC_OVERFLOW(ts)           \
+       ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX)
 
-#define gethrestime(ts)                        __gethrestime(ts)
-#define clock_gettime(fl, tp)          __clock_gettime(fl, tp)
-#define gethrtime()                    __gethrtime()
+static inline void
+gethrestime(timestruc_t *now)
+{
+       struct timespec ts;
+       getnstimeofday(&ts);
+       now->tv_sec = ts.tv_sec;
+       now->tv_nsec = ts.tv_nsec;
+}
 
-static __inline__ time_t
+static inline time_t
 gethrestime_sec(void)
 {
-        timestruc_t now;
-
-        __gethrestime(&now);
-        return now.tv_sec;
+       struct timespec ts;
+       getnstimeofday(&ts);
+       return (ts.tv_sec);
 }
 
-#define TIMESPEC_OVERFLOW(ts)          \
-       ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX)
+static inline hrtime_t
+gethrtime(void)
+{
+       struct timespec now;
+       getrawmonotonic(&now);
+       return (((hrtime_t)now.tv_sec * NSEC_PER_SEC) + now.tv_nsec);
+}
 
 #endif  /* _SPL_TIME_H */
index fcec0fa31b980784e52cd27af523de1ddb66f295..11a32549495ef795378ee1b37953775d5120fde3 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/uaccess_compat.h>
 #include <linux/file_compat.h>
 #include <linux/list_compat.h>
-#include <linux/time_compat.h>
 #include <linux/bitops_compat.h>
 #include <linux/smp_compat.h>
 #include <linux/kallsyms_compat.h>
index 34b480127e21bd92d7cc2670c16644000cc1d862..30620349f899f745b6da29bdd7dbff4a09a290d9 100644 (file)
@@ -14,7 +14,6 @@ $(MODULE)-objs += @top_srcdir@/module/spl/spl-taskq.o
 $(MODULE)-objs += @top_srcdir@/module/spl/spl-rwlock.o
 $(MODULE)-objs += @top_srcdir@/module/spl/spl-vnode.o
 $(MODULE)-objs += @top_srcdir@/module/spl/spl-err.o
-$(MODULE)-objs += @top_srcdir@/module/spl/spl-time.o
 $(MODULE)-objs += @top_srcdir@/module/spl/spl-kobj.o
 $(MODULE)-objs += @top_srcdir@/module/spl/spl-generic.o
 $(MODULE)-objs += @top_srcdir@/module/spl/spl-atomic.o
diff --git a/module/spl/spl-time.c b/module/spl/spl-time.c
deleted file mode 100644 (file)
index 0ed49cc..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*****************************************************************************\
- *  Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
- *  Copyright (C) 2007 The Regents of the University of California.
- *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
- *  Written by Brian Behlendorf <behlendorf1@llnl.gov>.
- *  UCRL-CODE-235197
- *
- *  This file is part of the SPL, Solaris Porting Layer.
- *  For details, see <http://zfsonlinux.org/>.
- *
- *  The SPL is free software; you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License as published by the
- *  Free Software Foundation; either version 2 of the License, or (at your
- *  option) any later version.
- *
- *  The SPL is distributed in the hope that it will be useful, but WITHOUT
- *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- *  for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
- *****************************************************************************
- *  Solaris Porting Layer (SPL) Time Implementation.
-\*****************************************************************************/
-
-#include <sys/sysmacros.h>
-#include <sys/time.h>
-
-#ifdef HAVE_MONOTONIC_CLOCK
-extern unsigned long long monotonic_clock(void);
-#endif
-
-#ifdef DEBUG_SUBSYSTEM
-#undef DEBUG_SUBSYSTEM
-#endif
-
-#define DEBUG_SUBSYSTEM S_TIME
-
-void
-__gethrestime(timestruc_t *ts)
-{
-       struct timespec tspec;
-
-       getnstimeofday(&tspec);
-
-       ts->tv_sec = tspec.tv_sec;
-       ts->tv_nsec = tspec.tv_nsec;
-}
-EXPORT_SYMBOL(__gethrestime);
-
-/* Use monotonic_clock() by default. It's faster and is available on older
- * kernels, but few architectures have them, so we must fallback to
- * do_posix_clock_monotonic_gettime().
- */
-hrtime_t
-__gethrtime(void) {
-#ifdef HAVE_MONOTONIC_CLOCK
-        unsigned long long res = monotonic_clock();
-
-        /* Deal with signed/unsigned mismatch */
-        return (hrtime_t)(res & ~(1ULL << 63));
-#else
-        struct timespec ts;
-
-        do_posix_clock_monotonic_gettime(&ts);
-        return (((hrtime_t)ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec);
-#endif
-}
-EXPORT_SYMBOL(__gethrtime);
-
-/* set_normalized_timespec() API changes
- * 2.6.0  - 2.6.15: Inline function provided by linux/time.h
- * 2.6.16 - 2.6.25: Function prototype defined but not exported
- * 2.6.26 - 2.6.x:  Function defined and exported
- */
-#if !defined(HAVE_SET_NORMALIZED_TIMESPEC_INLINE) && \
-    !defined(HAVE_SET_NORMALIZED_TIMESPEC_EXPORT)
-void
-set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
-{
-       while (nsec >= NSEC_PER_SEC) {
-               nsec -= NSEC_PER_SEC;
-               ++sec;
-       }
-       while (nsec < 0) {
-               nsec += NSEC_PER_SEC;
-               --sec;
-       }
-       ts->tv_sec = sec;
-       ts->tv_nsec = nsec;
-}
-EXPORT_SYMBOL(set_normalized_timespec);
-#endif