0001
0002
0003
0004
0005
0006 #ifndef LINUX_VERSION_CODE
0007 # error Need LINUX_VERSION_CODE
0008 # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
0009 #endif
0010 #define BPF_ANY 0
0011 #define BPF_MAP_TYPE_ARRAY 2
0012 #define BPF_FUNC_map_lookup_elem 1
0013 #define BPF_FUNC_map_update_elem 2
0014
0015 static void *(*bpf_map_lookup_elem)(void *map, void *key) =
0016 (void *) BPF_FUNC_map_lookup_elem;
0017 static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
0018 (void *) BPF_FUNC_map_update_elem;
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #define __uint(name, val) int (*name)[val]
0036 #define __type(name, val) typeof(val) *name
0037
0038 #define SEC(NAME) __attribute__((section(NAME), used))
0039 struct {
0040 __uint(type, BPF_MAP_TYPE_ARRAY);
0041 __uint(max_entries, 1);
0042 __type(key, int);
0043 __type(value, int);
0044 } flip_table SEC(".maps");
0045
0046 SEC("func=do_epoll_wait")
0047 int bpf_func__SyS_epoll_pwait(void *ctx)
0048 {
0049 int ind =0;
0050 int *flag = bpf_map_lookup_elem(&flip_table, &ind);
0051 int new_flag;
0052 if (!flag)
0053 return 0;
0054
0055 new_flag = !*flag;
0056 bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
0057 return new_flag;
0058 }
0059 char _license[] SEC("license") = "GPL";
0060 int _version SEC("version") = LINUX_VERSION_CODE;