linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v3 00/37] perf tools: introduce 'perf bpf' command to load eBPF programs.
@ 2015-05-17 10:56 Wang Nan
  2015-05-17 10:56 ` [RFC PATCH v3 01/37] perf/events/core: fix race in bpf program unregister Wang Nan
                   ` (37 more replies)
  0 siblings, 38 replies; 108+ messages in thread
From: Wang Nan @ 2015-05-17 10:56 UTC (permalink / raw)
  To: paulus, a.p.zijlstra, mingo, acme, namhyung, jolsa, dsahern, ast,
	daniel, brendan.d.gregg, masami.hiramatsu.pt
  Cc: lizefan, linux-kernel, pi3orama

This is the 3rd version of 'perf bpf' patch series, based on
v4.1-rc3.

The goal of this series of patches is to integrate eBPF with perf.
After applying these patches, users are allowed to use following
command to load eBPF program compiled by LLVM into kernel then start
recording with filters on: 

 # perf bpf record --object sample_bpf.o -- -a sleep 4

I post new version before receiving enough comment because I found that
v2 series losts a small but importand patch (37/37 in this series). It
does the final work, attaches eBPF programs to perf event.

Other than the previous change, v3 patch series drops the '|' event
syntax introduced in v2, because I realized that in v2 users are
allowed to pass any bpf fd by using it, like:

 # perf bpf record -- -e sched:sched_switch|100| sleep 1

which may become trouble maker. In v3, patch 36/37 passes file
descriptors to evsel by bpf_for_each_program(), which iterates over
each bpf programs and calls a callback function. bpf_fd is set by the
callback.

According to Ingo's suggestion, I renamed every titles of all patches in
this series to make shortlog easier to read.

Since I haven't received enough comment, question in v2 is still open:

 Are we actually need a 'perf bpf' command? We can get similar result by
 modifying 'perf record' to make it load eBPF program before recording.

 I suggest to keep 'perf bpf', group all eBPF stuffs together using a
 uniform entry. Also, eBPF programs can act not only as filters but also
 data aggregator. It is possible to make something link 'perf bpf run'
 to simply make it run, and dump result after user hit 'C-c' or timeout.
 The 'config' section may be utilized in this case to let 'perf bpf'
 know how to display results.

Following is detail description. Most of following text is copied from
cover letter of v2. You can skip reading if you have already read this
in v2 series.

 Patch 1/37 - 5/37 are preparation and bugfixs. Some of them are already
 acked.
  
 Patch  6/37 - 26/37 creates tools/lib/bpf.

  Libbpf will be compiled into libbpf.a and libbpf.so. It can be
  devided into 2 parts:

    1) User-kernel interface. The API is defined by tools/lib/bpf/bpf.h,
       encapsulates map and program loading operations. In
       bpf_load_program(), it doesn't use log buffer in the first try to
       improve performance, and retry with log buffer enabled when
       failure.

    2) ELF operations. The structure of eBPF object file is defined
       here. API of this part can be found in tools/lib/bpf/libbpf.h.
       'struct bpf_map_def' is also put here.

       Libbpf's API hides internal structures. Callers access data of
       object files with handlers and accessors. 'struct bpf_object *'
       is handler of a whole object file. 'struct bpf_prog_handler *'
       is handler and iterator of programs. Some of accessors are
       defined to enable caller to retrive section name and file
       descriptor of a program. Further accessor can be appended.

       In the design of libbpf, I explictly separate full procedure
       into opening and loading phase. Data are collected during
       'opening' phase. BPF syscalls are called in 'loading' phase.
       The separation is designed for potential cross-objects
       operations. Such separation also give caller a chance to let
       him/her to adjust bytecode and/or maps before real loading.
       (API of such operation is not provided in this version).

       During loading, fields in 'struct bpf_map_def' are also swapped
       if endianess mismatched.

 Patch 27/37 - 37/37 are patches on perf, which introduce 'perf bpf'
                     command and 'perf bpf record' subcommand.

   'perf bpf' is not a standalone command. The usage should be:

     perf bpf [<options>] <command> --objects <objfile> -- \
	     <args passed to other cmds>

   First two patches make 'perf bpf' avaliable and make perf depend on
   libbpf. 29/37 creates 'perf bpf record' and directly passes
   everything after '--' to cmd_record(). Other stuffs resides in
   tools/perf/utils/bpf-loader.[ch], which are introduced in 30/37.
   Following patches do collection -> probing -> loading works step
   by step. In those operations, 'perf bpf' collects all required
   objects before creating kprobe points, and loads programs into
   kernel after probing finish.

   A 'bpf_unload()' is used to remove kprobe points. I use 'atexit'
   hook to ensure it called before exiting. However, I find that
   atexit hookers are not always work well. For example, when program
   is canceled by SIGINT. Therefore we still need to call bpf_unload()
   after cmd_record().

   Patch 36/37 adds bpf_fd field to evsel and config it.

   Patch 37/37 finally attachs eBPF program to perf event.

Wang Nan (37):
  perf/events/core: fix race in bpf program unregister
  perf tools: Set vmlinux_path__nr_entries to 0 in vmlinux_path__exit
  tools lib traceevent: Install libtraceevent.a into libdir
  tools: Change FEATURE_TESTS and FEATURE_DISPLAY to weak binding
  tools: Add __aligned_u64 to types.h
  bpf tools: Introduce 'bpf' library to tools
  bpf tools: Allow caller to set printing function
  bpf tools: Define basic interface
  bpf tools: Open eBPF object file and do basic validation
  bpf tools: Check endianess and set swap flag according to EHDR
  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 config string from 'config' 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: Clear libelf and ELF parsing resrouce to finish opening
  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
  perf tools: Add new 'perf bpf' command
  perf tools: Make perf depend on libbpf
  perf bpf: Add 'perf bpf record' subcommand
  perf bpf: Add bpf-loader and open ELF object files
  perf bpf: Collect all eBPF programs
  perf bpf: Parse probe points of eBPF programs during preparation
  perf bpf: Probe at kprobe points
  perf bpf: Load all eBPF object into kernel
  perf tools: Add a bpf_wrapper global flag
  perf tools: Add bpf_fd field to evsel and config it
  perf tools: Attach eBPF program to perf event

 kernel/events/core.c                  |    3 +-
 tools/build/Makefile.feature          |    4 +-
 tools/include/linux/types.h           |    5 +
 tools/lib/bpf/.gitignore              |    2 +
 tools/lib/bpf/Build                   |    1 +
 tools/lib/bpf/Makefile                |  191 ++++++
 tools/lib/bpf/bpf.c                   |   87 +++
 tools/lib/bpf/bpf.h                   |   24 +
 tools/lib/bpf/libbpf.c                | 1089 +++++++++++++++++++++++++++++++++
 tools/lib/bpf/libbpf.h                |   66 ++
 tools/lib/traceevent/Makefile         |   20 +-
 tools/perf/Build                      |    1 +
 tools/perf/Documentation/perf-bpf.txt |   18 +
 tools/perf/Makefile.perf              |   20 +-
 tools/perf/builtin-bpf.c              |  217 +++++++
 tools/perf/builtin-record.c           |    6 +
 tools/perf/builtin.h                  |    1 +
 tools/perf/command-list.txt           |    1 +
 tools/perf/perf.c                     |   10 +
 tools/perf/perf.h                     |    1 +
 tools/perf/util/Build                 |    1 +
 tools/perf/util/bpf-loader.c          |  262 ++++++++
 tools/perf/util/bpf-loader.h          |   34 +
 tools/perf/util/debug.c               |    5 +
 tools/perf/util/debug.h               |    1 +
 tools/perf/util/evlist.c              |   34 +
 tools/perf/util/evlist.h              |    1 +
 tools/perf/util/evsel.c               |   17 +
 tools/perf/util/evsel.h               |    1 +
 tools/perf/util/parse-options.c       |    8 +-
 tools/perf/util/parse-options.h       |    2 +
 tools/perf/util/symbol.c              |    1 +
 32 files changed, 2122 insertions(+), 12 deletions(-)
 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/Documentation/perf-bpf.txt
 create mode 100644 tools/perf/builtin-bpf.c
 create mode 100644 tools/perf/util/bpf-loader.c
 create mode 100644 tools/perf/util/bpf-loader.h

-- 
1.8.3.4


^ permalink raw reply	[flat|nested] 108+ messages in thread

end of thread, other threads:[~2015-05-26  6:24 UTC | newest]

Thread overview: 108+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-17 10:56 [RFC PATCH v3 00/37] perf tools: introduce 'perf bpf' command to load eBPF programs Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 01/37] perf/events/core: fix race in bpf program unregister Wang Nan
2015-05-18 16:59   ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 02/37] perf tools: Set vmlinux_path__nr_entries to 0 in vmlinux_path__exit Wang Nan
2015-05-18 17:01   ` Alexei Starovoitov
2015-05-18 20:28     ` Arnaldo Carvalho de Melo
2015-05-20 12:25   ` [tip:perf/core] " tip-bot for Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 03/37] tools lib traceevent: Install libtraceevent.a into libdir Wang Nan
2015-05-18 14:28   ` Jiri Olsa
2015-05-20 12:26   ` [tip:perf/core] " tip-bot for Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 04/37] tools: Change FEATURE_TESTS and FEATURE_DISPLAY to weak binding Wang Nan
2015-05-18 14:30   ` Jiri Olsa
2015-05-20 12:26   ` [tip:perf/core] tools build: " tip-bot for Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 05/37] tools: Add __aligned_u64 to types.h Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 06/37] bpf tools: Introduce 'bpf' library to tools Wang Nan
2015-05-18 17:35   ` Alexei Starovoitov
2015-05-20  3:48     ` Wangnan (F)
2015-05-20  5:24       ` Alexei Starovoitov
2015-05-21  0:24         ` Wangnan (F)
2015-05-21 17:53           ` Alexei Starovoitov
2015-05-21  7:10     ` Wangnan (F)
2015-05-17 10:56 ` [RFC PATCH v3 07/37] bpf tools: Allow caller to set printing function Wang Nan
2015-05-18 17:55   ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 08/37] bpf tools: Define basic interface Wang Nan
2015-05-18 17:57   ` Alexei Starovoitov
2015-05-22 17:22     ` Jiri Olsa
2015-05-17 10:56 ` [RFC PATCH v3 09/37] bpf tools: Open eBPF object file and do basic validation Wang Nan
2015-05-18 18:06   ` Alexei Starovoitov
2015-05-22 17:22   ` Jiri Olsa
2015-05-22 17:23   ` Jiri Olsa
2015-05-23  1:00     ` Alexei Starovoitov
2015-05-25 13:30       ` Arnaldo Carvalho de Melo
2015-05-26  0:05         ` Wangnan (F)
2015-05-26  0:41           ` Arnaldo Carvalho de Melo
2015-05-17 10:56 ` [RFC PATCH v3 10/37] bpf tools: Check endianess and set swap flag according to EHDR Wang Nan
2015-05-18 18:19   ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 11/37] bpf tools: Iterate over ELF sections to collect information Wang Nan
2015-05-18 18:21   ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 12/37] bpf tools: Collect version and license from ELF sections Wang Nan
2015-05-18 18:27   ` Alexei Starovoitov
2015-05-18 20:34     ` Arnaldo Carvalho de Melo
2015-05-18 20:51       ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 13/37] bpf tools: Collect map definitions from 'maps' section Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 14/37] bpf tools: Collect config string from 'config' section Wang Nan
2015-05-18 18:30   ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 15/37] bpf tools: Collect symbol table from SHT_SYMTAB section Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 16/37] bpf tools: Collect eBPF programs from their own sections Wang Nan
2015-05-18 12:29   ` Namhyung Kim
2015-05-18 12:47     ` Wangnan (F)
2015-05-18 18:32       ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 17/37] bpf tools: Collect relocation sections from SHT_REL sections Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 18/37] bpf tools: Record map accessing instructions for each program Wang Nan
2015-05-18 18:34   ` Alexei Starovoitov
2015-05-25  7:39     ` Wangnan (F)
2015-05-17 10:56 ` [RFC PATCH v3 19/37] bpf tools: Clear libelf and ELF parsing resrouce to finish opening Wang Nan
2015-05-18 18:36   ` Alexei Starovoitov
2015-05-18 20:35     ` Arnaldo Carvalho de Melo
2015-05-17 10:56 ` [RFC PATCH v3 20/37] bpf tools: Add bpf.c/h for common bpf operations Wang Nan
2015-05-18 18:39   ` Alexei Starovoitov
2015-05-22 17:24   ` Jiri Olsa
2015-05-17 10:56 ` [RFC PATCH v3 21/37] bpf tools: Create eBPF maps defined in an object file Wang Nan
2015-05-18 18:48   ` Alexei Starovoitov
2015-05-18 20:37     ` Arnaldo Carvalho de Melo
2015-05-25  9:23     ` Wangnan (F)
2015-05-22 17:23   ` Jiri Olsa
2015-05-17 10:56 ` [RFC PATCH v3 22/37] bpf tools: Relocate eBPF programs Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 23/37] bpf tools: Introduce bpf_load_program() to bpf.c Wang Nan
2015-05-18 18:52   ` Alexei Starovoitov
2015-05-18 20:37     ` Arnaldo Carvalho de Melo
2015-05-17 10:56 ` [RFC PATCH v3 24/37] bpf tools: Load eBPF programs in object files into kernel Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 25/37] bpf tools: Introduce accessors for struct bpf_program Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 26/37] bpf tools: Introduce accessors for struct bpf_object Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 27/37] perf tools: Add new 'perf bpf' command Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 28/37] perf tools: Make perf depend on libbpf Wang Nan
2015-05-22 17:24   ` Jiri Olsa
2015-05-17 10:56 ` [RFC PATCH v3 29/37] perf bpf: Add 'perf bpf record' subcommand Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 30/37] perf bpf: Add bpf-loader and open ELF object files Wang Nan
2015-05-22 17:24   ` Jiri Olsa
2015-05-25 11:47     ` Wangnan (F)
2015-05-25 13:00     ` Arnaldo Carvalho de Melo
2015-05-17 10:56 ` [RFC PATCH v3 31/37] perf bpf: Collect all eBPF programs Wang Nan
2015-05-17 10:56 ` [RFC PATCH v3 32/37] perf bpf: Parse probe points of eBPF programs during preparation Wang Nan
2015-05-22 17:24   ` Jiri Olsa
2015-05-17 10:56 ` [RFC PATCH v3 33/37] perf bpf: Probe at kprobe points Wang Nan
2015-05-18 19:25   ` Alexei Starovoitov
2015-05-17 10:56 ` [RFC PATCH v3 34/37] perf bpf: Load all eBPF object into kernel Wang Nan
2015-05-17 10:57 ` [RFC PATCH v3 35/37] perf tools: Add a bpf_wrapper global flag Wang Nan
2015-05-17 10:57 ` [RFC PATCH v3 36/37] perf tools: Add bpf_fd field to evsel and config it Wang Nan
2015-05-17 10:57 ` [RFC PATCH v3 37/37] perf tools: Attach eBPF program to perf event Wang Nan
2015-05-18 19:38 ` [RFC PATCH v3 00/37] perf tools: introduce 'perf bpf' command to load eBPF programs Alexei Starovoitov
2015-05-18 20:44   ` Arnaldo Carvalho de Melo
2015-05-18 21:05     ` Alexei Starovoitov
2015-05-18 21:20       ` Arnaldo Carvalho de Melo
2015-05-18 21:45         ` Alexei Starovoitov
2015-05-19 13:44           ` Arnaldo Carvalho de Melo
2015-05-19 16:04             ` Namhyung Kim
2015-05-19 16:40               ` Arnaldo Carvalho de Melo
2015-05-19 20:46                 ` Alexei Starovoitov
2015-05-19 21:10                   ` Arnaldo Carvalho de Melo
2015-05-19 21:42                     ` Alexei Starovoitov
2015-05-19 22:05                       ` Arnaldo Carvalho de Melo
2015-05-20  1:02                         ` Alexei Starovoitov
2015-05-20  1:14                           ` Arnaldo Carvalho de Melo
2015-05-20  0:30                     ` Namhyung Kim
2015-05-20  0:43                       ` Arnaldo Carvalho de Melo
2015-05-26  6:22                   ` Wangnan (F)
2015-05-20  0:23                 ` Namhyung Kim
2015-05-20  0:37                   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).