1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or https://opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _LIBSPL_SYS_TIME_H
28 #define _LIBSPL_SYS_TIME_H
29
30 #include <time.h>
31 #include <sys/types.h>
32 #include_next <sys/time.h>
33
34 #ifndef SEC
35 #define SEC 1
36 #endif
37
38 #ifndef MILLISEC
39 #define MILLISEC 1000
40 #endif
41
42 #ifndef MICROSEC
43 #define MICROSEC 1000000
44 #endif
45
46 #ifndef NANOSEC
47 #define NANOSEC 1000000000
48 #endif
49
50 #ifndef NSEC_PER_USEC
51 #define NSEC_PER_USEC 1000L
52 #endif
53
54 #ifndef MSEC2NSEC
55 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
56 #endif
57
58 #ifndef NSEC2MSEC
59 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
60 #endif
61
62 #ifndef USEC2NSEC
63 #define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
64 #endif
65
66 #ifndef NSEC2USEC
67 #define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
68 #endif
69
70 #ifndef NSEC2SEC
71 #define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
72 #endif
73
74 #ifndef SEC2NSEC
75 #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
76 #endif
77
78 typedef long long hrtime_t;
79 typedef struct timespec timespec_t;
80 typedef struct timespec inode_timespec_t;
81
82 static inline void
83 gethrestime(inode_timespec_t *ts)
84 {
85 struct timeval tv;
86 (void) gettimeofday(&tv, NULL);
87 ts->tv_sec = tv.tv_sec;
88 ts->tv_nsec = tv.tv_usec * NSEC_PER_USEC;
89 }
90
91 static inline uint64_t
92 gethrestime_sec(void)
93 {
94 struct timeval tv;
95 (void) gettimeofday(&tv, NULL);
96 return (tv.tv_sec);
97 }
98
99 static inline hrtime_t
100 gethrtime(void)
101 {
102 struct timespec ts;
103 (void) clock_gettime(CLOCK_MONOTONIC, &ts);
104 return ((((u_int64_t)ts.tv_sec) * NANOSEC) + ts.tv_nsec);
105 }
106
107 #endif /* _LIBSPL_SYS_TIME_H */
Cache object: 71744a17e717c0d16d022da0b29371da
|