Index: sys/sys/time.h =================================================================== --- sys/sys/time.h (revision 242924) +++ sys/sys/time.h (working copy) @@ -55,6 +55,21 @@ struct bintime { uint64_t frac; }; +extern int tc_timethreshold; +extern struct bintime tick_bt; + +#define FREQ2BT(freq, bt) \ +{ \ + (bt)->sec = 0; \ + (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \ +} +#define BT2FREQ(bt) \ + (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \ + ((bt)->frac >> 1)) + +#define TIMESEL(x, bt) \ + (((x) < (c_timethreshold)) ? binuptime(&bt) : getbinuptime(&bt)) + static __inline void bintime_addx(struct bintime *bt, uint64_t x) { Index: sys/kern/kern_tc.c =================================================================== --- sys/kern/kern_tc.c (revision 242924) +++ sys/kern/kern_tc.c (working copy) @@ -119,6 +119,11 @@ static int timestepwarnings; SYSCTL_INT(_kern_timecounter, OID_AUTO, stepwarnings, CTLFLAG_RW, ×tepwarnings, 0, "Log time steps"); +int tc_timethreshold; +struct bintime tick_bt; +SYSCTL_INT(_kern, OID_AUTO, tc_timethreshold, CTLFLAG_RW, + &tc_timethreshold, 0, "Precision threshold for timing measurements"); + static void tc_windup(void); static void cpu_tick_calibrate(int); @@ -1708,6 +1713,7 @@ tc_ticktock(int cnt) static void inittimecounter(void *dummy) { + int tick_rate; u_int p; /* @@ -1723,6 +1729,9 @@ inittimecounter(void *dummy) else tc_tick = 1; p = (tc_tick * 1000000) / hz; + tc_timethreshold = 20 * imin(1000000000 / hz, 1000000); + tick_rate = imax(hz, tc_tick); + FREQ2BT(tick_rate, &tick_bt); printf("Timecounters tick every %d.%03u msec\n", p / 1000, p % 1000); #ifdef FFCLOCK @@ -1928,3 +1937,4 @@ tc_fill_vdso_timehands32(struct vdso_timehands32 * return (enabled); } #endif + Index: sys/kern/kern_timeout.c =================================================================== --- sys/kern/kern_timeout.c (revision 242924) +++ sys/kern/kern_timeout.c (working copy) @@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef SMP #include @@ -171,12 +172,6 @@ struct callout_cpu cc_cpu; #define CC_UNLOCK(cc) mtx_unlock_spin(&(cc)->cc_lock) #define CC_LOCK_ASSERT(cc) mtx_assert(&(cc)->cc_lock, MA_OWNED) -#define FREQ2BT(freq, bt) \ -{ \ - (bt)->sec = 0; \ - (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \ -} - #define TIME_T_MAX \ (sizeof(time_t) == (sizeof(int64_t)) ? INT64_MAX : INT32_MAX) Index: sys/kern/kern_clocksource.c =================================================================== --- sys/kern/kern_clocksource.c (revision 242924) +++ sys/kern/kern_clocksource.c (working copy) @@ -147,15 +147,6 @@ struct pcpu_state { static DPCPU_DEFINE(struct pcpu_state, timerstate); -#define FREQ2BT(freq, bt) \ -{ \ - (bt)->sec = 0; \ - (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \ -} -#define BT2FREQ(bt) \ - (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \ - ((bt)->frac >> 1)) - /* * Timer broadcast IPI handler. */