xref: /onnv-gate/usr/src/uts/common/sys/timer.h (revision 6422:d51a10d738ba)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51885Sraf  * Common Development and Distribution License (the "License").
61885Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211885Sraf 
220Sstevel@tonic-gate /*
23*6422Sqiao  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_TIMER_H
280Sstevel@tonic-gate #define	_SYS_TIMER_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/proc.h>
340Sstevel@tonic-gate #include <sys/thread.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	_KERNEL
410Sstevel@tonic-gate 
421885Sraf #define	_TIMER_MAX	32
431885Sraf extern	int	timer_max;		/* patchable via /etc/system */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * Bit values for the it_lock field.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate #define	ITLK_LOCKED		0x01
490Sstevel@tonic-gate #define	ITLK_WANTED		0x02
500Sstevel@tonic-gate #define	ITLK_REMOVE		0x04
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * Bit values for the it_flags field.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate #define	IT_SIGNAL		0x01
560Sstevel@tonic-gate #define	IT_PORT			0x02	/* use event port notification */
570Sstevel@tonic-gate 
580Sstevel@tonic-gate struct clock_backend;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate typedef struct itimer {
610Sstevel@tonic-gate 	itimerspec_t	it_itime;
620Sstevel@tonic-gate 	hrtime_t	it_hrtime;
630Sstevel@tonic-gate 	ushort_t	it_flags;
640Sstevel@tonic-gate 	ushort_t	it_lock;
650Sstevel@tonic-gate 	void		*it_arg;
660Sstevel@tonic-gate 	sigqueue_t	*it_sigq;
670Sstevel@tonic-gate 	klwp_t		*it_lwp;
680Sstevel@tonic-gate 	struct proc	*it_proc;
690Sstevel@tonic-gate 	kcondvar_t	it_cv;
700Sstevel@tonic-gate 	int		it_blockers;
710Sstevel@tonic-gate 	int		it_pending;
720Sstevel@tonic-gate 	int		it_overrun;
730Sstevel@tonic-gate 	struct clock_backend *it_backend;
740Sstevel@tonic-gate 	kmutex_t	it_mutex;
750Sstevel@tonic-gate 	void		*it_portev;	/* port_kevent_t pointer */
760Sstevel@tonic-gate 	void		*it_portsrc;	/* port_source_t pointer */
770Sstevel@tonic-gate 	int		it_portfd;	/* port file descriptor */
780Sstevel@tonic-gate } itimer_t;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate typedef struct clock_backend {
810Sstevel@tonic-gate 	struct sigevent clk_default;
820Sstevel@tonic-gate 	int (*clk_clock_settime)(timespec_t *);
830Sstevel@tonic-gate 	int (*clk_clock_gettime)(timespec_t *);
840Sstevel@tonic-gate 	int (*clk_clock_getres)(timespec_t *);
850Sstevel@tonic-gate 	int (*clk_timer_create)(itimer_t *, struct sigevent *);
860Sstevel@tonic-gate 	int (*clk_timer_settime)(itimer_t *, int, const struct itimerspec *);
870Sstevel@tonic-gate 	int (*clk_timer_gettime)(itimer_t *, struct itimerspec *);
880Sstevel@tonic-gate 	int (*clk_timer_delete)(itimer_t *);
890Sstevel@tonic-gate 	void (*clk_timer_lwpbind)(itimer_t *);
900Sstevel@tonic-gate } clock_backend_t;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate extern void clock_add_backend(clockid_t clock, clock_backend_t *backend);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate extern void timer_fire(itimer_t *);
950Sstevel@tonic-gate extern void timer_lwpbind();
960Sstevel@tonic-gate 
970Sstevel@tonic-gate extern	void	timer_func(sigqueue_t *);
980Sstevel@tonic-gate extern	void	timer_exit(void);
990Sstevel@tonic-gate extern	void	timer_lwpexit(void);
1000Sstevel@tonic-gate extern	clock_t	hzto(struct timeval *);
1010Sstevel@tonic-gate extern	clock_t	timespectohz(timespec_t *, timespec_t);
102*6422Sqiao extern	int64_t	timespectohz64(timespec_t *);
1030Sstevel@tonic-gate extern	int	itimerspecfix(timespec_t *);
1040Sstevel@tonic-gate extern	void	timespecadd(timespec_t *, timespec_t *);
1050Sstevel@tonic-gate extern	void	timespecsub(timespec_t *, timespec_t *);
1060Sstevel@tonic-gate extern	void	timespecfix(timespec_t *);
1070Sstevel@tonic-gate extern	int	xgetitimer(uint_t, struct itimerval *, int);
1080Sstevel@tonic-gate extern	int	xsetitimer(uint_t, struct itimerval *, int);
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate #define	timerspecisset(tvp)		((tvp)->tv_sec || (tvp)->tv_nsec)
1110Sstevel@tonic-gate #define	timerspeccmp(tvp, uvp)		(((tvp)->tv_sec - (uvp)->tv_sec) ? \
1120Sstevel@tonic-gate 	((tvp)->tv_sec - (uvp)->tv_sec):((tvp)->tv_nsec - (uvp)->tv_nsec))
1130Sstevel@tonic-gate #define	timerspecclear(tvp)		((tvp)->tv_sec = (tvp)->tv_nsec = 0)
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate struct oldsigevent {
1160Sstevel@tonic-gate 	/* structure definition prior to notification attributes member */
1170Sstevel@tonic-gate 	int		_notify;
1180Sstevel@tonic-gate 	union {
1190Sstevel@tonic-gate 		int		_signo;
1200Sstevel@tonic-gate 		void		(*_notify_function)(union sigval);
1210Sstevel@tonic-gate 	} _un;
1220Sstevel@tonic-gate 	union sigval	_value;
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #if defined(_SYSCALL32)
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate struct oldsigevent32 {
1280Sstevel@tonic-gate 	int32_t		_notify;
1290Sstevel@tonic-gate 	union {
1300Sstevel@tonic-gate 		int32_t		_signo;
1310Sstevel@tonic-gate 		caddr32_t	_notify_function;
1320Sstevel@tonic-gate 	} _un;
1330Sstevel@tonic-gate 	union sigval32	_value;
1340Sstevel@tonic-gate };
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1370Sstevel@tonic-gate #endif	/* _KERNEL */
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate #ifdef	__cplusplus
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate #endif
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #endif	/* _SYS_TIMER_H */
144