27 #if !defined(_SYS_TIME_H_) || !defined(_KERNEL) 28 #error "must be included via <sys/time.h> in kernel space" 31 #include <machine/_timecounter.h> 35 #define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) 38 #define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) 41 #define timespeccmp(tvp, uvp, cmp) \ 42 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 43 ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ 44 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 48 #define timespecadd(tsp, usp, vsp) \ 50 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ 51 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ 52 if ((vsp)->tv_nsec >= 1000000000L) { \ 54 (vsp)->tv_nsec -= 1000000000L; \ 59 #define timespecsub(tsp, usp, vsp) \ 61 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ 62 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ 63 if ((vsp)->tv_nsec < 0) { \ 65 (vsp)->tv_nsec += 1000000000L; \ 78 #define TICKS_2_MSEC(t) max(1, (uint32_t)(hz == 1000) ? \ 79 (t) : (((uint64_t)(t) * (uint64_t)1000)/(uint64_t)hz)) 80 #define TICKS_2_USEC(t) max(1, (uint32_t)(hz == 1000) ? \ 81 ((t) * 1000) : (((uint64_t)(t) * (uint64_t)1000000)/(uint64_t)hz)) 82 #define MSEC_2_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \ 83 (m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000)) 84 #define USEC_2_TICKS(u) max(1, (uint32_t)((hz == 1000) ? \ 85 ((u) / 1000) : ((uint64_t)(u) * (uint64_t)hz)/(uint64_t)1000000)) 89 #define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) 90 #define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) 91 #define timevalcmp(tvp, uvp, cmp) \ 92 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 93 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 94 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 101 void inittodr(time_t base);
102 void resettodr(
void);
104 #define time_second _Timecounter_Time_second 105 #define time_uptime _Timecounter_Time_uptime 106 extern struct timeval boottime;
107 extern struct bintime tc_tick_bt;
108 extern sbintime_t tc_tick_sbt;
109 extern struct bintime tick_bt;
110 extern sbintime_t tick_sbt;
111 extern int tc_precexp;
112 extern int tc_timepercentage;
113 extern struct bintime bt_timethreshold;
114 extern struct bintime bt_tickthreshold;
115 extern sbintime_t sbt_timethreshold;
116 extern sbintime_t sbt_tickthreshold;
139 #define binuptime(_bt) _Timecounter_Binuptime(_bt) 140 #define nanouptime(_tsp) _Timecounter_Nanouptime(_tsp) 141 #define microuptime(_tvp) _Timecounter_Microuptime(_tvp) 143 static __inline sbintime_t
149 return (bttosbt(_bt));
152 #define bintime(_bt) _Timecounter_Bintime(_bt) 153 #define nanotime(_tsp) _Timecounter_Nanotime(_tsp) 154 #define microtime(_tvp) _Timecounter_Microtime(_tvp) 156 #define getbinuptime(_bt) _Timecounter_Getbinuptime(_bt) 157 #define getnanouptime(_tsp) _Timecounter_Getnanouptime(_tsp) 158 #define getmicrouptime(_tvp) _Timecounter_Getmicrouptime(_tvp) 160 static __inline sbintime_t
166 return (bttosbt(_bt));
169 #define getbintime(_bt) _Timecounter_Getbintime(_bt) 170 #define getnanotime(_tsp) _Timecounter_Getnanotime(_tsp) 171 #define getmicrotime(_tvp) _Timecounter_Getmicrotime(_tvp) 173 #define getboottime(_tvp) _Timecounter_Getboottime(_tvp) 174 #define getboottimebin(_bt) _Timecounter_Getboottimebin(_bt) 177 int itimerdecr(
struct itimerval *itp,
int usec);
178 int itimerfix(
struct timeval *tv);
179 int ppsratecheck(
struct timeval *,
int *,
int);
180 int ratecheck(
struct timeval *,
const struct timeval *);
181 void timevaladd(
struct timeval *t1,
const struct timeval *t2);
182 void timevalsub(
struct timeval *t1,
const struct timeval *t2);
183 int tvtohz(
struct timeval *tv);
185 #define TC_DEFAULTPERC 5 187 #define BT2FREQ(bt) \ 188 (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \ 191 #define SBT2FREQ(sbt) ((SBT_1S + ((sbt) >> 1)) / (sbt)) 193 #define FREQ2BT(freq, bt) \ 196 (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \ 199 #define TIMESEL(sbt, sbt2) \ 200 (((sbt2) >= sbt_timethreshold) ? \ 201 ((*(sbt) = getsbinuptime()), 1) : ((*(sbt) = sbinuptime()), 0))