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 while (fgets(buff
, sizeof(buff
), fp
)) {
25 n
= sscanf(buff
, "%u-%u", &start
, &end
);
27 printf("Failed to retrieve # possible CPUs!\n");
32 possible_cpus
= start
== 0 ? end
+ 1 : 0;
40 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
42 #define BPF_DECLARE_PERCPU(type, name) \
43 struct { type v; /* padding */ } __bpf_percpu_val_align \
44 name[bpf_num_possible_cpus()]
45 #define bpf_percpu(name, cpu) name[(cpu)].v
47 #endif /* __BPF_UTIL__ */