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
get_tsc_freq(void)29 get_tsc_freq(void)
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 RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
40 else if (tmp != 1)
41 RTE_LOG(WARNING, EAL, "TSC is not safe to use in SMP mode\n");
42
43 tmp = 0;
44
45 if (sysctlbyname("kern.timecounter.invariant_tsc", &tmp, &sz, NULL, 0))
46 RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
47 else if (tmp != 1)
48 RTE_LOG(WARNING, EAL, "TSC is not invariant\n");
49
50 sz = sizeof(tsc_hz);
51 if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) {
52 RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
53 return 0;
54 }
55
56 return tsc_hz;
57 }
58
59 int
rte_eal_timer_init(void)60 rte_eal_timer_init(void)
61 {
62 set_tsc_freq();
63 return 0;
64 }
65