xref: /onnv-gate/usr/src/uts/common/sys/time.h (revision 11066:cebb50cbe4f9)
10Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
20Sstevel@tonic-gate /*	  All Rights Reserved  	*/
30Sstevel@tonic-gate 
40Sstevel@tonic-gate 
50Sstevel@tonic-gate /*
66860Sdanmcd  * Copyright (c) 1982, 1986, 1993 Regents of the University of California.
70Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
80Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
90Sstevel@tonic-gate  */
100Sstevel@tonic-gate 
110Sstevel@tonic-gate /*
1210797SEric.Saxe@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
130Sstevel@tonic-gate  * Use is subject to license terms.
140Sstevel@tonic-gate  */
150Sstevel@tonic-gate 
160Sstevel@tonic-gate #ifndef _SYS_TIME_H
170Sstevel@tonic-gate #define	_SYS_TIME_H
180Sstevel@tonic-gate 
190Sstevel@tonic-gate #include <sys/feature_tests.h>
200Sstevel@tonic-gate 
210Sstevel@tonic-gate /*
220Sstevel@tonic-gate  * Structure returned by gettimeofday(2) system call,
230Sstevel@tonic-gate  * and used in other calls.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifdef	__cplusplus
270Sstevel@tonic-gate extern "C" {
280Sstevel@tonic-gate #endif
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
310Sstevel@tonic-gate 	defined(__EXTENSIONS__)
320Sstevel@tonic-gate #ifndef	_ASM
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #if !defined(_TIME_T) || __cplusplus >= 199711L
350Sstevel@tonic-gate #define	_TIME_T
360Sstevel@tonic-gate typedef	long	time_t;		/* time of day in seconds */
370Sstevel@tonic-gate #endif	/* _TIME_T */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef	_SUSECONDS_T
400Sstevel@tonic-gate #define	_SUSECONDS_T
410Sstevel@tonic-gate typedef	long	suseconds_t;	/* signed # of microseconds */
420Sstevel@tonic-gate #endif	/* _SUSECONDS_T */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate struct timeval {
450Sstevel@tonic-gate 	time_t		tv_sec;		/* seconds */
460Sstevel@tonic-gate 	suseconds_t	tv_usec;	/* and microseconds */
470Sstevel@tonic-gate };
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #if defined(_SYSCALL32)
500Sstevel@tonic-gate 
510Sstevel@tonic-gate #include <sys/types32.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #define	TIMEVAL32_TO_TIMEVAL(tv, tv32)	{	\
540Sstevel@tonic-gate 	(tv)->tv_sec = (time_t)(tv32)->tv_sec;	\
550Sstevel@tonic-gate 	(tv)->tv_usec = (tv32)->tv_usec;	\
560Sstevel@tonic-gate }
570Sstevel@tonic-gate 
580Sstevel@tonic-gate #define	TIMEVAL_TO_TIMEVAL32(tv32, tv)	{		\
590Sstevel@tonic-gate 	(tv32)->tv_sec = (time32_t)(tv)->tv_sec;	\
600Sstevel@tonic-gate 	(tv32)->tv_usec = (tv)->tv_usec;		\
610Sstevel@tonic-gate }
620Sstevel@tonic-gate 
630Sstevel@tonic-gate #define	TIME32_MAX	INT32_MAX
640Sstevel@tonic-gate #define	TIME32_MIN	INT32_MIN
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #define	TIMEVAL_OVERFLOW(tv)	\
670Sstevel@tonic-gate 	((tv)->tv_sec < TIME32_MIN || (tv)->tv_sec > TIME32_MAX)
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #endif	/* _SYSCALL32 || _KERNEL */
700Sstevel@tonic-gate 
710Sstevel@tonic-gate #endif	/* _ASM */
720Sstevel@tonic-gate #endif	/* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
730Sstevel@tonic-gate 
740Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
750Sstevel@tonic-gate #ifndef	_ASM
760Sstevel@tonic-gate struct timezone {
770Sstevel@tonic-gate 	int	tz_minuteswest;	/* minutes west of Greenwich */
780Sstevel@tonic-gate 	int	tz_dsttime;	/* type of dst correction */
790Sstevel@tonic-gate };
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #endif	/* _ASM */
820Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
830Sstevel@tonic-gate 
840Sstevel@tonic-gate #ifdef	__cplusplus
850Sstevel@tonic-gate }
860Sstevel@tonic-gate #endif
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * Needed for longlong_t type.  Placement of this due to <sys/types.h>
900Sstevel@tonic-gate  * including <sys/select.h> which relies on the presense of the itimerval
910Sstevel@tonic-gate  * structure.
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate #ifndef	_ASM
940Sstevel@tonic-gate #include <sys/types.h>
950Sstevel@tonic-gate #endif	/* _ASM */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #ifdef	__cplusplus
980Sstevel@tonic-gate extern "C" {
990Sstevel@tonic-gate #endif
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate #define	DST_NONE	0	/* not on dst */
1040Sstevel@tonic-gate #define	DST_USA		1	/* USA style dst */
1050Sstevel@tonic-gate #define	DST_AUST	2	/* Australian style dst */
1060Sstevel@tonic-gate #define	DST_WET		3	/* Western European dst */
1070Sstevel@tonic-gate #define	DST_MET		4	/* Middle European dst */
1080Sstevel@tonic-gate #define	DST_EET		5	/* Eastern European dst */
1090Sstevel@tonic-gate #define	DST_CAN		6	/* Canada */
1100Sstevel@tonic-gate #define	DST_GB		7	/* Great Britain and Eire */
1110Sstevel@tonic-gate #define	DST_RUM		8	/* Rumania */
1120Sstevel@tonic-gate #define	DST_TUR		9	/* Turkey */
1130Sstevel@tonic-gate #define	DST_AUSTALT	10	/* Australian style with shift in 1986 */
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate  * Operations on timevals.
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate #define	timerisset(tvp)		((tvp)->tv_sec || (tvp)->tv_usec)
1190Sstevel@tonic-gate #define	timercmp(tvp, uvp, cmp) \
1200Sstevel@tonic-gate 	(((tvp)->tv_sec == (uvp)->tv_sec) ? \
1210Sstevel@tonic-gate 	    /* CSTYLED */ \
1220Sstevel@tonic-gate 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1230Sstevel@tonic-gate 	    /* CSTYLED */ \
1240Sstevel@tonic-gate 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate #define	timerclear(tvp)		(tvp)->tv_sec = (tvp)->tv_usec = 0
1270Sstevel@tonic-gate 
1286860Sdanmcd #ifdef __lint
1296860Sdanmcd /*
1306860Sdanmcd  * Make innocuous, lint-happy versions until do {} while (0) is acknowleged as
1316860Sdanmcd  * lint-safe.  If the compiler could know that we always make tv_usec < 1000000
1326860Sdanmcd  * we wouldn't need a special linted version.
1336860Sdanmcd  */
1346860Sdanmcd #define	timeradd(tvp, uvp, vvp)					\
1356860Sdanmcd 	do								\
1366860Sdanmcd 	{								\
1376860Sdanmcd 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
1386860Sdanmcd 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
1396860Sdanmcd 		if ((vvp)->tv_usec >= 1000000)				\
1406860Sdanmcd 		{							\
1416860Sdanmcd 			(vvp)->tv_sec++;				\
1426860Sdanmcd 			(vvp)->tv_usec -= 1000000;			\
1436860Sdanmcd 		}							\
1446860Sdanmcd 	} while ((vvp)->tv_usec >= 1000000)
1456860Sdanmcd #define	timersub(tvp, uvp, vvp)					\
1466860Sdanmcd 	do								\
1476860Sdanmcd 	{								\
1486860Sdanmcd 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
1496860Sdanmcd 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
1506860Sdanmcd 		if ((vvp)->tv_usec < 0)					\
1516860Sdanmcd 		{							\
1526860Sdanmcd 			(vvp)->tv_sec--;				\
1536860Sdanmcd 			(vvp)->tv_usec += 1000000;			\
1546860Sdanmcd 		}							\
1556860Sdanmcd 	} while ((vvp)->tv_usec >= 1000000)
1566860Sdanmcd #else
1576860Sdanmcd #define	timeradd(tvp, uvp, vvp)					\
1586860Sdanmcd 	do								\
1596860Sdanmcd 	{								\
1606860Sdanmcd 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
1616860Sdanmcd 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
1626860Sdanmcd 		if ((vvp)->tv_usec >= 1000000)				\
1636860Sdanmcd 		{							\
1646860Sdanmcd 			(vvp)->tv_sec++;				\
1656860Sdanmcd 			(vvp)->tv_usec -= 1000000;			\
1666860Sdanmcd 		}							\
1676860Sdanmcd 	} while (0)
1686860Sdanmcd 
1696860Sdanmcd #define	timersub(tvp, uvp, vvp)					\
1706860Sdanmcd 	do								\
1716860Sdanmcd 	{								\
1726860Sdanmcd 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
1736860Sdanmcd 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
1746860Sdanmcd 		if ((vvp)->tv_usec < 0)					\
1756860Sdanmcd 		{							\
1766860Sdanmcd 			(vvp)->tv_sec--;				\
1776860Sdanmcd 			(vvp)->tv_usec += 1000000;			\
1786860Sdanmcd 		}							\
1796860Sdanmcd 	} while (0)
1806860Sdanmcd #endif /* __lint */
1816860Sdanmcd 
1820Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate  * Names of the interval timers, and structure
1870Sstevel@tonic-gate  * defining a timer setting.
1880Sstevel@tonic-gate  */
1890Sstevel@tonic-gate #define	ITIMER_REAL	0	/* Decrements in real time */
1900Sstevel@tonic-gate #define	ITIMER_VIRTUAL	1	/* Decrements in process virtual time */
1910Sstevel@tonic-gate #define	ITIMER_PROF	2	/* Decrements both in process virtual */
1920Sstevel@tonic-gate 				/* time and when system is running on */
1930Sstevel@tonic-gate 				/* behalf of the process. */
1940Sstevel@tonic-gate #define	ITIMER_REALPROF	3	/* Decrements in real time for real- */
1950Sstevel@tonic-gate 				/* time profiling of multithreaded */
1960Sstevel@tonic-gate 				/* programs. */
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate #ifndef	_ASM
1990Sstevel@tonic-gate struct	itimerval {
2000Sstevel@tonic-gate 	struct	timeval it_interval;	/* timer interval */
2010Sstevel@tonic-gate 	struct	timeval it_value;	/* current value */
2020Sstevel@tonic-gate };
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate #if defined(_SYSCALL32)
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate struct itimerval32 {
2070Sstevel@tonic-gate 	struct	timeval32 it_interval;
2080Sstevel@tonic-gate 	struct	timeval32 it_value;
2090Sstevel@tonic-gate };
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate #define	ITIMERVAL32_TO_ITIMERVAL(itv, itv32)	{	\
2120Sstevel@tonic-gate 	TIMEVAL32_TO_TIMEVAL(&(itv)->it_interval, &(itv32)->it_interval); \
2130Sstevel@tonic-gate 	TIMEVAL32_TO_TIMEVAL(&(itv)->it_value, &(itv32)->it_value);	\
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate #define	ITIMERVAL_TO_ITIMERVAL32(itv32, itv)	{	\
2170Sstevel@tonic-gate 	TIMEVAL_TO_TIMEVAL32(&(itv32)->it_interval, &(itv)->it_interval); \
2180Sstevel@tonic-gate 	TIMEVAL_TO_TIMEVAL32(&(itv32)->it_value, &(itv)->it_value);	\
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate #define	ITIMERVAL_OVERFLOW(itv)				\
2220Sstevel@tonic-gate 	(TIMEVAL_OVERFLOW(&(itv)->it_interval) ||	\
2230Sstevel@tonic-gate 	TIMEVAL_OVERFLOW(&(itv)->it_value))
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2260Sstevel@tonic-gate #endif	/* _ASM */
2270Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate  *	Definitions for commonly used resolutions.
2330Sstevel@tonic-gate  */
2340Sstevel@tonic-gate #define	SEC		1
2350Sstevel@tonic-gate #define	MILLISEC	1000
2360Sstevel@tonic-gate #define	MICROSEC	1000000
2370Sstevel@tonic-gate #define	NANOSEC		1000000000
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate #ifndef	_ASM
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate  * Time expressed as a 64-bit nanosecond counter.
2450Sstevel@tonic-gate  */
2460Sstevel@tonic-gate typedef	longlong_t	hrtime_t;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate #ifdef _KERNEL
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate #include <sys/time_impl.h>
2510Sstevel@tonic-gate #include <sys/mutex.h>
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate extern int tick_per_msec;	/* clock ticks per millisecond (may be zero) */
2540Sstevel@tonic-gate extern int msec_per_tick;	/* milliseconds per clock tick (may be zero) */
2550Sstevel@tonic-gate extern int usec_per_tick;	/* microseconds per clock tick */
2560Sstevel@tonic-gate extern int nsec_per_tick;	/* nanoseconds per clock tick */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * Macros to convert from common units of time (sec, msec, usec, nsec,
2600Sstevel@tonic-gate  * timeval, timestruc) to clock ticks and vice versa.
2610Sstevel@tonic-gate  */
2620Sstevel@tonic-gate #define	TICK_TO_SEC(tick)	((tick) / hz)
2630Sstevel@tonic-gate #define	SEC_TO_TICK(sec)	((sec) * hz)
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate #define	TICK_TO_MSEC(tick)	\
2660Sstevel@tonic-gate 	(msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
2670Sstevel@tonic-gate #define	MSEC_TO_TICK(msec)	\
2680Sstevel@tonic-gate 	(msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
2690Sstevel@tonic-gate #define	MSEC_TO_TICK_ROUNDUP(msec)	\
2700Sstevel@tonic-gate 	(msec_per_tick ? \
2710Sstevel@tonic-gate 	((msec) == 0 ? 0 : ((msec) - 1) / msec_per_tick + 1) : \
2720Sstevel@tonic-gate 	(msec) * tick_per_msec)
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate #define	TICK_TO_USEC(tick)		((tick) * usec_per_tick)
2750Sstevel@tonic-gate #define	USEC_TO_TICK(usec)		((usec) / usec_per_tick)
2760Sstevel@tonic-gate #define	USEC_TO_TICK_ROUNDUP(usec)	\
2770Sstevel@tonic-gate 	((usec) == 0 ? 0 : USEC_TO_TICK((usec) - 1) + 1)
2780Sstevel@tonic-gate 
2798048SMadhavan.Venkataraman@Sun.COM #define	TICK_TO_NSEC(tick)		((hrtime_t)(tick) * nsec_per_tick)
2800Sstevel@tonic-gate #define	NSEC_TO_TICK(nsec)		((nsec) / nsec_per_tick)
2810Sstevel@tonic-gate #define	NSEC_TO_TICK_ROUNDUP(nsec)	\
2820Sstevel@tonic-gate 	((nsec) == 0 ? 0 : NSEC_TO_TICK((nsec) - 1) + 1)
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate #define	TICK_TO_TIMEVAL(tick, tvp) {	\
2850Sstevel@tonic-gate 	clock_t __tmptck = (tick);	\
2860Sstevel@tonic-gate 	(tvp)->tv_sec = TICK_TO_SEC(__tmptck);	\
2870Sstevel@tonic-gate 	(tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK((tvp)->tv_sec)); \
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate #define	TICK_TO_TIMEVAL32(tick, tvp) {	\
2910Sstevel@tonic-gate 	clock_t __tmptck = (tick);	\
2920Sstevel@tonic-gate 	time_t __tmptm = TICK_TO_SEC(__tmptck);	\
2930Sstevel@tonic-gate 	(tvp)->tv_sec = (time32_t)__tmptm;	\
2940Sstevel@tonic-gate 	(tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK(__tmptm)); \
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate #define	TICK_TO_TIMESTRUC(tick, tsp) {	\
2980Sstevel@tonic-gate 	clock_t __tmptck = (tick);	\
2990Sstevel@tonic-gate 	(tsp)->tv_sec = TICK_TO_SEC(__tmptck);	\
3000Sstevel@tonic-gate 	(tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK((tsp)->tv_sec)); \
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate #define	TICK_TO_TIMESTRUC32(tick, tsp) {	\
3040Sstevel@tonic-gate 	clock_t __tmptck = (tick);			\
3050Sstevel@tonic-gate 	time_t __tmptm = TICK_TO_SEC(__tmptck);		\
3060Sstevel@tonic-gate 	(tsp)->tv_sec = (time32_t)__tmptm;		\
3070Sstevel@tonic-gate 	(tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK(__tmptm));	\
3080Sstevel@tonic-gate }
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate #define	TIMEVAL_TO_TICK(tvp)	\
3110Sstevel@tonic-gate 	(SEC_TO_TICK((tvp)->tv_sec) + USEC_TO_TICK((tvp)->tv_usec))
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate #define	TIMESTRUC_TO_TICK(tsp)	\
3140Sstevel@tonic-gate 	(SEC_TO_TICK((tsp)->tv_sec) + NSEC_TO_TICK((tsp)->tv_nsec))
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate typedef struct todinfo {
3170Sstevel@tonic-gate 	int	tod_sec;	/* seconds 0-59 */
3180Sstevel@tonic-gate 	int	tod_min;	/* minutes 0-59 */
3190Sstevel@tonic-gate 	int	tod_hour;	/* hours 0-23 */
3200Sstevel@tonic-gate 	int	tod_dow;	/* day of week 1-7 */
3210Sstevel@tonic-gate 	int	tod_day;	/* day of month 1-31 */
3220Sstevel@tonic-gate 	int	tod_month;	/* month 1-12 */
3230Sstevel@tonic-gate 	int	tod_year;	/* year 70+ */
3240Sstevel@tonic-gate } todinfo_t;
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate extern	int64_t		timedelta;
3274123Sdm120769 extern	int		timechanged;
3280Sstevel@tonic-gate extern	int		tod_needsync;
3290Sstevel@tonic-gate extern	kmutex_t	tod_lock;
3304551Ssudheer extern	volatile timestruc_t	hrestime;
3310Sstevel@tonic-gate extern	hrtime_t	hres_last_tick;
3320Sstevel@tonic-gate extern	int64_t		hrestime_adj;
3330Sstevel@tonic-gate extern	uint_t		adj_shift;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate extern	timestruc_t	tod_get(void);
3360Sstevel@tonic-gate extern	void		tod_set(timestruc_t);
3370Sstevel@tonic-gate extern	void		set_hrestime(timestruc_t *);
3380Sstevel@tonic-gate extern	todinfo_t	utc_to_tod(time_t);
3390Sstevel@tonic-gate extern	time_t		tod_to_utc(todinfo_t);
3400Sstevel@tonic-gate extern	int		hr_clock_lock(void);
3410Sstevel@tonic-gate extern	void		hr_clock_unlock(int);
3420Sstevel@tonic-gate extern	hrtime_t 	gethrtime(void);
3430Sstevel@tonic-gate extern	hrtime_t 	gethrtime_unscaled(void);
3440Sstevel@tonic-gate extern	hrtime_t	gethrtime_max(void);
3450Sstevel@tonic-gate extern	hrtime_t	gethrtime_waitfree(void);
3460Sstevel@tonic-gate extern	void		scalehrtime(hrtime_t *);
34710797SEric.Saxe@Sun.COM extern	uint64_t	unscalehrtime(hrtime_t);
3480Sstevel@tonic-gate extern	void 		gethrestime(timespec_t *);
3490Sstevel@tonic-gate extern	time_t 		gethrestime_sec(void);
3500Sstevel@tonic-gate extern	void		gethrestime_lasttick(timespec_t *);
3510Sstevel@tonic-gate extern	void		hrt2ts(hrtime_t, timestruc_t *);
3520Sstevel@tonic-gate extern	hrtime_t	ts2hrt(const timestruc_t *);
3530Sstevel@tonic-gate extern	void		hrt2tv(hrtime_t, struct timeval *);
3540Sstevel@tonic-gate extern	hrtime_t	tv2hrt(struct timeval *);
3550Sstevel@tonic-gate extern	int		itimerfix(struct timeval *, int);
3560Sstevel@tonic-gate extern	int		itimerdecr(struct itimerval *, int);
3570Sstevel@tonic-gate extern	void		timevaladd(struct timeval *, struct timeval *);
3580Sstevel@tonic-gate extern	void		timevalsub(struct timeval *, struct timeval *);
3590Sstevel@tonic-gate extern	void		timevalfix(struct timeval *);
3600Sstevel@tonic-gate extern	void		dtrace_hres_tick(void);
3610Sstevel@tonic-gate 
362*11066Srafael.vanoni@sun.com extern clock_t		ddi_get_lbolt(void);
363*11066Srafael.vanoni@sun.com extern int64_t		ddi_get_lbolt64(void);
364*11066Srafael.vanoni@sun.com 
3650Sstevel@tonic-gate #if defined(_SYSCALL32)
3660Sstevel@tonic-gate extern	void		hrt2ts32(hrtime_t, timestruc32_t *);
3670Sstevel@tonic-gate #endif
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate #endif /* _KERNEL */
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
3720Sstevel@tonic-gate #if defined(__STDC__)
3730Sstevel@tonic-gate int adjtime(struct timeval *, struct timeval *);
3740Sstevel@tonic-gate #else
3750Sstevel@tonic-gate int adjtime();
3760Sstevel@tonic-gate #endif
3770Sstevel@tonic-gate #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || \
3800Sstevel@tonic-gate 	defined(_ATFILE_SOURCE) || defined(__EXTENSIONS__)
3810Sstevel@tonic-gate #if defined(__STDC__)
3820Sstevel@tonic-gate int futimesat(int, const char *, const struct timeval *);
3830Sstevel@tonic-gate #else
3840Sstevel@tonic-gate int futimesat();
3850Sstevel@tonic-gate #endif /* defined(__STDC__) */
3860Sstevel@tonic-gate #endif /* defined(__ATFILE_SOURCE) */
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
3890Sstevel@tonic-gate 	defined(__EXTENSIONS__)
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate #if defined(__STDC__)
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate int getitimer(int, struct itimerval *);
3940Sstevel@tonic-gate int utimes(const char *, const struct timeval *);
3950Sstevel@tonic-gate #if defined(_XPG4_2)
3960Sstevel@tonic-gate int setitimer(int, const struct itimerval *_RESTRICT_KYWD,
3970Sstevel@tonic-gate 	struct itimerval *_RESTRICT_KYWD);
3980Sstevel@tonic-gate #else
3990Sstevel@tonic-gate int setitimer(int, struct itimerval *_RESTRICT_KYWD,
4000Sstevel@tonic-gate 	struct itimerval *_RESTRICT_KYWD);
4010Sstevel@tonic-gate #endif /* defined(_XPG2_2) */
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate #else /* __STDC__ */
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate int gettimer();
4060Sstevel@tonic-gate int settimer();
4070Sstevel@tonic-gate int utimes();
4080Sstevel@tonic-gate #endif /* __STDC__ */
4090Sstevel@tonic-gate #endif /* !defined(_KERNEL) ... defined(_XPG4_2) */
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate  * gettimeofday() and settimeofday() were included in SVr4 due to their
4130Sstevel@tonic-gate  * common use in BSD based applications.  They were to be included exactly
4140Sstevel@tonic-gate  * as in BSD, with two parameters.  However, AT&T/USL noted that the second
4150Sstevel@tonic-gate  * parameter was unused and deleted it, thereby making a routine included
4160Sstevel@tonic-gate  * for compatibility, incompatible.
4170Sstevel@tonic-gate  *
4180Sstevel@tonic-gate  * XSH4.2 (spec 1170) defines gettimeofday and settimeofday to have two
4190Sstevel@tonic-gate  * parameters.
4200Sstevel@tonic-gate  *
4210Sstevel@tonic-gate  * This has caused general disagreement in the application community as to
4220Sstevel@tonic-gate  * the syntax of these routines.  Solaris defaults to the XSH4.2 definition.
4230Sstevel@tonic-gate  * The flag _SVID_GETTOD may be used to force the SVID version.
4240Sstevel@tonic-gate  */
4250Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate #if defined(__STDC__)
4280Sstevel@tonic-gate #if defined(_SVID_GETTOD)
4290Sstevel@tonic-gate int settimeofday(struct timeval *);
4300Sstevel@tonic-gate #else
4310Sstevel@tonic-gate int settimeofday(struct timeval *, void *);
4320Sstevel@tonic-gate #endif
4330Sstevel@tonic-gate hrtime_t	gethrtime(void);
4340Sstevel@tonic-gate hrtime_t	gethrvtime(void);
4350Sstevel@tonic-gate #else /* __STDC__ */
4360Sstevel@tonic-gate int settimeofday();
4370Sstevel@tonic-gate hrtime_t	gethrtime();
4380Sstevel@tonic-gate hrtime_t	gethrvtime();
4390Sstevel@tonic-gate #endif /* __STDC__ */
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate #endif /* !(defined _KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
4440Sstevel@tonic-gate 	defined(__EXTENSIONS__)
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate #if defined(__STDC__)
4470Sstevel@tonic-gate #if defined(_SVID_GETTOD)
4480Sstevel@tonic-gate int gettimeofday(struct timeval *);
4490Sstevel@tonic-gate #else
4500Sstevel@tonic-gate int gettimeofday(struct timeval *_RESTRICT_KYWD, void *_RESTRICT_KYWD);
4510Sstevel@tonic-gate #endif
4520Sstevel@tonic-gate #else /* __STDC__ */
4530Sstevel@tonic-gate int gettimeofday();
4540Sstevel@tonic-gate #endif /* __STDC__ */
4550Sstevel@tonic-gate 
4560Sstevel@tonic-gate #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate /*
4590Sstevel@tonic-gate  * The inclusion of <time.h> is historical and was added for
4600Sstevel@tonic-gate  * backward compatibility in delta 1.2 when a number of definitions
4610Sstevel@tonic-gate  * were moved out of <sys/time.h>.  More recently, the timespec and
4620Sstevel@tonic-gate  * itimerspec structure definitions, along with the _CLOCK_*, CLOCK_*,
4630Sstevel@tonic-gate  * _TIMER_*, and TIMER_* symbols were moved to <sys/time_impl.h>,
4640Sstevel@tonic-gate  * which is now included by <time.h>.  This change was due to POSIX
4650Sstevel@tonic-gate  * 1003.1b-1993 and X/Open UNIX 98 requirements.  For non-POSIX and
4660Sstevel@tonic-gate  * non-X/Open applications, including this header will still make
4670Sstevel@tonic-gate  * visible these definitions.
4680Sstevel@tonic-gate  */
4693446Smrj #if !defined(_BOOT) && !defined(_KERNEL) && \
4703446Smrj 	!defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
4710Sstevel@tonic-gate #include <time.h>
4720Sstevel@tonic-gate #endif
4730Sstevel@tonic-gate 
4740Sstevel@tonic-gate /*
4750Sstevel@tonic-gate  * The inclusion of <sys/select.h> is needed for the FD_CLR,
4760Sstevel@tonic-gate  * FD_ISSET, FD_SET, and FD_SETSIZE macros as well as the
4770Sstevel@tonic-gate  * select() prototype defined in the XOpen specifications
4780Sstevel@tonic-gate  * beginning with XSH4v2.  Placement required after definition
4790Sstevel@tonic-gate  * for itimerval.
4800Sstevel@tonic-gate  */
4810Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
4820Sstevel@tonic-gate 	defined(__EXTENSIONS__)
4830Sstevel@tonic-gate #include <sys/select.h>
4840Sstevel@tonic-gate #endif
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate #endif	/* _ASM */
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate #ifdef	__cplusplus
4890Sstevel@tonic-gate }
4900Sstevel@tonic-gate #endif
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate #endif	/* _SYS_TIME_H */
493