2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
8 * This file is part of the SPL, Solaris Porting Layer.
10 * The SPL is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * The SPL is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * You should have received a copy of the GNU General Public License along
21 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
27 #include <linux/module.h>
28 #include <linux/time.h>
29 #include <sys/types.h>
30 #include <sys/timer.h>
32 #if defined(CONFIG_64BIT)
33 #define TIME_MAX INT64_MAX
34 #define TIME_MIN INT64_MIN
36 #define TIME_MAX INT32_MAX
37 #define TIME_MIN INT32_MIN
42 #define MICROSEC 1000000
43 #define NANOSEC 1000000000
45 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
46 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
48 #define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
49 #define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
51 #define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
52 #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
54 static const int hz
= HZ
;
56 typedef longlong_t hrtime_t
;
57 typedef struct timespec timespec_t
;
59 #define TIMESPEC_OVERFLOW(ts) \
60 ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX)
62 #if defined(HAVE_INODE_TIMESPEC64_TIMES)
63 typedef struct timespec64 inode_timespec_t
;
65 typedef struct timespec inode_timespec_t
;
68 /* Include for Lustre compatibility */
69 #define timestruc_t inode_timespec_t
72 gethrestime(inode_timespec_t
*ts
)
74 #if defined(HAVE_INODE_TIMESPEC64_TIMES)
76 #if defined(HAVE_KTIME_GET_COARSE_REAL_TS64)
77 ktime_get_coarse_real_ts64(ts
);
79 *ts
= current_kernel_time64();
80 #endif /* HAVE_KTIME_GET_COARSE_REAL_TS64 */
83 *ts
= current_kernel_time();
87 static inline uint64_t
90 #if defined(HAVE_INODE_TIMESPEC64_TIMES)
91 #if defined(HAVE_KTIME_GET_COARSE_REAL_TS64)
93 ktime_get_coarse_real_ts64(&ts
);
95 inode_timespec_t ts
= current_kernel_time64();
96 #endif /* HAVE_KTIME_GET_COARSE_REAL_TS64 */
99 inode_timespec_t ts
= current_kernel_time();
104 static inline hrtime_t
107 #if defined(HAVE_KTIME_GET_RAW_TS64)
108 struct timespec64 ts
;
109 ktime_get_raw_ts64(&ts
);
112 getrawmonotonic(&ts
);
114 return (((hrtime_t
)ts
.tv_sec
* NSEC_PER_SEC
) + ts
.tv_nsec
);
117 #endif /* _SPL_TIME_H */