xref: /titanic_41/usr/src/uts/common/sys/timer.h (revision e0cf54a5673ecf2b9054101898211427b97772f7)
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 2009 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 #include <sys/types.h>
31 #include <sys/proc.h>
32 #include <sys/thread.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #ifdef	_KERNEL
39 
40 #define	_TIMER_MAX	32
41 extern	int	timer_max;		/* patchable via /etc/system */
42 
43 /*
44  * Bit values for the it_lock field.
45  */
46 #define	ITLK_LOCKED		0x01
47 #define	ITLK_WANTED		0x02
48 #define	ITLK_REMOVE		0x04
49 
50 /*
51  * Bit values for the it_flags field.
52  */
53 #define	IT_SIGNAL		0x01
54 #define	IT_PORT			0x02	/* use event port notification */
55 
56 struct clock_backend;
57 
58 typedef struct itimer {
59 	itimerspec_t	it_itime;
60 	hrtime_t	it_hrtime;
61 	ushort_t	it_flags;
62 	ushort_t	it_lock;
63 	void		*it_arg;
64 	sigqueue_t	*it_sigq;
65 	klwp_t		*it_lwp;
66 	struct proc	*it_proc;
67 	kcondvar_t	it_cv;
68 	int		it_blockers;
69 	int		it_pending;
70 	int		it_overrun;
71 	struct clock_backend *it_backend;
72 	kmutex_t	it_mutex;
73 	void		*it_portev;	/* port_kevent_t pointer */
74 	void		*it_portsrc;	/* port_source_t pointer */
75 	int		it_portfd;	/* port file descriptor */
76 } itimer_t;
77 
78 typedef struct clock_backend {
79 	struct sigevent clk_default;
80 	int (*clk_clock_settime)(timespec_t *);
81 	int (*clk_clock_gettime)(timespec_t *);
82 	int (*clk_clock_getres)(timespec_t *);
83 	int (*clk_timer_create)(itimer_t *, struct sigevent *);
84 	int (*clk_timer_settime)(itimer_t *, int, const struct itimerspec *);
85 	int (*clk_timer_gettime)(itimer_t *, struct itimerspec *);
86 	int (*clk_timer_delete)(itimer_t *);
87 	void (*clk_timer_lwpbind)(itimer_t *);
88 } clock_backend_t;
89 
90 extern void clock_add_backend(clockid_t clock, clock_backend_t *backend);
91 
92 extern void timer_fire(itimer_t *);
93 extern void timer_lwpbind();
94 
95 extern	void	timer_func(sigqueue_t *);
96 extern	void	timer_exit(void);
97 extern	void	timer_lwpexit(void);
98 extern	clock_t	hzto(struct timeval *);
99 extern	clock_t	timespectohz(timespec_t *, timespec_t);
100 extern	int64_t	timespectohz64(timespec_t *);
101 extern	int	itimerspecfix(timespec_t *);
102 extern	void	timespecadd(timespec_t *, timespec_t *);
103 extern	void	timespecsub(timespec_t *, timespec_t *);
104 extern	void	timespecfix(timespec_t *);
105 extern	int	xgetitimer(uint_t, struct itimerval *, int);
106 extern	int	xsetitimer(uint_t, struct itimerval *, int);
107 extern	void	delete_itimer_realprof(void);
108 
109 #define	timerspecisset(tvp)		((tvp)->tv_sec || (tvp)->tv_nsec)
110 #define	timerspeccmp(tvp, uvp)		(((tvp)->tv_sec - (uvp)->tv_sec) ? \
111 	((tvp)->tv_sec - (uvp)->tv_sec):((tvp)->tv_nsec - (uvp)->tv_nsec))
112 #define	timerspecclear(tvp)		((tvp)->tv_sec = (tvp)->tv_nsec = 0)
113 
114 struct oldsigevent {
115 	/* structure definition prior to notification attributes member */
116 	int		_notify;
117 	union {
118 		int		_signo;
119 		void		(*_notify_function)(union sigval);
120 	} _un;
121 	union sigval	_value;
122 };
123 
124 #if defined(_SYSCALL32)
125 
126 struct oldsigevent32 {
127 	int32_t		_notify;
128 	union {
129 		int32_t		_signo;
130 		caddr32_t	_notify_function;
131 	} _un;
132 	union sigval32	_value;
133 };
134 
135 #endif	/* _SYSCALL32 */
136 #endif	/* _KERNEL */
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif	/* _SYS_TIMER_H */
143