Tue Jul 20 08:37:20 2021 UTC ()
no need for extern kmutex_t itimer_mutex or #include <sys/mutex.h> here.


(skrll)
diff -r1.47 -r1.48 src/sys/sys/timevar.h

cvs diff -r1.47 -r1.48 src/sys/sys/timevar.h (switch to unified diff)

--- src/sys/sys/timevar.h 2021/07/20 08:36:11 1.47
+++ src/sys/sys/timevar.h 2021/07/20 08:37:20 1.48
@@ -1,261 +1,258 @@ @@ -1,261 +1,258 @@
1/* $NetBSD: timevar.h,v 1.47 2021/07/20 08:36:11 skrll Exp $ */ 1/* $NetBSD: timevar.h,v 1.48 2021/07/20 08:37:20 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2005, 2008, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2005, 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Copyright (c) 1982, 1986, 1993 30 * Copyright (c) 1982, 1986, 1993
31 * The Regents of the University of California. All rights reserved. 31 * The Regents of the University of California. All rights reserved.
32 * 32 *
33 * Redistribution and use in source and binary forms, with or without 33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions 34 * modification, are permitted provided that the following conditions
35 * are met: 35 * are met:
36 * 1. Redistributions of source code must retain the above copyright 36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer. 37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright 38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the 39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution. 40 * documentation and/or other materials provided with the distribution.
41 * 3. Neither the name of the University nor the names of its contributors 41 * 3. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software 42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission. 43 * without specific prior written permission.
44 * 44 *
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE. 55 * SUCH DAMAGE.
56 * 56 *
57 * @(#)time.h 8.5 (Berkeley) 5/4/95 57 * @(#)time.h 8.5 (Berkeley) 5/4/95
58 */ 58 */
59 59
60#ifndef _SYS_TIMEVAR_H_ 60#ifndef _SYS_TIMEVAR_H_
61#define _SYS_TIMEVAR_H_ 61#define _SYS_TIMEVAR_H_
62 62
63#include <sys/callout.h> 63#include <sys/callout.h>
64#include <sys/queue.h> 64#include <sys/queue.h>
65#include <sys/signal.h> 65#include <sys/signal.h>
66#include <sys/systm.h> 66#include <sys/systm.h>
67#include <sys/mutex.h> 
68 67
69struct itimer; 68struct itimer;
70LIST_HEAD(itlist, itimer); 69LIST_HEAD(itlist, itimer);
71 70
72/* 71/*
73 * Interval timer operations vector. 72 * Interval timer operations vector.
74 * 73 *
75 * Required fields: 74 * Required fields:
76 * 75 *
77 * - ito_fire: A function to be called when the itimer fires. 76 * - ito_fire: A function to be called when the itimer fires.
78 * The timer implementation should perform whatever processing 77 * The timer implementation should perform whatever processing
79 * is necessary for that timer type. 78 * is necessary for that timer type.
80 * 79 *
81 * Optional fields: 80 * Optional fields:
82 * 81 *
83 * - ito_realtime_changed: A function that is called when the system 82 * - ito_realtime_changed: A function that is called when the system
84 * time (CLOCK_REALTIME) is called. 83 * time (CLOCK_REALTIME) is called.
85 */ 84 */
86struct itimer_ops { 85struct itimer_ops {
87 void (*ito_fire)(struct itimer *); 86 void (*ito_fire)(struct itimer *);
88 void (*ito_realtime_changed)(struct itimer *); 87 void (*ito_realtime_changed)(struct itimer *);
89}; 88};
90 89
91/* 90/*
92 * Common interval timer data. 91 * Common interval timer data.
93 */ 92 */
94struct itimer { 93struct itimer {
95 union { 94 union {
96 struct { 95 struct {
97 callout_t it_ch; 96 callout_t it_ch;
98 LIST_ENTRY(itimer) it_rtchgq; 97 LIST_ENTRY(itimer) it_rtchgq;
99 } it_real; 98 } it_real;
100 struct { 99 struct {
101 struct itlist *it_vlist; 100 struct itlist *it_vlist;
102 LIST_ENTRY(itimer) it_list; 101 LIST_ENTRY(itimer) it_list;
103 bool it_active; 102 bool it_active;
104 } it_virtual; 103 } it_virtual;
105 }; 104 };
106 const struct itimer_ops *it_ops; 105 const struct itimer_ops *it_ops;
107 struct itimerspec it_time; 106 struct itimerspec it_time;
108 clockid_t it_clockid; 107 clockid_t it_clockid;
109 int it_overruns; /* Overruns currently accumulating */ 108 int it_overruns; /* Overruns currently accumulating */
110 bool it_dying; 109 bool it_dying;
111}; 110};
112 111
113#define it_ch it_real.it_ch 112#define it_ch it_real.it_ch
114#define it_rtchgq it_real.it_rtchgq 113#define it_rtchgq it_real.it_rtchgq
115 114
116#define it_vlist it_virtual.it_vlist 115#define it_vlist it_virtual.it_vlist
117#define it_list it_virtual.it_list 116#define it_list it_virtual.it_list
118#define it_active it_virtual.it_active 117#define it_active it_virtual.it_active
119 118
120/* 119/*
121 * Structure used to manage timers in a process. 120 * Structure used to manage timers in a process.
122 */ 121 */
123struct ptimer { 122struct ptimer {
124 struct itimer pt_itimer;/* common interval timer data */ 123 struct itimer pt_itimer;/* common interval timer data */
125 124
126 TAILQ_ENTRY(ptimer) pt_chain; /* link in signalling queue */ 125 TAILQ_ENTRY(ptimer) pt_chain; /* link in signalling queue */
127 struct sigevent pt_ev; /* event notification info */ 126 struct sigevent pt_ev; /* event notification info */
128 int pt_poverruns; /* Overruns associated w/ a delivery */ 127 int pt_poverruns; /* Overruns associated w/ a delivery */
129 int pt_entry; /* slot in proc's timer table */ 128 int pt_entry; /* slot in proc's timer table */
130 struct proc *pt_proc; /* associated process */ 129 struct proc *pt_proc; /* associated process */
131 bool pt_queued; /* true if linked into signalling queue */ 130 bool pt_queued; /* true if linked into signalling queue */
132}; 131};
133 132
134#define TIMER_MIN 4 /* [0..3] are reserved for setitimer(2) */ 133#define TIMER_MIN 4 /* [0..3] are reserved for setitimer(2) */
135 /* REAL=0,VIRTUAL=1,PROF=2,MONOTONIC=3 */ 134 /* REAL=0,VIRTUAL=1,PROF=2,MONOTONIC=3 */
136#define TIMER_MAX 36 /* 32 is minimum user timers per POSIX */ 135#define TIMER_MAX 36 /* 32 is minimum user timers per POSIX */
137#define TIMERS_ALL 0 136#define TIMERS_ALL 0
138#define TIMERS_POSIX 1 137#define TIMERS_POSIX 1
139 138
140struct ptimers { 139struct ptimers {
141 struct itlist pts_virtual; 140 struct itlist pts_virtual;
142 struct itlist pts_prof; 141 struct itlist pts_prof;
143 struct itimer *pts_timers[TIMER_MAX]; 142 struct itimer *pts_timers[TIMER_MAX];
144}; 143};
145 144
146extern kmutex_t itimer_mutex; /* XXX */ 
147 
148/* 145/*
149 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() 146 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time()
150 * 147 *
151 * Functions without the "get" prefix returns the best timestamp 148 * Functions without the "get" prefix returns the best timestamp
152 * we can produce in the given format. 149 * we can produce in the given format.
153 * 150 *
154 * "bin" == struct bintime == seconds + 64 bit fraction of seconds. 151 * "bin" == struct bintime == seconds + 64 bit fraction of seconds.
155 * "nano" == struct timespec == seconds + nanoseconds. 152 * "nano" == struct timespec == seconds + nanoseconds.
156 * "micro" == struct timeval == seconds + microseconds. 153 * "micro" == struct timeval == seconds + microseconds.
157 * 154 *
158 * Functions containing "up" returns time relative to boot and 155 * Functions containing "up" returns time relative to boot and
159 * should be used for calculating time intervals. 156 * should be used for calculating time intervals.
160 * 157 *
161 * Functions without "up" returns GMT time. 158 * Functions without "up" returns GMT time.
162 * 159 *
163 * Functions with the "get" prefix returns a less precise result 160 * Functions with the "get" prefix returns a less precise result
164 * much faster than the functions without "get" prefix and should 161 * much faster than the functions without "get" prefix and should
165 * be used where a precision of 1/HZ (eg 10 msec on a 100HZ machine) 162 * be used where a precision of 1/HZ (eg 10 msec on a 100HZ machine)
166 * is acceptable or where performance is priority. 163 * is acceptable or where performance is priority.
167 * (NB: "precision", _not_ "resolution" !) 164 * (NB: "precision", _not_ "resolution" !)
168 * 165 *
169 */ 166 */
170 167
171void binuptime(struct bintime *); 168void binuptime(struct bintime *);
172void nanouptime(struct timespec *); 169void nanouptime(struct timespec *);
173void microuptime(struct timeval *); 170void microuptime(struct timeval *);
174 171
175void bintime(struct bintime *); 172void bintime(struct bintime *);
176void nanotime(struct timespec *); 173void nanotime(struct timespec *);
177void microtime(struct timeval *); 174void microtime(struct timeval *);
178 175
179void getbinuptime(struct bintime *); 176void getbinuptime(struct bintime *);
180void getnanouptime(struct timespec *); 177void getnanouptime(struct timespec *);
181void getmicrouptime(struct timeval *); 178void getmicrouptime(struct timeval *);
182 179
183void getbintime(struct bintime *); 180void getbintime(struct bintime *);
184void getnanotime(struct timespec *); 181void getnanotime(struct timespec *);
185void getmicrotime(struct timeval *); 182void getmicrotime(struct timeval *);
186 183
187void getbinboottime(struct bintime *); 184void getbinboottime(struct bintime *);
188void getnanoboottime(struct timespec *); 185void getnanoboottime(struct timespec *);
189void getmicroboottime(struct timeval *); 186void getmicroboottime(struct timeval *);
190 187
191/* Other functions */ 188/* Other functions */
192int ts2timo(clockid_t, int, struct timespec *, int *, struct timespec *); 189int ts2timo(clockid_t, int, struct timespec *, int *, struct timespec *);
193void adjtime1(const struct timeval *, struct timeval *, struct proc *); 190void adjtime1(const struct timeval *, struct timeval *, struct proc *);
194int clock_getres1(clockid_t, struct timespec *); 191int clock_getres1(clockid_t, struct timespec *);
195int clock_gettime1(clockid_t, struct timespec *); 192int clock_gettime1(clockid_t, struct timespec *);
196int clock_settime1(struct proc *, clockid_t, const struct timespec *, bool); 193int clock_settime1(struct proc *, clockid_t, const struct timespec *, bool);
197void clock_timeleft(clockid_t, struct timespec *, struct timespec *); 194void clock_timeleft(clockid_t, struct timespec *, struct timespec *);
198int dogetitimer(struct proc *, int, struct itimerval *); 195int dogetitimer(struct proc *, int, struct itimerval *);
199int dosetitimer(struct proc *, int, struct itimerval *); 196int dosetitimer(struct proc *, int, struct itimerval *);
200int dotimer_gettime(int, struct proc *, struct itimerspec *); 197int dotimer_gettime(int, struct proc *, struct itimerspec *);
201int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int, 198int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int,
202 struct proc *); 199 struct proc *);
203int tshzto(const struct timespec *); 200int tshzto(const struct timespec *);
204int tshztoup(const struct timespec *); 201int tshztoup(const struct timespec *);
205int tvhzto(const struct timeval *); 202int tvhzto(const struct timeval *);
206void inittimecounter(void); 203void inittimecounter(void);
207int itimerfix(struct timeval *); 204int itimerfix(struct timeval *);
208int itimespecfix(struct timespec *); 205int itimespecfix(struct timespec *);
209int ppsratecheck(struct timeval *, int *, int); 206int ppsratecheck(struct timeval *, int *, int);
210int ratecheck(struct timeval *, const struct timeval *); 207int ratecheck(struct timeval *, const struct timeval *);
211int settime(struct proc *p, struct timespec *); 208int settime(struct proc *p, struct timespec *);
212int nanosleep1(struct lwp *, clockid_t, int, struct timespec *, 209int nanosleep1(struct lwp *, clockid_t, int, struct timespec *,
213 struct timespec *); 210 struct timespec *);
214int settimeofday1(const struct timeval *, bool, 211int settimeofday1(const struct timeval *, bool,
215 const void *, struct lwp *, bool); 212 const void *, struct lwp *, bool);
216int timer_create1(timer_t *, clockid_t, struct sigevent *, copyin_t, 213int timer_create1(timer_t *, clockid_t, struct sigevent *, copyin_t,
217 struct lwp *); 214 struct lwp *);
218int tstohz(const struct timespec *); 215int tstohz(const struct timespec *);
219int tvtohz(const struct timeval *); 216int tvtohz(const struct timeval *);
220int inittimeleft(struct timespec *, struct timespec *); 217int inittimeleft(struct timespec *, struct timespec *);
221int gettimeleft(struct timespec *, struct timespec *); 218int gettimeleft(struct timespec *, struct timespec *);
222void timerupcall(struct lwp *); 219void timerupcall(struct lwp *);
223void time_init(void); 220void time_init(void);
224bool time_wraps(struct timespec *, struct timespec *); 221bool time_wraps(struct timespec *, struct timespec *);
225 222
226void itimer_init(struct itimer *, const struct itimer_ops *, 223void itimer_init(struct itimer *, const struct itimer_ops *,
227 clockid_t, struct itlist *); 224 clockid_t, struct itlist *);
228void itimer_poison(struct itimer *); 225void itimer_poison(struct itimer *);
229void itimer_fini(struct itimer *); 226void itimer_fini(struct itimer *);
230 227
231void itimer_lock(void); 228void itimer_lock(void);
232void itimer_unlock(void); 229void itimer_unlock(void);
233bool itimer_lock_held(void); /* for diagnostic assertions only */ 230bool itimer_lock_held(void); /* for diagnostic assertions only */
234int itimer_settime(struct itimer *); 231int itimer_settime(struct itimer *);
235void itimer_gettime(const struct itimer *, struct itimerspec *); 232void itimer_gettime(const struct itimer *, struct itimerspec *);
236 233
237void ptimer_tick(struct lwp *, bool); 234void ptimer_tick(struct lwp *, bool);
238void ptimers_free(struct proc *, int); 235void ptimers_free(struct proc *, int);
239 236
240extern volatile time_t time_second; /* current second in the epoch */ 237extern volatile time_t time_second; /* current second in the epoch */
241extern volatile time_t time_uptime; /* system uptime in seconds */ 238extern volatile time_t time_uptime; /* system uptime in seconds */
242 239
243#define DEFAULT_TIMEOUT_EPSILON \ 240#define DEFAULT_TIMEOUT_EPSILON \
244 (&(const struct bintime) { \ 241 (&(const struct bintime) { \
245 .sec = 0, \ 242 .sec = 0, \
246 .frac = ((uint64_t)1 << 32)/hz << 32, \ 243 .frac = ((uint64_t)1 << 32)/hz << 32, \
247 }) 244 })
248 245
249static __inline time_t time_mono_to_wall(time_t t) 246static __inline time_t time_mono_to_wall(time_t t)
250{ 247{
251 248
252 return t - time_uptime + time_second; 249 return t - time_uptime + time_second;
253} 250}
254 251
255static __inline time_t time_wall_to_mono(time_t t) 252static __inline time_t time_wall_to_mono(time_t t)
256{ 253{
257 254
258 return t - time_second + time_uptime; 255 return t - time_second + time_uptime;
259} 256}
260 257
261#endif /* !_SYS_TIMEVAR_H_ */ 258#endif /* !_SYS_TIMEVAR_H_ */