Commit 56a268cd authored by Thomas Meyer's avatar Thomas Meyer Committed by Shuah Khan

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: default avatarThomas Meyer <thomas@m3y3r.de>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
parent 6f000336
...@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void) ...@@ -12,6 +12,7 @@ static inline unsigned int bpf_num_possible_cpus(void)
unsigned int start, end, possible_cpus = 0; unsigned int start, end, possible_cpus = 0;
char buff[128]; char buff[128];
FILE *fp; FILE *fp;
int n;
fp = fopen(fcpu, "r"); fp = fopen(fcpu, "r");
if (!fp) { if (!fp) {
...@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void) ...@@ -20,17 +21,17 @@ static inline unsigned int bpf_num_possible_cpus(void)
} }
while (fgets(buff, sizeof(buff), fp)) { while (fgets(buff, sizeof(buff), fp)) {
if (sscanf(buff, "%u-%u", &start, &end) == 2) { n = sscanf(buff, "%u-%u", &start, &end);
possible_cpus = start == 0 ? end + 1 : 0; if (n == 0) {
break; 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); fclose(fp);
if (!possible_cpus) {
printf("Failed to retrieve # possible CPUs!\n");
exit(1);
}
return possible_cpus; return possible_cpus;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment