From patchwork Mon Sep 26 07:27:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 77010 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp1033582qgf; Mon, 26 Sep 2016 00:31:36 -0700 (PDT) X-Received: by 10.66.26.49 with SMTP id i17mr8806251pag.145.1474875096035; Mon, 26 Sep 2016 00:31:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z80si19082585pfj.29.2016.09.26.00.31.35; Mon, 26 Sep 2016 00:31:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161375AbcIZHbZ (ORCPT + 27 others); Mon, 26 Sep 2016 03:31:25 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:18515 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034803AbcIZHbV (ORCPT ); Mon, 26 Sep 2016 03:31:21 -0400 Received: from 172.24.1.47 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DNR66929; Mon, 26 Sep 2016 15:27:47 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Mon, 26 Sep 2016 15:27:40 +0800 From: Wang Nan To: , CC: , , , Wang Nan , Arnaldo Carvalho de Melo , Alexei Starovoitov , He Kuang , Jiri Olsa Subject: [PATCH v2 09/18] perf clang: Update test case to use real BPF script Date: Mon, 26 Sep 2016 07:27:03 +0000 Message-ID: <1474874832-134786-10-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 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.57E8CDF4.0072, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: d5fa00988d46b754e145c78f86f78588 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow C++ code to use util.h and tests/llvm.h. Let perf test to compile a real BPF script. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa --- tools/perf/Makefile.config | 27 +++++++++++++++------------ tools/perf/tests/llvm-cxx.h | 13 +++++++++++++ tools/perf/util/c++/clang-test.cpp | 17 ++++++++++++++--- tools/perf/util/util-cxx.h | 26 ++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 tools/perf/tests/llvm-cxx.h create mode 100644 tools/perf/util/util-cxx.h -- 1.8.3.4 diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index b99c597..3cf3cb5 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -212,24 +212,27 @@ ifeq ($(DEBUG),0) endif endif -CFLAGS += -I$(src-perf)/util/include -CFLAGS += -I$(src-perf)/arch/$(ARCH)/include -CFLAGS += -I$(srctree)/tools/include/uapi -CFLAGS += -I$(srctree)/tools/include/ -CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/uapi -CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/ -CFLAGS += -I$(srctree)/tools/arch/$(ARCH)/ +INC_FLAGS += -I$(src-perf)/util/include +INC_FLAGS += -I$(src-perf)/arch/$(ARCH)/include +INC_FLAGS += -I$(srctree)/tools/include/uapi +INC_FLAGS += -I$(srctree)/tools/include/ +INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/uapi +INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/include/ +INC_FLAGS += -I$(srctree)/tools/arch/$(ARCH)/ # $(obj-perf) for generated common-cmds.h # $(obj-perf)/util for generated bison/flex headers ifneq ($(OUTPUT),) -CFLAGS += -I$(obj-perf)/util -CFLAGS += -I$(obj-perf) +INC_FLAGS += -I$(obj-perf)/util +INC_FLAGS += -I$(obj-perf) endif -CFLAGS += -I$(src-perf)/util -CFLAGS += -I$(src-perf) -CFLAGS += -I$(srctree)/tools/lib/ +INC_FLAGS += -I$(src-perf)/util +INC_FLAGS += -I$(src-perf) +INC_FLAGS += -I$(srctree)/tools/lib/ + +CFLAGS += $(INC_FLAGS) +CXXFLAGS += $(INC_FLAGS) CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE diff --git a/tools/perf/tests/llvm-cxx.h b/tools/perf/tests/llvm-cxx.h new file mode 100644 index 0000000..d9c98fa --- /dev/null +++ b/tools/perf/tests/llvm-cxx.h @@ -0,0 +1,13 @@ +#ifndef PERF_TEST_LLVM_CXX_H +#define PERF_TEST_LLVM_CXX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tests/llvm.h" + +#ifdef __cplusplus +} +#endif +#endif diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp index 0f484fb..c5546fd 100644 --- a/tools/perf/util/c++/clang-test.cpp +++ b/tools/perf/util/c++/clang-test.cpp @@ -3,6 +3,10 @@ #include "llvm/IR/Function.h" #include "llvm/IR/LLVMContext.h" +#include +#include +#include + class perf_clang_scope { public: explicit perf_clang_scope() {perf_clang__init();} @@ -14,17 +18,24 @@ extern "C" { int test__clang_to_IR(void) { perf_clang_scope _scope; + unsigned int kernel_version; + + if (fetch_kernel_version(&kernel_version, NULL, 0)) + return -1; + + std::string cflag_kver("-DLINUX_VERSION_CODE=" + + std::to_string(kernel_version)); std::unique_ptr M = - perf::getModuleFromSource({"-DRESULT=1"}, + perf::getModuleFromSource({cflag_kver.c_str()}, "perf-test.c", - "int myfunc(void) {return RESULT;}"); + test_llvm__bpf_base_prog); if (!M) return -1; for (llvm::Function& F : *M) - if (F.getName() == "myfunc") + if (F.getName() == "bpf_func__SyS_epoll_wait") return 0; return -1; } diff --git a/tools/perf/util/util-cxx.h b/tools/perf/util/util-cxx.h new file mode 100644 index 0000000..0e0e019 --- /dev/null +++ b/tools/perf/util/util-cxx.h @@ -0,0 +1,26 @@ +/* + * Support C++ source use utilities defined in util.h + */ + +#ifndef PERF_UTIL_UTIL_CXX_H +#define PERF_UTIL_UTIL_CXX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Now 'new' is the only C++ keyword found in util.h: + * in tools/include/linux/rbtree.h + * + * Other keywords, like class and delete, should be + * redefined if necessary. + */ +#define new _new +#include "util.h" +#undef new + +#ifdef __cplusplus +} +#endif +#endif