Skip to content

Commit

Permalink
selftests/bpf: Make bpf_util work on uniprocessor systems
Browse files Browse the repository at this point in the history
The current implementation fails to work on uniprocessor systems.
Fix the parser to also handle the uniprocessor case.

Signed-off-by: Thomas Meyer <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
thomasmey authored and Shuah Khan committed Sep 18, 2017
1 parent 6f00033 commit 56a268c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tools/testing/selftests/bpf/bpf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
unsigned int start, end, possible_cpus = 0;
char buff[128];
FILE *fp;
int n;

fp = fopen(fcpu, "r");
if (!fp) {
Expand All @@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
}

while (fgets(buff, sizeof(buff), fp)) {
if (sscanf(buff, "%u-%u", &start, &end) == 2) {
possible_cpus = start == 0 ? end + 1 : 0;
break;
n = sscanf(buff, "%u-%u", &start, &end);
if (n == 0) {
printf("Failed to retrieve # possible CPUs!\n");
exit(1);
} else if (n == 1) {
end = start;
}
possible_cpus = start == 0 ? end + 1 : 0;
break;
}

fclose(fp);
if (!possible_cpus) {
printf("Failed to retrieve # possible CPUs!\n");
exit(1);
}

return possible_cpus;
}
Expand Down

0 comments on commit 56a268c

Please sign in to comment.