\*****************************************************************************/
#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
-/* Already defined in include/linux/time.h */
-#undef CLOCK_THREAD_CPUTIME_ID
-#undef CLOCK_REALTIME
-#undef CLOCK_MONOTONIC
-#undef CLOCK_PROCESS_CPUTIME_ID
+#define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
+#define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
-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 USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
+#define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
-#define hz \
-({ \
- ASSERT(HZ >= 100 && HZ <= MICROSEC); \
- HZ; \
-})
+#define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
+#define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
-extern void __gethrestime(timestruc_t *);
-extern int __clock_gettime(clock_type_t, timespec_t *);
-extern hrtime_t __gethrtime(void);
+typedef longlong_t hrtime_t;
+typedef struct timespec timespec_t;
-#define gethrestime(ts) __gethrestime(ts)
-#define clock_gettime(fl, tp) __clock_gettime(fl, tp)
-#define gethrtime() __gethrtime()
+static const int hz = HZ;
-static __inline__ time_t
+#define TIMESPEC_OVERFLOW(ts) \
+ ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX)
+
+#if defined(HAVE_INODE_TIMESPEC64_TIMES)
+typedef struct timespec64 inode_timespec_t;
+#else
+typedef struct timespec inode_timespec_t;
+#endif
+
+static inline void
+gethrestime(inode_timespec_t *ts)
+ {
+#if defined(HAVE_INODE_TIMESPEC64_TIMES)
+ *ts = current_kernel_time64();
+#else
+ *ts = current_kernel_time();
+#endif
+}
+
+static inline time_t
gethrestime_sec(void)
{
- timestruc_t now;
-
- __gethrestime(&now);
- return now.tv_sec;
+ struct timespec ts;
+ ts = current_kernel_time();
+ 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 ts;
+ getrawmonotonic(&ts);
+ return (((hrtime_t)ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec);
+}
#endif /* _SPL_TIME_H */