1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
3
4
5 /*
6 * Copyright (c) 1982, 1986, 1993 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
11 /*
12 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
13 *
14 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
15 * Use is subject to license terms.
16 *
17 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
18 */
19
20 /*
21 * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
22 */
23
24 #ifndef _SYS_TIME_H
25 #define _SYS_TIME_H
26
27 #include <sys/feature_tests.h>
28
29 /*
30 * Structure returned by gettimeofday(2) system call,
31 * and used in other calls.
32 */
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
244 #define MICROSEC 1000000
245 #define NANOSEC 1000000000LL
246
247 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
248 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
249
250 #define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
251 #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
252
253 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
254
255 #ifndef _ASM
256
257 /*
258 * Time expressed as a 64-bit nanosecond counter.
259 */
260 typedef longlong_t hrtime_t;
261
262 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
263
264 #include <sys/time_impl.h>
265 #include <sys/mutex.h>
266
267 extern int tick_per_msec; /* clock ticks per millisecond (may be zero) */
268 extern int msec_per_tick; /* milliseconds per clock tick (may be zero) */
269 extern int usec_per_tick; /* microseconds per clock tick */
270 extern int nsec_per_tick; /* nanoseconds per clock tick */
271
272 /*
273 * Macros to convert from common units of time (sec, msec, usec, nsec,
274 * timeval, timestruc) to clock ticks and vice versa.
275 */
276 #define TICK_TO_SEC(tick) ((tick) / hz)
277 #define SEC_TO_TICK(sec) ((sec) * hz)
278
279 #define TICK_TO_MSEC(tick) \
280 (msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
281 #define MSEC_TO_TICK(msec) \
282 (msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
283 #define MSEC_TO_TICK_ROUNDUP(msec) \
|
1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
3
4
5 /*
6 * Copyright (c) 1982, 1986, 1993 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
11 /*
12 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
13 *
14 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
15 * Use is subject to license terms.
16 *
17 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
18 * Copyright 2016 Joyent, Inc.
19 */
20
21 /*
22 * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
23 */
24
25 #ifndef _SYS_TIME_H
26 #define _SYS_TIME_H
27
28 #include <sys/feature_tests.h>
29
30 /*
31 * Structure returned by gettimeofday(2) system call,
32 * and used in other calls.
33 */
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
245 #define MICROSEC 1000000
246 #define NANOSEC 1000000000LL
247
248 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
249 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
250
251 #define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
252 #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
253
254 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
255
256 #ifndef _ASM
257
258 /*
259 * Time expressed as a 64-bit nanosecond counter.
260 */
261 typedef longlong_t hrtime_t;
262
263 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
264
265 /*
266 * Unsigned counterpart to hrtime_t
267 */
268 typedef u_longlong_t uhrtime_t;
269
270 #define HRTIME_MAX LLONG_MAX
271 #define UHRTIME_MAX ULLONG_MAX
272
273 #include <sys/time_impl.h>
274 #include <sys/mutex.h>
275
276 extern int tick_per_msec; /* clock ticks per millisecond (may be zero) */
277 extern int msec_per_tick; /* milliseconds per clock tick (may be zero) */
278 extern int usec_per_tick; /* microseconds per clock tick */
279 extern int nsec_per_tick; /* nanoseconds per clock tick */
280
281 /*
282 * Macros to convert from common units of time (sec, msec, usec, nsec,
283 * timeval, timestruc) to clock ticks and vice versa.
284 */
285 #define TICK_TO_SEC(tick) ((tick) / hz)
286 #define SEC_TO_TICK(sec) ((sec) * hz)
287
288 #define TICK_TO_MSEC(tick) \
289 (msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
290 #define MSEC_TO_TICK(msec) \
291 (msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
292 #define MSEC_TO_TICK_ROUNDUP(msec) \
|