This is the 4th version of patch series which tries to introduce eBPF programs to perf. Based on v4.1-rc3. This patch series improves 'perf record', enables commands like
# perf record --event bpf-file.o sleep 1 to select events defined in bpf-file.o and filter those events using bpf programs inside it. Different from previous (perf tools: introduce 'perf bpf' command to load eBPF programs.) version, the 4th version drops 'perf bpf' subcommand, merges event filtering use case directly into 'perf record'. Other improvments including: 1. Simply return an error if byte ordering mismatch, instead of trying to correct it. 2. Introduce zfree() and zclose() to free memory and close file to ensure the pointers are set to NULL and fd set to -1. 3. Use OO style naming. For example, bpf_object__open() instead of bpf_open_object() in v3. 4. libbpf use linked list to link all bpf_object together. Caller doesn't need to store pointers of bpf_object and bpf_program. 5. Doesn't treat 'config' section specially. 6. Remove 'atexit' hook. 7. Bugfix: if multiple perf events are created for one kprobe event, only the first try to hook eBPF program can success. Other try returns EEXIST. Such error should be ignored. 8. Coding style, makefile and license correction. Patch 1/29 - 4/29 are preparations, moves some headers from perf internal include directory to tools/include. libbpf will use them. Patch 5/29 - 22/29 introduces libbpf. The design principle is similar to v3, except that allow caller iterate over objects using macro. Patch 23/29 - 29/29 improve 'perf record' subcommand. In patch 24, event parsing syntax is improved to accept strings like './bpf-file.o' and 'bpf-object.bpf' to be passed by '--event'. To make it work, following acked patches should be cherry-picked before applying this series: tools: Change FEATURE_TESTS and FEATURE_DISPLAY to weak binding perf tools: Set vmlinux_path__nr_entries to 0 in vmlinux_path__exit perf/events/core: fix race in bpf program unregister Wang Nan (29): tools: Add __aligned_u64 to types.h perf tools: Move linux/kernel.h to tools/include perf tools: Move linux/{list.h,poison.h} to tools/include bpf tools: Introduce 'bpf' library to tools bpf tools: Allow caller to set printing function bpf tools: Open eBPF object file and do basic validation bpf tools: Check endianess and make libbpf fail early bpf tools: Iterate over ELF sections to collect information bpf tools: Collect version and license from ELF sections bpf tools: Collect map definitions from 'maps' section bpf tools: Collect symbol table from SHT_SYMTAB section bpf tools: Collect eBPF programs from their own sections bpf tools: Collect relocation sections from SHT_REL sections bpf tools: Record map accessing instructions for each program bpf tools: Add bpf.c/h for common bpf operations bpf tools: Create eBPF maps defined in an object file bpf tools: Relocate eBPF programs bpf tools: Introduce bpf_load_program() to bpf.c bpf tools: Load eBPF programs in object files into kernel bpf tools: Introduce accessors for struct bpf_program bpf tools: Introduce accessors for struct bpf_object bpf tools: Link all bpf objects onto a list perf tools: Make perf depend on libbpf perf record: Enable passing bpf object file to --event perf tools: Parse probe points of eBPF programs during preparation perf record: Probe at kprobe points perf record: Load all eBPF object into kernel perf tools: Add bpf_fd field to evsel and config it perf tools: Attach eBPF program to perf event tools/{perf/util => }/include/linux/kernel.h | 0 tools/{perf/util => }/include/linux/list.h | 6 +- tools/include/linux/poison.h | 1 + tools/include/linux/types.h | 5 + tools/lib/bpf/.gitignore | 2 + tools/lib/bpf/Build | 1 + tools/lib/bpf/Makefile | 190 ++++++ tools/lib/bpf/bpf.c | 90 +++ tools/lib/bpf/bpf.h | 23 + tools/lib/bpf/libbpf.c | 969 +++++++++++++++++++++++++++ tools/lib/bpf/libbpf.h | 75 +++ tools/perf/Makefile.perf | 19 +- tools/perf/builtin-record.c | 32 + tools/perf/util/Build | 1 + tools/perf/util/bpf-loader.c | 284 ++++++++ tools/perf/util/bpf-loader.h | 32 + tools/perf/util/debug.c | 5 + tools/perf/util/debug.h | 1 + tools/perf/util/evlist.c | 32 + tools/perf/util/evlist.h | 1 + tools/perf/util/evsel.c | 17 + tools/perf/util/evsel.h | 1 + tools/perf/util/include/linux/poison.h | 1 - tools/perf/util/parse-events.c | 16 + tools/perf/util/parse-events.h | 2 + tools/perf/util/parse-events.l | 5 +- tools/perf/util/parse-events.y | 18 +- 27 files changed, 1822 insertions(+), 7 deletions(-) rename tools/{perf/util => }/include/linux/kernel.h (100%) rename tools/{perf/util => }/include/linux/list.h (90%) create mode 100644 tools/include/linux/poison.h create mode 100644 tools/lib/bpf/.gitignore create mode 100644 tools/lib/bpf/Build create mode 100644 tools/lib/bpf/Makefile create mode 100644 tools/lib/bpf/bpf.c create mode 100644 tools/lib/bpf/bpf.h create mode 100644 tools/lib/bpf/libbpf.c create mode 100644 tools/lib/bpf/libbpf.h create mode 100644 tools/perf/util/bpf-loader.c create mode 100644 tools/perf/util/bpf-loader.h delete mode 100644 tools/perf/util/include/linux/poison.h -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/