9 #include <asm/byteorder.h>
11 #if __BYTE_ORDER == __LITTLE_ENDIAN
12 # define __bpf_ntohs(x) __builtin_bswap16(x)
13 # define __bpf_htons(x) __builtin_bswap16(x)
14 #elif __BYTE_ORDER == __BIG_ENDIAN
15 # define __bpf_ntohs(x) (x)
16 # define __bpf_htons(x) (x)
18 # error "Fix your __BYTE_ORDER?!"
21 #define bpf_htons(x) \
22 (__builtin_constant_p(x) ? \
23 __constant_htons(x) : __bpf_htons(x))
24 #define bpf_ntohs(x) \
25 (__builtin_constant_p(x) ? \
26 __constant_ntohs(x) : __bpf_ntohs(x))
28 static inline unsigned int bpf_num_possible_cpus(void)
30 static const char *fcpu = "/sys/devices/system/cpu/possible";
31 unsigned int start, end, possible_cpus = 0;
35 fp = fopen(fcpu, "r");
37 printf("Failed to open %s: '%s'!\n", fcpu, strerror(errno));
41 while (fgets(buff, sizeof(buff), fp)) {
42 if (sscanf(buff, "%u-%u", &start, &end) == 2) {
43 possible_cpus = start == 0 ? end + 1 : 0;
50 printf("Failed to retrieve # possible CPUs!\n");
57 #endif /* __BPF_UTIL__ */