]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/testing/selftests/bpf/bpf_util.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;
17 fp
= fopen(fcpu
, "r");
19 printf("Failed to open %s: '%s'!\n", fcpu
, strerror(errno
));
23 while (fgets(buff
, sizeof(buff
), fp
)) {
24 n
= sscanf(buff
, "%u-%u", &start
, &end
);
26 printf("Failed to retrieve # possible CPUs!\n");
31 possible_cpus
= start
== 0 ? end
+ 1 : 0;
39 #define __bpf_percpu_val_align __attribute__((__aligned__(8)))
41 #define BPF_DECLARE_PERCPU(type, name) \
42 struct { type v; /* padding */ } __bpf_percpu_val_align \
43 name[bpf_num_possible_cpus()]
44 #define bpf_percpu(name, cpu) name[(cpu)].v
46 #endif /* __BPF_UTIL__ */