46#if defined(_SYS_TIME_H_) && defined(_KERNEL)
52#define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0)
55#define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec)
58#define timespeccmp(tvp, uvp, cmp) \
59 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
60 ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
61 ((tvp)->tv_sec cmp (uvp)->tv_sec))
65#define timespecadd(tsp, usp, vsp) \
67 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
68 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
69 if ((vsp)->tv_nsec >= 1000000000L) { \
71 (vsp)->tv_nsec -= 1000000000L; \
76#define timespecsub(tsp, usp, vsp) \
78 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
79 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
80 if ((vsp)->tv_nsec < 0) { \
82 (vsp)->tv_nsec += 1000000000L; \
95#define TICKS_2_MSEC(t) max(1, (uint32_t)(hz == 1000) ? \
96 (t) : (((uint64_t)(t) * (uint64_t)1000)/(uint64_t)hz))
97#define TICKS_2_USEC(t) max(1, (uint32_t)(hz == 1000) ? \
98 ((t) * 1000) : (((uint64_t)(t) * (uint64_t)1000000)/(uint64_t)hz))
99#define MSEC_2_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \
100 (m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000))
101#define USEC_2_TICKS(u) max(1, (uint32_t)((hz == 1000) ? \
102 ((u) / 1000) : ((uint64_t)(u) * (uint64_t)hz)/(uint64_t)1000000))
106#define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
107#define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
108#define timevalcmp(tvp, uvp, cmp) \
109 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
110 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
111 ((tvp)->tv_sec cmp (uvp)->tv_sec))
118void inittodr(time_t base);
121#define time_second _Timecounter_Time_second
122#define time_uptime _Timecounter_Time_uptime
123extern struct timeval boottime;
124extern struct bintime tc_tick_bt;
125extern sbintime_t tc_tick_sbt;
126extern struct bintime tick_bt;
127extern sbintime_t tick_sbt;
128extern int tc_precexp;
129extern int tc_timepercentage;
130extern struct bintime bt_timethreshold;
131extern struct bintime bt_tickthreshold;
132extern sbintime_t sbt_timethreshold;
133extern sbintime_t sbt_tickthreshold;
156#define binuptime(_bt) _Timecounter_Binuptime(_bt)
157#define nanouptime(_tsp) _Timecounter_Nanouptime(_tsp)
158#define microuptime(_tvp) _Timecounter_Microuptime(_tvp)
160static __inline sbintime_t
166 return (bttosbt(_bt));
169#define bintime(_bt) _Timecounter_Bintime(_bt)
170#define nanotime(_tsp) _Timecounter_Nanotime(_tsp)
171#define microtime(_tvp) _Timecounter_Microtime(_tvp)
173#define getbinuptime(_bt) _Timecounter_Getbinuptime(_bt)
174#define getnanouptime(_tsp) _Timecounter_Getnanouptime(_tsp)
175#define getmicrouptime(_tvp) _Timecounter_Getmicrouptime(_tvp)
177static __inline sbintime_t
183 return (bttosbt(_bt));
186#define getbintime(_bt) _Timecounter_Getbintime(_bt)
187#define getnanotime(_tsp) _Timecounter_Getnanotime(_tsp)
188#define getmicrotime(_tvp) _Timecounter_Getmicrotime(_tvp)
190#define getboottime(_tvp) _Timecounter_Getboottime(_tvp)
191#define getboottimebin(_bt) _Timecounter_Getboottimebin(_bt)
194int itimerdecr(
struct itimerval *itp,
int usec);
195int itimerfix(
struct timeval *tv);
196int ppsratecheck(
struct timeval *,
int *,
int);
197int ratecheck(
struct timeval *,
const struct timeval *);
198void timevaladd(
struct timeval *t1,
const struct timeval *t2);
199void timevalsub(
struct timeval *t1,
const struct timeval *t2);
200int tvtohz(
struct timeval *tv);
202#define TC_DEFAULTPERC 5
205 (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \
208#define SBT2FREQ(sbt) ((SBT_1S + ((sbt) >> 1)) / (sbt))
210#define FREQ2BT(freq, bt) \
213 (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \
216#define TIMESEL(sbt, sbt2) \
217 (((sbt2) >= sbt_timethreshold) ? \
218 ((*(sbt) = getsbinuptime()), 1) : ((*(sbt) = sbinuptime()), 0))
221#error "must be included via <sys/time.h> in kernel space"
This header file provides timecounter definitions for the kernel space (_KERNEL is defined before inc...