Tue Jul 20 08:36:11 2021 UTC ()
Trailing whitespace


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

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

--- src/sys/sys/timevar.h 2020/12/08 04:09:38 1.46
+++ src/sys/sys/timevar.h 2021/07/20 08:36:11 1.47
@@ -1,261 +1,261 @@ @@ -1,261 +1,261 @@
1/* $NetBSD: timevar.h,v 1.46 2020/12/08 04:09:38 thorpej Exp $ */ 1/* $NetBSD: timevar.h,v 1.47 2021/07/20 08:36:11 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> 67#include <sys/mutex.h>
68 68
69struct itimer; 69struct itimer;
70LIST_HEAD(itlist, itimer); 70LIST_HEAD(itlist, itimer);
71 71
72/* 72/*
73 * Interval timer operations vector. 73 * Interval timer operations vector.
74 * 74 *
75 * Required fields: 75 * Required fields:
76 * 76 *
77 * - ito_fire: A function to be called when the itimer fires. 77 * - ito_fire: A function to be called when the itimer fires.
78 * The timer implementation should perform whatever processing 78 * The timer implementation should perform whatever processing
79 * is necessary for that timer type. 79 * is necessary for that timer type.
80 * 80 *
81 * Optional fields: 81 * Optional fields:
82 * 82 *
83 * - ito_realtime_changed: A function that is called when the system 83 * - ito_realtime_changed: A function that is called when the system
84 * time (CLOCK_REALTIME) is called. 84 * time (CLOCK_REALTIME) is called.
85 */ 85 */
86struct itimer_ops { 86struct itimer_ops {
87 void (*ito_fire)(struct itimer *); 87 void (*ito_fire)(struct itimer *);
88 void (*ito_realtime_changed)(struct itimer *); 88 void (*ito_realtime_changed)(struct itimer *);
89}; 89};
90 90
91/* 91/*
92 * Common interval timer data. 92 * Common interval timer data.
93 */ 93 */
94struct itimer { 94struct itimer {
95 union { 95 union {
96 struct { 96 struct {
97 callout_t it_ch; 97 callout_t it_ch;
98 LIST_ENTRY(itimer) it_rtchgq; 98 LIST_ENTRY(itimer) it_rtchgq;
99 } it_real; 99 } it_real;
100 struct { 100 struct {
101 struct itlist *it_vlist; 101 struct itlist *it_vlist;
102 LIST_ENTRY(itimer) it_list; 102 LIST_ENTRY(itimer) it_list;
103 bool it_active; 103 bool it_active;
104 } it_virtual; 104 } it_virtual;
105 }; 105 };
106 const struct itimer_ops *it_ops; 106 const struct itimer_ops *it_ops;
107 struct itimerspec it_time; 107 struct itimerspec it_time;
108 clockid_t it_clockid; 108 clockid_t it_clockid;
109 int it_overruns; /* Overruns currently accumulating */ 109 int it_overruns; /* Overruns currently accumulating */
110 bool it_dying; 110 bool it_dying;
111}; 111};
112 112
113#define it_ch it_real.it_ch 113#define it_ch it_real.it_ch
114#define it_rtchgq it_real.it_rtchgq 114#define it_rtchgq it_real.it_rtchgq
115 115
116#define it_vlist it_virtual.it_vlist 116#define it_vlist it_virtual.it_vlist
117#define it_list it_virtual.it_list 117#define it_list it_virtual.it_list
118#define it_active it_virtual.it_active 118#define it_active it_virtual.it_active
119 119
120/* 120/*
121 * Structure used to manage timers in a process. 121 * Structure used to manage timers in a process.
122 */ 122 */
123struct ptimer { 123struct ptimer {
124 struct itimer pt_itimer;/* common interval timer data */ 124 struct itimer pt_itimer;/* common interval timer data */
125 125
126 TAILQ_ENTRY(ptimer) pt_chain; /* link in signalling queue */ 126 TAILQ_ENTRY(ptimer) pt_chain; /* link in signalling queue */
127 struct sigevent pt_ev; /* event notification info */ 127 struct sigevent pt_ev; /* event notification info */
128 int pt_poverruns; /* Overruns associated w/ a delivery */ 128 int pt_poverruns; /* Overruns associated w/ a delivery */
129 int pt_entry; /* slot in proc's timer table */ 129 int pt_entry; /* slot in proc's timer table */
130 struct proc *pt_proc; /* associated process */ 130 struct proc *pt_proc; /* associated process */
131 bool pt_queued; /* true if linked into signalling queue */ 131 bool pt_queued; /* true if linked into signalling queue */
132}; 132};
133 133
134#define TIMER_MIN 4 /* [0..3] are reserved for setitimer(2) */ 134#define TIMER_MIN 4 /* [0..3] are reserved for setitimer(2) */
135 /* REAL=0,VIRTUAL=1,PROF=2,MONOTONIC=3 */ 135 /* REAL=0,VIRTUAL=1,PROF=2,MONOTONIC=3 */
136#define TIMER_MAX 36 /* 32 is minimum user timers per POSIX */ 136#define TIMER_MAX 36 /* 32 is minimum user timers per POSIX */
137#define TIMERS_ALL 0 137#define TIMERS_ALL 0
138#define TIMERS_POSIX 1 138#define TIMERS_POSIX 1
139 139
140struct ptimers { 140struct ptimers {
141 struct itlist pts_virtual; 141 struct itlist pts_virtual;
142 struct itlist pts_prof; 142 struct itlist pts_prof;
143 struct itimer *pts_timers[TIMER_MAX]; 143 struct itimer *pts_timers[TIMER_MAX];
144}; 144};
145 145
146extern kmutex_t itimer_mutex; /* XXX */ 146extern kmutex_t itimer_mutex; /* XXX */
147 147
148/* 148/*
149 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() 149 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time()
150 * 150 *
151 * Functions without the "get" prefix returns the best timestamp 151 * Functions without the "get" prefix returns the best timestamp
152 * we can produce in the given format. 152 * we can produce in the given format.
153 * 153 *
154 * "bin" == struct bintime == seconds + 64 bit fraction of seconds. 154 * "bin" == struct bintime == seconds + 64 bit fraction of seconds.
155 * "nano" == struct timespec == seconds + nanoseconds. 155 * "nano" == struct timespec == seconds + nanoseconds.
156 * "micro" == struct timeval == seconds + microseconds. 156 * "micro" == struct timeval == seconds + microseconds.
157 *  157 *
158 * Functions containing "up" returns time relative to boot and 158 * Functions containing "up" returns time relative to boot and
159 * should be used for calculating time intervals. 159 * should be used for calculating time intervals.
160 * 160 *
161 * Functions without "up" returns GMT time. 161 * Functions without "up" returns GMT time.
162 * 162 *
163 * Functions with the "get" prefix returns a less precise result 163 * Functions with the "get" prefix returns a less precise result
164 * much faster than the functions without "get" prefix and should 164 * 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) 165 * be used where a precision of 1/HZ (eg 10 msec on a 100HZ machine)
166 * is acceptable or where performance is priority. 166 * is acceptable or where performance is priority.
167 * (NB: "precision", _not_ "resolution" !)  167 * (NB: "precision", _not_ "resolution" !)
168 *  168 *
169 */ 169 */
170 170
171void binuptime(struct bintime *); 171void binuptime(struct bintime *);
172void nanouptime(struct timespec *); 172void nanouptime(struct timespec *);
173void microuptime(struct timeval *); 173void microuptime(struct timeval *);
174 174
175void bintime(struct bintime *); 175void bintime(struct bintime *);
176void nanotime(struct timespec *); 176void nanotime(struct timespec *);
177void microtime(struct timeval *); 177void microtime(struct timeval *);
178 178
179void getbinuptime(struct bintime *); 179void getbinuptime(struct bintime *);
180void getnanouptime(struct timespec *); 180void getnanouptime(struct timespec *);
181void getmicrouptime(struct timeval *); 181void getmicrouptime(struct timeval *);
182 182
183void getbintime(struct bintime *); 183void getbintime(struct bintime *);
184void getnanotime(struct timespec *); 184void getnanotime(struct timespec *);
185void getmicrotime(struct timeval *); 185void getmicrotime(struct timeval *);
186 186
187void getbinboottime(struct bintime *); 187void getbinboottime(struct bintime *);
188void getnanoboottime(struct timespec *); 188void getnanoboottime(struct timespec *);
189void getmicroboottime(struct timeval *); 189void getmicroboottime(struct timeval *);
190 190
191/* Other functions */ 191/* Other functions */
192int ts2timo(clockid_t, int, struct timespec *, int *, struct timespec *); 192int ts2timo(clockid_t, int, struct timespec *, int *, struct timespec *);
193void adjtime1(const struct timeval *, struct timeval *, struct proc *); 193void adjtime1(const struct timeval *, struct timeval *, struct proc *);
194int clock_getres1(clockid_t, struct timespec *); 194int clock_getres1(clockid_t, struct timespec *);
195int clock_gettime1(clockid_t, struct timespec *); 195int clock_gettime1(clockid_t, struct timespec *);
196int clock_settime1(struct proc *, clockid_t, const struct timespec *, bool); 196int clock_settime1(struct proc *, clockid_t, const struct timespec *, bool);
197void clock_timeleft(clockid_t, struct timespec *, struct timespec *); 197void clock_timeleft(clockid_t, struct timespec *, struct timespec *);
198int dogetitimer(struct proc *, int, struct itimerval *); 198int dogetitimer(struct proc *, int, struct itimerval *);
199int dosetitimer(struct proc *, int, struct itimerval *); 199int dosetitimer(struct proc *, int, struct itimerval *);
200int dotimer_gettime(int, struct proc *, struct itimerspec *); 200int dotimer_gettime(int, struct proc *, struct itimerspec *);
201int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int, 201int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int,
202 struct proc *); 202 struct proc *);
203int tshzto(const struct timespec *); 203int tshzto(const struct timespec *);
204int tshztoup(const struct timespec *); 204int tshztoup(const struct timespec *);
205int tvhzto(const struct timeval *); 205int tvhzto(const struct timeval *);
206void inittimecounter(void); 206void inittimecounter(void);
207int itimerfix(struct timeval *); 207int itimerfix(struct timeval *);
208int itimespecfix(struct timespec *); 208int itimespecfix(struct timespec *);
209int ppsratecheck(struct timeval *, int *, int); 209int ppsratecheck(struct timeval *, int *, int);
210int ratecheck(struct timeval *, const struct timeval *); 210int ratecheck(struct timeval *, const struct timeval *);
211int settime(struct proc *p, struct timespec *); 211int settime(struct proc *p, struct timespec *);
212int nanosleep1(struct lwp *, clockid_t, int, struct timespec *, 212int nanosleep1(struct lwp *, clockid_t, int, struct timespec *,
213 struct timespec *); 213 struct timespec *);
214int settimeofday1(const struct timeval *, bool, 214int settimeofday1(const struct timeval *, bool,
215 const void *, struct lwp *, bool); 215 const void *, struct lwp *, bool);
216int timer_create1(timer_t *, clockid_t, struct sigevent *, copyin_t, 216int timer_create1(timer_t *, clockid_t, struct sigevent *, copyin_t,
217 struct lwp *); 217 struct lwp *);
218int tstohz(const struct timespec *); 218int tstohz(const struct timespec *);
219int tvtohz(const struct timeval *); 219int tvtohz(const struct timeval *);
220int inittimeleft(struct timespec *, struct timespec *); 220int inittimeleft(struct timespec *, struct timespec *);
221int gettimeleft(struct timespec *, struct timespec *); 221int gettimeleft(struct timespec *, struct timespec *);
222void timerupcall(struct lwp *); 222void timerupcall(struct lwp *);
223void time_init(void); 223void time_init(void);
224bool time_wraps(struct timespec *, struct timespec *); 224bool time_wraps(struct timespec *, struct timespec *);
225 225
226void itimer_init(struct itimer *, const struct itimer_ops *, 226void itimer_init(struct itimer *, const struct itimer_ops *,
227 clockid_t, struct itlist *); 227 clockid_t, struct itlist *);
228void itimer_poison(struct itimer *); 228void itimer_poison(struct itimer *);
229void itimer_fini(struct itimer *); 229void itimer_fini(struct itimer *);
230 230
231void itimer_lock(void); 231void itimer_lock(void);
232void itimer_unlock(void); 232void itimer_unlock(void);
233bool itimer_lock_held(void); /* for diagnostic assertions only */ 233bool itimer_lock_held(void); /* for diagnostic assertions only */
234int itimer_settime(struct itimer *); 234int itimer_settime(struct itimer *);
235void itimer_gettime(const struct itimer *, struct itimerspec *); 235void itimer_gettime(const struct itimer *, struct itimerspec *);
236 236
237void ptimer_tick(struct lwp *, bool); 237void ptimer_tick(struct lwp *, bool);
238void ptimers_free(struct proc *, int); 238void ptimers_free(struct proc *, int);
239 239
240extern volatile time_t time_second; /* current second in the epoch */ 240extern volatile time_t time_second; /* current second in the epoch */
241extern volatile time_t time_uptime; /* system uptime in seconds */ 241extern volatile time_t time_uptime; /* system uptime in seconds */
242 242
243#define DEFAULT_TIMEOUT_EPSILON \ 243#define DEFAULT_TIMEOUT_EPSILON \
244 (&(const struct bintime) { \ 244 (&(const struct bintime) { \
245 .sec = 0, \ 245 .sec = 0, \
246 .frac = ((uint64_t)1 << 32)/hz << 32, \ 246 .frac = ((uint64_t)1 << 32)/hz << 32, \
247 }) 247 })
248 248
249static __inline time_t time_mono_to_wall(time_t t) 249static __inline time_t time_mono_to_wall(time_t t)
250{ 250{
251 251
252 return t - time_uptime + time_second; 252 return t - time_uptime + time_second;
253} 253}
254 254
255static __inline time_t time_wall_to_mono(time_t t) 255static __inline time_t time_wall_to_mono(time_t t)
256{ 256{
257 257
258 return t - time_second + time_uptime; 258 return t - time_second + time_uptime;
259} 259}
260 260
261#endif /* !_SYS_TIMEVAR_H_ */ 261#endif /* !_SYS_TIMEVAR_H_ */