Linux Perf
llvm-src-base.c
Go to the documentation of this file.
1 #include <tests/llvm.h>
3 "/*\n"
4 " * bpf-script-example.c\n"
5 " * Test basic LLVM building\n"
6 " */\n"
7 "#ifndef LINUX_VERSION_CODE\n"
8 "# error Need LINUX_VERSION_CODE\n"
9 "# error Example: for 4.2 kernel, put 'clang-opt=\"-DLINUX_VERSION_CODE=0x40200\" into llvm section of ~/.perfconfig'\n"
10 "#endif\n"
11 "#define BPF_ANY 0\n"
12 "#define BPF_MAP_TYPE_ARRAY 2\n"
13 "#define BPF_FUNC_map_lookup_elem 1\n"
14 "#define BPF_FUNC_map_update_elem 2\n"
15 "\n"
16 "static void *(*bpf_map_lookup_elem)(void *map, void *key) =\n"
17 " (void *) BPF_FUNC_map_lookup_elem;\n"
18 "static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =\n"
19 " (void *) BPF_FUNC_map_update_elem;\n"
20 "\n"
21 "struct bpf_map_def {\n"
22 " unsigned int type;\n"
23 " unsigned int key_size;\n"
24 " unsigned int value_size;\n"
25 " unsigned int max_entries;\n"
26 "};\n"
27 "\n"
28 "#define SEC(NAME) __attribute__((section(NAME), used))\n"
29 "struct bpf_map_def SEC(\"maps\") flip_table = {\n"
30 " .type = BPF_MAP_TYPE_ARRAY,\n"
31 " .key_size = sizeof(int),\n"
32 " .value_size = sizeof(int),\n"
33 " .max_entries = 1,\n"
34 "};\n"
35 "\n"
36 "SEC(\"func=SyS_epoll_wait\")\n"
37 "int bpf_func__SyS_epoll_wait(void *ctx)\n"
38 "{\n"
39 " int ind =0;\n"
40 " int *flag = bpf_map_lookup_elem(&flip_table, &ind);\n"
41 " int new_flag;\n"
42 " if (!flag)\n"
43 " return 0;\n"
44 " /* flip flag and store back */\n"
45 " new_flag = !*flag;\n"
46 " bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);\n"
47 " return new_flag;\n"
48 "}\n"
49 "char _license[] SEC(\"license\") = \"GPL\";\n"
50 "int _version SEC(\"version\") = LINUX_VERSION_CODE;\n"
51 ;
const char test_llvm__bpf_base_prog[]
Definition: llvm-src-base.c:2