1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 #include <string.h> 5 #include <stdio.h> 6 #include <unistd.h> 7 #include <inttypes.h> 8 #include <sys/types.h> 9 #include <sys/sysctl.h> 10 #include <errno.h> 11 12 #include <rte_common.h> 13 #include <rte_log.h> 14 #include <rte_cycles.h> 15 #include <rte_memory.h> 16 #include <rte_eal.h> 17 #include <rte_debug.h> 18 19 #include "eal_private.h" 20 #include "eal_internal_cfg.h" 21 22 #ifdef RTE_LIBEAL_USE_HPET 23 #warning HPET is not supported in FreeBSD 24 #endif 25 26 enum timer_source eal_timer_source = EAL_TIMER_TSC; 27 28 uint64_t 29 get_tsc_freq(uint64_t arch_hz) 30 { 31 size_t sz; 32 int tmp; 33 uint64_t tsc_hz; 34 35 sz = sizeof(tmp); 36 tmp = 0; 37 38 if (sysctlbyname("kern.timecounter.smp_tsc", &tmp, &sz, NULL, 0)) 39 EAL_LOG(WARNING, "%s", strerror(errno)); 40 else if (tmp != 1) 41 EAL_LOG(WARNING, "TSC is not safe to use in SMP mode"); 42 43 tmp = 0; 44 45 if (sysctlbyname("kern.timecounter.invariant_tsc", &tmp, &sz, NULL, 0)) 46 EAL_LOG(WARNING, "%s", strerror(errno)); 47 else if (tmp != 1) 48 EAL_LOG(WARNING, "TSC is not invariant"); 49 50 sz = sizeof(tsc_hz); 51 if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) { 52 EAL_LOG(WARNING, "%s", strerror(errno)); 53 return arch_hz; 54 } 55 56 if (arch_hz && RTE_MAX(arch_hz, tsc_hz) - RTE_MIN(arch_hz, tsc_hz) > arch_hz / 100) 57 EAL_LOG(WARNING, "Host tsc_freq %"PRIu64" at odds with cpu value %"PRIu64, 58 tsc_hz, arch_hz); 59 60 return tsc_hz; 61 } 62 63 int 64 rte_eal_timer_init(void) 65 { 66 set_tsc_freq(); 67 return 0; 68 } 69