24 #define CACHE_LINE_DEFAULT 128
25 #define CORES_DEFAULT 1
27 #include <freeradius-devel/util/hw.h>
28 #include <freeradius-devel/util/syserror.h>
29 #include <freeradius-devel/util/strerror.h>
32 #if defined(__APPLE__) || defined(__FreeBSD__)
33 #include <sys/sysctl.h>
37 size_t cache_line_size_len =
sizeof(cache_line_size);
39 sysctlbyname(
"hw.cachelinesize", &cache_line_size, &cache_line_size_len, 0, 0);
41 return cache_line_size;
47 size_t num_cores_len =
sizeof(num_cores);
49 sysctlbyname(
"hw.physicalcpu", &num_cores, &num_cores_len, 0, 0);
54 #elif defined(__linux__)
62 file = fopen(
"/sys/devices/system/cpu/cpu0/cache/index0/coherency_cache_line_size",
"r");
64 if (fscanf(
file,
"%d", &cache_line_size) != 1) {
70 return cache_line_size;
80 for (lcores = 0;;lcores++) {
83 snprintf(path,
sizeof(path),
"/sys/devices/system/cpu/cpu%u/topology/thread_siblings_list", lcores);
85 cpu = fopen(path,
"r");
88 while (fscanf(cpu,
"%[0-9]",
buff)) {
90 if (fgetc(cpu) !=
',')
break;
102 if (
unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) {
107 #ifdef STATIC_ANALYZER
111 if ((tsibs / lcores) == 0)
return 0;
114 return lcores / (tsibs / lcores);
size_t fr_hw_cache_line_size(void)
#define CACHE_LINE_DEFAULT
uint32_t fr_hw_num_cores_active(void)
static char buff[sizeof("18446744073709551615")+3]
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.