kern_tc.c (3d9d64aa1846217eac9229f8cba5cb6646a688b7) | kern_tc.c (bb53dd56c30c6360fc82be762ed98b0af6b9f69f) |
---|---|
1/*- 2 * SPDX-License-Identifier: Beerware 3 * 4 * ---------------------------------------------------------------------------- 5 * "THE BEER-WARE LICENSE" (Revision 42): 6 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 7 * can do whatever you want with this stuff. If we meet some day, and you think 8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp --- 2141 unchanged lines hidden (view full) --- 2150} 2151 2152/* 2153 * We need to be slightly careful converting cputicks to microseconds. 2154 * There is plenty of margin in 64 bits of microseconds (half a million 2155 * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply 2156 * before divide conversion (to retain precision) we find that the 2157 * margin shrinks to 1.5 hours (one millionth of 146y). | 1/*- 2 * SPDX-License-Identifier: Beerware 3 * 4 * ---------------------------------------------------------------------------- 5 * "THE BEER-WARE LICENSE" (Revision 42): 6 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you 7 * can do whatever you want with this stuff. If we meet some day, and you think 8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp --- 2141 unchanged lines hidden (view full) --- 2150} 2151 2152/* 2153 * We need to be slightly careful converting cputicks to microseconds. 2154 * There is plenty of margin in 64 bits of microseconds (half a million 2155 * years) and in 64 bits at 4 GHz (146 years), but if we do a multiply 2156 * before divide conversion (to retain precision) we find that the 2157 * margin shrinks to 1.5 hours (one millionth of 146y). |
2158 * With a three prong approach we never lose significant bits, no 2159 * matter what the cputick rate and length of timeinterval is. | |
2160 */ 2161 2162uint64_t 2163cputick2usec(uint64_t tick) 2164{ | 2158 */ 2159 2160uint64_t 2161cputick2usec(uint64_t tick) 2162{ |
2165 2166 if (tick > 18446744073709551LL) /* floor(2^64 / 1000) */ 2167 return (tick / (cpu_tickrate() / 1000000LL)); 2168 else if (tick > 18446744073709LL) /* floor(2^64 / 1000000) */ 2169 return ((tick * 1000LL) / (cpu_tickrate() / 1000LL)); 2170 else 2171 return ((tick * 1000000LL) / cpu_tickrate()); | 2163 uint64_t tr; 2164 tr = cpu_tickrate(); 2165 return ((tick / tr) * 1000000ULL) + ((tick % tr) * 1000000ULL) / tr; |
2172} 2173 2174cpu_tick_f *cpu_ticks = tc_cpu_ticks; 2175 2176static int vdso_th_enable = 1; 2177static int 2178sysctl_fast_gettime(SYSCTL_HANDLER_ARGS) 2179{ --- 90 unchanged lines hidden --- | 2166} 2167 2168cpu_tick_f *cpu_ticks = tc_cpu_ticks; 2169 2170static int vdso_th_enable = 1; 2171static int 2172sysctl_fast_gettime(SYSCTL_HANDLER_ARGS) 2173{ --- 90 unchanged lines hidden --- |