55 const f64 round_to_units = 100e5;
57 f64 time_now, time_start, time_limit, freq;
61 time_limit = time_now + sample_time;
63 while (time_now < time_limit)
67 freq = (t[1] - t[0]) / (time_now - time_start);
69 freq = ifreq * round_to_units;
85 #if defined(__aarch64__) 90 fd = open (
"/proc/cpuinfo", 0);
99 if (
unformat (&input,
"cpu MHz : %f", &cpu_freq))
101 else if (
unformat (&input,
"timebase : %f", &ppc_timebase))
112 if (ppc_timebase != 0)
113 cpu_freq = ppc_timebase;
129 fd = open (
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", 0);
134 (void)
unformat (&input,
"%f", &cpu_freq);
145 #if defined (__aarch64__) 151 asm volatile (
"mrs %0, cntfrq_el0":
"=r" (hz));
156 if (clib_cpu_supports_invariant_tsc ())
200 f64 new_clocks_per_second, delta;
212 dtr_max = dtr_max > 8.0 ? dtr_max : 8.0;
214 if (dtr <= 0.0 || dtr > dtr_max)
222 f64 next_pow10, est_round_to_units;
229 est_round_to_units = ((
f64) dtc / dtr) * 0.001;
230 next_pow10 = ceil (log10 (est_round_to_units));
238 new_clocks_per_second =
248 clib_warning (
"Rejecting large frequency change of %.2f%%",
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static u64 clib_cpu_time_now(void)
u32 log2_clocks_per_second
static f64 unix_time_now(void)
static u64 min_log2_u64(u64 x)
u32 log2_clocks_per_frequency_verify
void clib_time_init(clib_time_t *c)
void clib_time_verify_frequency(clib_time_t *c)
#define clib_warning(format, args...)
static f64 clock_frequency_from_sys_filesystem(void)
f64 os_cpu_clock_frequency(void)
static f64 clock_frequency_from_proc_filesystem(void)
f64 last_verify_reference_time
static word flt_round_nearest(f64 x)
static f64 estimate_clock_frequency(f64 sample_time)