xref: /onnv-gate/usr/src/uts/common/sys/timer.h (revision 9870:b2e907fa2ec2)
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*9870SRoger.Faulkner@Sun.COM  * Copyright 2009 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 #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/proc.h>
320Sstevel@tonic-gate #include <sys/thread.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	_KERNEL
390Sstevel@tonic-gate 
401885Sraf #define	_TIMER_MAX	32
411885Sraf extern	int	timer_max;		/* patchable via /etc/system */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * Bit values for the it_lock field.
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate #define	ITLK_LOCKED		0x01
470Sstevel@tonic-gate #define	ITLK_WANTED		0x02
480Sstevel@tonic-gate #define	ITLK_REMOVE		0x04
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * Bit values for the it_flags field.
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate #define	IT_SIGNAL		0x01
540Sstevel@tonic-gate #define	IT_PORT			0x02	/* use event port notification */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate struct clock_backend;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate typedef struct itimer {
590Sstevel@tonic-gate 	itimerspec_t	it_itime;
600Sstevel@tonic-gate 	hrtime_t	it_hrtime;
610Sstevel@tonic-gate 	ushort_t	it_flags;
620Sstevel@tonic-gate 	ushort_t	it_lock;
630Sstevel@tonic-gate 	void		*it_arg;
640Sstevel@tonic-gate 	sigqueue_t	*it_sigq;
650Sstevel@tonic-gate 	klwp_t		*it_lwp;
660Sstevel@tonic-gate 	struct proc	*it_proc;
670Sstevel@tonic-gate 	kcondvar_t	it_cv;
680Sstevel@tonic-gate 	int		it_blockers;
690Sstevel@tonic-gate 	int		it_pending;
700Sstevel@tonic-gate 	int		it_overrun;
710Sstevel@tonic-gate 	struct clock_backend *it_backend;
720Sstevel@tonic-gate 	kmutex_t	it_mutex;
730Sstevel@tonic-gate 	void		*it_portev;	/* port_kevent_t pointer */
740Sstevel@tonic-gate 	void		*it_portsrc;	/* port_source_t pointer */
750Sstevel@tonic-gate 	int		it_portfd;	/* port file descriptor */
760Sstevel@tonic-gate } itimer_t;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate typedef struct clock_backend {
790Sstevel@tonic-gate 	struct sigevent clk_default;
800Sstevel@tonic-gate 	int (*clk_clock_settime)(timespec_t *);
810Sstevel@tonic-gate 	int (*clk_clock_gettime)(timespec_t *);
820Sstevel@tonic-gate 	int (*clk_clock_getres)(timespec_t *);
830Sstevel@tonic-gate 	int (*clk_timer_create)(itimer_t *, struct sigevent *);
840Sstevel@tonic-gate 	int (*clk_timer_settime)(itimer_t *, int, const struct itimerspec *);
850Sstevel@tonic-gate 	int (*clk_timer_gettime)(itimer_t *, struct itimerspec *);
860Sstevel@tonic-gate 	int (*clk_timer_delete)(itimer_t *);
870Sstevel@tonic-gate 	void (*clk_timer_lwpbind)(itimer_t *);
880Sstevel@tonic-gate } clock_backend_t;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate extern void clock_add_backend(clockid_t clock, clock_backend_t *backend);
910Sstevel@tonic-gate 
920Sstevel@tonic-gate extern void timer_fire(itimer_t *);
930Sstevel@tonic-gate extern void timer_lwpbind();
940Sstevel@tonic-gate 
950Sstevel@tonic-gate extern	void	timer_func(sigqueue_t *);
960Sstevel@tonic-gate extern	void	timer_exit(void);
970Sstevel@tonic-gate extern	void	timer_lwpexit(void);
980Sstevel@tonic-gate extern	clock_t	hzto(struct timeval *);
990Sstevel@tonic-gate extern	clock_t	timespectohz(timespec_t *, timespec_t);
1006422Sqiao extern	int64_t	timespectohz64(timespec_t *);
1010Sstevel@tonic-gate extern	int	itimerspecfix(timespec_t *);
1020Sstevel@tonic-gate extern	void	timespecadd(timespec_t *, timespec_t *);
1030Sstevel@tonic-gate extern	void	timespecsub(timespec_t *, timespec_t *);
1040Sstevel@tonic-gate extern	void	timespecfix(timespec_t *);
1050Sstevel@tonic-gate extern	int	xgetitimer(uint_t, struct itimerval *, int);
1060Sstevel@tonic-gate extern	int	xsetitimer(uint_t, struct itimerval *, int);
107*9870SRoger.Faulkner@Sun.COM extern	void	delete_itimer_realprof(void);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate #define	timerspecisset(tvp)		((tvp)->tv_sec || (tvp)->tv_nsec)
1100Sstevel@tonic-gate #define	timerspeccmp(tvp, uvp)		(((tvp)->tv_sec - (uvp)->tv_sec) ? \
1110Sstevel@tonic-gate 	((tvp)->tv_sec - (uvp)->tv_sec):((tvp)->tv_nsec - (uvp)->tv_nsec))
1120Sstevel@tonic-gate #define	timerspecclear(tvp)		((tvp)->tv_sec = (tvp)->tv_nsec = 0)
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate struct oldsigevent {
1150Sstevel@tonic-gate 	/* structure definition prior to notification attributes member */
1160Sstevel@tonic-gate 	int		_notify;
1170Sstevel@tonic-gate 	union {
1180Sstevel@tonic-gate 		int		_signo;
1190Sstevel@tonic-gate 		void		(*_notify_function)(union sigval);
1200Sstevel@tonic-gate 	} _un;
1210Sstevel@tonic-gate 	union sigval	_value;
1220Sstevel@tonic-gate };
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #if defined(_SYSCALL32)
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate struct oldsigevent32 {
1270Sstevel@tonic-gate 	int32_t		_notify;
1280Sstevel@tonic-gate 	union {
1290Sstevel@tonic-gate 		int32_t		_signo;
1300Sstevel@tonic-gate 		caddr32_t	_notify_function;
1310Sstevel@tonic-gate 	} _un;
1320Sstevel@tonic-gate 	union sigval32	_value;
1330Sstevel@tonic-gate };
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1360Sstevel@tonic-gate #endif	/* _KERNEL */
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate #ifdef	__cplusplus
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate #endif
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #endif	/* _SYS_TIMER_H */
143