1 #ifndef LINUX_VERSION_CODE
2 # error Need LINUX_VERSION_CODE
3 # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
6 #define BPF_MAP_TYPE_ARRAY 2
7 #define BPF_FUNC_map_lookup_elem 1
8 #define BPF_FUNC_map_update_elem 2
10 static void *(*bpf_map_lookup_elem)(void *map, void *key) =
11 (void *) BPF_FUNC_map_lookup_elem;
12 static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
13 (void *) BPF_FUNC_map_update_elem;
17 unsigned int key_size;
18 unsigned int value_size;
19 unsigned int max_entries;
22 #define SEC(NAME) __attribute__((section(NAME), used))
23 struct bpf_map_def SEC("maps") flip_table = {
24 .type = BPF_MAP_TYPE_ARRAY,
25 .key_size = sizeof(int),
26 .value_size = sizeof(int),
30 SEC("func=sys_epoll_pwait")
31 int bpf_func__sys_epoll_pwait(void *ctx)
34 int *flag = bpf_map_lookup_elem(&flip_table, &ind);
38 /* flip flag and store back */
40 bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
43 char _license[] SEC("license") = "GPL";
44 int _version SEC("version") = LINUX_VERSION_CODE;