1 /* $NetBSD: timevar.h,v 1.29 2010/04/08 11:51:13 njoly Exp $ */ 2 3 /* 4 * Copyright (c) 2005, 2008 The NetBSD Foundation. 5 * 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 * 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 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 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 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 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * Copyright (c) 1982, 1986, 1993 31 * The Regents of the University of California. All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 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 43 * without specific prior written permission. 44 * 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 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 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 55 * SUCH DAMAGE. 56 * 57 * @(#)time.h 8.5 (Berkeley) 5/4/95 58 */ 59 60 #ifndef _SYS_TIMEVAR_H_ 61 #define _SYS_TIMEVAR_H_ 62 63 #include <sys/callout.h> 64 #include <sys/queue.h> 65 #include <sys/signal.h> 66 #include <sys/systm.h> 67 68 /* 69 * Structure used to manage timers in a process. 70 */ 71 struct ptimer { 72 union { 73 callout_t pt_ch; 74 struct { 75 LIST_ENTRY(ptimer) pt_list; 76 int pt_active; 77 } pt_nonreal; 78 } pt_data; 79 struct sigevent pt_ev; 80 struct itimerspec pt_time; 81 struct ksiginfo pt_info; 82 int pt_overruns; /* Overruns currently accumulating */ 83 int pt_poverruns; /* Overruns associated w/ a delivery */ 84 int pt_type; 85 int pt_entry; 86 int pt_queued; 87 struct proc *pt_proc; 88 TAILQ_ENTRY(ptimer) pt_chain; 89 }; 90 91 #define pt_ch pt_data.pt_ch 92 #define pt_list pt_data.pt_nonreal.pt_list 93 #define pt_active pt_data.pt_nonreal.pt_active 94 95 #define TIMER_MAX 32 /* See ptimers->pts_fired if you enlarge this */ 96 #define TIMERS_ALL 0 97 #define TIMERS_POSIX 1 98 99 LIST_HEAD(ptlist, ptimer); 100 101 struct ptimers { 102 struct ptlist pts_virtual; 103 struct ptlist pts_prof; 104 struct ptimer *pts_timers[TIMER_MAX]; 105 int pts_fired; 106 }; 107 108 /* 109 * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() 110 * 111 * Functions without the "get" prefix returns the best timestamp 112 * we can produce in the given format. 113 * 114 * "bin" == struct bintime == seconds + 64 bit fraction of seconds. 115 * "nano" == struct timespec == seconds + nanoseconds. 116 * "micro" == struct timeval == seconds + microseconds. 117 * 118 * Functions containing "up" returns time relative to boot and 119 * should be used for calculating time intervals. 120 * 121 * Functions without "up" returns GMT time. 122 * 123 * Functions with the "get" prefix returns a less precise result 124 * much faster than the functions without "get" prefix and should 125 * be used where a precision of 1/HZ (eg 10 msec on a 100HZ machine) 126 * is acceptable or where performance is priority. 127 * (NB: "precision", _not_ "resolution" !) 128 * 129 */ 130 131 void binuptime(struct bintime *); 132 void nanouptime(struct timespec *); 133 void microuptime(struct timeval *); 134 135 void bintime(struct bintime *); 136 void nanotime(struct timespec *); 137 void microtime(struct timeval *); 138 139 void getbinuptime(struct bintime *); 140 void getnanouptime(struct timespec *); 141 void getmicrouptime(struct timeval *); 142 143 void getbintime(struct bintime *); 144 void getnanotime(struct timespec *); 145 void getmicrotime(struct timeval *); 146 147 /* Other functions */ 148 int abstimeout2timo(struct timespec *, int *); 149 void adjtime1(const struct timeval *, struct timeval *, struct proc *); 150 int clock_getres1(clockid_t, struct timespec *); 151 int clock_gettime1(clockid_t, struct timespec *); 152 int clock_settime1(struct proc *, clockid_t, const struct timespec *, bool); 153 int dogetitimer(struct proc *, int, struct itimerval *); 154 int dosetitimer(struct proc *, int, struct itimerval *); 155 int dotimer_gettime(int, struct proc *, struct itimerspec *); 156 int dotimer_settime(int, struct itimerspec *, struct itimerspec *, int, 157 struct proc *); 158 int tshzto(const struct timespec *); 159 int tvhzto(const struct timeval *); 160 void inittimecounter(void); 161 int itimerfix(struct timeval *); 162 int itimespecfix(struct timespec *); 163 int ppsratecheck(struct timeval *, int *, int); 164 int ratecheck(struct timeval *, const struct timeval *); 165 void realtimerexpire(void *); 166 int settime(struct proc *p, struct timespec *); 167 int nanosleep1(struct lwp *l, struct timespec *, struct timespec *); 168 int settimeofday1(const struct timeval *, bool, 169 const void *, struct lwp *, bool); 170 int timer_create1(timer_t *, clockid_t, struct sigevent *, copyin_t, 171 struct lwp *); 172 void timer_gettime(struct ptimer *, struct itimerspec *); 173 void timer_settime(struct ptimer *); 174 struct ptimers *timers_alloc(struct proc *); 175 void timers_free(struct proc *, int); 176 void timer_tick(struct lwp *, bool); 177 int tstohz(const struct timespec *); 178 int tvtohz(const struct timeval *); 179 int inittimeleft(struct timespec *, struct timespec *); 180 int gettimeleft(struct timespec *, struct timespec *); 181 void timerupcall(struct lwp *); 182 void time_init(void); 183 void time_init2(void); 184 bool time_wraps(struct timespec *, struct timespec *); 185 186 extern time_t time_second; /* current second in the epoch */ 187 extern time_t time_uptime; /* system uptime in seconds */ 188 189 #endif /* !_SYS_TIMEVAR_H_ */ 190