config/dracut/90zfs: handle cases where hostid(1) returns all zeros
[zfs.git] / include / os / linux / spl / sys / time.h
blobfec85f8b8d13dea6051e1fd4927f1e2eb9882c49
1 /*
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>.
6 * UCRL-CODE-235197
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
18 * for more details.
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/>.
24 #ifndef _SPL_TIME_H
25 #define _SPL_TIME_H
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
35 #else
36 #define TIME_MAX INT32_MAX
37 #define TIME_MIN INT32_MIN
38 #endif
40 #define SEC 1
41 #define MILLISEC 1000
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;
64 #else
65 typedef struct timespec inode_timespec_t;
66 #endif
68 /* Include for Lustre compatibility */
69 #define timestruc_t inode_timespec_t
71 static inline void
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);
78 #else
79 *ts = current_kernel_time64();
80 #endif /* HAVE_KTIME_GET_COARSE_REAL_TS64 */
82 #else
83 *ts = current_kernel_time();
84 #endif
87 static inline uint64_t
88 gethrestime_sec(void)
90 #if defined(HAVE_INODE_TIMESPEC64_TIMES)
91 #if defined(HAVE_KTIME_GET_COARSE_REAL_TS64)
92 inode_timespec_t ts;
93 ktime_get_coarse_real_ts64(&ts);
94 #else
95 inode_timespec_t ts = current_kernel_time64();
96 #endif /* HAVE_KTIME_GET_COARSE_REAL_TS64 */
98 #else
99 inode_timespec_t ts = current_kernel_time();
100 #endif
101 return (ts.tv_sec);
104 static inline hrtime_t
105 gethrtime(void)
107 #if defined(HAVE_KTIME_GET_RAW_TS64)
108 struct timespec64 ts;
109 ktime_get_raw_ts64(&ts);
110 #else
111 struct timespec ts;
112 getrawmonotonic(&ts);
113 #endif
114 return (((hrtime_t)ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec);
117 #endif /* _SPL_TIME_H */