From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754246AbbJNPwr (ORCPT ); Wed, 14 Oct 2015 11:52:47 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:35781 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753652AbbJNPwq (ORCPT ); Wed, 14 Oct 2015 11:52:46 -0400 Date: Thu, 15 Oct 2015 00:48:42 +0900 From: Namhyung Kim To: Wang Nan Cc: acme@kernel.org, ast@plumgrid.com, brendan.d.gregg@gmail.com, a.p.zijlstra@chello.nl, daniel@iogearbox.net, dsahern@gmail.com, hekuang@huawei.com, jolsa@kernel.org, lizefan@huawei.com, masami.hiramatsu.pt@hitachi.com, paulus@samba.org, linux-kernel@vger.kernel.org, pi3orama@163.com, xiakaixu@huawei.com, Arnaldo Carvalho de Melo Subject: Re: [PATCH 10/31] perf test: Enforce LLVM test for BPF test Message-ID: <20151014154842.GC4085@danjae.kornet> References: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> <1444826502-49291-11-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1444826502-49291-11-git-send-email-wangnan0@huawei.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 14, 2015 at 12:41:21PM +0000, Wang Nan wrote: > This patch replaces the original toy BPF program with previous introduced > bpf-script-example.c. Dynamically embedded it into 'llvm-src.c'. > > The newly introduced BPF program attaches a BPF program at > 'sys_epoll_pwait()', and collect half samples from it. perf itself never > use that syscall, so further test can verify their result with it. > > Since BPF program require LINUX_VERSION_CODE of runtime kernel, this > patch computes that code from uname. > > Since the resuling BPF object is useful for further testcases, this patch > introduces 'prepare' and 'cleanup' method to tests, and makes test__llvm() > create a MAP_SHARED memory array to hold the resulting object. > > Signed-off-by: He Kuang > Signed-off-by: Wang Nan > Cc: Arnaldo Carvalho de Melo > Cc: Alexei Starovoitov > Cc: Brendan Gregg > Cc: Daniel Borkmann > Cc: David Ahern > 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 > --- [SNIP] > +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) It should check MAP_FAILED instead. > + return; > + memset((void *)p_test_llvm__bpf_result, '\0', SHARED_BUF_INIT_SIZE); > +} > + > +void test__llvm_cleanup(void) > +{ > + unsigned long boundary, buf_end; > + > + if (!p_test_llvm__bpf_result) Ditto. Thanks, Namhyung > + 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; > + } > + > + buf_end = (unsigned long)p_test_llvm__bpf_result + SHARED_BUF_INIT_SIZE; > + > + boundary = (unsigned long)(p_test_llvm__bpf_result); > + boundary += p_test_llvm__bpf_result->size; > + boundary = (boundary + (page_size - 1)) & > + (~((unsigned long)page_size - 1)); > + munmap((void *)boundary, buf_end - boundary); > +} > diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h > new file mode 100644 > index 0000000..1e89e46 > --- /dev/null > +++ b/tools/perf/tests/llvm.h > @@ -0,0 +1,14 @@ > +#ifndef PERF_TEST_LLVM_H > +#define PERF_TEST_LLVM_H > + > +#include /* for size_t */ > + > +struct test_llvm__bpf_result { > + size_t size; > + char object[]; > +}; > + > +extern struct test_llvm__bpf_result *p_test_llvm__bpf_result; > +extern const char test_llvm__bpf_prog[]; > + > +#endif > diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h > index c804869..a848802 100644 > --- a/tools/perf/tests/tests.h > +++ b/tools/perf/tests/tests.h > @@ -27,6 +27,8 @@ enum { > struct test { > const char *desc; > int (*func)(void); > + void (*prepare)(void); > + void (*cleanup)(void); > }; > > /* Tests */ > @@ -66,6 +68,8 @@ int test__fdarray__add(void); > int test__kmod_path__parse(void); > int test__thread_map(void); > int test__llvm(void); > +void test__llvm_prepare(void); > +void test__llvm_cleanup(void); > int test_session_topology(void); > > #if defined(__arm__) || defined(__aarch64__) > -- > 1.8.3.4 >