xref: /illumos-gate/usr/src/uts/common/sys/time.h (revision ae115bc7)
17c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate 
57c478bd9Sstevel@tonic-gate /*
67c478bd9Sstevel@tonic-gate  * Copyright (c) 1982, 1986 Regents of the University of California.
77c478bd9Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
87c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
97c478bd9Sstevel@tonic-gate  */
107c478bd9Sstevel@tonic-gate 
117c478bd9Sstevel@tonic-gate /*
12*ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
137c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
147c478bd9Sstevel@tonic-gate  */
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #ifndef _SYS_TIME_H
177c478bd9Sstevel@tonic-gate #define	_SYS_TIME_H
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.16	*/
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
247c478bd9Sstevel@tonic-gate  * Structure returned by gettimeofday(2) system call,
257c478bd9Sstevel@tonic-gate  * and used in other calls.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
337c478bd9Sstevel@tonic-gate 	defined(__EXTENSIONS__)
347c478bd9Sstevel@tonic-gate #ifndef	_ASM
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #if !defined(_TIME_T) || __cplusplus >= 199711L
377c478bd9Sstevel@tonic-gate #define	_TIME_T
387c478bd9Sstevel@tonic-gate typedef	long	time_t;		/* time of day in seconds */
397c478bd9Sstevel@tonic-gate #endif	/* _TIME_T */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifndef	_SUSECONDS_T
427c478bd9Sstevel@tonic-gate #define	_SUSECONDS_T
437c478bd9Sstevel@tonic-gate typedef	long	suseconds_t;	/* signed # of microseconds */
447c478bd9Sstevel@tonic-gate #endif	/* _SUSECONDS_T */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate struct timeval {
477c478bd9Sstevel@tonic-gate 	time_t		tv_sec;		/* seconds */
487c478bd9Sstevel@tonic-gate 	suseconds_t	tv_usec;	/* and microseconds */
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #include <sys/types32.h>
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	TIMEVAL32_TO_TIMEVAL(tv, tv32)	{	\
567c478bd9Sstevel@tonic-gate 	(tv)->tv_sec = (time_t)(tv32)->tv_sec;	\
577c478bd9Sstevel@tonic-gate 	(tv)->tv_usec = (tv32)->tv_usec;	\
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	TIMEVAL_TO_TIMEVAL32(tv32, tv)	{		\
617c478bd9Sstevel@tonic-gate 	(tv32)->tv_sec = (time32_t)(tv)->tv_sec;	\
627c478bd9Sstevel@tonic-gate 	(tv32)->tv_usec = (tv)->tv_usec;		\
637c478bd9Sstevel@tonic-gate }
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define	TIME32_MAX	INT32_MAX
667c478bd9Sstevel@tonic-gate #define	TIME32_MIN	INT32_MIN
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	TIMEVAL_OVERFLOW(tv)	\
697c478bd9Sstevel@tonic-gate 	((tv)->tv_sec < TIME32_MIN || (tv)->tv_sec > TIME32_MAX)
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 || _KERNEL */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #endif	/* _ASM */
747c478bd9Sstevel@tonic-gate #endif	/* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
777c478bd9Sstevel@tonic-gate #ifndef	_ASM
787c478bd9Sstevel@tonic-gate struct timezone {
797c478bd9Sstevel@tonic-gate 	int	tz_minuteswest;	/* minutes west of Greenwich */
807c478bd9Sstevel@tonic-gate 	int	tz_dsttime;	/* type of dst correction */
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #endif	/* _ASM */
847c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate #endif
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Needed for longlong_t type.  Placement of this due to <sys/types.h>
927c478bd9Sstevel@tonic-gate  * including <sys/select.h> which relies on the presense of the itimerval
937c478bd9Sstevel@tonic-gate  * structure.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #ifndef	_ASM
967c478bd9Sstevel@tonic-gate #include <sys/types.h>
977c478bd9Sstevel@tonic-gate #endif	/* _ASM */
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1007c478bd9Sstevel@tonic-gate extern "C" {
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #define	DST_NONE	0	/* not on dst */
1067c478bd9Sstevel@tonic-gate #define	DST_USA		1	/* USA style dst */
1077c478bd9Sstevel@tonic-gate #define	DST_AUST	2	/* Australian style dst */
1087c478bd9Sstevel@tonic-gate #define	DST_WET		3	/* Western European dst */
1097c478bd9Sstevel@tonic-gate #define	DST_MET		4	/* Middle European dst */
1107c478bd9Sstevel@tonic-gate #define	DST_EET		5	/* Eastern European dst */
1117c478bd9Sstevel@tonic-gate #define	DST_CAN		6	/* Canada */
1127c478bd9Sstevel@tonic-gate #define	DST_GB		7	/* Great Britain and Eire */
1137c478bd9Sstevel@tonic-gate #define	DST_RUM		8	/* Rumania */
1147c478bd9Sstevel@tonic-gate #define	DST_TUR		9	/* Turkey */
1157c478bd9Sstevel@tonic-gate #define	DST_AUSTALT	10	/* Australian style with shift in 1986 */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Operations on timevals.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate #define	timerisset(tvp)		((tvp)->tv_sec || (tvp)->tv_usec)
1217c478bd9Sstevel@tonic-gate #define	timercmp(tvp, uvp, cmp) \
1227c478bd9Sstevel@tonic-gate 	(((tvp)->tv_sec == (uvp)->tv_sec) ? \
1237c478bd9Sstevel@tonic-gate 	    /* CSTYLED */ \
1247c478bd9Sstevel@tonic-gate 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1257c478bd9Sstevel@tonic-gate 	    /* CSTYLED */ \
1267c478bd9Sstevel@tonic-gate 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #define	timerclear(tvp)		(tvp)->tv_sec = (tvp)->tv_usec = 0
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Names of the interval timers, and structure
1357c478bd9Sstevel@tonic-gate  * defining a timer setting.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate #define	ITIMER_REAL	0	/* Decrements in real time */
1387c478bd9Sstevel@tonic-gate #define	ITIMER_VIRTUAL	1	/* Decrements in process virtual time */
1397c478bd9Sstevel@tonic-gate #define	ITIMER_PROF	2	/* Decrements both in process virtual */
1407c478bd9Sstevel@tonic-gate 				/* time and when system is running on */
1417c478bd9Sstevel@tonic-gate 				/* behalf of the process. */
1427c478bd9Sstevel@tonic-gate #define	ITIMER_REALPROF	3	/* Decrements in real time for real- */
1437c478bd9Sstevel@tonic-gate 				/* time profiling of multithreaded */
1447c478bd9Sstevel@tonic-gate 				/* programs. */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #ifndef	_ASM
1477c478bd9Sstevel@tonic-gate struct	itimerval {
1487c478bd9Sstevel@tonic-gate 	struct	timeval it_interval;	/* timer interval */
1497c478bd9Sstevel@tonic-gate 	struct	timeval it_value;	/* current value */
1507c478bd9Sstevel@tonic-gate };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate struct itimerval32 {
1557c478bd9Sstevel@tonic-gate 	struct	timeval32 it_interval;
1567c478bd9Sstevel@tonic-gate 	struct	timeval32 it_value;
1577c478bd9Sstevel@tonic-gate };
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #define	ITIMERVAL32_TO_ITIMERVAL(itv, itv32)	{	\
1607c478bd9Sstevel@tonic-gate 	TIMEVAL32_TO_TIMEVAL(&(itv)->it_interval, &(itv32)->it_interval); \
1617c478bd9Sstevel@tonic-gate 	TIMEVAL32_TO_TIMEVAL(&(itv)->it_value, &(itv32)->it_value);	\
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #define	ITIMERVAL_TO_ITIMERVAL32(itv32, itv)	{	\
1657c478bd9Sstevel@tonic-gate 	TIMEVAL_TO_TIMEVAL32(&(itv32)->it_interval, &(itv)->it_interval); \
1667c478bd9Sstevel@tonic-gate 	TIMEVAL_TO_TIMEVAL32(&(itv32)->it_value, &(itv)->it_value);	\
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define	ITIMERVAL_OVERFLOW(itv)				\
1707c478bd9Sstevel@tonic-gate 	(TIMEVAL_OVERFLOW(&(itv)->it_interval) ||	\
1717c478bd9Sstevel@tonic-gate 	TIMEVAL_OVERFLOW(&(itv)->it_value))
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1747c478bd9Sstevel@tonic-gate #endif	/* _ASM */
1757c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  *	Definitions for commonly used resolutions.
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate #define	SEC		1
1837c478bd9Sstevel@tonic-gate #define	MILLISEC	1000
1847c478bd9Sstevel@tonic-gate #define	MICROSEC	1000000
1857c478bd9Sstevel@tonic-gate #define	NANOSEC		1000000000
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #ifndef	_ASM
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * Time expressed as a 64-bit nanosecond counter.
1937c478bd9Sstevel@tonic-gate  */
1947c478bd9Sstevel@tonic-gate typedef	longlong_t	hrtime_t;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate #include <sys/time_impl.h>
1997c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate extern int tick_per_msec;	/* clock ticks per millisecond (may be zero) */
2027c478bd9Sstevel@tonic-gate extern int msec_per_tick;	/* milliseconds per clock tick (may be zero) */
2037c478bd9Sstevel@tonic-gate extern int usec_per_tick;	/* microseconds per clock tick */
2047c478bd9Sstevel@tonic-gate extern int nsec_per_tick;	/* nanoseconds per clock tick */
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Macros to convert from common units of time (sec, msec, usec, nsec,
2087c478bd9Sstevel@tonic-gate  * timeval, timestruc) to clock ticks and vice versa.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate #define	TICK_TO_SEC(tick)	((tick) / hz)
2117c478bd9Sstevel@tonic-gate #define	SEC_TO_TICK(sec)	((sec) * hz)
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate #define	TICK_TO_MSEC(tick)	\
2147c478bd9Sstevel@tonic-gate 	(msec_per_tick ? (tick) * msec_per_tick : (tick) / tick_per_msec)
2157c478bd9Sstevel@tonic-gate #define	MSEC_TO_TICK(msec)	\
2167c478bd9Sstevel@tonic-gate 	(msec_per_tick ? (msec) / msec_per_tick : (msec) * tick_per_msec)
2177c478bd9Sstevel@tonic-gate #define	MSEC_TO_TICK_ROUNDUP(msec)	\
2187c478bd9Sstevel@tonic-gate 	(msec_per_tick ? \
2197c478bd9Sstevel@tonic-gate 	((msec) == 0 ? 0 : ((msec) - 1) / msec_per_tick + 1) : \
2207c478bd9Sstevel@tonic-gate 	(msec) * tick_per_msec)
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate #define	TICK_TO_USEC(tick)		((tick) * usec_per_tick)
2237c478bd9Sstevel@tonic-gate #define	USEC_TO_TICK(usec)		((usec) / usec_per_tick)
2247c478bd9Sstevel@tonic-gate #define	USEC_TO_TICK_ROUNDUP(usec)	\
2257c478bd9Sstevel@tonic-gate 	((usec) == 0 ? 0 : USEC_TO_TICK((usec) - 1) + 1)
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #define	TICK_TO_NSEC(tick)		((tick) * nsec_per_tick)
2287c478bd9Sstevel@tonic-gate #define	NSEC_TO_TICK(nsec)		((nsec) / nsec_per_tick)
2297c478bd9Sstevel@tonic-gate #define	NSEC_TO_TICK_ROUNDUP(nsec)	\
2307c478bd9Sstevel@tonic-gate 	((nsec) == 0 ? 0 : NSEC_TO_TICK((nsec) - 1) + 1)
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #define	TICK_TO_TIMEVAL(tick, tvp) {	\
2337c478bd9Sstevel@tonic-gate 	clock_t __tmptck = (tick);	\
2347c478bd9Sstevel@tonic-gate 	(tvp)->tv_sec = TICK_TO_SEC(__tmptck);	\
2357c478bd9Sstevel@tonic-gate 	(tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK((tvp)->tv_sec)); \
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate #define	TICK_TO_TIMEVAL32(tick, tvp) {	\
2397c478bd9Sstevel@tonic-gate 	clock_t __tmptck = (tick);	\
2407c478bd9Sstevel@tonic-gate 	time_t __tmptm = TICK_TO_SEC(__tmptck);	\
2417c478bd9Sstevel@tonic-gate 	(tvp)->tv_sec = (time32_t)__tmptm;	\
2427c478bd9Sstevel@tonic-gate 	(tvp)->tv_usec = TICK_TO_USEC(__tmptck - SEC_TO_TICK(__tmptm)); \
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate #define	TICK_TO_TIMESTRUC(tick, tsp) {	\
2467c478bd9Sstevel@tonic-gate 	clock_t __tmptck = (tick);	\
2477c478bd9Sstevel@tonic-gate 	(tsp)->tv_sec = TICK_TO_SEC(__tmptck);	\
2487c478bd9Sstevel@tonic-gate 	(tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK((tsp)->tv_sec)); \
2497c478bd9Sstevel@tonic-gate }
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate #define	TICK_TO_TIMESTRUC32(tick, tsp) {	\
2527c478bd9Sstevel@tonic-gate 	clock_t __tmptck = (tick);			\
2537c478bd9Sstevel@tonic-gate 	time_t __tmptm = TICK_TO_SEC(__tmptck);		\
2547c478bd9Sstevel@tonic-gate 	(tsp)->tv_sec = (time32_t)__tmptm;		\
2557c478bd9Sstevel@tonic-gate 	(tsp)->tv_nsec = TICK_TO_NSEC(__tmptck - SEC_TO_TICK(__tmptm));	\
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate #define	TIMEVAL_TO_TICK(tvp)	\
2597c478bd9Sstevel@tonic-gate 	(SEC_TO_TICK((tvp)->tv_sec) + USEC_TO_TICK((tvp)->tv_usec))
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #define	TIMESTRUC_TO_TICK(tsp)	\
2627c478bd9Sstevel@tonic-gate 	(SEC_TO_TICK((tsp)->tv_sec) + NSEC_TO_TICK((tsp)->tv_nsec))
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate typedef struct todinfo {
2657c478bd9Sstevel@tonic-gate 	int	tod_sec;	/* seconds 0-59 */
2667c478bd9Sstevel@tonic-gate 	int	tod_min;	/* minutes 0-59 */
2677c478bd9Sstevel@tonic-gate 	int	tod_hour;	/* hours 0-23 */
2687c478bd9Sstevel@tonic-gate 	int	tod_dow;	/* day of week 1-7 */
2697c478bd9Sstevel@tonic-gate 	int	tod_day;	/* day of month 1-31 */
2707c478bd9Sstevel@tonic-gate 	int	tod_month;	/* month 1-12 */
2717c478bd9Sstevel@tonic-gate 	int	tod_year;	/* year 70+ */
2727c478bd9Sstevel@tonic-gate } todinfo_t;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate extern	int64_t		timedelta;
2757c478bd9Sstevel@tonic-gate extern	int		timechanged;
2767c478bd9Sstevel@tonic-gate extern	int		tod_needsync;
2777c478bd9Sstevel@tonic-gate extern	kmutex_t	tod_lock;
2787c478bd9Sstevel@tonic-gate extern	timestruc_t	hrestime;
2797c478bd9Sstevel@tonic-gate extern	hrtime_t	hres_last_tick;
2807c478bd9Sstevel@tonic-gate extern	int64_t		hrestime_adj;
2817c478bd9Sstevel@tonic-gate extern	uint_t		adj_shift;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate extern	timestruc_t	tod_get(void);
2847c478bd9Sstevel@tonic-gate extern	void		tod_set(timestruc_t);
2857c478bd9Sstevel@tonic-gate extern	void		set_hrestime(timestruc_t *);
2867c478bd9Sstevel@tonic-gate extern	todinfo_t	utc_to_tod(time_t);
2877c478bd9Sstevel@tonic-gate extern	time_t		tod_to_utc(todinfo_t);
2887c478bd9Sstevel@tonic-gate extern	int		hr_clock_lock(void);
2897c478bd9Sstevel@tonic-gate extern	void		hr_clock_unlock(int);
2907c478bd9Sstevel@tonic-gate extern	hrtime_t 	gethrtime(void);
2917c478bd9Sstevel@tonic-gate extern	hrtime_t 	gethrtime_unscaled(void);
2927c478bd9Sstevel@tonic-gate extern	hrtime_t	gethrtime_max(void);
2937c478bd9Sstevel@tonic-gate extern	hrtime_t	gethrtime_waitfree(void);
2947c478bd9Sstevel@tonic-gate extern	void		scalehrtime(hrtime_t *);
2957c478bd9Sstevel@tonic-gate extern  uint64_t	unscalehrtime(hrtime_t);
2967c478bd9Sstevel@tonic-gate extern	void 		gethrestime(timespec_t *);
2977c478bd9Sstevel@tonic-gate extern	time_t 		gethrestime_sec(void);
2987c478bd9Sstevel@tonic-gate extern	void		gethrestime_lasttick(timespec_t *);
2997c478bd9Sstevel@tonic-gate extern	void		hrt2ts(hrtime_t, timestruc_t *);
3007c478bd9Sstevel@tonic-gate extern	hrtime_t	ts2hrt(const timestruc_t *);
3017c478bd9Sstevel@tonic-gate extern	void		hrt2tv(hrtime_t, struct timeval *);
3027c478bd9Sstevel@tonic-gate extern	hrtime_t	tv2hrt(struct timeval *);
3037c478bd9Sstevel@tonic-gate extern	int		itimerfix(struct timeval *, int);
3047c478bd9Sstevel@tonic-gate extern	int		itimerdecr(struct itimerval *, int);
3057c478bd9Sstevel@tonic-gate extern	void		timevaladd(struct timeval *, struct timeval *);
3067c478bd9Sstevel@tonic-gate extern	void		timevalsub(struct timeval *, struct timeval *);
3077c478bd9Sstevel@tonic-gate extern	void		timevalfix(struct timeval *);
3087c478bd9Sstevel@tonic-gate extern	void		dtrace_hres_tick(void);
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
3117c478bd9Sstevel@tonic-gate extern	void		hrt2ts32(hrtime_t, timestruc32_t *);
3127c478bd9Sstevel@tonic-gate #endif
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
3177c478bd9Sstevel@tonic-gate #if defined(__STDC__)
3187c478bd9Sstevel@tonic-gate int adjtime(struct timeval *, struct timeval *);
3197c478bd9Sstevel@tonic-gate #else
3207c478bd9Sstevel@tonic-gate int adjtime();
3217c478bd9Sstevel@tonic-gate #endif
3227c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || \
3257c478bd9Sstevel@tonic-gate 	defined(_ATFILE_SOURCE) || defined(__EXTENSIONS__)
3267c478bd9Sstevel@tonic-gate #if defined(__STDC__)
3277c478bd9Sstevel@tonic-gate int futimesat(int, const char *, const struct timeval *);
3287c478bd9Sstevel@tonic-gate #else
3297c478bd9Sstevel@tonic-gate int futimesat();
3307c478bd9Sstevel@tonic-gate #endif /* defined(__STDC__) */
3317c478bd9Sstevel@tonic-gate #endif /* defined(__ATFILE_SOURCE) */
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
3347c478bd9Sstevel@tonic-gate 	defined(__EXTENSIONS__)
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate #if defined(__STDC__)
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate int getitimer(int, struct itimerval *);
3397c478bd9Sstevel@tonic-gate int utimes(const char *, const struct timeval *);
3407c478bd9Sstevel@tonic-gate #if defined(_XPG4_2)
3417c478bd9Sstevel@tonic-gate int setitimer(int, const struct itimerval *_RESTRICT_KYWD,
3427c478bd9Sstevel@tonic-gate 	struct itimerval *_RESTRICT_KYWD);
3437c478bd9Sstevel@tonic-gate #else
3447c478bd9Sstevel@tonic-gate int setitimer(int, struct itimerval *_RESTRICT_KYWD,
3457c478bd9Sstevel@tonic-gate 	struct itimerval *_RESTRICT_KYWD);
3467c478bd9Sstevel@tonic-gate #endif /* defined(_XPG2_2) */
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate #else /* __STDC__ */
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate int gettimer();
3517c478bd9Sstevel@tonic-gate int settimer();
3527c478bd9Sstevel@tonic-gate int utimes();
3537c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
3547c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) ... defined(_XPG4_2) */
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate /*
3577c478bd9Sstevel@tonic-gate  * gettimeofday() and settimeofday() were included in SVr4 due to their
3587c478bd9Sstevel@tonic-gate  * common use in BSD based applications.  They were to be included exactly
3597c478bd9Sstevel@tonic-gate  * as in BSD, with two parameters.  However, AT&T/USL noted that the second
3607c478bd9Sstevel@tonic-gate  * parameter was unused and deleted it, thereby making a routine included
3617c478bd9Sstevel@tonic-gate  * for compatibility, incompatible.
3627c478bd9Sstevel@tonic-gate  *
3637c478bd9Sstevel@tonic-gate  * XSH4.2 (spec 1170) defines gettimeofday and settimeofday to have two
3647c478bd9Sstevel@tonic-gate  * parameters.
3657c478bd9Sstevel@tonic-gate  *
3667c478bd9Sstevel@tonic-gate  * This has caused general disagreement in the application community as to
3677c478bd9Sstevel@tonic-gate  * the syntax of these routines.  Solaris defaults to the XSH4.2 definition.
3687c478bd9Sstevel@tonic-gate  * The flag _SVID_GETTOD may be used to force the SVID version.
3697c478bd9Sstevel@tonic-gate  */
3707c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate #if defined(__STDC__)
3737c478bd9Sstevel@tonic-gate #if defined(_SVID_GETTOD)
3747c478bd9Sstevel@tonic-gate int settimeofday(struct timeval *);
3757c478bd9Sstevel@tonic-gate #else
3767c478bd9Sstevel@tonic-gate int settimeofday(struct timeval *, void *);
3777c478bd9Sstevel@tonic-gate #endif
3787c478bd9Sstevel@tonic-gate hrtime_t	gethrtime(void);
3797c478bd9Sstevel@tonic-gate hrtime_t	gethrvtime(void);
3807c478bd9Sstevel@tonic-gate #else /* __STDC__ */
3817c478bd9Sstevel@tonic-gate int settimeofday();
3827c478bd9Sstevel@tonic-gate hrtime_t	gethrtime();
3837c478bd9Sstevel@tonic-gate hrtime_t	gethrvtime();
3847c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate #endif /* !(defined _KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
3897c478bd9Sstevel@tonic-gate 	defined(__EXTENSIONS__)
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate #if defined(__STDC__)
3927c478bd9Sstevel@tonic-gate #if defined(_SVID_GETTOD)
3937c478bd9Sstevel@tonic-gate int gettimeofday(struct timeval *);
3947c478bd9Sstevel@tonic-gate #else
3957c478bd9Sstevel@tonic-gate int gettimeofday(struct timeval *_RESTRICT_KYWD, void *_RESTRICT_KYWD);
3967c478bd9Sstevel@tonic-gate #endif
3977c478bd9Sstevel@tonic-gate #else /* __STDC__ */
3987c478bd9Sstevel@tonic-gate int gettimeofday();
3997c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate #endif /* !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) ... */
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate /*
4047c478bd9Sstevel@tonic-gate  * The inclusion of <time.h> is historical and was added for
4057c478bd9Sstevel@tonic-gate  * backward compatibility in delta 1.2 when a number of definitions
4067c478bd9Sstevel@tonic-gate  * were moved out of <sys/time.h>.  More recently, the timespec and
4077c478bd9Sstevel@tonic-gate  * itimerspec structure definitions, along with the _CLOCK_*, CLOCK_*,
4087c478bd9Sstevel@tonic-gate  * _TIMER_*, and TIMER_* symbols were moved to <sys/time_impl.h>,
4097c478bd9Sstevel@tonic-gate  * which is now included by <time.h>.  This change was due to POSIX
4107c478bd9Sstevel@tonic-gate  * 1003.1b-1993 and X/Open UNIX 98 requirements.  For non-POSIX and
4117c478bd9Sstevel@tonic-gate  * non-X/Open applications, including this header will still make
4127c478bd9Sstevel@tonic-gate  * visible these definitions.
4137c478bd9Sstevel@tonic-gate  */
414*ae115bc7Smrj #if !defined(_BOOT) && !defined(_KERNEL) && \
415*ae115bc7Smrj 	!defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
4167c478bd9Sstevel@tonic-gate #include <time.h>
4177c478bd9Sstevel@tonic-gate #endif
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate /*
4207c478bd9Sstevel@tonic-gate  * The inclusion of <sys/select.h> is needed for the FD_CLR,
4217c478bd9Sstevel@tonic-gate  * FD_ISSET, FD_SET, and FD_SETSIZE macros as well as the
4227c478bd9Sstevel@tonic-gate  * select() prototype defined in the XOpen specifications
4237c478bd9Sstevel@tonic-gate  * beginning with XSH4v2.  Placement required after definition
4247c478bd9Sstevel@tonic-gate  * for itimerval.
4257c478bd9Sstevel@tonic-gate  */
4267c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) && !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
4277c478bd9Sstevel@tonic-gate 	defined(__EXTENSIONS__)
4287c478bd9Sstevel@tonic-gate #include <sys/select.h>
4297c478bd9Sstevel@tonic-gate #endif
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate #endif	/* _ASM */
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate #endif
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate #endif	/* _SYS_TIME_H */
438