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