1 /* SPDX-License-Identifier: GPL-2.0 */
10 static inline unsigned int bpf_num_possible_cpus(void)
12 static const char *fcpu
= "/sys/devices/system/cpu/possible";
13 unsigned int start
, end
, possible_cpus
= 0;
18 fp
= fopen(fcpu
, "r");
20 printf("Failed to open %s: '%s'!\n", fcpu
, strerror(errno
));
24 if (!fgets(buff
, sizeof(buff
), fp
)) {
25 printf("Failed to read %s!\n", fcpu
);
30 for (i
= 0; i
<= len
; i
++) {
31 if (buff
[i
] == ',' || buff
[i
] == '\0') {
33 n
= sscanf(&buff
[j
], "%u-%u", &start
, &end
);
35 printf("Failed to retrieve # possible CPUs!\n");
40 possible_cpus
+= end
- start
+ 1;
50 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
52 #define BPF_DECLARE_PERCPU(type, name) \
53 struct { type v; /* padding */ } __bpf_percpu_val_align \
54 name[bpf_num_possible_cpus()]
55 #define bpf_percpu(name, cpu) name[(cpu)].v
58 # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
61 #endif /* __BPF_UTIL__ */