32#include <sys/timetc.h>
34#include <machine/cpu.h>
45 uint64_t clk0, clk1, clk_delay, n,
passes = 0;
46 uint64_t t0, t1, tadj, tlast;
101 t0 = tc->tc_get_timecount(tc) & tc->tc_counter_mask;
109 t1 = tc->tc_get_timecount(tc) & tc->tc_counter_mask;
110 while (t1 + tadj < tlast)
111 tadj += (uint64_t)tc->tc_counter_mask + 1;
116 if (t1 > tc->tc_frequency) {
117 printf(
"Statistical %s calibration failed! "
118 "Clocks might be ticking at variable rates.\n",
120 printf(
"Falling back to slow %s calibration.\n",
122 freq = (double)(tc->tc_frequency) * clk1 / t1;
131 mu_clk += d1 * inv_n;
132 d2 = d1 * (clk1 - mu_clk);
133 va_clk += (d2 - va_clk) * inv_n;
138 d2 = d1 * (t1 - mu_t);
139 va_t += (d2 - va_t) * inv_n;
142 d2 = d1 * (clk1 - mu_clk);
143 cva += (d2 - cva) * inv_n;
149#define TSC_PPM_UNCERTAINTY 1
150#define TSC_UNCERTAINTY TSC_PPM_UNCERTAINTY * 0.000001
151#define TSC_UNCERTAINTY_SQR TSC_UNCERTAINTY * TSC_UNCERTAINTY
153 (va_t + 4) * (va_clk + 4) - cva * cva)
160 freq = (double)(tc->tc_frequency) * cva / va_t;
162 printf(
"Statistical %s calibration took"
163 " %lu us and %lu data points\n",
164 clkname, (
unsigned long)(t1 *
165 1000000.0 / tc->tc_frequency),
177 clk_delay = clk() + (clk() - clk0) / (n * n);
178 while (clk() < clk_delay)
struct timecounter * timecounter
static driver_list_t passes
uint64_t clockcalib(uint64_t(*clk)(void), const char *clkname)
#define TSC_UNCERTAINTY_SQR
int printf(const char *fmt,...)