Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1215710 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2015-08-29 06:30 +0200 |
| Last post | 2015-08-29 06:50 +0200 |
| Articles | 8 — 3 participants |
Back to article view | Back to linux.kernel
[GIT PULL 00/31] perf tools: filtering events using eBPF programs Wang Nan <wangnan0@huawei.com> - 2015-08-29 06:30 +0200
[PATCH 18/31] perf test: Add 'perf test BPF' Wang Nan <wangnan0@huawei.com> - 2015-08-29 06:30 +0200
Re: [PATCH 18/31] perf test: Add 'perf test BPF' Namhyung Kim <namhyung@kernel.org> - 2015-09-02 14:50 +0200
Re: [PATCH 18/31] perf test: Add 'perf test BPF' Wang Nan <pi3orama@163.com> - 2015-09-05 14:30 +0200
[PATCH 12/31] perf tools: Allow filter option to be applied to bof object Wang Nan <wangnan0@huawei.com> - 2015-08-29 06:40 +0200
[PATCH 30/31] perf tools: Fix cross compiling error Wang Nan <wangnan0@huawei.com> - 2015-08-29 06:40 +0200
[PATCH 05/31] perf ebpf: Add the libbpf glue Wang Nan <wangnan0@huawei.com> - 2015-08-29 06:40 +0200
[PATCH 13/31] perf tools: Attach eBPF program to perf event Wang Nan <wangnan0@huawei.com> - 2015-08-29 06:50 +0200
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-08-29 06:30 +0200 |
| Subject | [GIT PULL 00/31] perf tools: filtering events using eBPF programs |
| Message-ID | <q2FWa-7Rj-5@gated-at.bofh.it> |
Hi Arnaldo and Ingo,
Several small proglems are fixed based on yesterday's pull request. Please
see below. Since patch order is changed (original 20/32 and 32/32 are
dropped), I decide to send all of them again. Sorry for the noisy.
In addition: I collect a cross-compiling fix I posted yesterday into this
cset (the last one).
The following changes since commit 2c07144dfce366e21465cc7b0ada9f0b6dc7b7ed:
perf evlist: Add backpointer for perf_env to evlist (2015-08-28 14:54:14 -0300)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pi3orama/linux tags/perf-ebpf-for-acme-20150829
for you to fetch changes up to d4a337392b3724899a084170d9ea36a8e2392097:
tools lib traceevent: Support function __get_dynamic_array_len (2015-08-29 02:57:40 +0000)
----------------------------------------------------------------
perf BPF related improvements and bugfix:
- Rebase to Arnaldo's newest perf/core.
- Fix a missing include in builtin-trace.c.
- Drop patch 'perf tools: Fix probe-event.h include' since
the problem has been fixed by commit 5a023b57.
- Fix a cross compiling error (introduced by inter pt).
- Drop patch 'bpf: Introduce function for outputing data to
perf event' because we want to do better.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
----------------------------------------------------------------
He Kuang (4):
perf tools: Move linux/filter.h to tools/include
perf tools: Introduce arch_get_reg_info() for x86
perf record: Support custom vmlinux path
tools lib traceevent: Support function __get_dynamic_array_len
Wang Nan (27):
bpf tools: New API to get name from a BPF object
perf tools: Don't set cmdline_group_boundary if no evsel is collected
perf tools: Introduce dummy evsel
perf tools: Make perf depend on libbpf
perf ebpf: Add the libbpf glue
perf tools: Enable passing bpf object file to --event
perf probe: Attach trace_probe_event with perf_probe_event
perf record, bpf: Parse and probe eBPF programs probe points
perf bpf: Collect 'struct perf_probe_event' for bpf_program
perf record: Load all eBPF object into kernel
perf tools: Add bpf_fd field to evsel and config it
perf tools: Allow filter option to be applied to bof object
perf tools: Attach eBPF program to perf event
perf tools: Suppress probing messages when probing by BPF loading
perf record: Add clang options for compiling BPF scripts
perf tools: Infrastructure for compiling scriptlets when passing '.c' to --event
perf tests: Enforce LLVM test for BPF test
perf test: Add 'perf test BPF'
bpf tools: Load a program with different instances using preprocessor
perf probe: Reset args and nargs for probe_trace_event when failure
perf tools: Add BPF_PROLOGUE config options for further patches
perf tools: Add prologue for BPF programs for fetching arguments
perf tools: Generate prologue for BPF programs
perf tools: Use same BPF program if arguments are identical
perf probe: Init symbol as kprobe
perf tools: Support attach BPF program on uprobe events
perf tools: Fix cross compiling error
tools/build/Makefile.feature | 6 +-
tools/include/linux/filter.h | 237 +++++++
tools/lib/bpf/libbpf.c | 168 ++++-
tools/lib/bpf/libbpf.h | 26 +-
tools/lib/traceevent/event-parse.c | 56 +-
tools/lib/traceevent/event-parse.h | 1 +
tools/perf/MANIFEST | 4 +
tools/perf/Makefile.perf | 19 +-
tools/perf/arch/x86/Makefile | 1 +
tools/perf/arch/x86/util/Build | 2 +
tools/perf/arch/x86/util/dwarf-regs.c | 104 ++-
tools/perf/builtin-probe.c | 4 +-
tools/perf/builtin-record.c | 64 +-
tools/perf/builtin-stat.c | 9 +-
tools/perf/builtin-top.c | 11 +-
tools/perf/builtin-trace.c | 7 +-
tools/perf/config/Makefile | 31 +-
tools/perf/tests/Build | 10 +-
tools/perf/tests/bpf-script-example.c | 44 ++
tools/perf/tests/bpf.c | 170 +++++
tools/perf/tests/builtin-test.c | 12 +
tools/perf/tests/llvm.c | 125 +++-
tools/perf/tests/llvm.h | 15 +
tools/perf/tests/make | 4 +-
tools/perf/tests/tests.h | 3 +
tools/perf/util/Build | 4 +-
tools/perf/util/bpf-loader.c | 730 +++++++++++++++++++++
tools/perf/util/bpf-loader.h | 95 +++
tools/perf/util/bpf-prologue.c | 442 +++++++++++++
tools/perf/util/bpf-prologue.h | 34 +
tools/perf/util/evlist.c | 107 +++
tools/perf/util/evlist.h | 2 +
tools/perf/util/evsel.c | 49 ++
tools/perf/util/evsel.h | 7 +
tools/perf/util/include/dwarf-regs.h | 7 +
tools/perf/util/parse-events.c | 73 ++-
tools/perf/util/parse-events.h | 4 +
tools/perf/util/parse-events.l | 6 +
tools/perf/util/parse-events.y | 29 +-
tools/perf/util/probe-event.c | 79 ++-
tools/perf/util/probe-event.h | 7 +-
tools/perf/util/probe-file.c | 5 +-
tools/perf/util/probe-finder.c | 4 +
.../perf/util/scripting-engines/trace-event-perl.c | 1 +
.../util/scripting-engines/trace-event-python.c | 1 +
45 files changed, 2698 insertions(+), 121 deletions(-)
create mode 100644 tools/include/linux/filter.h
create mode 100644 tools/perf/tests/bpf-script-example.c
create mode 100644 tools/perf/tests/bpf.c
create mode 100644 tools/perf/tests/llvm.h
create mode 100644 tools/perf/util/bpf-loader.c
create mode 100644 tools/perf/util/bpf-loader.h
create mode 100644 tools/perf/util/bpf-prologue.c
create mode 100644 tools/perf/util/bpf-prologue.h
--
2.1.0
--
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/
[toc] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-08-29 06:30 +0200 |
| Subject | [PATCH 18/31] perf test: Add 'perf test BPF' |
| Message-ID | <q2FWc-7Rj-67@gated-at.bofh.it> |
| In reply to | #1215710 |
This patch adds BPF testcase for testing BPF event filtering.
By utilizing the result of 'perf test LLVM', this patch compiles the
eBPF sample program then test it ability. The BPF script in 'perf test
LLVM' collects half of execution of epoll_pwait(). This patch runs 111
times of it, so the resule should contains 56 samples.
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: He Kuang <hekuang@huawei.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/1440151770-129878-16-git-send-email-wangnan0@huawei.com
---
tools/perf/tests/Build | 1 +
tools/perf/tests/bpf.c | 170 ++++++++++++++++++++++++++++++++++++++++
tools/perf/tests/builtin-test.c | 4 +
tools/perf/tests/llvm.c | 19 +++++
tools/perf/tests/llvm.h | 1 +
tools/perf/tests/tests.h | 1 +
tools/perf/util/bpf-loader.c | 14 ++++
tools/perf/util/bpf-loader.h | 8 ++
8 files changed, 218 insertions(+)
create mode 100644 tools/perf/tests/bpf.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 8c98409..7ceb448 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -33,6 +33,7 @@ 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 += bpf.o
$(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c
$(Q)echo '#include <tests/llvm.h>' > $@
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
new file mode 100644
index 0000000..6c238ca
--- /dev/null
+++ b/tools/perf/tests/bpf.c
@@ -0,0 +1,170 @@
+#include <stdio.h>
+#include <sys/epoll.h>
+#include <util/bpf-loader.h>
+#include <util/evlist.h>
+#include "tests.h"
+#include "llvm.h"
+#include "debug.h"
+#define NR_ITERS 111
+
+#ifdef HAVE_LIBBPF_SUPPORT
+
+static int epoll_pwait_loop(void)
+{
+ int i;
+
+ /* Should fail NR_ITERS times */
+ for (i = 0; i < NR_ITERS; i++)
+ epoll_pwait(-(i + 1), NULL, 0, 0, NULL);
+ return 0;
+}
+
+static int prepare_bpf(void *obj_buf, size_t obj_buf_sz)
+{
+ int err;
+ char errbuf[BUFSIZ];
+
+ err = bpf__prepare_load_buffer(obj_buf, obj_buf_sz, NULL);
+ if (err) {
+ bpf__strerror_prepare_load("[buffer]", false, err, errbuf,
+ sizeof(errbuf));
+ fprintf(stderr, " (%s)", errbuf);
+ return TEST_FAIL;
+ }
+
+ err = bpf__probe();
+ if (err) {
+ bpf__strerror_load(err, errbuf, sizeof(errbuf));
+ fprintf(stderr, " (%s)", errbuf);
+ if (getuid() != 0)
+ fprintf(stderr, " (try run as root)");
+ return TEST_FAIL;
+ }
+
+ err = bpf__load();
+ if (err) {
+ bpf__strerror_load(err, errbuf, sizeof(errbuf));
+ fprintf(stderr, " (%s)", errbuf);
+ return TEST_FAIL;
+ }
+
+ return 0;
+}
+
+static int do_test(void)
+{
+ struct record_opts opts = {
+ .target = {
+ .uid = UINT_MAX,
+ .uses_mmap = true,
+ },
+ .freq = 0,
+ .mmap_pages = 256,
+ .default_interval = 1,
+ };
+
+ int err, i, count = 0;
+ char pid[16];
+ char sbuf[STRERR_BUFSIZE];
+ struct perf_evlist *evlist;
+
+ snprintf(pid, sizeof(pid), "%d", getpid());
+ pid[sizeof(pid) - 1] = '\0';
+ opts.target.tid = opts.target.pid = pid;
+
+ /* Instead of perf_evlist__new_default, don't add default events */
+ evlist = perf_evlist__new();
+ if (!evlist) {
+ pr_debug("No ehough memory to create evlist\n");
+ return -ENOMEM;
+ }
+
+ err = perf_evlist__create_maps(evlist, &opts.target);
+ if (err < 0) {
+ pr_debug("Not enough memory to create thread/cpu maps\n");
+ goto out_delete_evlist;
+ }
+
+ err = perf_evlist__add_bpf(evlist);
+ if (err) {
+ fprintf(stderr, " (Failed to add events selected by BPF)");
+ goto out_delete_evlist;
+ }
+
+ perf_evlist__config(evlist, &opts);
+
+ err = perf_evlist__open(evlist);
+ if (err < 0) {
+ pr_debug("perf_evlist__open: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
+ goto out_delete_evlist;
+ }
+
+ err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
+ if (err < 0) {
+ pr_debug("perf_evlist__mmap: %s\n",
+ strerror_r(errno, sbuf, sizeof(sbuf)));
+ goto out_delete_evlist;
+ }
+
+ perf_evlist__enable(evlist);
+ epoll_pwait_loop();
+ perf_evlist__disable(evlist);
+
+ for (i = 0; i < evlist->nr_mmaps; i++) {
+ union perf_event *event;
+
+ while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
+ const u32 type = event->header.type;
+
+ if (type == PERF_RECORD_SAMPLE)
+ count ++;
+ }
+ }
+
+ if (count != (NR_ITERS + 1) / 2) {
+ fprintf(stderr, " (filter result incorrect)");
+ err = -EBADF;
+ }
+
+out_delete_evlist:
+ perf_evlist__delete(evlist);
+ if (err)
+ return TEST_FAIL;
+ return 0;
+}
+
+int test__bpf(void)
+{
+ int err;
+ void *obj_buf;
+ size_t obj_buf_sz;
+
+ test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz);
+ if (!obj_buf || !obj_buf_sz) {
+ if (verbose == 0)
+ fprintf(stderr, " (fix 'perf test LLVM' first)");
+ return TEST_SKIP;
+ }
+
+ err = prepare_bpf(obj_buf, obj_buf_sz);
+ if (err)
+ goto out;
+
+ err = do_test();
+ if (err)
+ goto out;
+out:
+ bpf__unprobe();
+ bpf__clear();
+ if (err)
+ return TEST_FAIL;
+ return 0;
+}
+
+#else
+int test__bpf(void)
+{
+ return TEST_SKIP;
+}
+#endif
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 1a349e8..c32c836 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -183,6 +183,10 @@ static struct test {
.cleanup = test__llvm_cleanup,
},
{
+ .desc = "Test BPF filter",
+ .func = test__bpf,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 236bf39..fd5fdb0 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -174,3 +174,22 @@ void test__llvm_cleanup(void)
(~((unsigned long)page_size - 1));
munmap((void *)boundary, buf_end - boundary);
}
+
+void
+test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz)
+{
+ *p_obj_buf = NULL;
+ *p_obj_buf_sz = 0;
+
+ if (!p_test_llvm__bpf_result) {
+ test__llvm_prepare();
+ test__llvm();
+ test__llvm_cleanup();
+ }
+
+ if (!p_test_llvm__bpf_result)
+ return;
+
+ *p_obj_buf = p_test_llvm__bpf_result->object;
+ *p_obj_buf_sz = p_test_llvm__bpf_result->size;
+}
diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h
index 1e89e46..2fd7ed6 100644
--- a/tools/perf/tests/llvm.h
+++ b/tools/perf/tests/llvm.h
@@ -10,5 +10,6 @@ struct test_llvm__bpf_result {
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);
#endif
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 0d79f04..f8ded73 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -65,6 +65,7 @@ int test__thread_map(void);
int test__llvm(void);
void test__llvm_prepare(void);
void test__llvm_cleanup(void);
+int test__bpf(void);
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index c2aafe2..95e529b 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -153,6 +153,20 @@ sync_bpf_program_pev(struct bpf_program *prog)
return 0;
}
+int bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
+ const char *name)
+{
+ struct bpf_object *obj;
+
+ obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);
+ if (!obj) {
+ pr_debug("bpf: failed to load buffer\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
int bpf__prepare_load(const char *filename, bool source)
{
struct bpf_object *obj;
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 97aed65..dead4d4 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -19,6 +19,8 @@ typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
#ifdef HAVE_LIBBPF_SUPPORT
int bpf__prepare_load(const char *filename, bool source);
+int bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
+ const char *name);
int bpf__strerror_prepare_load(const char *filename, bool source,
int err, char *buf, size_t size);
int bpf__probe(void);
@@ -39,6 +41,12 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused,
return -1;
}
+static inline int bpf__prepare_load_buffer(void *obj_buf __maybe_unused,
+ size_t obj_buf_sz __maybe_unused)
+{
+ return bpf__prepare_load(NULL, false);
+}
+
static inline int bpf__probe(void) { return 0; }
static inline int bpf__unprobe(void) { return 0; }
static inline int bpf__load(void) { return 0; }
--
2.1.0
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Namhyung Kim <namhyung@kernel.org> |
|---|---|
| Date | 2015-09-02 14:50 +0200 |
| Subject | Re: [PATCH 18/31] perf test: Add 'perf test BPF' |
| Message-ID | <q4fEe-5kp-23@gated-at.bofh.it> |
| In reply to | #1215711 |
On Sat, Aug 29, 2015 at 04:21:52AM +0000, Wang Nan wrote:
> This patch adds BPF testcase for testing BPF event filtering.
>
> By utilizing the result of 'perf test LLVM', this patch compiles the
> eBPF sample program then test it ability. The BPF script in 'perf test
> LLVM' collects half of execution of epoll_pwait(). This patch runs 111
> times of it, so the resule should contains 56 samples.
>
> 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: He Kuang <hekuang@huawei.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/1440151770-129878-16-git-send-email-wangnan0@huawei.com
> ---
[SNIP]
> +static int prepare_bpf(void *obj_buf, size_t obj_buf_sz)
> +{
> + int err;
> + char errbuf[BUFSIZ];
> +
> + err = bpf__prepare_load_buffer(obj_buf, obj_buf_sz, NULL);
> + if (err) {
> + bpf__strerror_prepare_load("[buffer]", false, err, errbuf,
> + sizeof(errbuf));
> + fprintf(stderr, " (%s)", errbuf);
> + return TEST_FAIL;
> + }
> +
> + err = bpf__probe();
> + if (err) {
> + bpf__strerror_load(err, errbuf, sizeof(errbuf));
> + fprintf(stderr, " (%s)", errbuf);
> + if (getuid() != 0)
geteuid() ?
Thanks,
Namhyung
> + fprintf(stderr, " (try run as root)");
> + return TEST_FAIL;
> + }
> +
> + err = bpf__load();
> + if (err) {
> + bpf__strerror_load(err, errbuf, sizeof(errbuf));
> + fprintf(stderr, " (%s)", errbuf);
> + return TEST_FAIL;
> + }
> +
> + return 0;
> +}
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <pi3orama@163.com> |
|---|---|
| Date | 2015-09-05 14:30 +0200 |
| Subject | Re: [PATCH 18/31] perf test: Add 'perf test BPF' |
| Message-ID | <q5kLv-mE-1@gated-at.bofh.it> |
| In reply to | #1217581 |
On 09/02/2015 08:45 PM, Namhyung Kim wrote:
> On Sat, Aug 29, 2015 at 04:21:52AM +0000, Wang Nan wrote:
>> This patch adds BPF testcase for testing BPF event filtering.
>>
>> By utilizing the result of 'perf test LLVM', this patch compiles the
>> eBPF sample program then test it ability. The BPF script in 'perf test
>> LLVM' collects half of execution of epoll_pwait(). This patch runs 111
>> times of it, so the resule should contains 56 samples.
>>
>> 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: He Kuang <hekuang@huawei.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/1440151770-129878-16-git-send-email-wangnan0@huawei.com
>> ---
>
> [SNIP]
>
>> +static int prepare_bpf(void *obj_buf, size_t obj_buf_sz)
>> +{
>> + int err;
>> + char errbuf[BUFSIZ];
>> +
>> + err = bpf__prepare_load_buffer(obj_buf, obj_buf_sz, NULL);
>> + if (err) {
>> + bpf__strerror_prepare_load("[buffer]", false, err, errbuf,
>> + sizeof(errbuf));
>> + fprintf(stderr, " (%s)", errbuf);
>> + return TEST_FAIL;
>> + }
>> +
>> + err = bpf__probe();
>> + if (err) {
>> + bpf__strerror_load(err, errbuf, sizeof(errbuf));
>> + fprintf(stderr, " (%s)", errbuf);
>> + if (getuid() != 0)
>
> geteuid() ?
>
> Thanks,
> Namhyung
>
Already changed.
Thank you.
>
>> + fprintf(stderr, " (try run as root)");
>> + return TEST_FAIL;
>> + }
>> +
>> + err = bpf__load();
>> + if (err) {
>> + bpf__strerror_load(err, errbuf, sizeof(errbuf));
>> + fprintf(stderr, " (%s)", errbuf);
>> + return TEST_FAIL;
>> + }
>> +
>> + return 0;
>> +}
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-08-29 06:40 +0200 |
| Subject | [PATCH 12/31] perf tools: Allow filter option to be applied to bof object |
| Message-ID | <q2G5P-82q-1@gated-at.bofh.it> |
| In reply to | #1215710 |
Before this patch, --filter options can't be applied to BPF object
'events'. For example, the following command:
# perf record -e cycles -e test_bpf.o --exclude-perf -a sleep 1
doesn't apply '--exclude-perf' to events in test_bpf.o. Instead, the
filter will be applied to 'cycles' event. This is caused by the delay
manner of adding real BPF events. Because all BPF probing points are
probed by one call, we can't add real events until all BPF objects
are collected. In previous patch (perf tools: Enable passing bpf object
file to --event), nothing is appended to evlist.
This patch fixes this by utilizing the dummy event linked during
parse_events(). Filter settings goes to dummy event, and be synced with
real events in add_bpf_event().
Signed-off-by: Wang Nan <wangnan0@huawei.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: He Kuang <hekuang@huawei.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: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/r/1440742821-44548-5-git-send-email-wangnan0@huawei.com
---
tools/perf/builtin-record.c | 6 ++++-
tools/perf/util/bpf-loader.c | 8 ++++++-
tools/perf/util/bpf-loader.h | 2 ++
tools/perf/util/evlist.c | 53 +++++++++++++++++++++++++++++++++++++++++---
4 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 5051d3b..fd56a5b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1113,7 +1113,6 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
argc = parse_options(argc, argv, record_options, record_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- perf_evlist__purge_dummy(rec->evlist);
if (!argc && target__none(&rec->opts.target))
usage_with_options(record_usage, record_options);
@@ -1178,6 +1177,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
pr_err("Failed to add events from BPF object(s)\n");
goto out_symbol_exit;
}
+ /*
+ * Until now let's purge dummy event. Filter options should
+ * have been attached to real events by perf_evlist__add_bpf().
+ */
+ perf_evlist__purge_dummy(rec->evlist);
symbol__init(NULL);
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 126aa71..c3bc0a8 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -293,6 +293,12 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg)
int err;
bpf_object__for_each_safe(obj, tmp) {
+ const char *obj_name;
+
+ obj_name = bpf_object__get_name(obj);
+ if (!obj_name)
+ obj_name = "[unknown]";
+
bpf_object__for_each_program(prog, obj) {
struct probe_trace_event *tev;
struct perf_probe_event *pev;
@@ -316,7 +322,7 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg)
return fd;
}
- err = func(tev, fd, arg);
+ err = func(tev, obj_name, fd, arg);
if (err) {
pr_debug("bpf: call back failed, stop iterate\n");
return err;
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 34656f8..323e664 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -6,6 +6,7 @@
#define __BPF_LOADER_H
#include <linux/compiler.h>
+#include <linux/perf_event.h>
#include <string.h>
#include "probe-event.h"
#include "debug.h"
@@ -13,6 +14,7 @@
#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
+ const char *obj_name,
int fd, void *arg);
#ifdef HAVE_LIBBPF_SUPPORT
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f79bbf8..c00e939 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -197,7 +197,45 @@ error:
return -ENOMEM;
}
-static int add_bpf_event(struct probe_trace_event *tev, int fd,
+static void
+sync_with_dummy(struct perf_evlist *evlist, const char *obj_name,
+ struct list_head *list)
+{
+ struct perf_evsel *dummy_evsel, *pos;
+ const char *filter;
+ bool found = false;
+ int err;
+
+ evlist__for_each(evlist, dummy_evsel) {
+ if (!perf_evsel__is_dummy(dummy_evsel))
+ continue;
+
+ if (strcmp(dummy_evsel->name, obj_name) == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ pr_debug("Failed to find dummy event of '%s'\n",
+ obj_name);
+ return;
+ }
+
+ filter = dummy_evsel->filter;
+ if (!filter)
+ return;
+
+ list_for_each_entry(pos, list, node) {
+ err = perf_evsel__set_filter(pos, filter);
+ if (err)
+ pr_debug("Failed to set filter '%s' to evsel %s\n",
+ filter, pos->name);
+ }
+}
+
+static int add_bpf_event(struct probe_trace_event *tev,
+ const char *obj_name, int fd,
void *arg)
{
struct perf_evlist *evlist = arg;
@@ -205,8 +243,8 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd,
struct list_head list;
int err, idx, entries;
- pr_debug("add bpf event %s:%s and attach bpf program %d\n",
- tev->group, tev->event, fd);
+ pr_debug("add bpf event %s:%s and attach bpf program %d (from %s)\n",
+ tev->group, tev->event, fd, obj_name);
INIT_LIST_HEAD(&list);
idx = evlist->nr_entries;
@@ -228,6 +266,15 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd,
list_for_each_entry(pos, &list, node)
pos->bpf_fd = fd;
entries = idx - evlist->nr_entries;
+
+ sync_with_dummy(evlist, obj_name, &list);
+
+ /*
+ * Currectly we don't need to link those new events at the
+ * same place where dummy node reside because order of
+ * events in cmdline won't be used after
+ * 'perf_evlist__add_bpf'.
+ */
perf_evlist__splice_list_tail(evlist, &list, entries);
return 0;
}
--
2.1.0
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-08-29 06:40 +0200 |
| Subject | [PATCH 30/31] perf tools: Fix cross compiling error |
| Message-ID | <q2G5P-82q-3@gated-at.bofh.it> |
| In reply to | #1215710 |
Cross compiling perf to other platform failed due to missing symbol: ... AR /pathofperf/libperf.a LD /pathofperf/tests/perf-in.o LD /pathofperf/perf-in.o LINK /pathofperf/perf /pathofperf/libperf.a(libperf-in.o): In function `intel_pt_synth_branch_sample': /usr/src/kernel/tools/perf/util/intel-pt.c:899: undefined reference to `tsc_to_perf_time' /pathofperf/libperf.a(libperf-in.o): In function `intel_pt_synth_transaction_sample': /usr/src/kernel/tools/perf/util/intel-pt.c:992: undefined reference to `tsc_to_perf_time' /pathofperf/libperf.a(libperf-in.o): In function `intel_pt_synth_instruction_sample': /usr/src/kernel/tools/perf/util/intel-pt.c:943: undefined reference to `tsc_to_perf_time' ... This is because we allow newly introduced intel-pt-decoder to be compiled to not only X86, but tsc.c which required by it is compiled for x86 only. This patch fix the compiling error by allow tsc.c to be compiled if CONFIG_AUXTRACE is set, no matter the target platform. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Link: http://lkml.kernel.org/n/1440766442-48116-1-git-send-email-wangnan0@huawei.com --- tools/perf/util/Build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index fd2f084..c8d9c7e 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -74,7 +74,7 @@ libperf-y += stat-shadow.o libperf-y += record.o libperf-y += srcline.o libperf-y += data.o -libperf-$(CONFIG_X86) += tsc.o +libperf-$(CONFIG_AUXTRACE) += tsc.o libperf-y += cloexec.o libperf-y += thread-stack.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o -- 2.1.0 -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-08-29 06:40 +0200 |
| Subject | [PATCH 05/31] perf ebpf: Add the libbpf glue |
| Message-ID | <q2G5P-82q-5@gated-at.bofh.it> |
| In reply to | #1215710 |
The 'bpf-loader.[ch]' files are introduced in this patch. Which will be
the interface between perf and libbpf. bpf__prepare_load() resides in
bpf-loader.c. Dummy functions should be used because bpf-loader.c is
available only when CONFIG_LIBBPF is on.
Functions in bpf-loader.c should not report error explicitly. Instead,
strerror style error reporting should be used.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: 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: He Kuang <hekuang@huawei.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/1436445342-1402-19-git-send-email-wangnan0@huawei.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/bpf-loader.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/bpf-loader.h | 47 ++++++++++++++++++++++
2 files changed, 139 insertions(+)
create mode 100644 tools/perf/util/bpf-loader.c
create mode 100644 tools/perf/util/bpf-loader.h
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
new file mode 100644
index 0000000..88531ea
--- /dev/null
+++ b/tools/perf/util/bpf-loader.c
@@ -0,0 +1,92 @@
+/*
+ * bpf-loader.c
+ *
+ * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
+ * Copyright (C) 2015 Huawei Inc.
+ */
+
+#include <bpf/libbpf.h>
+#include "perf.h"
+#include "debug.h"
+#include "bpf-loader.h"
+
+#define DEFINE_PRINT_FN(name, level) \
+static int libbpf_##name(const char *fmt, ...) \
+{ \
+ va_list args; \
+ int ret; \
+ \
+ va_start(args, fmt); \
+ ret = veprintf(level, verbose, pr_fmt(fmt), args);\
+ va_end(args); \
+ return ret; \
+}
+
+DEFINE_PRINT_FN(warning, 0)
+DEFINE_PRINT_FN(info, 0)
+DEFINE_PRINT_FN(debug, 1)
+
+static bool libbpf_initialized;
+
+int bpf__prepare_load(const char *filename)
+{
+ struct bpf_object *obj;
+
+ if (!libbpf_initialized)
+ libbpf_set_print(libbpf_warning,
+ libbpf_info,
+ libbpf_debug);
+
+ obj = bpf_object__open(filename);
+ if (!obj) {
+ pr_debug("bpf: failed to load %s\n", filename);
+ return -EINVAL;
+ }
+
+ /*
+ * Throw object pointer away: it will be retrived using
+ * bpf_objects iterater.
+ */
+
+ return 0;
+}
+
+void bpf__clear(void)
+{
+ struct bpf_object *obj, *tmp;
+
+ bpf_object__for_each_safe(obj, tmp)
+ bpf_object__close(obj);
+}
+
+#define bpf__strerror_head(err, buf, size) \
+ char sbuf[STRERR_BUFSIZE], *emsg;\
+ if (!size)\
+ return 0;\
+ if (err < 0)\
+ err = -err;\
+ emsg = strerror_r(err, sbuf, sizeof(sbuf));\
+ switch (err) {\
+ default:\
+ scnprintf(buf, size, "%s", emsg);\
+ break;
+
+#define bpf__strerror_entry(val, fmt...)\
+ case val: {\
+ scnprintf(buf, size, fmt);\
+ break;\
+ }
+
+#define bpf__strerror_end(buf, size)\
+ }\
+ buf[size - 1] = '\0';
+
+int bpf__strerror_prepare_load(const char *filename, int err,
+ char *buf, size_t size)
+{
+ bpf__strerror_head(err, buf, size);
+ bpf__strerror_entry(EINVAL, "%s: BPF object file '%s' is invalid",
+ emsg, filename)
+ bpf__strerror_end(buf, size);
+ return 0;
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
new file mode 100644
index 0000000..12be630
--- /dev/null
+++ b/tools/perf/util/bpf-loader.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
+ * Copyright (C) 2015, Huawei Inc.
+ */
+#ifndef __BPF_LOADER_H
+#define __BPF_LOADER_H
+
+#include <linux/compiler.h>
+#include <string.h>
+#include "debug.h"
+
+#ifdef HAVE_LIBBPF_SUPPORT
+int bpf__prepare_load(const char *filename);
+int bpf__strerror_prepare_load(const char *filename, int err,
+ char *buf, size_t size);
+
+void bpf__clear(void);
+#else
+static inline int bpf__prepare_load(const char *filename __maybe_unused)
+{
+ pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
+ return -1;
+}
+
+static inline void bpf__clear(void) { }
+
+static inline int
+__bpf_strerror(char *buf, size_t size)
+{
+ if (!size)
+ return 0;
+ strncpy(buf,
+ "ERROR: eBPF object loading is disabled during compiling.\n",
+ size);
+ buf[size - 1] = '\0';
+ return 0;
+}
+
+static inline int
+bpf__strerror_prepare_load(const char *filename __maybe_unused,
+ int err __maybe_unused,
+ char *buf, size_t size)
+{
+ return __bpf_strerror(buf, size);
+}
+#endif
+#endif
--
2.1.0
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-08-29 06:50 +0200 |
| Subject | [PATCH 13/31] perf tools: Attach eBPF program to perf event |
| Message-ID | <q2Gfw-8e1-7@gated-at.bofh.it> |
| In reply to | #1215710 |
This is the final patch which makes basic BPF filter work. After
applying this patch, users are allowed to use BPF filter like:
# perf record --event ./hello_world.c ls
In this patch PERF_EVENT_IOC_SET_BPF ioctl is used to attach eBPF
program to a newly created perf event. The file descriptor of the
eBPF program is passed to perf record using previous patches, and
stored into evsel->bpf_fd.
It is possible that different perf event are created for one kprobe
events for different CPUs. In this case, when trying to call the
ioctl, EEXIST will be return. This patch doesn't treat it as an error.
Signed-off-by: Wang Nan <wangnan0@huawei.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: He Kuang <hekuang@huawei.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: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/n/1436445342-1402-26-git-send-email-wangnan0@huawei.com
---
tools/perf/util/evsel.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 6fff961..5f59841 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1365,6 +1365,22 @@ retry_open:
err);
goto try_fallback;
}
+
+ if (evsel->bpf_fd >= 0) {
+ int evt_fd = FD(evsel, cpu, thread);
+ int bpf_fd = evsel->bpf_fd;
+
+ err = ioctl(evt_fd,
+ PERF_EVENT_IOC_SET_BPF,
+ bpf_fd);
+ if (err && errno != EEXIST) {
+ pr_err("failed to attach bpf fd %d: %s\n",
+ bpf_fd, strerror(errno));
+ err = -EINVAL;
+ goto out_close;
+ }
+ }
+
set_rlimit = NO_CHANGE;
/*
--
2.1.0
--
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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web