xref: /titanic_52/usr/src/uts/common/sys/timer.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_SYS_TIMER_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_TIMER_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/proc.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
37*7c478bd9Sstevel@tonic-gate extern "C" {
38*7c478bd9Sstevel@tonic-gate #endif
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #define	_TIMER_MAX 32
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * Bit values for the it_lock field.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate #define	ITLK_LOCKED		0x01
48*7c478bd9Sstevel@tonic-gate #define	ITLK_WANTED		0x02
49*7c478bd9Sstevel@tonic-gate #define	ITLK_REMOVE		0x04
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate  * Bit values for the it_flags field.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate #define	IT_SIGNAL		0x01
55*7c478bd9Sstevel@tonic-gate #define	IT_PORT			0x02	/* use event port notification */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate struct clock_backend;
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate typedef struct itimer {
60*7c478bd9Sstevel@tonic-gate 	itimerspec_t	it_itime;
61*7c478bd9Sstevel@tonic-gate 	hrtime_t	it_hrtime;
62*7c478bd9Sstevel@tonic-gate 	ushort_t	it_flags;
63*7c478bd9Sstevel@tonic-gate 	ushort_t	it_lock;
64*7c478bd9Sstevel@tonic-gate 	void		*it_arg;
65*7c478bd9Sstevel@tonic-gate 	sigqueue_t	*it_sigq;
66*7c478bd9Sstevel@tonic-gate 	klwp_t		*it_lwp;
67*7c478bd9Sstevel@tonic-gate 	struct proc	*it_proc;
68*7c478bd9Sstevel@tonic-gate 	kcondvar_t	it_cv;
69*7c478bd9Sstevel@tonic-gate 	int		it_blockers;
70*7c478bd9Sstevel@tonic-gate 	int		it_pending;
71*7c478bd9Sstevel@tonic-gate 	int		it_overrun;
72*7c478bd9Sstevel@tonic-gate 	struct clock_backend *it_backend;
73*7c478bd9Sstevel@tonic-gate 	kmutex_t	it_mutex;
74*7c478bd9Sstevel@tonic-gate 	void		*it_portev;	/* port_kevent_t pointer */
75*7c478bd9Sstevel@tonic-gate 	void		*it_portsrc;	/* port_source_t pointer */
76*7c478bd9Sstevel@tonic-gate 	int		it_portfd;	/* port file descriptor */
77*7c478bd9Sstevel@tonic-gate } itimer_t;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate typedef struct clock_backend {
80*7c478bd9Sstevel@tonic-gate 	struct sigevent clk_default;
81*7c478bd9Sstevel@tonic-gate 	int (*clk_clock_settime)(timespec_t *);
82*7c478bd9Sstevel@tonic-gate 	int (*clk_clock_gettime)(timespec_t *);
83*7c478bd9Sstevel@tonic-gate 	int (*clk_clock_getres)(timespec_t *);
84*7c478bd9Sstevel@tonic-gate 	int (*clk_timer_create)(itimer_t *, struct sigevent *);
85*7c478bd9Sstevel@tonic-gate 	int (*clk_timer_settime)(itimer_t *, int, const struct itimerspec *);
86*7c478bd9Sstevel@tonic-gate 	int (*clk_timer_gettime)(itimer_t *, struct itimerspec *);
87*7c478bd9Sstevel@tonic-gate 	int (*clk_timer_delete)(itimer_t *);
88*7c478bd9Sstevel@tonic-gate 	void (*clk_timer_lwpbind)(itimer_t *);
89*7c478bd9Sstevel@tonic-gate } clock_backend_t;
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate extern void clock_add_backend(clockid_t clock, clock_backend_t *backend);
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate extern void timer_fire(itimer_t *);
94*7c478bd9Sstevel@tonic-gate extern void timer_lwpbind();
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate extern	void	timer_func(sigqueue_t *);
97*7c478bd9Sstevel@tonic-gate extern	void	timer_exit(void);
98*7c478bd9Sstevel@tonic-gate extern	void	timer_lwpexit(void);
99*7c478bd9Sstevel@tonic-gate extern	clock_t	hzto(struct timeval *);
100*7c478bd9Sstevel@tonic-gate extern	clock_t	timespectohz(timespec_t *, timespec_t);
101*7c478bd9Sstevel@tonic-gate extern	clock_t	timespectohz_adj(timespec_t *, timespec_t);
102*7c478bd9Sstevel@tonic-gate extern	int	itimerspecfix(timespec_t *);
103*7c478bd9Sstevel@tonic-gate extern	void	timespecadd(timespec_t *, timespec_t *);
104*7c478bd9Sstevel@tonic-gate extern	void	timespecsub(timespec_t *, timespec_t *);
105*7c478bd9Sstevel@tonic-gate extern	void	timespecfix(timespec_t *);
106*7c478bd9Sstevel@tonic-gate extern	int	xgetitimer(uint_t, struct itimerval *, int);
107*7c478bd9Sstevel@tonic-gate extern	int	xsetitimer(uint_t, struct itimerval *, int);
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate #define	timerspecisset(tvp)		((tvp)->tv_sec || (tvp)->tv_nsec)
110*7c478bd9Sstevel@tonic-gate #define	timerspeccmp(tvp, uvp)		(((tvp)->tv_sec - (uvp)->tv_sec) ? \
111*7c478bd9Sstevel@tonic-gate 	((tvp)->tv_sec - (uvp)->tv_sec):((tvp)->tv_nsec - (uvp)->tv_nsec))
112*7c478bd9Sstevel@tonic-gate #define	timerspecclear(tvp)		((tvp)->tv_sec = (tvp)->tv_nsec = 0)
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate struct oldsigevent {
115*7c478bd9Sstevel@tonic-gate 	/* structure definition prior to notification attributes member */
116*7c478bd9Sstevel@tonic-gate 	int		_notify;
117*7c478bd9Sstevel@tonic-gate 	union {
118*7c478bd9Sstevel@tonic-gate 		int		_signo;
119*7c478bd9Sstevel@tonic-gate 		void		(*_notify_function)(union sigval);
120*7c478bd9Sstevel@tonic-gate 	} _un;
121*7c478bd9Sstevel@tonic-gate 	union sigval	_value;
122*7c478bd9Sstevel@tonic-gate };
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate struct oldsigevent32 {
127*7c478bd9Sstevel@tonic-gate 	int32_t		_notify;
128*7c478bd9Sstevel@tonic-gate 	union {
129*7c478bd9Sstevel@tonic-gate 		int32_t		_signo;
130*7c478bd9Sstevel@tonic-gate 		caddr32_t	_notify_function;
131*7c478bd9Sstevel@tonic-gate 	} _un;
132*7c478bd9Sstevel@tonic-gate 	union sigval32	_value;
133*7c478bd9Sstevel@tonic-gate };
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
136*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate #endif
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_TIMER_H */
143