xref: /illumos-gate/usr/src/uts/common/sys/timer.h (revision 34709573)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*34709573Sraf  * Common Development and Distribution License (the "License").
6*34709573Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*34709573Sraf 
227c478bd9Sstevel@tonic-gate /*
23*34709573Sraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_TIMER_H
287c478bd9Sstevel@tonic-gate #define	_SYS_TIMER_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/proc.h>
347c478bd9Sstevel@tonic-gate #include <sys/thread.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	_TIMER_MAX	32
43*34709573Sraf extern	int	timer_max;		/* patchable via /etc/system */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Bit values for the it_lock field.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate #define	ITLK_LOCKED		0x01
497c478bd9Sstevel@tonic-gate #define	ITLK_WANTED		0x02
507c478bd9Sstevel@tonic-gate #define	ITLK_REMOVE		0x04
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Bit values for the it_flags field.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	IT_SIGNAL		0x01
567c478bd9Sstevel@tonic-gate #define	IT_PORT			0x02	/* use event port notification */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate struct clock_backend;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate typedef struct itimer {
617c478bd9Sstevel@tonic-gate 	itimerspec_t	it_itime;
627c478bd9Sstevel@tonic-gate 	hrtime_t	it_hrtime;
637c478bd9Sstevel@tonic-gate 	ushort_t	it_flags;
647c478bd9Sstevel@tonic-gate 	ushort_t	it_lock;
657c478bd9Sstevel@tonic-gate 	void		*it_arg;
667c478bd9Sstevel@tonic-gate 	sigqueue_t	*it_sigq;
677c478bd9Sstevel@tonic-gate 	klwp_t		*it_lwp;
687c478bd9Sstevel@tonic-gate 	struct proc	*it_proc;
697c478bd9Sstevel@tonic-gate 	kcondvar_t	it_cv;
707c478bd9Sstevel@tonic-gate 	int		it_blockers;
717c478bd9Sstevel@tonic-gate 	int		it_pending;
727c478bd9Sstevel@tonic-gate 	int		it_overrun;
737c478bd9Sstevel@tonic-gate 	struct clock_backend *it_backend;
747c478bd9Sstevel@tonic-gate 	kmutex_t	it_mutex;
757c478bd9Sstevel@tonic-gate 	void		*it_portev;	/* port_kevent_t pointer */
767c478bd9Sstevel@tonic-gate 	void		*it_portsrc;	/* port_source_t pointer */
777c478bd9Sstevel@tonic-gate 	int		it_portfd;	/* port file descriptor */
787c478bd9Sstevel@tonic-gate } itimer_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef struct clock_backend {
817c478bd9Sstevel@tonic-gate 	struct sigevent clk_default;
827c478bd9Sstevel@tonic-gate 	int (*clk_clock_settime)(timespec_t *);
837c478bd9Sstevel@tonic-gate 	int (*clk_clock_gettime)(timespec_t *);
847c478bd9Sstevel@tonic-gate 	int (*clk_clock_getres)(timespec_t *);
857c478bd9Sstevel@tonic-gate 	int (*clk_timer_create)(itimer_t *, struct sigevent *);
867c478bd9Sstevel@tonic-gate 	int (*clk_timer_settime)(itimer_t *, int, const struct itimerspec *);
877c478bd9Sstevel@tonic-gate 	int (*clk_timer_gettime)(itimer_t *, struct itimerspec *);
887c478bd9Sstevel@tonic-gate 	int (*clk_timer_delete)(itimer_t *);
897c478bd9Sstevel@tonic-gate 	void (*clk_timer_lwpbind)(itimer_t *);
907c478bd9Sstevel@tonic-gate } clock_backend_t;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate extern void clock_add_backend(clockid_t clock, clock_backend_t *backend);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate extern void timer_fire(itimer_t *);
957c478bd9Sstevel@tonic-gate extern void timer_lwpbind();
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate extern	void	timer_func(sigqueue_t *);
987c478bd9Sstevel@tonic-gate extern	void	timer_exit(void);
997c478bd9Sstevel@tonic-gate extern	void	timer_lwpexit(void);
1007c478bd9Sstevel@tonic-gate extern	clock_t	hzto(struct timeval *);
1017c478bd9Sstevel@tonic-gate extern	clock_t	timespectohz(timespec_t *, timespec_t);
1027c478bd9Sstevel@tonic-gate extern	clock_t	timespectohz_adj(timespec_t *, timespec_t);
1037c478bd9Sstevel@tonic-gate extern	int	itimerspecfix(timespec_t *);
1047c478bd9Sstevel@tonic-gate extern	void	timespecadd(timespec_t *, timespec_t *);
1057c478bd9Sstevel@tonic-gate extern	void	timespecsub(timespec_t *, timespec_t *);
1067c478bd9Sstevel@tonic-gate extern	void	timespecfix(timespec_t *);
1077c478bd9Sstevel@tonic-gate extern	int	xgetitimer(uint_t, struct itimerval *, int);
1087c478bd9Sstevel@tonic-gate extern	int	xsetitimer(uint_t, struct itimerval *, int);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #define	timerspecisset(tvp)		((tvp)->tv_sec || (tvp)->tv_nsec)
1117c478bd9Sstevel@tonic-gate #define	timerspeccmp(tvp, uvp)		(((tvp)->tv_sec - (uvp)->tv_sec) ? \
1127c478bd9Sstevel@tonic-gate 	((tvp)->tv_sec - (uvp)->tv_sec):((tvp)->tv_nsec - (uvp)->tv_nsec))
1137c478bd9Sstevel@tonic-gate #define	timerspecclear(tvp)		((tvp)->tv_sec = (tvp)->tv_nsec = 0)
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate struct oldsigevent {
1167c478bd9Sstevel@tonic-gate 	/* structure definition prior to notification attributes member */
1177c478bd9Sstevel@tonic-gate 	int		_notify;
1187c478bd9Sstevel@tonic-gate 	union {
1197c478bd9Sstevel@tonic-gate 		int		_signo;
1207c478bd9Sstevel@tonic-gate 		void		(*_notify_function)(union sigval);
1217c478bd9Sstevel@tonic-gate 	} _un;
1227c478bd9Sstevel@tonic-gate 	union sigval	_value;
1237c478bd9Sstevel@tonic-gate };
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate struct oldsigevent32 {
1287c478bd9Sstevel@tonic-gate 	int32_t		_notify;
1297c478bd9Sstevel@tonic-gate 	union {
1307c478bd9Sstevel@tonic-gate 		int32_t		_signo;
1317c478bd9Sstevel@tonic-gate 		caddr32_t	_notify_function;
1327c478bd9Sstevel@tonic-gate 	} _un;
1337c478bd9Sstevel@tonic-gate 	union sigval32	_value;
1347c478bd9Sstevel@tonic-gate };
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1377c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate #endif
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #endif	/* _SYS_TIMER_H */
144