mirror of
https://github.com/torvalds/linux.git
synced 2024-10-30 00:32:38 +00:00
selftests/bpf: Make bpf_util work on uniprocessor systems
The current implementation fails to work on uniprocessor systems. Fix the parser to also handle the uniprocessor case. Signed-off-by: Thomas Meyer <thomas@m3y3r.de> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
This commit is contained in:
parent
6f0003363a
commit
56a268cd4a
@ -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) {
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user