FreeBSD/Linux Kernel Cross Reference
sys/sys/timevar.h
1 /* $NetBSD: timevar.h,v 1.6 2006/07/23 22:06:14 ad Exp $ */
2
3 /*
4 * Copyright (c) 2005 The NetBSD Foundation.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to the NetBSD Foundation
8 * by Quentin Garnier.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1982, 1986, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)time.h 8.5 (Berkeley) 5/4/95
68 */
69
70 #ifndef _SYS_TIMEVAR_H_
71 #define _SYS_TIMEVAR_H_
72
73 #include <sys/callout.h>
74 #include <sys/queue.h>
75 #include <sys/signal.h>
76 #include <sys/systm.h>
77
78 /*
79 * Structure used to manage timers in a process.
80 */
81 struct ptimer {
82 union {
83 struct callout pt_ch;
84 struct {
85 LIST_ENTRY(ptimer) pt_list;
86 int pt_active;
87 } pt_nonreal;
88 } pt_data;
89 struct sigevent pt_ev;
90 struct itimerval pt_time;
91 struct ksiginfo pt_info;
92 int pt_overruns; /* Overruns currently accumulating */
93 int pt_poverruns; /* Overruns associated w/ a delivery */
94 int pt_type;
95 int pt_entry;
96 struct proc *pt_proc;
97 };
98
99 #define pt_ch pt_data.pt_ch
100 #define pt_list pt_data.pt_nonreal.pt_list
101 #define pt_active pt_data.pt_nonreal.pt_active
102
103 #define TIMER_MAX 32 /* See ptimers->pts_fired if you enlarge this */
104 #define TIMERS_ALL 0
105 #define TIMERS_POSIX 1
106
107 LIST_HEAD(ptlist, ptimer);
108
109 struct ptimers {
110 struct ptlist pts_virtual;
111 struct ptlist pts_prof;
112 struct ptimer *pts_timers[TIMER_MAX];
113 int pts_fired;
114 };
115
116 /*
117 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time()
118 *
119 * Functions without the "get" prefix returns the best timestamp
120 * we can produce in the given format.
121 *
122 * "bin" == struct bintime == seconds + 64 bit fraction of seconds.
123 * "nano" == struct timespec == seconds + nanoseconds.
124 * "micro" == struct timeval == seconds + microseconds.
125 *
126 * Functions containing "up" returns time relative to boot and
127 * should be used for calculating time intervals.
128 *
129 * Functions without "up" returns GMT time.
130 *
131 * Functions with the "get" prefix returns a less precise result
132 * much faster than the functions without "get" prefix and should
133 * be used where a precision of 10 msec is acceptable or where
134 * performance is priority. (NB: "precision", _not_ "resolution" !)
135 *
136 */
137
138 #ifdef __HAVE_TIMECOUNTER
139 void binuptime(struct bintime *);
140 void nanouptime(struct timespec *);
141 void microuptime(struct timeval *);
142
143 void bintime(struct bintime *);
144 void nanotime(struct timespec *);
145 void microtime(struct timeval *);
146
147 void getbinuptime(struct bintime *);
148 void getnanouptime(struct timespec *);
149 void getmicrouptime(struct timeval *);
150
151 void getbintime(struct bintime *);
152 void getnanotime(struct timespec *);
153 void getmicrotime(struct timeval *);
154 #else /* !__HAVE_TIMECOUNTER */
155 /* timecounter compat functions */
156 void microtime(struct timeval *);
157 void nanotime(struct timespec *);
158
159 void nanouptime(struct timespec *);
160 void getbinuptime(struct bintime *);
161 void getnanouptime(struct timespec *);
162 void getmicrouptime(struct timeval *);
163
164 void getnanotime(struct timespec *);
165 void getmicrotime(struct timeval *);
166 #endif /* !__HAVE_TIMECOUNTER */
167
168 /* Other functions */
169 int adjtime1(const struct timeval *, struct timeval *, struct proc *);
170 int clock_settime1(struct proc *, clockid_t, const struct timespec *);
171 int dogetitimer(struct proc *, int, struct itimerval *);
172 int dosetitimer(struct proc *, int, struct itimerval *);
173 int dotimer_gettime(int, struct proc *, struct itimerspec *);
174 int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int,
175 struct proc *);
176 int hzto(struct timeval *);
177 void inittimecounter(void);
178 int itimerdecr(struct ptimer *, int);
179 void itimerfire(struct ptimer *);
180 int itimerfix(struct timeval *tv);
181 int ppsratecheck(struct timeval *, int *, int);
182 int ratecheck(struct timeval *, const struct timeval *);
183 void realtimerexpire(void *);
184 int settime(struct proc *p, struct timespec *);
185 int settimeofday1(const struct timeval *, const struct timezone *,
186 struct proc *);
187 int timer_create1(timer_t *, clockid_t, struct sigevent *, copyin_t,
188 struct lwp *);
189 void timer_gettime(struct ptimer *, struct itimerval *);
190 void timer_settime(struct ptimer *);
191 void timers_alloc(struct proc *);
192 void timers_free(struct proc *, int);
193 int tstohz(struct timespec *);
194 int tvtohz(struct timeval *);
195 int inittimeleft(struct timeval *, struct timeval *);
196 int gettimeleft(struct timeval *, struct timeval *);
197
198 #ifdef __HAVE_TIMECOUNTER
199 extern time_t time_second; /* current second in the epoch */
200 extern time_t time_uptime; /* system uptime in seconds */
201 #else /* !__HAVE_TIMECOUNTER */
202 extern volatile struct timeval mono_time;
203 extern volatile struct timeval time;
204 #define time_second time.tv_sec
205 #define time_uptime mono_time.tv_sec
206 #endif /* !__HAVE_TIMECOUNTER */
207
208 #endif /* !_SYS_TIMEVAR_H_ */
Cache object: 61dfaf57f400cdecd1f2b184af0b417e
|