Re: [GIT PULL 00/31] perf tools: filtering events using eBPF programs

From: Namhyung Kim
Date: Wed Oct 14 2015 - 11:48:34 EST


Hello,

On Wed, Oct 14, 2015 at 12:41:11PM +0000, Wang Nan wrote:
> Hi Arnaldo,
>
> I know you don't have enough time to review my code. I send
> this patchset to let you and other know what we are working on.
>
> In this new patchset, we create a new perf cmdline syntax so
> perf users are able to pass perf events created by perf to BPF
> maps, which makes bpf_perf_event_read() usable. Compare with out
> previous solution[1] which embedded 'struct perf_event_attr' to
> "maps" section, this solution is easier to use.
>
> If you or anyone have any different views on this solution,
> please let us know so we can stop our further development base
> on it as soon as possible.

Thanks for working on this. I've only reviewed the first part and
will continue to review it tomorrow (or later). :)

For patch 01 - 08,

Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>

Thanks,
Namhyung


>
> Thank you.
>
> [1] http://lkml.kernel.org/r/1440672142-89311-1-git-send-email-xiakaixu@xxxxxxxxxx
>
> The following changes since commit 31eb4360546b4bd890f349db01295a173c09b0fb:
>
> perf hists browser: Add 'm' key for context menu display (2015-10-12 23:29:14 -0300)
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/pi3orama/linux.git tags/perf-ebpf-for-acme-20151014
>
> for you to fetch changes up to 6df036cb7d42a2e0ebf312e127b02425bd57bc55:
>
> perf tools: Enable BPF object configure syntax (2015-10-14 10:09:17 +0000)
>
> ----------------------------------------------------------------
> EBPF support for perf
>
> - Rebase to newest perf/core
>
> - Bugfix: kprobe events not remove if bpf__probe() failure occur
> after it creates some kprobe points successfully.
>
> - Bugfix: when multiple BPF functions reside in one BPF object,
> the last BPF program would be attached to all kprobe events.
> This bug is introduced by removal of dummy event placeholder.
>
> - New function: support BPF program reading counter through
> bpf_perf_event_read() by adding new syntax and support code
> in event selector. The new BPF object configuration mechanism
> can be extended to support BPF data output.
>
> In this patchset, following BPF function can be used to measure
> cycles a kernel function cost:
>
> ===== BPF program bpf_program.c =====
>
> struct bpf_map_def SEC("maps") pmu_map = {
> .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
> .key_size = sizeof(int),
> .value_size = sizeof(u32),
> .max_entries = __NR_CPUS__,
> };
>
> SEC("func_write=sys_write")
> int func_write(void *ctx)
> {
> unsigned long long val;
> char fmt[] = "sys_write: pmu=%llu\n";
> val = bpf_perf_event_read(&pmu_map, bpf_get_smp_processor_id());
> bpf_trace_printk(fmt, sizeof(fmt), val);
> return 0;
> }
>
> SEC("func_write_return=sys_write%return")
> int func_write_return(void *ctx)
> {
> unsigned long long val = 0;
> char fmt[] = "sys_write_return: pmu=%llu\n";
> val = bpf_perf_event_read(&pmu_map, bpf_get_smp_processor_id());
> bpf_trace_printk(fmt, sizeof(fmt), val);
> return 0;
> }
>
> With cmdline like this:
>
> ===== cmdline =====
> # echo "" > /sys/kernel/debug/tracing/trace
> # perf record -e evt=cycles/period=0x7fffffffffffffff/ \
> -e bpf_program.c/maps.pmu_map.event=evt/
> -a ls
> # cat /sys/kernel/debug/tracing/trace | grep ls
> ls-3363 [003] d... 75475.056190: : sys_write: pmu=3961415
> ls-3363 [003] dN.. 75475.056212: : sys_write_return: pmu=4051390
> ls-3363 [003] d... 75475.056216: : sys_write: pmu=4065447
> ls-3363 [003] dN.. 75475.056227: : sys_write_return: pmu=4109760
> ls-3363 [003] d... 75475.056230: : sys_write: pmu=4120776
> ls-3363 [003] dN.. 75475.056245: : sys_write_return: pmu=4178441
> ...
> # perf report --stdio
> Error:
> The perf.data file has no samples!
>
> Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
>
> ----------------------------------------------------------------
> He Kuang (5):
> perf tools: Add prologue for BPF programs for fetching arguments
> perf record: Support custom vmlinux path
> bpf tools: Add helper function for updating bpf maps elements
> perf tools: Support perf event alias name
> perf record: Apply config to BPF objects before recording
>
> Wang Nan (26):
> perf tools: Make perf depend on libbpf
> perf ebpf: Add the libbpf glue
> perf tools: Enable passing bpf object file to --event
> perf record, bpf: Create probe points for BPF programs
> perf record: Load eBPF object into kernel
> perf tools: Collect perf_evsel in BPF object files
> perf tools: Attach eBPF program to perf event
> perf record: Add clang options for compiling BPF scripts
> perf tools: Compile scriptlets to BPF objects when passing '.c' to --event
> perf test: Enforce LLVM test for BPF test
> perf test: Add 'perf test BPF'
> perf probe: Reset args and nargs for probe_trace_event when failure
> bpf tools: Load a program with different instances using preprocessor
> perf tools: Add BPF_PROLOGUE config options for further patches
> perf tools: Compile dwarf-regs.c if CONFIG_BPF_PROLOGUE is on
> perf tools: Generate prologue for BPF programs
> perf tools: Use same BPF program if arguments are identical
> perf tools: Allow BPF program attach to uprobe events
> perf test: Enforce LLVM test, add kbuild test
> perf test: Test BPF prologue
> bpf tools: Collect map definition in bpf_object
> bpf tools: Extract and collect map names from BPF object file
> perf tools: Pass available CPU number to clang compiler
> perf tools: Add API to config maps in bpf object
> perf tools: Add API to apply config to BPF map
> perf tools: Enable BPF object configure syntax
>
> tools/build/Makefile.feature | 6 +-
> tools/lib/bpf/bpf.c | 14 +
> tools/lib/bpf/bpf.h | 2 +
> tools/lib/bpf/libbpf.c | 392 +++++++++---
> tools/lib/bpf/libbpf.h | 46 ++
> tools/perf/MANIFEST | 3 +
> tools/perf/Makefile.perf | 21 +-
> tools/perf/arch/x86/util/Build | 1 +
> tools/perf/builtin-record.c | 21 +
> tools/perf/config/Makefile | 31 +-
> tools/perf/perf.c | 2 +
> tools/perf/tests/Build | 24 +-
> tools/perf/tests/bpf-script-example.c | 48 ++
> tools/perf/tests/bpf-script-test-kbuild.c | 21 +
> tools/perf/tests/bpf-script-test-prologue.c | 35 ++
> tools/perf/tests/bpf.c | 227 +++++++
> tools/perf/tests/builtin-test.c | 10 +
> tools/perf/tests/llvm.c | 210 ++++++-
> tools/perf/tests/llvm.h | 29 +
> tools/perf/tests/make | 4 +-
> tools/perf/tests/tests.h | 5 +
> tools/perf/util/Build | 2 +
> tools/perf/util/bpf-loader.c | 933 ++++++++++++++++++++++++++++
> tools/perf/util/bpf-loader.h | 148 +++++
> tools/perf/util/bpf-prologue.c | 443 +++++++++++++
> tools/perf/util/bpf-prologue.h | 34 +
> tools/perf/util/evlist.c | 16 +
> tools/perf/util/evlist.h | 4 +
> tools/perf/util/evsel.c | 17 +
> tools/perf/util/evsel.h | 2 +
> tools/perf/util/llvm-utils.c | 24 +-
> tools/perf/util/parse-events.c | 221 ++++++-
> tools/perf/util/parse-events.h | 15 +
> tools/perf/util/parse-events.l | 6 +
> tools/perf/util/parse-events.y | 55 +-
> tools/perf/util/probe-finder.c | 4 +
> 36 files changed, 2968 insertions(+), 108 deletions(-)
> create mode 100644 tools/perf/tests/bpf-script-example.c
> create mode 100644 tools/perf/tests/bpf-script-test-kbuild.c
> create mode 100644 tools/perf/tests/bpf-script-test-prologue.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
>
> --
> 1.8.3.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/