From patchwork Thu Oct 8 08:29:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54632 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 08B6622FF8 for ; Thu, 8 Oct 2015 08:35:08 +0000 (UTC) Received: by wibzt1 with SMTP id zt1sf1123813wib.2 for ; Thu, 08 Oct 2015 01:35:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=EqqjimhukUTmSzwvrORic/fYWTTRJvdEXHQyaFKlGoQ=; b=JAwG1H2ll6P0z0lbBrgCJyHgFJg1zWMG9toVWT679WDlCeRcYIDTc/icNjJGFVmFTN I/B2cUUPVr1r7Qyo4Wk/FyKI4yDzF2gNVbzwqncgPQABOnGc4mFPCRZIxFSXrTk1Yq5q mqBsvDEoUatsUVSIYw2BHm2fVCtE/kCTnp1yvaVHE+BXnOOnTtSOu5rzv+26vdTeZg/K QIFUb8TizNTF+hjxY9JTeYDwFKHnKZK6p2JZHAhUkFELFUXSKbclJ43tqQFHOnUQQKt1 8TaOy7RrnLh4En/133YFnzNY99uV6GsDInaVoOx4pFxc4pFVsCiY6nZcf4RTsFpE5CP2 KoEw== X-Gm-Message-State: ALoCoQnGySK/t79hz0Y1RsAzw/AVI8dBhELUQYc4A5UEx4ECsIrZeN8x/ywMTC70QkiXWkPlvCFz X-Received: by 10.112.63.165 with SMTP id h5mr1147875lbs.18.1444293307269; Thu, 08 Oct 2015 01:35:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.18.226 with SMTP id 95ls162187lfs.1.gmail; Thu, 08 Oct 2015 01:35:07 -0700 (PDT) X-Received: by 10.112.198.198 with SMTP id je6mr3004278lbc.31.1444293307089; Thu, 08 Oct 2015 01:35:07 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id e78si28800158lfg.157.2015.10.08.01.35.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 01:35:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbwt4 with SMTP id wt4so38650164lbb.1 for ; Thu, 08 Oct 2015 01:35:07 -0700 (PDT) X-Received: by 10.25.19.73 with SMTP id j70mr1919196lfi.29.1444293306827; Thu, 08 Oct 2015 01:35:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp439460lbq; Thu, 8 Oct 2015 01:35:05 -0700 (PDT) X-Received: by 10.107.16.158 with SMTP id 30mr7141104ioq.50.1444293305506; Thu, 08 Oct 2015 01:35:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b138si30798148ioe.67.2015.10.08.01.35.05; Thu, 08 Oct 2015 01:35:05 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754517AbbJHIfB (ORCPT + 30 others); Thu, 8 Oct 2015 04:35:01 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:51316 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754203AbbJHIe4 (ORCPT ); Thu, 8 Oct 2015 04:34:56 -0400 Received: from 172.24.1.49 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BOO15960; Thu, 08 Oct 2015 16:30:51 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Oct 2015 16:29:45 +0800 From: Wang Nan To: CC: , , , Wang Nan , Alexei Starovoitov , Brendan Gregg , Daniel Borkmann , David Ahern , He Kuang , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra Subject: [PATCH 21/22] perf test: Enforce LLVM test, add kbuild test Date: Thu, 8 Oct 2015 08:29:43 +0000 Message-ID: <1444292984-13135-22-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444292984-13135-1-git-send-email-wangnan0@huawei.com> References: <1444292984-13135-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.0A090204.56162A84.00A8, 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: 2456318d7876ac63b31fe84e071235c1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch enforces existing LLVM test, makes it compile more than one BPF source file. The compiled results are stored, can be used for other testcases. Except the first testcase (named LLVM_TESTCASE_BASE), failures of other test cases are not considered as failure of the whole test. Adds a kbuild testcase to check whether kernel headers can be correctly found. For example: # perf test LLVM 38: Test LLVM searching and compiling : (llvm.kbuild-dir can be fixed) Ok Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/ebpf-6yw9eg0ej3l4jnqhinngkw86@git.kernel.org --- tools/perf/tests/Build | 11 ++- tools/perf/tests/bpf-script-example.c | 4 + tools/perf/tests/bpf-script-test-kbuild.c | 21 ++++ tools/perf/tests/bpf.c | 3 +- tools/perf/tests/llvm.c | 154 ++++++++++++++++++++++-------- tools/perf/tests/llvm.h | 10 +- 6 files changed, 156 insertions(+), 47 deletions(-) create mode 100644 tools/perf/tests/bpf-script-test-kbuild.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index d0278a9..23e2201 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -31,17 +31,24 @@ perf-y += sample-parsing.o perf-y += parse-no-sample-id-all.o perf-y += kmod-path.o perf-y += thread-map.o -perf-y += llvm.o llvm-src.o +perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o perf-y += bpf.o perf-y += topology.o -$(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c +$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c $(call rule_mkdir) $(Q)echo '#include ' > $@ $(Q)echo 'const char test_llvm__bpf_prog[] =' >> $@ $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ $(Q)echo ';' >> $@ +$(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c + $(call rule_mkdir) + $(Q)echo '#include ' > $@ + $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@ + $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ + $(Q)echo ';' >> $@ + ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64)) perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o endif diff --git a/tools/perf/tests/bpf-script-example.c b/tools/perf/tests/bpf-script-example.c index 410a70b..0ec9c2c 100644 --- a/tools/perf/tests/bpf-script-example.c +++ b/tools/perf/tests/bpf-script-example.c @@ -1,3 +1,7 @@ +/* + * 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' diff --git a/tools/perf/tests/bpf-script-test-kbuild.c b/tools/perf/tests/bpf-script-test-kbuild.c new file mode 100644 index 0000000..a11f589 --- /dev/null +++ b/tools/perf/tests/bpf-script-test-kbuild.c @@ -0,0 +1,21 @@ +/* + * bpf-script-test-kbuild.c + * Test include from kernel header + */ +#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 SEC(NAME) __attribute__((section(NAME), used)) + +#include +#include + +SEC("func=vfs_llseek") +int bpf_func__vfs_llseek(struct pt_regs *ctx) +{ + return 0; +} + +char _license[] SEC("license") = "GPL"; +int _version SEC("version") = LINUX_VERSION_CODE; diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index d7cdc84..4dd701b 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c @@ -140,7 +140,8 @@ int test__bpf(void) return TEST_SKIP; } - test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz); + test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz, LLVM_TESTCASE_BASE); + if (!obj_buf || !obj_buf_sz) { if (verbose == 0) fprintf(stderr, " (fix 'perf test LLVM' first)"); diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c index fd5fdb0..75cd99f 100644 --- a/tools/perf/tests/llvm.c +++ b/tools/perf/tests/llvm.c @@ -9,6 +9,22 @@ #include "debug.h" #include "llvm.h" +#define SHARED_BUF_INIT_SIZE (1 << 20) +struct llvm_testcase { + const char *source; + const char *errmsg; + struct test_llvm__bpf_result *result; + bool tried; +} llvm_testcases[NR_LLVM_TESTCASES + 1] = { + [LLVM_TESTCASE_BASE] = {.source = test_llvm__bpf_prog, + .errmsg = "Basic LLVM compiling failed", + .tried = false}, + [LLVM_TESTCASE_KBUILD] = {.source = test_llvm__bpf_test_kbuild_prog, + .errmsg = "llvm.kbuild-dir can be fixed", + .tried = false}, + {.source = NULL} +}; + static int perf_config_cb(const char *var, const char *val, void *arg __maybe_unused) { @@ -36,7 +52,7 @@ static int test__bpf_parsing(void *obj_buf __maybe_unused, #endif static char * -compose_source(void) +compose_source(const char *raw_source) { struct utsname utsname; int version, patchlevel, sublevel, err; @@ -56,25 +72,27 @@ compose_source(void) version_code = (version << 16) + (patchlevel << 8) + sublevel; err = asprintf(&code, "#define LINUX_VERSION_CODE 0x%08lx;\n%s", - version_code, test_llvm__bpf_prog); + version_code, raw_source); if (err < 0) return NULL; return code; } -#define SHARED_BUF_INIT_SIZE (1 << 20) -struct test_llvm__bpf_result *p_test_llvm__bpf_result; -int test__llvm(void) +static int __test__llvm(int i) { - char *tmpl_new, *clang_opt_new; void *obj_buf; size_t obj_buf_sz; int err, old_verbose; - char *source; + const char *tmpl_old, *clang_opt_old; + char *tmpl_new, *clang_opt_new, *source; + const char *raw_source = llvm_testcases[i].source; + struct test_llvm__bpf_result *result = llvm_testcases[i].result; perf_config(perf_config_cb, NULL); + clang_opt_old = llvm_param.clang_opt; + tmpl_old = llvm_param.clang_bpf_cmd_template; /* * Skip this test if user's .perfconfig doesn't set [llvm] section @@ -99,15 +117,17 @@ int test__llvm(void) if (!llvm_param.clang_opt) llvm_param.clang_opt = strdup(""); - source = compose_source(); + source = compose_source(raw_source); if (!source) { pr_err("Failed to compose source code\n"); return -1; } /* Quote __EOF__ so strings in source won't be expanded by shell */ - err = asprintf(&tmpl_new, "cat << '__EOF__' | %s\n%s\n__EOF__\n", - llvm_param.clang_bpf_cmd_template, source); + err = asprintf(&tmpl_new, "cat << '__EOF__' | %s %s \n%s\n__EOF__\n", + llvm_param.clang_bpf_cmd_template, + !old_verbose ? "2>/dev/null" : "", + source); free(source); source = NULL; if (err < 0) { @@ -123,73 +143,123 @@ int test__llvm(void) llvm_param.clang_opt = clang_opt_new; err = llvm__compile_bpf("-", &obj_buf, &obj_buf_sz); + free((void *)llvm_param.clang_bpf_cmd_template); + free((void *)llvm_param.clang_opt); + llvm_param.clang_bpf_cmd_template = tmpl_old; + llvm_param.clang_opt = clang_opt_old; + verbose = old_verbose; - if (err) { - if (!verbose) - fprintf(stderr, " (use -v to see error message)"); + if (err) return -1; - } err = test__bpf_parsing(obj_buf, obj_buf_sz); - if (!err && p_test_llvm__bpf_result) { + if (!err && result) { if (obj_buf_sz > SHARED_BUF_INIT_SIZE) { pr_err("Resulting object too large\n"); } else { - p_test_llvm__bpf_result->size = obj_buf_sz; - memcpy(p_test_llvm__bpf_result->object, - obj_buf, obj_buf_sz); + result->size = obj_buf_sz; + memcpy(result->object, obj_buf, obj_buf_sz); } } free(obj_buf); return err; } +int test__llvm(void) +{ + int i, ret; + + for (i = 0; llvm_testcases[i].source; i++) { + ret = __test__llvm(i); + if (i == 0 && ret) { + /* + * First testcase tests basic LLVM compiling. If it + * fails, no need to check others. + */ + if (!verbose) + fprintf(stderr, " (use -v to see error message)"); + return ret; + } else if (ret) { + if (!verbose && llvm_testcases[i].errmsg) + fprintf(stderr, " (%s)", llvm_testcases[i].errmsg); + return 0; + } + } + return 0; +} + void test__llvm_prepare(void) { - p_test_llvm__bpf_result = mmap(NULL, SHARED_BUF_INIT_SIZE, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_ANONYMOUS, -1, 0); - if (!p_test_llvm__bpf_result) - return; - memset((void *)p_test_llvm__bpf_result, '\0', SHARED_BUF_INIT_SIZE); + int i; + + for (i = 0; llvm_testcases[i].source; i++) { + struct test_llvm__bpf_result *result; + + result = mmap(NULL, SHARED_BUF_INIT_SIZE, + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + if (!result) + return; + memset((void *)result, '\0', SHARED_BUF_INIT_SIZE); + + llvm_testcases[i].result = result; + } } void test__llvm_cleanup(void) { - unsigned long boundary, buf_end; + int i; - if (!p_test_llvm__bpf_result) - return; - if (p_test_llvm__bpf_result->size == 0) { - munmap((void *)p_test_llvm__bpf_result, SHARED_BUF_INIT_SIZE); - p_test_llvm__bpf_result = NULL; - return; - } + for (i = 0; llvm_testcases[i].source; i++) { + struct test_llvm__bpf_result *result; + unsigned long boundary, buf_end; - buf_end = (unsigned long)p_test_llvm__bpf_result + SHARED_BUF_INIT_SIZE; + result = llvm_testcases[i].result; + llvm_testcases[i].tried = true; - boundary = (unsigned long)(p_test_llvm__bpf_result); - boundary += p_test_llvm__bpf_result->size; - boundary = (boundary + (page_size - 1)) & + if (!result) + continue; + + if (result->size == 0) { + munmap((void *)result, SHARED_BUF_INIT_SIZE); + result = NULL; + llvm_testcases[i].result = NULL; + continue; + } + + buf_end = (unsigned long)result + SHARED_BUF_INIT_SIZE; + + boundary = (unsigned long)(result); + boundary += result->size; + boundary = (boundary + (page_size - 1)) & (~((unsigned long)page_size - 1)); - munmap((void *)boundary, buf_end - boundary); + munmap((void *)boundary, buf_end - boundary); + } } void -test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz) +test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, int index) { + struct test_llvm__bpf_result *result; + *p_obj_buf = NULL; *p_obj_buf_sz = 0; - if (!p_test_llvm__bpf_result) { + if (index > NR_LLVM_TESTCASES) + return; + + result = llvm_testcases[index].result; + + if (!result && !llvm_testcases[index].tried) { test__llvm_prepare(); test__llvm(); test__llvm_cleanup(); } - if (!p_test_llvm__bpf_result) + result = llvm_testcases[index].result; + if (!result) return; - *p_obj_buf = p_test_llvm__bpf_result->object; - *p_obj_buf_sz = p_test_llvm__bpf_result->size; + *p_obj_buf = result->object; + *p_obj_buf_sz = result->size; } diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h index 2fd7ed6..78ec01d 100644 --- a/tools/perf/tests/llvm.h +++ b/tools/perf/tests/llvm.h @@ -8,8 +8,14 @@ struct test_llvm__bpf_result { char object[]; }; -extern struct test_llvm__bpf_result *p_test_llvm__bpf_result; extern const char test_llvm__bpf_prog[]; -void test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz); +extern const char test_llvm__bpf_test_kbuild_prog[]; + +enum test_llvm__testcase { + LLVM_TESTCASE_BASE, + LLVM_TESTCASE_KBUILD, + NR_LLVM_TESTCASES, +}; +void test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, int index); #endif