From 2dc2abb1d213012336c21e91bea350a64ba48cda Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 5 Jun 2023 14:48:09 -0700 Subject: til_util: actually enforce TIL_MAXCPUS uniformly The win32 and mach builds were free to violate this, as it's always just been a local define for putting some kind of bound on the linux "/sys/devices/system/cpu/cpuN" probing loop. But in preparation for moving TIL_MAXCPUS out to til_util.h for public consumption in sizing per-cpu arrays, it needs to actually be enforced consistently as an upper bound cap. That way everything can safely assume n_cpus won't ever exceed TIL_MAXCPUS. --- src/til_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/til_util.c b/src/til_util.c index dd2fca2..e91f9d6 100644 --- a/src/til_util.c +++ b/src/til_util.c @@ -15,7 +15,7 @@ #include "til_util.h" #define TIL_SYSFS_CPU "/sys/devices/system/cpu/cpu" -#define TIL_MAXCPUS 1024 +#define TIL_MAXCPUS 1024 unsigned til_get_ncpus(void) { @@ -24,7 +24,7 @@ unsigned til_get_ncpus(void) GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; + return MIN(sysinfo.dwNumberOfProcessors, TIL_MAXCPUS); #endif #ifdef __MACH__ @@ -34,7 +34,7 @@ unsigned til_get_ncpus(void) if (sysctlbyname("hw.logicalcpu_max", &count, &count_len, NULL, 0) < 0) return 1; - return count; + return MIN(count, TIL_MAXCPUS); #else char path[cstrlen(TIL_SYSFS_CPU "1024") + 1]; unsigned n; -- cgit v1.2.3