ARC: Cache arc_c value during arc_evict()
[zfs.git] / lib / libspl / include / sys / time.h
blob0f7d5196b31ce6114706c019fd1c3f39914649b2
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LIBSPL_SYS_TIME_H
28 #define _LIBSPL_SYS_TIME_H
30 #include <time.h>
31 #include <sys/types.h>
32 #include_next <sys/time.h>
34 #ifndef SEC
35 #define SEC 1
36 #endif
38 #ifndef MILLISEC
39 #define MILLISEC 1000
40 #endif
42 #ifndef MICROSEC
43 #define MICROSEC 1000000
44 #endif
46 #ifndef NANOSEC
47 #define NANOSEC 1000000000
48 #endif
50 #ifndef NSEC_PER_USEC
51 #define NSEC_PER_USEC 1000L
52 #endif
54 #ifndef MSEC2NSEC
55 #define MSEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MILLISEC))
56 #endif
58 #ifndef NSEC2MSEC
59 #define NSEC2MSEC(n) ((n) / (NANOSEC / MILLISEC))
60 #endif
62 #ifndef USEC2NSEC
63 #define USEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / MICROSEC))
64 #endif
66 #ifndef NSEC2USEC
67 #define NSEC2USEC(n) ((n) / (NANOSEC / MICROSEC))
68 #endif
70 #ifndef NSEC2SEC
71 #define NSEC2SEC(n) ((n) / (NANOSEC / SEC))
72 #endif
74 #ifndef SEC2NSEC
75 #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC))
76 #endif
78 typedef long long hrtime_t;
79 typedef struct timespec timespec_t;
80 typedef struct timespec inode_timespec_t;
82 static inline void
83 gethrestime(inode_timespec_t *ts)
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;
91 static inline uint64_t
92 gethrestime_sec(void)
94 struct timeval tv;
95 (void) gettimeofday(&tv, NULL);
96 return (tv.tv_sec);
99 static inline hrtime_t
100 gethrtime(void)
102 struct timespec ts;
103 (void) clock_gettime(CLOCK_MONOTONIC, &ts);
104 return ((((uint64_t)ts.tv_sec) * NANOSEC) + ts.tv_nsec);
107 #endif /* _LIBSPL_SYS_TIME_H */