From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161300AbcIZH3J (ORCPT ); Mon, 26 Sep 2016 03:29:09 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:7683 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161212AbcIZH3E (ORCPT ); Mon, 26 Sep 2016 03:29:04 -0400 From: Wang Nan To: , CC: , , , Wang Nan , Arnaldo Carvalho de Melo , Alexei Starovoitov , He Kuang , Jiri Olsa Subject: [PATCH v2 17/18] perf clang: Include helpers to BPF scripts Date: Mon, 26 Sep 2016 07:27:11 +0000 Message-ID: <1474874832-134786-18-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1474874832-134786-1-git-send-email-wangnan0@huawei.com> References: <1474874832-134786-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.57E8CDFB.0013,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 6d98b8e5957455aa050edeec017be3aa Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Automatically include common used macros and struct definitions into BPF scripts. Script writers are no longer required to define 'SEC' and 'struct bpf_map_def' in each of their scripts. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa --- tools/perf/tests/bpf-script-example.c | 2 ++ tools/perf/tests/bpf-script-test-kbuild.c | 2 ++ tools/perf/tests/bpf-script-test-prologue.c | 2 ++ tools/perf/tests/bpf-script-test-relocation.c | 2 ++ tools/perf/util/c++/Build | 1 + tools/perf/util/c++/bpf-helper-str.c | 13 +++++++++++++ tools/perf/util/c++/clang-bpf-includes.h | 1 + tools/perf/util/c++/clang.cpp | 1 + 8 files changed, 24 insertions(+) create mode 100644 tools/perf/util/c++/bpf-helper-str.c diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c index 5fb3e66..c82d67b 100644 --- a/tools/perf/tests/bpf-script-example.c +++ b/tools/perf/tests/bpf-script-example.c @@ -9,6 +9,7 @@ #define BPF_ANY 0 #define BPF_MAP_TYPE_ARRAY 2 +#ifndef BPF_HELPER_DEFINED struct bpf_map_def { unsigned int type; unsigned int key_size; @@ -17,6 +18,7 @@ struct bpf_map_def { }; #define SEC(NAME) __attribute__((section(NAME), used)) +#endif #ifndef BPF_FUNCS_DEFINED #define BPF_FUNC_map_lookup_elem 1 diff --git a/tools/perf/tests/bpf-script-test-kbuild.c b/tools/perf/tests/bpf-script-test-kbuild.c index 3626924..d01126b 100644 --- a/tools/perf/tests/bpf-script-test-kbuild.c +++ b/tools/perf/tests/bpf-script-test-kbuild.c @@ -6,7 +6,9 @@ # error Need LINUX_VERSION_CODE # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' #endif +#ifndef BPF_HELPER_DEFINED #define SEC(NAME) __attribute__((section(NAME), used)) +#endif #include #include diff --git a/tools/perf/tests/bpf-script-test-prologue.c b/tools/perf/tests/bpf-script-test-prologue.c index e8dba36..e7ecbf1 100644 --- a/tools/perf/tests/bpf-script-test-prologue.c +++ b/tools/perf/tests/bpf-script-test-prologue.c @@ -6,7 +6,9 @@ # error Need LINUX_VERSION_CODE # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' #endif +#ifndef BPF_HELPER_DEFINED #define SEC(NAME) __attribute__((section(NAME), used)) +#endif #include diff --git a/tools/perf/tests/bpf-script-test-relocation.c b/tools/perf/tests/bpf-script-test-relocation.c index a9638eb7..dfccdf6 100644 --- a/tools/perf/tests/bpf-script-test-relocation.c +++ b/tools/perf/tests/bpf-script-test-relocation.c @@ -9,6 +9,7 @@ #define BPF_ANY 0 #define BPF_MAP_TYPE_ARRAY 2 +#ifndef BPF_HELPER_DEFINED struct bpf_map_def { unsigned int type; unsigned int key_size; @@ -17,6 +18,7 @@ struct bpf_map_def { }; #define SEC(NAME) __attribute__((section(NAME), used)) +#endif #ifndef BPF_FUNCS_DEFINED #define BPF_FUNC_map_lookup_elem 1 diff --git a/tools/perf/util/c++/Build b/tools/perf/util/c++/Build index bd71abf..faa0268 100644 --- a/tools/perf/util/c++/Build +++ b/tools/perf/util/c++/Build @@ -1,3 +1,4 @@ libperf-$(CONFIG_CLANGLLVM) += clang.o libperf-$(CONFIG_CLANGLLVM) += clang-test.o libperf-$(CONFIG_CLANGLLVM) += bpf-funcs-str.o +libperf-$(CONFIG_CLANGLLVM) += bpf-helper-str.o diff --git a/tools/perf/util/c++/bpf-helper-str.c b/tools/perf/util/c++/bpf-helper-str.c new file mode 100644 index 0000000..285ff01 --- /dev/null +++ b/tools/perf/util/c++/bpf-helper-str.c @@ -0,0 +1,13 @@ +#include "clang-bpf-includes.h" +const char clang_builtin_bpf_helper_str[] = +"#ifndef BPF_HELPER_DEFINED\n" +"#define BPF_HELPER_DEFINED\n" +"struct bpf_map_def {\n" +" unsigned int type;\n" +" unsigned int key_size;\n" +" unsigned int value_size;\n" +" unsigned int max_entries;\n" +"};\n" +"#define SEC(NAME) __attribute__((section(NAME), used))\n" +"#endif" +; diff --git a/tools/perf/util/c++/clang-bpf-includes.h b/tools/perf/util/c++/clang-bpf-includes.h index 385a5bb..577b40c 100644 --- a/tools/perf/util/c++/clang-bpf-includes.h +++ b/tools/perf/util/c++/clang-bpf-includes.h @@ -5,6 +5,7 @@ extern "C" { #endif extern const char clang_builtin_bpf_funcs_str[]; +extern const char clang_builtin_bpf_helper_str[]; #ifdef __cplusplus } diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp index 1016d5d..a2de788 100644 --- a/tools/perf/util/c++/clang.cpp +++ b/tools/perf/util/c++/clang.cpp @@ -38,6 +38,7 @@ static struct BPFHeader { llvm::StringRef Content; } BPFHeaders[] = { {"/virtual/bpf-funcs.h", clang_builtin_bpf_funcs_str}, + {"/virtual/bpf-helper.h", clang_builtin_bpf_helper_str}, }; static std::unique_ptr LLVMCtx; -- 1.8.3.4