Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Count line of processor in /proc/cpuinfo on linux, that matches... #4512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sergey-dryabzhinsky wants to merge 7 commits into facebook:dev
base: dev
Choose a base branch
Loading
from sergey-dryabzhinsky:fix-cpu-count-linux-parse-cpuinfo
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
View file Open in desktop
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /