Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1246940

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

From Namhyung Kim <namhyung@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH 10/31] perf test: Enforce LLVM test for BPF test
Date 2015-10-14 18:00 +0200
Message-ID <qjwD8-39a-19@gated-at.bofh.it> (permalink)
References <qjtFf-7cv-3@gated-at.bofh.it> <qjtFi-7cv-57@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.


> +		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 <stddef.h> /* 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
> 
--
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/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/31] perf tools: filtering events using eBPF programs Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 28/31] perf tools: Add API to config maps in bpf object Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 12/31] perf probe: Reset args and nargs for probe_trace_event when failure Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 31/31] perf tools: Enable BPF object configure syntax Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 06/31] perf tools: Collect perf_evsel in BPF object files Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 10/31] perf test: Enforce LLVM test for BPF test Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
    Re: [PATCH 10/31] perf test: Enforce LLVM test for BPF test Namhyung Kim <namhyung@kernel.org> - 2015-10-14 18:00 +0200
      Re: [PATCH 10/31] perf test: Enforce LLVM test for BPF test "Wangnan (F)" <wangnan0@huawei.com> - 2015-10-15 14:10 +0200
  [PATCH 01/31] perf tools: Make perf depend on libbpf Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 29/31] perf tools: Add API to apply config to BPF map Wang Nan <wangnan0@huawei.com> - 2015-10-14 14:50 +0200
  [PATCH 22/31] perf test: Test BPF prologue Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 07/31] perf tools: Attach eBPF program to perf event Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 26/31] perf tools: Support perf event alias name Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 05/31] perf record: Load eBPF object into kernel Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 25/31] bpf tools: Extract and collect map names from BPF object file Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 18/31] perf tools: Use same BPF program if arguments are identical Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 04/31] perf record, bpf: Create probe points for BPF programs Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 21/31] perf test: Enforce LLVM test, add kbuild test Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  [PATCH 03/31] perf tools: Enable passing bpf object file to --event Wang Nan <wangnan0@huawei.com> - 2015-10-14 15:00 +0200
  Re: [GIT PULL 00/31] perf tools: filtering events using eBPF programs Namhyung Kim <namhyung@kernel.org> - 2015-10-14 17:50 +0200

csiph-web