xref: /illumos-gate/usr/src/uts/intel/sys/hrtcntl.h (revision dd72704bd9e794056c558153663c739e2012d721)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1997-1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 #ifndef _SYS_HRTCNTL_H
32 #define	_SYS_HRTCNTL_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * The following are the possible commands for the hrtcntl,
40  * hrtalarm, and hrtsleep system calls.
41  */
42 
43 typedef	enum	hrtcmds {
44 
45 		/*   hrtcntl	commands   */
46 	HRT_GETRES,		/* Get the resolution of a clock.	*/
47 	HRT_TOFD,		/* Get the value of time since		*/
48 				/* 00:00:00 GMT, January 1, 1970	*/
49 	HRT_STARTIT,		/* Start timing an activity		*/
50 	HRT_GETIT,		/* Return the interval time elapsed	*/
51 				/* since the corresponding HRT_STARTIT	*/
52 				/* command has been issued.		*/
53 		/*   hrtalarm   commands   */
54 	HRT_ALARM,		/* Start a timer and post an alarm	*/
55 				/* event after the time interval has	*/
56 				/* elapsed.				*/
57 	HRT_RALARM,		/* Post an alarm repeatedly after	*/
58 				/* every time interval.			*/
59 	HRT_TODALARM,		/* Similar to HRT_ALARM except that	*/
60 				/* the time at which the alarm is to	*/
61 				/* posted is specified by an absolute	*/
62 				/* time.				*/
63 	HRT_INT_RPT,		/* Start a repeating alarm some time	*/
64 				/* in the future.			*/
65 	HRT_TOD_RPT,		/* Similar to HRT_INT_RPT except that	*/
66 				/* the time of day when the alarm	*/
67 				/* should begin is specified.		*/
68 	HRT_PENDING,		/* Determine the time remaining until	*/
69 				/* a pending alarm fires.		*/
70 		/*   hrtsleep   commands  */
71 	HRT_INTSLP,		/* Put the process to sleep for an	*/
72 				/* interval.				*/
73 	HRT_TODSLP,		/* Put the process to sleep until	*/
74 				/* a specified time of day.		*/
75 		/*
76 		 * The following fields will be used
77 		 * to implement BSD timers
78 		 */
79 	HRT_BSD,
80 	HRT_BSD_PEND,
81 	HRT_RBSD,
82 	HRT_BSD_REP,
83 	HRT_BSD_CANCEL
84 } hrtcmds_t;
85 
86 /*
87  *	Definitions for specifying rounding mode.
88  */
89 
90 #define	HRT_TRUNC	0	/* Round results down.	*/
91 #define	HRT_RND		1	/* Round results (rnd up if fractional	*/
92 				/*   part >= .5 otherwise round down).	*/
93 #define	HRT_RNDUP	2	/* Always round results up.	*/
94 
95 /*
96  *	Definition for the type of internal buffer used with the
97  *	HRT_STARTIT and HRT_GETIT commands.
98  */
99 
100 typedef	struct interval {
101 	unsigned long	i_word1;
102 	unsigned long	i_word2;
103 	int		i_clock;
104 } interval_t;
105 
106 /*
107  *	Structure used to represent a high-resolution time-of-day
108  *	or interval.
109  */
110 
111 typedef struct hrtime {
112 	ulong_t	hrt_secs;	/* Seconds.				*/
113 	long	hrt_rem;	/* A value less than a second.		*/
114 	ulong_t	hrt_res;	/* The resolution of hrt_rem.		*/
115 } hrtimes_t;
116 
117 
118 /*
119  *	The structure used for the hrtalarm and hrtsleep system calls.
120  */
121 
122 typedef struct hrtcmd {
123 	int		hrtc_cmd;	/* A timer command.		*/
124 	int		hrtc_clk;	/* Which clock to use.		*/
125 	hrtimes_t	hrtc_int;	/* A time interval.		*/
126 	hrtimes_t	hrtc_tod;	/* A time of day.		*/
127 	int		hrtc_flags;	/* Various flags. 		*/
128 	int		hrtc_error;	/* An error code		*/
129 					/* (see eys/errno.h).		*/
130 #ifdef notdef
131 	ecb_t		hrtc_ecb;	/* An event control block.	*/
132 #endif
133 } hrtcmd_t;
134 
135 /*
136  * Flags for the hrtc_flags field.
137  */
138 
139 #define	HRTF_DONE	0x0001	/* The requested alarm has been set.	*/
140 #define	HRTF_ERROR	0x0002	/* An error has been encountered.	*/
141 
142 /*
143  * Multiple clocks
144  */
145 
146 #define	CLK_STD		0x0001	/* The standard real-time clock.	*/
147 #define	CLK_USERVIRT	0x0002	/* A clock measuring user process	*/
148 				/* virtual time.			*/
149 #define	CLK_PROCVIRT	0x0004	/* A clock measuring a process' virtual */
150 				/* time.				*/
151 
152 /*
153  * Function Prototypes
154  * ===================
155  *
156  *	The following are prototypes for the library functions which
157  *	users call.
158  */
159 
160 #if defined(__STDC__) && !defined(_KERNEL)
161 int   hrtcntl(int, int, interval_t *, hrtimes_t *);
162 int   hrtalarm(hrtcmd_t *, int);
163 int   hrtsleep(hrtcmd_t *);
164 int   hrtcancel(const long *, int);
165 #endif
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif	/* _SYS_HRTCNTL_H */
172