| Commit | Line | Data |
|---|---|---|
| 984263bc MD |
1 | /* |
| 2 | * Copyright (c) 1982, 1986, 1993 | |
| 3 | * The Regents of the University of California. All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions | |
| 7 | * are met: | |
| 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. All advertising materials mentioning features or use of this software | |
| 14 | * must display the following acknowledgement: | |
| 15 | * This product includes software developed by the University of | |
| 16 | * California, Berkeley and its contributors. | |
| 17 | * 4. Neither the name of the University nor the names of its contributors | |
| 18 | * may be used to endorse or promote products derived from this software | |
| 19 | * without specific prior written permission. | |
| 20 | * | |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
| 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 31 | * SUCH DAMAGE. | |
| 32 | * | |
| 33 | * @(#)time.h 8.5 (Berkeley) 5/4/95 | |
| 34 | * $FreeBSD: src/sys/sys/time.h,v 1.42 1999/12/29 04:24:48 peter Exp $ | |
| 04a0f5ef | 35 | * $DragonFly: src/sys/sys/time.h,v 1.20 2008/06/18 09:36:07 hasso Exp $ |
| 984263bc MD |
36 | */ |
| 37 | ||
| 38 | #ifndef _SYS_TIME_H_ | |
| 39 | #define _SYS_TIME_H_ | |
| 40 | ||
| e2565a42 | 41 | #ifndef _SYS_TYPES_H_ |
| 984263bc | 42 | #include <sys/types.h> |
| e2565a42 | 43 | #endif |
| 984263bc | 44 | |
| 1d3685c4 | 45 | #include <sys/_timespec.h> |
| 04a0f5ef | 46 | #include <sys/_timeval.h> |
| 42b6a120 SS |
47 | #include <sys/select.h> |
| 48 | ||
| 984263bc MD |
49 | #define TIMEVAL_TO_TIMESPEC(tv, ts) \ |
| 50 | do { \ | |
| 51 | (ts)->tv_sec = (tv)->tv_sec; \ | |
| 52 | (ts)->tv_nsec = (tv)->tv_usec * 1000; \ | |
| 53 | } while (0) | |
| 54 | #define TIMESPEC_TO_TIMEVAL(tv, ts) \ | |
| 55 | do { \ | |
| 56 | (tv)->tv_sec = (ts)->tv_sec; \ | |
| 57 | (tv)->tv_usec = (ts)->tv_nsec / 1000; \ | |
| 58 | } while (0) | |
| 59 | ||
| 60 | struct timezone { | |
| 61 | int tz_minuteswest; /* minutes west of Greenwich */ | |
| 62 | int tz_dsttime; /* type of dst correction */ | |
| 63 | }; | |
| 64 | #define DST_NONE 0 /* not on dst */ | |
| 65 | #define DST_USA 1 /* USA style dst */ | |
| 66 | #define DST_AUST 2 /* Australian style dst */ | |
| 67 | #define DST_WET 3 /* Western European dst */ | |
| 68 | #define DST_MET 4 /* Middle European dst */ | |
| 69 | #define DST_EET 5 /* Eastern European dst */ | |
| 70 | #define DST_CAN 6 /* Canada */ | |
| 71 | ||
| 984263bc MD |
72 | #ifdef _KERNEL |
| 73 | ||
| 74 | /* Operations on timespecs */ | |
| 75 | #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) | |
| 76 | #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) | |
| 77 | #define timespeccmp(tvp, uvp, cmp) \ | |
| 78 | (((tvp)->tv_sec == (uvp)->tv_sec) ? \ | |
| 79 | ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ | |
| 80 | ((tvp)->tv_sec cmp (uvp)->tv_sec)) | |
| 81 | #define timespecadd(vvp, uvp) \ | |
| 82 | do { \ | |
| 83 | (vvp)->tv_sec += (uvp)->tv_sec; \ | |
| 84 | (vvp)->tv_nsec += (uvp)->tv_nsec; \ | |
| 85 | if ((vvp)->tv_nsec >= 1000000000) { \ | |
| 86 | (vvp)->tv_sec++; \ | |
| 87 | (vvp)->tv_nsec -= 1000000000; \ | |
| 88 | } \ | |
| 89 | } while (0) | |
| 90 | #define timespecsub(vvp, uvp) \ | |
| 91 | do { \ | |
| 92 | (vvp)->tv_sec -= (uvp)->tv_sec; \ | |
| 93 | (vvp)->tv_nsec -= (uvp)->tv_nsec; \ | |
| 94 | if ((vvp)->tv_nsec < 0) { \ | |
| 95 | (vvp)->tv_sec--; \ | |
| 96 | (vvp)->tv_nsec += 1000000000; \ | |
| 97 | } \ | |
| 98 | } while (0) | |
| 99 | ||
| 100 | /* Operations on timevals. */ | |
| 101 | ||
| 102 | #define timevalclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 | |
| 103 | #define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) | |
| 104 | #define timevalcmp(tvp, uvp, cmp) \ | |
| 105 | (((tvp)->tv_sec == (uvp)->tv_sec) ? \ | |
| 106 | ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ | |
| 107 | ((tvp)->tv_sec cmp (uvp)->tv_sec)) | |
| 108 | ||
| 109 | /* timevaladd and timevalsub are not inlined */ | |
| 110 | ||
| 111 | #endif /* _KERNEL */ | |
| 112 | ||
| 9a7c6212 | 113 | #ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */ |
| 984263bc MD |
114 | |
| 115 | #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 | |
| 116 | #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) | |
| 117 | #define timercmp(tvp, uvp, cmp) \ | |
| 118 | (((tvp)->tv_sec == (uvp)->tv_sec) ? \ | |
| 119 | ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ | |
| 120 | ((tvp)->tv_sec cmp (uvp)->tv_sec)) | |
| 121 | #define timeradd(tvp, uvp, vvp) \ | |
| 122 | do { \ | |
| 123 | (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ | |
| 124 | (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ | |
| 125 | if ((vvp)->tv_usec >= 1000000) { \ | |
| 126 | (vvp)->tv_sec++; \ | |
| 127 | (vvp)->tv_usec -= 1000000; \ | |
| 128 | } \ | |
| 129 | } while (0) | |
| 130 | #define timersub(tvp, uvp, vvp) \ | |
| 131 | do { \ | |
| 132 | (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ | |
| 133 | (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ | |
| 134 | if ((vvp)->tv_usec < 0) { \ | |
| 135 | (vvp)->tv_sec--; \ | |
| 136 | (vvp)->tv_usec += 1000000; \ | |
| 137 | } \ | |
| 138 | } while (0) | |
| 139 | #endif | |
| 140 | ||
| 141 | /* | |
| 142 | * Names of the interval timers, and structure | |
| 143 | * defining a timer setting. | |
| 144 | */ | |
| 145 | #define ITIMER_REAL 0 | |
| 146 | #define ITIMER_VIRTUAL 1 | |
| 147 | #define ITIMER_PROF 2 | |
| 148 | ||
| 149 | struct itimerval { | |
| 150 | struct timeval it_interval; /* timer interval */ | |
| 151 | struct timeval it_value; /* current value */ | |
| 152 | }; | |
| 153 | ||
| 154 | /* | |
| 155 | * Getkerninfo clock information structure | |
| f5d21610 JS |
156 | * |
| 157 | * XXX Should be removed, use kinfo_clockinfo insteada. | |
| 984263bc MD |
158 | */ |
| 159 | struct clockinfo { | |
| 160 | int hz; /* clock frequency */ | |
| 161 | int tick; /* micro-seconds per hz tick */ | |
| 162 | int tickadj; /* clock skew rate for adjtime() */ | |
| 163 | int stathz; /* statistics clock frequency */ | |
| 164 | int profhz; /* profiling clock frequency */ | |
| 165 | }; | |
| 166 | ||
| 167 | /* CLOCK_REALTIME and TIMER_ABSTIME are supposed to be in time.h */ | |
| 168 | ||
| 169 | #ifndef CLOCK_REALTIME | |
| 91810a6f | 170 | #define CLOCK_REALTIME 0 |
| 984263bc | 171 | #endif |
| 91810a6f MD |
172 | #define CLOCK_VIRTUAL 1 |
| 173 | #define CLOCK_PROF 2 | |
| 174 | #define CLOCK_MONOTONIC 4 | |
| 175 | ||
| 176 | #define CLOCK_UPTIME 5 /* from freebsd */ | |
| 177 | #define CLOCK_UPTIME_PRECISE 7 /* from freebsd */ | |
| 178 | #define CLOCK_UPTIME_FAST 8 /* from freebsd */ | |
| 179 | #define CLOCK_REALTIME_PRECISE 9 /* from freebsd */ | |
| 180 | #define CLOCK_REALTIME_FAST 10 /* from freebsd */ | |
| 181 | #define CLOCK_MONOTONIC_PRECISE 11 /* from freebsd */ | |
| 182 | #define CLOCK_MONOTONIC_FAST 12 /* from freebsd */ | |
| 183 | #define CLOCK_SECOND 13 /* from freebsd */ | |
| 984263bc MD |
184 | |
| 185 | #define TIMER_RELTIME 0x0 /* relative timer */ | |
| 186 | #ifndef TIMER_ABSTIME | |
| 187 | #define TIMER_ABSTIME 0x1 /* absolute timer */ | |
| 188 | #endif | |
| 189 | ||
| c8dfd00d | 190 | #ifdef _KERNEL |
| abae1c58 | 191 | |
| 984263bc | 192 | extern time_t time_second; |
| 4026c000 JS |
193 | extern int64_t ntp_tick_permanent; |
| 194 | extern int64_t ntp_tick_acc; | |
| 195 | extern int64_t ntp_delta; | |
| 196 | extern int64_t ntp_big_delta; | |
| 197 | extern int32_t ntp_tick_delta; | |
| 198 | extern int32_t ntp_default_tick_delta; | |
| a1aefcd0 EN |
199 | extern time_t ntp_leap_second; |
| 200 | extern int ntp_leap_insert; | |
| 984263bc | 201 | |
| 88c4d2f6 | 202 | void initclocks_pcpu(void); |
| b153f746 RG |
203 | void getmicrouptime (struct timeval *tv); |
| 204 | void getmicrotime (struct timeval *tv); | |
| 205 | void getnanouptime (struct timespec *tv); | |
| 206 | void getnanotime (struct timespec *tv); | |
| b153f746 RG |
207 | int itimerdecr (struct itimerval *itp, int usec); |
| 208 | int itimerfix (struct timeval *tv); | |
| 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); | |
| 25b804e7 | 215 | time_t get_approximate_time_t(void); |
| 88c4d2f6 | 216 | void set_timeofday(struct timespec *ts); |
| 4026c000 JS |
217 | void kern_adjtime(int64_t, int64_t *); |
| 218 | void kern_reladjtime(int64_t); | |
| 9deadd02 SZ |
219 | void timevaladd (struct timeval *, const struct timeval *); |
| 220 | void timevalsub (struct timeval *, const struct timeval *); | |
| a94976ad MD |
221 | int tvtohz_high (struct timeval *); |
| 222 | int tvtohz_low (struct timeval *); | |
| a591f597 MD |
223 | int tstohz_high (struct timespec *); |
| 224 | int tstohz_low (struct timespec *); | |
| d2412a2e MD |
225 | int64_t tsc_get_target(int ns); |
| 226 | int tsc_test_target(int64_t target); | |
| b12defdc | 227 | void tsc_delay(int ns); |
| 3b58baa0 | 228 | int nanosleep1(struct timespec *rqt, struct timespec *rmt); |
| 38d65057 | 229 | |
| 984263bc | 230 | #else /* !_KERNEL */ |
| 984263bc | 231 | |
| 38d65057 | 232 | #include <time.h> |
| 984263bc MD |
233 | #include <sys/cdefs.h> |
| 234 | ||
| 38d65057 MD |
235 | #endif /* !_KERNEL */ |
| 236 | ||
| 984263bc | 237 | __BEGIN_DECLS |
| b153f746 RG |
238 | int adjtime (const struct timeval *, struct timeval *); |
| 239 | int futimes (int, const struct timeval *); | |
| 240 | int getitimer (int, struct itimerval *); | |
| 241 | int gettimeofday (struct timeval *, struct timezone *); | |
| 242 | int lutimes (const char *, const struct timeval *); | |
| 243 | int setitimer (int, const struct itimerval *, struct itimerval *); | |
| 244 | int settimeofday (const struct timeval *, const struct timezone *); | |
| 245 | int utimes (const char *, const struct timeval *); | |
| 984263bc MD |
246 | __END_DECLS |
| 247 | ||
| 984263bc MD |
248 | |
| 249 | #endif /* !_SYS_TIME_H_ */ |