55 f64 time_now, time_start, time_limit, freq;
59 time_limit = time_now + sample_time;
61 while (time_now < time_limit)
65 freq = (t[1] - t[0]) / (time_now - time_start);
81 #if defined(__aarch64__) 86 fd = open (
"/proc/cpuinfo", 0);
95 if (
unformat (&input,
"cpu MHz : %f", &cpu_freq))
97 else if (
unformat (&input,
"timebase : %f", &ppc_timebase))
108 if (ppc_timebase != 0)
109 cpu_freq = ppc_timebase;
125 fd = open (
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", 0);
130 (void)
unformat (&input,
"%f", &cpu_freq);
141 #if defined (__aarch64__) 147 asm volatile (
"mrs %0, cntfrq_el0":
"=r" (hz));
153 u32 __clib_unused eax = 0, ebx = 0, ecx = 0, edx = 0;
168 return (
u64) ecx *ebx / eax;
170 if (max_leaf >= 0x16)
179 return 1e6 * (eax & 0xffff);
185 if (clib_cpu_supports_invariant_tsc ())
223 clib_warning (
"os_cpu_clock_frequency() returned 0.0, use 2e9...");
253 f64 now_reference, delta_reference, delta_reference_max;
254 f64 delta_clock_in_seconds;
255 u64 now_clock, delta_clock;
256 f64 new_clocks_per_second, delta;
292 delta_reference_max = delta_reference_max > 8.0 ? delta_reference_max : 8.0;
295 if (delta_reference <= 0.0 || delta_reference > delta_reference_max)
302 new_clocks_per_second = ((
f64) delta_clock) / delta_reference;
312 clib_warning (
"Rejecting large frequency change of %.2f%%",
335 int verbose = va_arg (*args,
int);
336 f64 now, reftime, delta_reftime_in_seconds,
error;
342 s =
format (s,
"Time now %.6f", now);
349 error = now - delta_reftime_in_seconds;
351 s =
format (s,
", reftime %.6f, error %.6f, clocks/sec %.6f",
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 clib_time_now(clib_time_t *c)
static u64 clib_cpu_time_now(void)
u32 log2_clocks_per_second
description fragment has unexpected format
static f64 unix_time_now(void)
__clib_export void clib_time_verify_frequency(clib_time_t *c)
static u64 min_log2_u64(u64 x)
u32 log2_clocks_per_frequency_verify
static int clib_get_cpuid(const u32 lev, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
__clib_export f64 os_cpu_clock_frequency(void)
#define clib_warning(format, args...)
static f64 clock_frequency_from_sys_filesystem(void)
static f64 clock_frequency_from_proc_filesystem(void)
__clib_export void clib_time_init(clib_time_t *c)
__clib_export u8 * format_clib_time(u8 *s, va_list *args)
f64 last_verify_reference_time
static f64 estimate_clock_frequency(f64 sample_time)