From eb1a09df610bcf5ffc387b847df3db74c2ec1d6a Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Tue, 2 Mar 2021 20:13:51 +1100 Subject: [PATCH 1/2] If cpuinfo parsing fails fallback to sysconf --- programs/util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/programs/util.c b/programs/util.c index 3fd4cd17e66..be048332b16 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1215,9 +1215,12 @@ int UTIL_countPhysicalCores(void) if (siblings && cpu_cores) { ratio = siblings / cpu_cores; } + + numPhysicalCores = numPhysicalCores / ratio; + failed: fclose(cpuinfo); - return numPhysicalCores = numPhysicalCores / ratio; + return numPhysicalCores; } } From 4d6c78fb892cc190bd86e3430650af3f946973e9 Mon Sep 17 00:00:00 2001 From: Paul Bone Date: Tue, 2 Mar 2021 20:31:23 +1100 Subject: [PATCH 2/2] Only set numPhysicalCores if ratio is valid --- programs/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/util.c b/programs/util.c index be048332b16..9b0405043f8 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1212,11 +1212,13 @@ int UTIL_countPhysicalCores(void) /* fall back on the sysconf value */ goto failed; } } - if (siblings && cpu_cores) { + if (siblings && cpu_cores && siblings > cpu_cores) { ratio = siblings / cpu_cores; } - numPhysicalCores = numPhysicalCores / ratio; + if (ratio && numPhysicalCores > ratio) { + numPhysicalCores = numPhysicalCores / ratio; + } failed: fclose(cpuinfo);