Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions programs/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions programs/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down