1*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 3*7c478bd9Sstevel@tonic-gate 4*7c478bd9Sstevel@tonic-gate 5*7c478bd9Sstevel@tonic-gate /* 6*7c478bd9Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 7*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*7c478bd9Sstevel@tonic-gate */ 10*7c478bd9Sstevel@tonic-gate 11*7c478bd9Sstevel@tonic-gate /* 12*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 13*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 14*7c478bd9Sstevel@tonic-gate */ 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #ifndef _SYS_TIME_H 17*7c478bd9Sstevel@tonic-gate #define _SYS_TIME_H 18*7c478bd9Sstevel@tonic-gate 19*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.16 */ 20*7c478bd9Sstevel@tonic-gate 21*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate /* 24*7c478bd9Sstevel@tonic-gate * Structure returned by gettimeofday(2) system call, 25*7c478bd9Sstevel@tonic-gate * and used in other calls. 26*7c478bd9Sstevel@tonic-gate */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 29*7c478bd9Sstevel@tonic-gate extern "C" { 30*7c478bd9Sstevel@tonic-gate #endif 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 33*7c478bd9Sstevel@tonic-gate defined(__EXTENSIONS__) 34*7c478bd9Sstevel@tonic-gate #ifndef _ASM 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #if !defined(_TIME_T) || __cplusplus >= 199711L 37*7c478bd9Sstevel@tonic-gate #define _TIME_T 38*7c478bd9Sstevel@tonic-gate typedef long time_t; /* time of day in seconds */ 39*7c478bd9Sstevel@tonic-gate #endif /* _TIME_T */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #ifndef _SUSECONDS_T 42*7c478bd9Sstevel@tonic-gate #define _SUSECONDS_T 43*7c478bd9Sstevel@tonic-gate typedef long suseconds_t; /* signed # of microseconds */ 44*7c478bd9Sstevel@tonic-gate #endif /* _SUSECONDS_T */ 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate struct timeval { 47*7c478bd9Sstevel@tonic-gate time_t tv_sec; /* seconds */ 48*7c478bd9Sstevel@tonic-gate suseconds_t tv_usec; /* and microseconds */ 49*7c478bd9Sstevel@tonic-gate }; 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate #include <sys/types32.h> 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #define TIMEVAL32_TO_TIMEVAL(tv, tv32) { \ 56*7c478bd9Sstevel@tonic-gate (tv)->tv_sec = (time_t)(tv32)->tv_sec; \ 57*7c478bd9Sstevel@tonic-gate (tv)->tv_usec = (tv32)->tv_usec; \ 58*7c478bd9Sstevel@tonic-gate } 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate #define TIMEVAL_TO_TIMEVAL32(tv32, tv) { \ 61*7c478bd9Sstevel@tonic-gate (tv32)->tv_sec = (time32_t)(tv)->tv_sec; \ 62*7c478bd9Sstevel@tonic-gate (tv32)->tv_usec = (tv)->tv_usec; \ 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate #define TIME32_MAX INT32_MAX 66*7c478bd9Sstevel@tonic-gate #define TIME32_MIN INT32_MIN 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate #define TIMEVAL_OVERFLOW(tv) \ 69*7c478bd9Sstevel@tonic-gate ((tv)->tv_sec < TIME32_MIN || (tv)->tv_sec > TIME32_MAX) 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 || _KERNEL */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #endif /* _ASM */ 74*7c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */ 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 77*7c478bd9Sstevel@tonic-gate #ifndef _ASM 78*7c478bd9Sstevel@tonic-gate struct timezone { 79*7c478bd9Sstevel@tonic-gate int tz_minuteswest; /* minutes west of Greenwich */ 80*7c478bd9Sstevel@tonic-gate int tz_dsttime; /* type of dst correction */ 81*7c478bd9Sstevel@tonic-gate }; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate #endif /* _ASM */ 84*7c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate #endif 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate /* 91*7c478bd9Sstevel@tonic-gate * Needed for longlong_t type. Placement of this due to <sys/types.h> 92*7c478bd9Sstevel@tonic-gate * including <sys/select.h> which relies on the presense of the itimerval 93*7c478bd9Sstevel@tonic-gate * structure. 94*7c478bd9Sstevel@tonic-gate */ 95*7c478bd9Sstevel@tonic-gate #ifndef _ASM 96*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 97*7c478bd9Sstevel@tonic-gate #endif /* _ASM */ 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 100*7c478bd9Sstevel@tonic-gate extern "C" { 101*7c478bd9Sstevel@tonic-gate #endif 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate #define DST_NONE 0 /* not on dst */ 106*7c478bd9Sstevel@tonic-gate #define DST_USA 1 /* USA style dst */ 107*7c478bd9Sstevel@tonic-gate #define DST_AUST 2 /* Australian style dst */ 108*7c478bd9Sstevel@tonic-gate #define DST_WET 3 /* Western European dst */ 109*7c478bd9Sstevel@tonic-gate #define DST_MET 4 /* Middle European dst */ 110*7c478bd9Sstevel@tonic-gate #define DST_EET 5 /* Eastern European dst */ 111*7c478bd9Sstevel@tonic-gate #define DST_CAN 6 /* Canada */ 112*7c478bd9Sstevel@tonic-gate #define DST_GB 7 /* Great Britain and Eire */ 113*7c478bd9Sstevel@tonic-gate #define DST_RUM 8 /* Rumania */ 114*7c478bd9Sstevel@tonic-gate #define DST_TUR 9 /* Turkey */ 115*7c478bd9Sstevel@tonic-gate #define DST_AUSTALT 10 /* Australian style with shift in 1986 */ 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate /* 118*7c478bd9Sstevel@tonic-gate * Operations on timevals. 119*7c478bd9Sstevel@tonic-gate */ 120*7c478bd9Sstevel@tonic-gate #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 121*7c478bd9Sstevel@tonic-gate #define timercmp(tvp, uvp, cmp) \ 122*7c478bd9Sstevel@tonic-gate (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 123*7c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 124*7c478bd9Sstevel@tonic-gate ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 125*7c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 126*7c478bd9Sstevel@tonic-gate ((tvp)->tv_sec cmp (uvp)->tv_sec)) 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__) 133*7c478bd9Sstevel@tonic-gate /* 134*7c478bd9Sstevel@tonic-gate * Names of the interval timers, and structure 135*7c478bd9Sstevel@tonic-gate * defining a timer setting. 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate #define ITIMER_REAL 0 /* Decrements in real time */ 138*7c478bd9Sstevel@tonic-gate #define ITIMER_VIRTUAL 1 /* Decrements in process virtual time */ 139*7c478bd9Sstevel@tonic-gate #define ITIMER_PROF 2 /* Decrements both in process virtual */ 140*7c478bd9Sstevel@tonic-gate /* time and when system is running on */ 141*7c478bd9Sstevel@tonic-gate /* behalf of the process. */ 142*7c478bd9Sstevel@tonic-gate #define ITIMER_REALPROF 3 /* Decrements in real time for real- */ 143*7c478bd9Sstevel@tonic-gate /* time profiling of multithreaded */ 144*7c478bd9Sstevel@tonic-gate /* programs. */ 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate #ifndef _ASM 147*7c478bd9Sstevel@tonic-gate struct itimerval { 148*7c478bd9Sstevel@tonic-gate struct timeval it_interval; /* timer interval */ 149*7c478bd9Sstevel@tonic-gate struct timeval it_value; /* current value */ 150*7c478bd9Sstevel@tonic-gate }; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate struct itimerval32 { 155*7c478bd9Sstevel@tonic-gate struct timeval32 it_interval; 156*7c478bd9Sstevel@tonic-gate struct timeval32 it_value; 157*7c478bd9Sstevel@tonic-gate }; 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate #define ITIMERVAL32_TO_ITIMERVAL(itv, itv32) { \ 160*7c478bd9Sstevel@tonic-gate TIMEVAL32_TO_TIMEVAL(&(itv)->it_interval, &(itv32)->it_interval); \ 161*7c478bd9Sstevel@tonic-gate TIMEVAL32_TO_TIMEVAL(&(itv)->it_value, &(itv32)->it_value); \ 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate #define ITIMERVAL_TO_ITIMERVAL32(itv32, itv) { \ 165*7c478bd9Sstevel@tonic-gate TIMEVAL_TO_TIMEVAL32(&(itv32)->it_interval, &(itv)->it_interval); \ 166*7c478bd9Sstevel@tonic-gate TIMEVAL_TO_TIMEVAL32(&(itv32)->it_value, &(itv)->it_value); \ 167*7c478bd9Sstevel@tonic-gate } 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate #define ITIMERVAL_OVERFLOW(itv) \ 170*7c478bd9Sstevel@tonic-gate (TIMEVAL_OVERFLOW(&(itv)->it_interval) || \ 171*7c478bd9Sstevel@tonic-gate TIMEVAL_OVERFLOW(&(itv)->it_value)) 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 174*7c478bd9Sstevel@tonic-gate #endif /* _ASM */ 175*7c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */ 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * Definitions for commonly used resolutions. 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate #define SEC 1 183*7c478bd9Sstevel@tonic-gate #define MILLISEC 1000 184*7c478bd9Sstevel@tonic-gate #define MICROSEC 1000000 185*7c478bd9Sstevel@tonic-gate #define NANOSEC 1000000000 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate #ifndef _ASM 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate /* 192*7c478bd9Sstevel@tonic-gate * Time expressed as a 64-bit nanosecond counter. 193*7c478bd9Sstevel@tonic-gate */ 194*7c478bd9Sstevel@tonic-gate typedef longlong_t hrtime_t; 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate #include <sys/time_impl.h> 199*7c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate extern int tick_per_msec; /* clock ticks per millisecond (may be zero) */ 202*7c478bd9Sstevel@tonic-gate extern int msec_per_tick; /* milliseconds per clock tick (may be zero) */ 203*7c478bd9Sstevel@tonic-gate extern int usec_per_tick; /* microseconds per clock tick */ 204*7c478bd9Sstevel@tonic-gate extern int nsec_per_tick; /* nanoseconds per clock tick */ 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate /* 207*7c478bd9Sstevel@tonic-gate * Macros to convert from common units of time (sec, msec, usec, nsec, 208*7c478bd9Sstevel@tonic-gate * timeval, timestruc) to clock ticks and vice versa. 209*7c478bd9Sstevel@tonic-gate */ 210*7c478bd9Sstevel@tonic-gate #define TICK_TO_SEC(tick) ((tick) / hz) 211*7c478bd9Sstevel@tonic-gate #define SEC_TO_TICK(sec) ((sec) * hz) 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate #define TICK_TO_MSEC(tick) \ 214*7c478bd9Sstevel@tonic-gate (msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec) 215*7c478bd9Sstevel@tonic-gate #define MSEC_TO_TICK(msec) \ 216*7c478bd9Sstevel@tonic-gate (msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec) 217*7c478bd9Sstevel@tonic-gate #define MSEC_TO_TICK_ROUNDUP(msec) \ 218*7c478bd9Sstevel@tonic-gate (msec_per_tick ? \ 219*7c478bd9Sstevel@tonic-gate ((msec) == 0 ? 0 : ((msec) - 1) / msec_per_tick + 1) : \ 220*7c478bd9Sstevel@tonic-gate (msec) * tick_per_msec) 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate #define TICK_TO_USEC(tick) ((tick) * usec_per_tick) 223*7c478bd9Sstevel@tonic-gate #define USEC_TO_TICK(usec) ((usec) / usec_per_tick) 224*7c478bd9Sstevel@tonic-gate #define USEC_TO_TICK_ROUNDUP(usec) \ 225*7c478bd9Sstevel@tonic-gate ((usec) == 0 ? 0 : USEC_TO_TICK((usec) - 1) + 1) 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate #define TICK_TO_NSEC(tick) ((tick) * nsec_per_tick) 228*7c478bd9Sstevel@tonic-gate #define NSEC_TO_TICK(nsec) ((nsec) / nsec_per_tick) 229*7c478bd9Sstevel@tonic-gate #define NSEC_TO_TICK_ROUNDUP(nsec) \ 230*7c478bd9Sstevel@tonic-gate ((nsec) == 0 ? 0 : NSEC_TO_TICK((nsec) - 1) + 1) 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate #define TICK_TO_TIMEVAL(tick, tvp) { \ 233*7c478bd9Sstevel@tonic-gate clock_t __tmptck = (tick); \ 234*7c478bd9Sstevel@tonic-gate (tvp)->tv_sec = TICK_TO_SEC(__tmptck); \ 235*7c478bd9Sstevel@tonic-gate (tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK((tvp)->tv_sec)); \ 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate #define TICK_TO_TIMEVAL32(tick, tvp) { \ 239*7c478bd9Sstevel@tonic-gate clock_t __tmptck = (tick); \ 240*7c478bd9Sstevel@tonic-gate time_t __tmptm = TICK_TO_SEC(__tmptck); \ 241*7c478bd9Sstevel@tonic-gate (tvp)->tv_sec = (time32_t)__tmptm; \ 242*7c478bd9Sstevel@tonic-gate (tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK(__tmptm)); \ 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate #define TICK_TO_TIMESTRUC(tick, tsp) { \ 246*7c478bd9Sstevel@tonic-gate clock_t __tmptck = (tick); \ 247*7c478bd9Sstevel@tonic-gate (tsp)->tv_sec = TICK_TO_SEC(__tmptck); \ 248*7c478bd9Sstevel@tonic-gate (tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK((tsp)->tv_sec)); \ 249*7c478bd9Sstevel@tonic-gate } 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate #define TICK_TO_TIMESTRUC32(tick, tsp) { \ 252*7c478bd9Sstevel@tonic-gate clock_t __tmptck = (tick); \ 253*7c478bd9Sstevel@tonic-gate time_t __tmptm = TICK_TO_SEC(__tmptck); \ 254*7c478bd9Sstevel@tonic-gate (tsp)->tv_sec = (time32_t)__tmptm; \ 255*7c478bd9Sstevel@tonic-gate (tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK(__tmptm)); \ 256*7c478bd9Sstevel@tonic-gate } 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate #define TIMEVAL_TO_TICK(tvp) \ 259*7c478bd9Sstevel@tonic-gate (SEC_TO_TICK((tvp)->tv_sec) + USEC_TO_TICK((tvp)->tv_usec)) 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate #define TIMESTRUC_TO_TICK(tsp) \ 262*7c478bd9Sstevel@tonic-gate (SEC_TO_TICK((tsp)->tv_sec) + NSEC_TO_TICK((tsp)->tv_nsec)) 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate typedef struct todinfo { 265*7c478bd9Sstevel@tonic-gate int tod_sec; /* seconds 0-59 */ 266*7c478bd9Sstevel@tonic-gate int tod_min; /* minutes 0-59 */ 267*7c478bd9Sstevel@tonic-gate int tod_hour; /* hours 0-23 */ 268*7c478bd9Sstevel@tonic-gate int tod_dow; /* day of week 1-7 */ 269*7c478bd9Sstevel@tonic-gate int tod_day; /* day of month 1-31 */ 270*7c478bd9Sstevel@tonic-gate int tod_month; /* month 1-12 */ 271*7c478bd9Sstevel@tonic-gate int tod_year; /* year 70+ */ 272*7c478bd9Sstevel@tonic-gate } todinfo_t; 273*7c478bd9Sstevel@tonic-gate 274*7c478bd9Sstevel@tonic-gate extern int64_t timedelta; 275*7c478bd9Sstevel@tonic-gate extern int timechanged; 276*7c478bd9Sstevel@tonic-gate extern int tod_needsync; 277*7c478bd9Sstevel@tonic-gate extern kmutex_t tod_lock; 278*7c478bd9Sstevel@tonic-gate extern timestruc_t hrestime; 279*7c478bd9Sstevel@tonic-gate extern hrtime_t hres_last_tick; 280*7c478bd9Sstevel@tonic-gate extern int64_t hrestime_adj; 281*7c478bd9Sstevel@tonic-gate extern uint_t adj_shift; 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate extern timestruc_t tod_get(void); 284*7c478bd9Sstevel@tonic-gate extern void tod_set(timestruc_t); 285*7c478bd9Sstevel@tonic-gate extern void set_hrestime(timestruc_t *); 286*7c478bd9Sstevel@tonic-gate extern todinfo_t utc_to_tod(time_t); 287*7c478bd9Sstevel@tonic-gate extern time_t tod_to_utc(todinfo_t); 288*7c478bd9Sstevel@tonic-gate extern int hr_clock_lock(void); 289*7c478bd9Sstevel@tonic-gate extern void hr_clock_unlock(int); 290*7c478bd9Sstevel@tonic-gate extern hrtime_t gethrtime(void); 291*7c478bd9Sstevel@tonic-gate extern hrtime_t gethrtime_unscaled(void); 292*7c478bd9Sstevel@tonic-gate extern hrtime_t gethrtime_max(void); 293*7c478bd9Sstevel@tonic-gate extern hrtime_t gethrtime_waitfree(void); 294*7c478bd9Sstevel@tonic-gate extern void scalehrtime(hrtime_t *); 295*7c478bd9Sstevel@tonic-gate extern uint64_t unscalehrtime(hrtime_t); 296*7c478bd9Sstevel@tonic-gate extern void gethrestime(timespec_t *); 297*7c478bd9Sstevel@tonic-gate extern time_t gethrestime_sec(void); 298*7c478bd9Sstevel@tonic-gate extern void gethrestime_lasttick(timespec_t *); 299*7c478bd9Sstevel@tonic-gate extern void hrt2ts(hrtime_t, timestruc_t *); 300*7c478bd9Sstevel@tonic-gate extern hrtime_t ts2hrt(const timestruc_t *); 301*7c478bd9Sstevel@tonic-gate extern void hrt2tv(hrtime_t, struct timeval *); 302*7c478bd9Sstevel@tonic-gate extern hrtime_t tv2hrt(struct timeval *); 303*7c478bd9Sstevel@tonic-gate extern int itimerfix(struct timeval *, int); 304*7c478bd9Sstevel@tonic-gate extern int itimerdecr(struct itimerval *, int); 305*7c478bd9Sstevel@tonic-gate extern void timevaladd(struct timeval *, struct timeval *); 306*7c478bd9Sstevel@tonic-gate extern void timevalsub(struct timeval *, struct timeval *); 307*7c478bd9Sstevel@tonic-gate extern void timevalfix(struct timeval *); 308*7c478bd9Sstevel@tonic-gate extern void dtrace_hres_tick(void); 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 311*7c478bd9Sstevel@tonic-gate extern void hrt2ts32(hrtime_t, timestruc32_t *); 312*7c478bd9Sstevel@tonic-gate #endif 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 317*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 318*7c478bd9Sstevel@tonic-gate int adjtime(struct timeval *, struct timeval *); 319*7c478bd9Sstevel@tonic-gate #else 320*7c478bd9Sstevel@tonic-gate int adjtime(); 321*7c478bd9Sstevel@tonic-gate #endif 322*7c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */ 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || \ 325*7c478bd9Sstevel@tonic-gate defined(_ATFILE_SOURCE) || defined(__EXTENSIONS__) 326*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 327*7c478bd9Sstevel@tonic-gate int futimesat(int, const char *, const struct timeval *); 328*7c478bd9Sstevel@tonic-gate #else 329*7c478bd9Sstevel@tonic-gate int futimesat(); 330*7c478bd9Sstevel@tonic-gate #endif /* defined(__STDC__) */ 331*7c478bd9Sstevel@tonic-gate #endif /* defined(__ATFILE_SOURCE) */ 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 334*7c478bd9Sstevel@tonic-gate defined(__EXTENSIONS__) 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate int getitimer(int, struct itimerval *); 339*7c478bd9Sstevel@tonic-gate int utimes(const char *, const struct timeval *); 340*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) 341*7c478bd9Sstevel@tonic-gate int setitimer(int, const struct itimerval *_RESTRICT_KYWD, 342*7c478bd9Sstevel@tonic-gate struct itimerval *_RESTRICT_KYWD); 343*7c478bd9Sstevel@tonic-gate #else 344*7c478bd9Sstevel@tonic-gate int setitimer(int, struct itimerval *_RESTRICT_KYWD, 345*7c478bd9Sstevel@tonic-gate struct itimerval *_RESTRICT_KYWD); 346*7c478bd9Sstevel@tonic-gate #endif /* defined(_XPG2_2) */ 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate int gettimer(); 351*7c478bd9Sstevel@tonic-gate int settimer(); 352*7c478bd9Sstevel@tonic-gate int utimes(); 353*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 354*7c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) ... defined(_XPG4_2) */ 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate /* 357*7c478bd9Sstevel@tonic-gate * gettimeofday() and settimeofday() were included in SVr4 due to their 358*7c478bd9Sstevel@tonic-gate * common use in BSD based applications. They were to be included exactly 359*7c478bd9Sstevel@tonic-gate * as in BSD, with two parameters. However, AT&T/USL noted that the second 360*7c478bd9Sstevel@tonic-gate * parameter was unused and deleted it, thereby making a routine included 361*7c478bd9Sstevel@tonic-gate * for compatibility, incompatible. 362*7c478bd9Sstevel@tonic-gate * 363*7c478bd9Sstevel@tonic-gate * XSH4.2 (spec 1170) defines gettimeofday and settimeofday to have two 364*7c478bd9Sstevel@tonic-gate * parameters. 365*7c478bd9Sstevel@tonic-gate * 366*7c478bd9Sstevel@tonic-gate * This has caused general disagreement in the application community as to 367*7c478bd9Sstevel@tonic-gate * the syntax of these routines. Solaris defaults to the XSH4.2 definition. 368*7c478bd9Sstevel@tonic-gate * The flag _SVID_GETTOD may be used to force the SVID version. 369*7c478bd9Sstevel@tonic-gate */ 370*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 373*7c478bd9Sstevel@tonic-gate #if defined(_SVID_GETTOD) 374*7c478bd9Sstevel@tonic-gate int settimeofday(struct timeval *); 375*7c478bd9Sstevel@tonic-gate #else 376*7c478bd9Sstevel@tonic-gate int settimeofday(struct timeval *, void *); 377*7c478bd9Sstevel@tonic-gate #endif 378*7c478bd9Sstevel@tonic-gate hrtime_t gethrtime(void); 379*7c478bd9Sstevel@tonic-gate hrtime_t gethrvtime(void); 380*7c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 381*7c478bd9Sstevel@tonic-gate int settimeofday(); 382*7c478bd9Sstevel@tonic-gate hrtime_t gethrtime(); 383*7c478bd9Sstevel@tonic-gate hrtime_t gethrvtime(); 384*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate #endif /* !(defined _KERNEL) && !defined(__XOPEN_OR_POSIX) ... */ 387*7c478bd9Sstevel@tonic-gate 388*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 389*7c478bd9Sstevel@tonic-gate defined(__EXTENSIONS__) 390*7c478bd9Sstevel@tonic-gate 391*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 392*7c478bd9Sstevel@tonic-gate #if defined(_SVID_GETTOD) 393*7c478bd9Sstevel@tonic-gate int gettimeofday(struct timeval *); 394*7c478bd9Sstevel@tonic-gate #else 395*7c478bd9Sstevel@tonic-gate int gettimeofday(struct timeval *_RESTRICT_KYWD, void *_RESTRICT_KYWD); 396*7c478bd9Sstevel@tonic-gate #endif 397*7c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 398*7c478bd9Sstevel@tonic-gate int gettimeofday(); 399*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */ 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate /* 404*7c478bd9Sstevel@tonic-gate * The inclusion of <time.h> is historical and was added for 405*7c478bd9Sstevel@tonic-gate * backward compatibility in delta 1.2 when a number of definitions 406*7c478bd9Sstevel@tonic-gate * were moved out of <sys/time.h>. More recently, the timespec and 407*7c478bd9Sstevel@tonic-gate * itimerspec structure definitions, along with the _CLOCK_*, CLOCK_*, 408*7c478bd9Sstevel@tonic-gate * _TIMER_*, and TIMER_* symbols were moved to <sys/time_impl.h>, 409*7c478bd9Sstevel@tonic-gate * which is now included by <time.h>. This change was due to POSIX 410*7c478bd9Sstevel@tonic-gate * 1003.1b-1993 and X/Open UNIX 98 requirements. For non-POSIX and 411*7c478bd9Sstevel@tonic-gate * non-X/Open applications, including this header will still make 412*7c478bd9Sstevel@tonic-gate * visible these definitions. 413*7c478bd9Sstevel@tonic-gate */ 414*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 415*7c478bd9Sstevel@tonic-gate #include <time.h> 416*7c478bd9Sstevel@tonic-gate #endif 417*7c478bd9Sstevel@tonic-gate 418*7c478bd9Sstevel@tonic-gate /* 419*7c478bd9Sstevel@tonic-gate * The inclusion of <sys/select.h> is needed for the FD_CLR, 420*7c478bd9Sstevel@tonic-gate * FD_ISSET, FD_SET, and FD_SETSIZE macros as well as the 421*7c478bd9Sstevel@tonic-gate * select() prototype defined in the XOpen specifications 422*7c478bd9Sstevel@tonic-gate * beginning with XSH4v2. Placement required after definition 423*7c478bd9Sstevel@tonic-gate * for itimerval. 424*7c478bd9Sstevel@tonic-gate */ 425*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 426*7c478bd9Sstevel@tonic-gate defined(__EXTENSIONS__) 427*7c478bd9Sstevel@tonic-gate #include <sys/select.h> 428*7c478bd9Sstevel@tonic-gate #endif 429*7c478bd9Sstevel@tonic-gate 430*7c478bd9Sstevel@tonic-gate #endif /* _ASM */ 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 433*7c478bd9Sstevel@tonic-gate } 434*7c478bd9Sstevel@tonic-gate #endif 435*7c478bd9Sstevel@tonic-gate 436*7c478bd9Sstevel@tonic-gate #endif /* _SYS_TIME_H */ 437