FreeBSD/Linux Kernel Cross Reference
sys/sys/time.h
1 /* $NetBSD: time.h,v 1.41 2003/09/06 22:01:21 christos Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)time.h 8.5 (Berkeley) 5/4/95
32 */
33
34 #ifndef _SYS_TIME_H_
35 #define _SYS_TIME_H_
36
37 #include <sys/featuretest.h>
38 #include <sys/types.h>
39 #ifdef _KERNEL
40 #include <sys/callout.h>
41 #include <sys/signal.h>
42 #include <sys/queue.h>
43 #endif
44
45 /*
46 * Structure returned by gettimeofday(2) system call,
47 * and used in other calls.
48 */
49 struct timeval {
50 long tv_sec; /* seconds */
51 long tv_usec; /* and microseconds */
52 };
53
54 /*
55 * Structure defined by POSIX.1b to be like a timeval.
56 */
57 struct timespec {
58 time_t tv_sec; /* seconds */
59 long tv_nsec; /* and nanoseconds */
60 };
61
62 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \
63 (ts)->tv_sec = (tv)->tv_sec; \
64 (ts)->tv_nsec = (tv)->tv_usec * 1000; \
65 }
66 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \
67 (tv)->tv_sec = (ts)->tv_sec; \
68 (tv)->tv_usec = (ts)->tv_nsec / 1000; \
69 }
70
71 /*
72 * Note: timezone is obsolete. All timezone handling is now in
73 * userland. Its just here for back compatibility.
74 */
75 struct timezone {
76 int tz_minuteswest; /* minutes west of Greenwich */
77 int tz_dsttime; /* type of dst correction */
78 };
79
80 /* Operations on timevals. */
81 #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
82 #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
83 #define timercmp(tvp, uvp, cmp) \
84 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
85 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
86 ((tvp)->tv_sec cmp (uvp)->tv_sec))
87 #define timeradd(tvp, uvp, vvp) \
88 do { \
89 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
90 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
91 if ((vvp)->tv_usec >= 1000000) { \
92 (vvp)->tv_sec++; \
93 (vvp)->tv_usec -= 1000000; \
94 } \
95 } while (/* CONSTCOND */ 0)
96 #define timersub(tvp, uvp, vvp) \
97 do { \
98 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
99 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
100 if ((vvp)->tv_usec < 0) { \
101 (vvp)->tv_sec--; \
102 (vvp)->tv_usec += 1000000; \
103 } \
104 } while (/* CONSTCOND */ 0)
105
106 /* Operations on timespecs. */
107 #define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
108 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
109 #define timespeccmp(tsp, usp, cmp) \
110 (((tsp)->tv_sec == (usp)->tv_sec) ? \
111 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
112 ((tsp)->tv_sec cmp (usp)->tv_sec))
113 #define timespecadd(tsp, usp, vsp) \
114 do { \
115 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
116 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
117 if ((vsp)->tv_nsec >= 1000000000L) { \
118 (vsp)->tv_sec++; \
119 (vsp)->tv_nsec -= 1000000000L; \
120 } \
121 } while (/* CONSTCOND */ 0)
122 #define timespecsub(tsp, usp, vsp) \
123 do { \
124 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
125 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
126 if ((vsp)->tv_nsec < 0) { \
127 (vsp)->tv_sec--; \
128 (vsp)->tv_nsec += 1000000000L; \
129 } \
130 } while (/* CONSTCOND */ 0)
131
132 /*
133 * Names of the interval timers, and structure
134 * defining a timer setting.
135 */
136 #define ITIMER_REAL 0
137 #define ITIMER_VIRTUAL 1
138 #define ITIMER_PROF 2
139
140 struct itimerval {
141 struct timeval it_interval; /* timer interval */
142 struct timeval it_value; /* current value */
143 };
144
145 /*
146 * Structure defined by POSIX.1b to be like a itimerval, but with
147 * timespecs. Used in the timer_*() system calls.
148 */
149 struct itimerspec {
150 struct timespec it_interval;
151 struct timespec it_value;
152 };
153
154 /*
155 * Getkerninfo clock information structure
156 */
157 struct clockinfo {
158 int hz; /* clock frequency */
159 int tick; /* micro-seconds per hz tick */
160 int tickadj; /* clock skew rate for adjtime() */
161 int stathz; /* statistics clock frequency */
162 int profhz; /* profiling clock frequency */
163 };
164
165 #define CLOCK_REALTIME 0
166 #define CLOCK_VIRTUAL 1
167 #define CLOCK_PROF 2
168 #define CLOCK_MONOTONIC 3
169
170 #define TIMER_RELTIME 0x0 /* relative timer */
171 #define TIMER_ABSTIME 0x1 /* absolute timer */
172
173 #ifdef _KERNEL
174 /*
175 * Structure used to manage timers in a process.
176 */
177 struct ptimer {
178 union {
179 struct callout pt_ch;
180 struct {
181 LIST_ENTRY(ptimer) pt_list;
182 int pt_active;
183 } pt_nonreal;
184 } pt_data;
185 struct sigevent pt_ev;
186 struct itimerval pt_time;
187 struct ksiginfo pt_info;
188 int pt_overruns; /* Overruns currently accumulating */
189 int pt_poverruns; /* Overruns associated w/ a delivery */
190 int pt_type;
191 int pt_entry;
192 struct proc *pt_proc;
193 };
194
195 #define pt_ch pt_data.pt_ch
196 #define pt_list pt_data.pt_nonreal.pt_list
197 #define pt_active pt_data.pt_nonreal.pt_active
198
199 #define TIMER_MAX 32 /* See ptimers->pts_fired if you enlarge this */
200 #define TIMERS_ALL 0
201 #define TIMERS_POSIX 1
202
203 LIST_HEAD(ptlist, ptimer);
204
205 struct ptimers {
206 struct ptlist pts_virtual;
207 struct ptlist pts_prof;
208 struct ptimer *pts_timers[TIMER_MAX];
209 int pts_fired;
210 };
211
212 int itimerfix __P((struct timeval *tv));
213 int itimerdecr __P((struct ptimer *, int));
214 void itimerfire __P((struct ptimer *));
215 void microtime __P((struct timeval *tv));
216 int settime __P((struct timeval *));
217 int ratecheck __P((struct timeval *, const struct timeval *));
218 int ppsratecheck __P((struct timeval *, int *, int));
219 int settimeofday1 __P((const struct timeval *, const struct timezone *,
220 struct proc *));
221 int adjtime1 __P((const struct timeval *, struct timeval *, struct proc *));
222 int clock_settime1 __P((clockid_t, const struct timespec *));
223 void timer_settime __P((struct ptimer *));
224 void timer_gettime __P((struct ptimer *, struct itimerval *));
225 void timers_alloc __P((struct proc *));
226 void timers_free __P((struct proc *, int));
227 void realtimerexpire __P((void *));
228 #else /* !_KERNEL */
229
230 #ifndef _STANDALONE
231 #include <time.h>
232
233 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
234 #include <sys/cdefs.h>
235
236 __BEGIN_DECLS
237 int adjtime __P((const struct timeval *, struct timeval *));
238 int futimes __P((int, const struct timeval *));
239 int getitimer __P((int, struct itimerval *));
240 int gettimeofday __P((struct timeval *, struct timezone *));
241 int lutimes __P((const char *, const struct timeval *));
242 int setitimer __P((int, const struct itimerval *, struct itimerval *));
243 int settimeofday __P((const struct timeval *, const struct timezone *));
244 int utimes __P((const char *, const struct timeval *));
245 __END_DECLS
246 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
247
248 #endif /* !_STANDALONE */
249
250 #endif /* !_KERNEL */
251
252 #endif /* !_SYS_TIME_H_ */
Cache object: 3282cb1c8f6a557532bb220f7b153f38
|