diff --git a/programs/util.c b/programs/util.c index 652530b1223..bff85f16455 100644 --- a/programs/util.c +++ b/programs/util.c @@ -1593,6 +1593,9 @@ int UTIL_countCores(int logical) int siblings = 0; int cpu_cores = 0; + #if ZSTD_PARSE_FULL_CPUINFO == 1 + int procs = 0; + #endif int ratio = 1; if (cpuinfo == NULL) { @@ -1622,6 +1625,17 @@ int UTIL_countCores(int logical) cpu_cores = atoi(sep + 1); } + #if ZSTD_PARSE_FULL_CPUINFO == 1 + if (strncmp(buff, "processor", 9) == 0) { + const char* const sep = strchr(buff, ':'); + if (sep == NULL || *sep == '\0') { + /* formatting was broken? */ + goto failed; + } + + procs++; + } + #endif } else if (ferror(cpuinfo)) { /* fall back on the sysconf value */ goto failed; @@ -1633,6 +1647,11 @@ int UTIL_countCores(int logical) if (ratio && numCores > ratio && !logical) { numCores = numCores / ratio; } +#if ZSTD_PARSE_FULL_CPUINFO == 1 + if (procs) { + numCores = procs; + } +#endif failed: fclose(cpuinfo); diff --git a/programs/util.h b/programs/util.h index 65e12633a67..bab22827870 100644 --- a/programs/util.h +++ b/programs/util.h @@ -87,6 +87,13 @@ # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif +/* enable or disable (default) parsing all /proc/cpuinfo to cout all cpu cores number + * That ruins physical/logical logics + */ +#ifndef ZSTD_PARSE_FULL_CPUINFO +# define ZSTD_PARSE_FULL_CPUINFO 0 +#endif + #if defined (__cplusplus) extern "C" {