Re: [RFC PATCH v7 00/37] perf tools: filtering events using eBPF programs

Alexei Starovoitov
2015-06-12T16:58:31Z

On 6/11/15 10:35 PM, Wang Nan wrote:
> This is the 7th version which tries to introduce eBPF programs to perf.
> It enables 'perf record' to filter events using eBPF programs like:
>
> # perf record --event bpf-file.c sleep 1
>
> and
>
> # perf record --event bpf-file.o sleep 1
>
> This patch series is based on tip/perf/core (028c63b).
>
> Compare with v6 patch, this series totally refactor code for llvm
> compiling '.c' into BPF object file using LLVM. Including:
>
> 1. A specific file tools/perf/util/llvm-utils.c is introduced for
> holding all llvm/clang related work, instead of putting them into
> bpf-loader.c.
>
> 2. Automatically detect kernel include options by embedded shell
> script.
>
> 3. Use command line template to generate compiler commands instead of
> assemble cmdline with printf, passing variables using environment.
> Which enable users to define their own compiler commands.
>
> 4. Introduce '[llvm]' section to perf default config.
> 5 options can be configured, but all of them can be omitted:
>
> [llvm]
> # Path to clang. If omit, search it from $PATH.
> clang-path = "/path/to/clang"
>
> # Cmdline template. Following line shows its default value.
> # Environment variable is used to passing options.
> clang-bpf-cmd-template = "$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c $CLANG_SOURCE -target bpf -O2 -o -"
>
> # Option passed to clang, will be passed to cmdline by $CLANG_OPTIONS.
> clang-opt = "-Wno-unused-value -Wno-pointer-sign"
>
> # kbuild directory. If not set, use /lib/modules/`uname -r`/build.
> # If set to "" deliberately, skip kernel header auto-detector.
> kbuild-dir = "/path/to/kernel/build"
>
> # Options passed to 'make' when detecting kernel header options.
> kbuild-opts = "ARCH=x86_64"
>
> Command line options '--clang-path' and '--clang-opt' is appended to
> 'perf record'.
>
> 5. LLVM and BPF opening testcase is adding into 'perf test':
>
> # perf test 37
> 37: Test LLVM searching and compiling : Ok
>
> 6. Warning and error messages improvement.
>
> 7. Issue clang command suit for newest clang which support
> '-target bpf', instead of calling
> 'clang -emit-llvm | llc -march=bpf' pipe.

All looks great to me.
Piping clang into stdout to skip .o on a disk is a nice touch.
'usability hints' have improved as well.
Thanks a lot for the hard work.

btw, what compile times do you see?
On my machine compiling basic hello_world.c with #include bpf_helpers.h
and few kernel headers take: 0.02 sec
So using .c is quite instant. Feels like interpreted language ;)