From b31de018a6284a25e0fdfeb028e724f8417ec3b1 Mon Sep 17 00:00:00 2001 From: Wang Nan Date: Fri, 6 Nov 2015 13:49:41 +0000 Subject: perf test: Enhance the LLVM test: update basic BPF test program This patch replaces the original toy BPF program with the previously introduced bpf-script-example.c. Dynamically embeddeding it into 'llvm-src-base.c'. The newly introduced BPF program attaches a BPF program to 'sys_epoll_pwait()'. perf itself never use that syscall, so further test can verify their result with it. The program would generate 1 sample in every 2 calls of epoll_pwait() system call. Since the resulting BPF object is useful per se for further tests, test_llvm__fetch_bpf_obj() is introduced for creating BPF objects from source. The LLVM test was rewritten to use it. Committer note: Running it: [root@zoo wb]# perf test -v LLVM 35: Test LLVM searching and compiling : --- start --- test child forked, pid 17740 Kernel build dir is set to /lib/modules/4.3.0-rc1+/build set env: KBUILD_DIR=/lib/modules/4.3.0-rc1+/build unset env: KBUILD_OPTS include option is set to -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.9.2/include -I/home/git/linux/arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated -I/home/git/linux/include -Iinclude -I/home/git/linux/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/home/git/linux/include/uapi -Iinclude/generated/uapi -include /home/git/linux/include/linux/kconfig.h set env: NR_CPUS=4 set env: LINUX_VERSION_CODE=0x40300 set env: CLANG_EXEC=/usr/libexec/icecc/bin/clang set env: CLANG_OPTIONS=-xc set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.9.2/include -I/home/git/linux/arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated -I/home/git/linux/include -Iinclude -I/home/git/linux/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/home/git/linux/include/uapi -Iinclude/generated/uapi -include /home/git/linux/include/linux/kconfig.h set env: WORKING_DIR=/lib/modules/4.3.0-rc1+/build set env: CLANG_SOURCE=- llvm compiling command template: echo '/* * bpf-script-example.c * Test basic LLVM building */ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' #endif #define BPF_ANY 0 #define BPF_MAP_TYPE_ARRAY 2 #define BPF_FUNC_map_lookup_elem 1 #define BPF_FUNC_map_update_elem 2 static void *(*bpf_map_lookup_elem)(void *map, void *key) = (void *) BPF_FUNC_map_lookup_elem; static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) = (void *) BPF_FUNC_map_update_elem; struct bpf_map_def { unsigned int type; unsigned int key_size; unsigned int value_size; unsigned int max_entries; }; #define SEC(NAME) __attribute__((section(NAME), used)) struct bpf_map_def SEC("maps") flip_table = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 1, }; SEC("func=sys_epoll_pwait") int bpf_func__sys_epoll_pwait(void *ctx) { int ind =0; int *flag = bpf_map_lookup_elem(&flip_table, &ind); int new_flag; if (!flag) return 0; /* flip flag and store back */ new_flag = !*flag; bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY); return new_flag; } char _license[] SEC("license") = "GPL"; int _version SEC("version") = LINUX_VERSION_CODE; ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o - test child finished with 0 ---- end ---- Test LLVM searching and compiling: Ok [root@zoo wb]# Signed-off-by: Wang Nan Tested-by: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1446817783-86722-6-git-send-email-wangnan0@huawei.com Signed-off-by: He Kuang Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/llvm.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tools/perf/tests/llvm.h (limited to 'tools/perf/tests/llvm.h') diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h new file mode 100644 index 0000000..bd63cee --- /dev/null +++ b/tools/perf/tests/llvm.h @@ -0,0 +1,16 @@ +#ifndef PERF_TEST_LLVM_H +#define PERF_TEST_LLVM_H + +#include /* for size_t */ +#include /* for bool */ + +extern const char test_llvm__bpf_base_prog[]; + +enum test_llvm__testcase { + LLVM_TESTCASE_BASE, + __LLVM_TESTCASE_MAX, +}; + +int test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, + enum test_llvm__testcase index, bool force); +#endif -- cgit v1.1 From 7af3f3d55b80cce40ad94b6b8e173dccedaf25e6 Mon Sep 17 00:00:00 2001 From: Wang Nan Date: Fri, 6 Nov 2015 13:49:42 +0000 Subject: perf test: Enhance the LLVM tests: add kbuild test This patch adds a kbuild testcase to check whether kernel headers can be correctly found. For example: # mv /lib/modules/4.3.0-rc5{,.bak} # perf test LLVM 38: Test LLVM searching and compiling : Skip # perf test -v LLVM ... :11:10: fatal error: 'uapi/linux/fs.h' file not found #include ^ 1 error generated. ERROR: unable to compile - Hint: Check error message shown above. Hint: You can also pre-compile it into .o using: clang -target bpf -O2 -c - with proper -I and -D options. Failed to compile test case: 'Test kbuild searching' test child finished with -2 Signed-off-by: Wang Nan Tested-by: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1446817783-86722-7-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/llvm.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools/perf/tests/llvm.h') diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h index bd63cee..d91d8f4 100644 --- a/tools/perf/tests/llvm.h +++ b/tools/perf/tests/llvm.h @@ -5,9 +5,11 @@ #include /* for bool */ extern const char test_llvm__bpf_base_prog[]; +extern const char test_llvm__bpf_test_kbuild_prog[]; enum test_llvm__testcase { LLVM_TESTCASE_BASE, + LLVM_TESTCASE_KBUILD, __LLVM_TESTCASE_MAX, }; -- cgit v1.1