2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)time.h 8.5 (Berkeley) 5/4/95
30 * $FreeBSD: src/sys/sys/time.h,v 1.42 1999/12/29 04:24:48 peter Exp $
37 #include <sys/types.h>
38 #include <machine/clock.h>
40 #include <machine/stdint.h>
43 #include <sys/_timespec.h>
44 #include <sys/_timeval.h>
45 #include <sys/select.h>
47 #define TIMEVAL_TO_TIMESPEC(tv, ts) \
49 (ts)->tv_sec = (tv)->tv_sec; \
50 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
52 #define TIMESPEC_TO_TIMEVAL(tv, ts) \
54 (tv)->tv_sec = (ts)->tv_sec; \
55 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
59 int tz_minuteswest
; /* minutes west of Greenwich */
60 int tz_dsttime
; /* type of dst correction */
62 #define DST_NONE 0 /* not on dst */
63 #define DST_USA 1 /* USA style dst */
64 #define DST_AUST 2 /* Australian style dst */
65 #define DST_WET 3 /* Western European dst */
66 #define DST_MET 4 /* Middle European dst */
67 #define DST_EET 5 /* Eastern European dst */
68 #define DST_CAN 6 /* Canada */
72 /* Operations on timespecs */
73 #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
74 #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec)
75 #define timespeccmp(tvp, uvp, cmp) \
76 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
77 ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
78 ((tvp)->tv_sec cmp (uvp)->tv_sec))
79 #define timespecadd(vvp, uvp) \
81 (vvp)->tv_sec += (uvp)->tv_sec; \
82 (vvp)->tv_nsec += (uvp)->tv_nsec; \
83 if ((vvp)->tv_nsec >= 1000000000) { \
85 (vvp)->tv_nsec -= 1000000000; \
88 #define timespecsub(vvp, uvp) \
90 (vvp)->tv_sec -= (uvp)->tv_sec; \
91 (vvp)->tv_nsec -= (uvp)->tv_nsec; \
92 if ((vvp)->tv_nsec < 0) { \
94 (vvp)->tv_nsec += 1000000000; \
98 /* Operations on timevals. */
100 #define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
101 #define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
102 #define timevalcmp(tvp, uvp, cmp) \
103 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
104 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
105 ((tvp)->tv_sec cmp (uvp)->tv_sec))
107 /* timevaladd and timevalsub are not inlined */
111 #ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */
113 #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
114 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
115 #define timercmp(tvp, uvp, cmp) \
116 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
117 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
118 ((tvp)->tv_sec cmp (uvp)->tv_sec))
119 #define timeradd(tvp, uvp, vvp) \
121 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
122 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
123 if ((vvp)->tv_usec >= 1000000) { \
125 (vvp)->tv_usec -= 1000000; \
128 #define timersub(tvp, uvp, vvp) \
130 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
131 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
132 if ((vvp)->tv_usec < 0) { \
134 (vvp)->tv_usec += 1000000; \
140 * Names of the interval timers, and structure
141 * defining a timer setting.
143 #define ITIMER_REAL 0
144 #define ITIMER_VIRTUAL 1
145 #define ITIMER_PROF 2
148 struct timeval it_interval
; /* timer interval */
149 struct timeval it_value
; /* current value */
153 * Getkerninfo clock information structure
156 int hz
; /* clock frequency */
157 int tick
; /* micro-seconds per hz tick */
158 int tickadj
; /* clock skew rate for adjtime() */
159 int stathz
; /* statistics clock frequency */
160 int profhz
; /* profiling clock frequency */
163 /* CLOCK_REALTIME and TIMER_ABSTIME are supposed to be in time.h */
165 #ifndef CLOCK_REALTIME
166 #define CLOCK_REALTIME 0
168 #define CLOCK_VIRTUAL 1
170 #define CLOCK_MONOTONIC 4
172 #define CLOCK_UPTIME 5 /* from freebsd */
173 #define CLOCK_UPTIME_PRECISE 7 /* from freebsd */
174 #define CLOCK_UPTIME_FAST 8 /* from freebsd */
175 #define CLOCK_REALTIME_PRECISE 9 /* from freebsd */
176 #define CLOCK_REALTIME_FAST 10 /* from freebsd */
177 #define CLOCK_MONOTONIC_PRECISE 11 /* from freebsd */
178 #define CLOCK_MONOTONIC_FAST 12 /* from freebsd */
179 #define CLOCK_SECOND 13 /* from freebsd */
180 #define CLOCK_THREAD_CPUTIME_ID 14
181 #define CLOCK_PROCESS_CPUTIME_ID 15
183 #define TIMER_RELTIME 0x0 /* relative timer */
184 #ifndef TIMER_ABSTIME
185 #define TIMER_ABSTIME 0x1 /* absolute timer */
190 extern time_t time_second
; /* simple time_t (can step) */
191 extern time_t time_uptime
; /* monotonic simple uptime / seconds */
192 extern int64_t ntp_tick_permanent
;
193 extern int64_t ntp_tick_acc
;
194 extern int64_t ntp_delta
;
195 extern int64_t ntp_big_delta
;
196 extern int32_t ntp_tick_delta
;
197 extern int32_t ntp_default_tick_delta
;
198 extern time_t ntp_leap_second
;
199 extern int ntp_leap_insert
;
201 void initclocks_pcpu(void);
202 void getmicrouptime(struct timeval
*tv
);
203 void getmicrotime(struct timeval
*tv
);
204 void getnanouptime(struct timespec
*tv
);
205 void getnanotime(struct timespec
*tv
);
206 int itimerdecr(struct itimerval
*itp
, int usec
);
207 int itimerfix(struct timeval
*tv
);
208 int itimespecfix(struct timespec
*ts
);
209 int ppsratecheck(struct timeval
*, int *, int usec
);
210 int ratecheck(struct timeval
*, const struct timeval
*);
211 void microuptime(struct timeval
*tv
);
212 void microtime(struct timeval
*tv
);
213 void nanouptime(struct timespec
*ts
);
214 void nanotime(struct timespec
*ts
);
215 time_t get_approximate_time_t(void);
216 void set_timeofday(struct timespec
*ts
);
217 void kern_adjtime(int64_t, int64_t *);
218 void kern_reladjtime(int64_t);
219 void timevaladd(struct timeval
*, const struct timeval
*);
220 void timevalsub(struct timeval
*, const struct timeval
*);
221 int tvtohz_high(struct timeval
*);
222 int tvtohz_low(struct timeval
*);
223 int tstohz_high(struct timespec
*);
224 int tstohz_low(struct timespec
*);
225 int tsc_test_target(int64_t target
);
226 void tsc_delay(int ns
);
227 int nanosleep1(struct timespec
*rqt
, struct timespec
*rmt
);
229 tsc_uclock_t
tsc_get_target(int ns
);
234 #include <sys/cdefs.h>
236 #endif /* !_KERNEL */
241 int adjtime(const struct timeval
*, struct timeval
*);
242 int futimes(int, const struct timeval
*);
243 int lutimes(const char *, const struct timeval
*);
244 int settimeofday(const struct timeval
*, const struct timezone
*);
248 int getitimer(int, struct itimerval
*);
249 int gettimeofday(struct timeval
* __restrict
, struct timezone
* __restrict
);
250 int setitimer(int, const struct itimerval
* __restrict
,
251 struct itimerval
* __restrict
);
252 int utimes(const char *, const struct timeval
*);
257 #endif /* !_SYS_TIME_H_ */