diff mbox

[10/31] perf test: Enforce LLVM test for BPF test

Message ID 561F94EE.2060503@huawei.com
State New
Headers show

Commit Message

Wang Nan Oct. 15, 2015, 11:58 a.m. UTC
On 2015/10/14 23:48, Namhyung Kim wrote:
> 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 <hekuang@huawei.com>
>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
>> Cc: Alexei Starovoitov <ast@plumgrid.com>
>> Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
>> Cc: Daniel Borkmann <daniel@iogearbox.net>
>> Cc: David Ahern <dsahern@gmail.com>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Cc: Kaixu Xia <xiakaixu@huawei.com>
>> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
>> Cc: Zefan Li <lizefan@huawei.com>
>> 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.
>

Fixed by this way:


Thank you.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Comments

Wang Nan Nov. 4, 2015, 1:41 a.m. UTC | #1
On 2015/11/4 2:24, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 15, 2015 at 07:58:38PM +0800, Wangnan (F) escreveu:

>>>> +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.

>>>

>> Fixed by this way:

> Can you please try refreshing this patchset on top of what is now in

> acme/perf/core?

>

> Also why do we need those struct test->{prepare,cleanup} pointers? You

> introduced it and then, on the next patch that touches 'perf test' and

> uses test__llvm_{prepare,cleanup} you call them directly, which I think

> should be enough, i.e. keep them as functions to call from inside

> the test called from run_test(), right?

>

> - Arnaldo

>   


This prepare/cleanup functions are introduced because I want BPF
test reuse the result of LLVM test, so it don't need to compile
those BPF scripts twice. This is the reason I use shared
memory. However, now I think compiling twice is acceptable and
can make things simpler.

I'll update this patchset in my next pull request.

Thank you.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index e722e8a..25ddeaf 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -199,12 +199,15 @@  void test__llvm_prepare(void)

         for (i = 0; llvm_testcases[i].source; i++) {
                 struct test_llvm__bpf_result *result;
+               void *p;

-               result = mmap(NULL, SHARED_BUF_INIT_SIZE,
-                             PROT_READ | PROT_WRITE,
-                             MAP_SHARED | MAP_ANONYMOUS, -1, 0);
-               if (!result)
+               p = mmap(NULL, SHARED_BUF_INIT_SIZE,
+                        PROT_READ | PROT_WRITE,
+                        MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+               if (p == MAP_FAILED)
                         return;
+
+               result = p;
                 memset((void *)result, '\0', SHARED_BUF_INIT_SIZE);

                 llvm_testcases[i].result = result;