powerpc/mm/4k: don't allocate larger pmd page table for 4k
[linux/fpc-iii.git] / tools / testing / selftests / bpf / bpf_util.h
blob84a5d1823f028344e7a4339e8aa5eb45506d797d
1 #ifndef __BPF_UTIL__
2 #define __BPF_UTIL__
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <errno.h>
9 static inline unsigned int bpf_num_possible_cpus(void)
11 static const char *fcpu = "/sys/devices/system/cpu/possible";
12 unsigned int start, end, possible_cpus = 0;
13 char buff[128];
14 FILE *fp;
16 fp = fopen(fcpu, "r");
17 if (!fp) {
18 printf("Failed to open %s: '%s'!\n", fcpu, strerror(errno));
19 exit(1);
22 while (fgets(buff, sizeof(buff), fp)) {
23 if (sscanf(buff, "%u-%u", &start, &end) == 2) {
24 possible_cpus = start == 0 ? end + 1 : 0;
25 break;
29 fclose(fp);
30 if (!possible_cpus) {
31 printf("Failed to retrieve # possible CPUs!\n");
32 exit(1);
35 return possible_cpus;
38 #endif /* __BPF_UTIL__ */