From 4af511389b00c6dd546efd253dbd94911edfbeac Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Sat, 18 Oct 2025 14:04:16 +0300 Subject: [PATCH 1/7] Count line of processor in /proc/cpuinfo on linux, that matches cpu cores even in lxc containers --- programs/util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/programs/util.c b/programs/util.c index 652530b1223..dc18a9ac042 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1593,6 +1593,7 @@ int UTIL_countCores(int logical) int siblings = 0; int cpu_cores = 0; + int procs = 0; int ratio = 1; if (cpuinfo == NULL) { @@ -1622,6 +1623,15 @@ int UTIL_countCores(int logical) cpu_cores = atoi(sep + 1); } + if (strncmp(buff, "processor", 9) == 0) { + const char* const sep = strchr(buff, ':'); + if (sep == NULL || *sep == '\0') { + /* formatting was broken? */ + goto failed; + } + + procs++; + } } else if (ferror(cpuinfo)) { /* fall back on the sysconf value */ goto failed; @@ -1633,6 +1643,9 @@ int UTIL_countCores(int logical) if (ratio && numCores > ratio && !logical) { numCores = numCores / ratio; } + if (procs) { + numCores = procs; + } failed: fclose(cpuinfo); From a6d80af29ba5069cd599395aaa88045f23028980 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 5 Nov 2025 15:13:15 +0300 Subject: [PATCH 2/7] Update util.h Adx new defined compile var --- programs/util.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/programs/util.h b/programs/util.h index 65e12633a67..a0ec820e7c0 100644 --- a/programs/util.h +++ b/programs/util.h @@ -87,6 +87,10 @@ # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif +#ifndef ZSTD_PARSEFULL_CPUINFO +# define ZSTD_PARSEFULL_CPUINFO 0 +#endif + #if defined (__cplusplus) extern "C" { From e215f803507e28ef43da16eeccd4337db959dd1a Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 5 Nov 2025 15:19:24 +0300 Subject: [PATCH 3/7] Update util.c Use new defined var to enable-disable hardcode --- programs/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/programs/util.c b/programs/util.c index dc18a9ac042..6e5d7f005d6 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1593,7 +1593,9 @@ int UTIL_countCores(int logical) int siblings = 0; int cpu_cores = 0; + #ifdef ZSTD_PARSEFULL_CPUINFO int procs = 0; + #endif int ratio = 1; if (cpuinfo == NULL) { @@ -1623,6 +1625,7 @@ int UTIL_countCores(int logical) cpu_cores = atoi(sep + 1); } + #ifdef ZSTD_PARSEFULL_CPUINFO if (strncmp(buff, "processor", 9) == 0) { const char* const sep = strchr(buff, ':'); if (sep == NULL || *sep == '\0') { @@ -1632,6 +1635,7 @@ int UTIL_countCores(int logical) procs++; } + #endif } else if (ferror(cpuinfo)) { /* fall back on the sysconf value */ goto failed; @@ -1643,9 +1647,11 @@ int UTIL_countCores(int logical) if (ratio && numCores > ratio && !logical) { numCores = numCores / ratio; } +#ifdef ZSTD_PARSEFULL_CPUINFO if (procs) { numCores = procs; } +#endif failed: fclose(cpuinfo); From 38b1e5ab32467586b1a1901a0d354ee1bad7df02 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 5 Nov 2025 15:23:50 +0300 Subject: [PATCH 4/7] Update util.h Add comments --- programs/util.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/programs/util.h b/programs/util.h index a0ec820e7c0..c248703cb8f 100644 --- a/programs/util.h +++ b/programs/util.h @@ -87,6 +87,8 @@ # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif +// enable or disable (defualt) parsing all /proc/cpuinfo to cout all cpu cores number +// That ruins physical/logical logics #ifndef ZSTD_PARSEFULL_CPUINFO # define ZSTD_PARSEFULL_CPUINFO 0 #endif From e1d78b8ac1b6eaa8314ff5c3d147069a16cba683 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Wed, 5 Nov 2025 15:27:36 +0300 Subject: [PATCH 5/7] Update util.h Fix comment --- programs/util.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/programs/util.h b/programs/util.h index c248703cb8f..8d0b26c2611 100644 --- a/programs/util.h +++ b/programs/util.h @@ -87,8 +87,9 @@ # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif -// enable or disable (defualt) parsing all /proc/cpuinfo to cout all cpu cores number -// That ruins physical/logical logics +/* enable or disable (default) parsing all /proc/cpuinfo to cout all cpu cores number + * That ruins physical/logical logics + */ #ifndef ZSTD_PARSEFULL_CPUINFO # define ZSTD_PARSEFULL_CPUINFO 0 #endif From fddb14f50cc8586cd2cd9c397cee57739d3f438b Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Thu, 6 Nov 2025 10:33:38 +0300 Subject: [PATCH 6/7] Update util.h Change var name --- programs/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/util.h b/programs/util.h index 8d0b26c2611..bab22827870 100644 --- a/programs/util.h +++ b/programs/util.h @@ -90,8 +90,8 @@ /* enable or disable (default) parsing all /proc/cpuinfo to cout all cpu cores number * That ruins physical/logical logics */ -#ifndef ZSTD_PARSEFULL_CPUINFO -# define ZSTD_PARSEFULL_CPUINFO 0 +#ifndef ZSTD_PARSE_FULL_CPUINFO +# define ZSTD_PARSE_FULL_CPUINFO 0 #endif From c8f694e59481c019bb53d93086d68559504cd5a1 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Thu, 6 Nov 2025 10:38:40 +0300 Subject: [PATCH 7/7] Update util.c Fixed prepocessor check on new var --- programs/util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/util.c b/programs/util.c index 6e5d7f005d6..bff85f16455 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1593,7 +1593,7 @@ int UTIL_countCores(int logical) int siblings = 0; int cpu_cores = 0; - #ifdef ZSTD_PARSEFULL_CPUINFO + #if ZSTD_PARSE_FULL_CPUINFO == 1 int procs = 0; #endif int ratio = 1; @@ -1625,7 +1625,7 @@ int UTIL_countCores(int logical) cpu_cores = atoi(sep + 1); } - #ifdef ZSTD_PARSEFULL_CPUINFO + #if ZSTD_PARSE_FULL_CPUINFO == 1 if (strncmp(buff, "processor", 9) == 0) { const char* const sep = strchr(buff, ':'); if (sep == NULL || *sep == '\0') { @@ -1647,7 +1647,7 @@ int UTIL_countCores(int logical) if (ratio && numCores > ratio && !logical) { numCores = numCores / ratio; } -#ifdef ZSTD_PARSEFULL_CPUINFO +#if ZSTD_PARSE_FULL_CPUINFO == 1 if (procs) { numCores = procs; }