All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 00/22] perf tools: introduce 'perf bpf' command to load eBPF programs.
@ 2015-04-30 10:52 Wang Nan
  2015-04-30 10:52 ` [RFC PATCH 01/22] perf: probe: avoid segfault if passed with '' Wang Nan
                   ` (24 more replies)
  0 siblings, 25 replies; 46+ messages in thread
From: Wang Nan @ 2015-04-30 10:52 UTC (permalink / raw)
  To: ast, davem, acme, mingo, a.p.zijlstra, masami.hiramatsu.pt, jolsa
  Cc: lizefan, linux-kernel, pi3orama, hekuang

This series of patches is an approach 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:

 $ perf bpf sample_bpf.o

The required BPF code and the loading procedure is similar to Alexei
Starovoitov's libbpf in sample/bpf, with following exceptions:

 1. The section name are not required leading with 'kprobe/' or
    'kretprobe/'. Without such leading, any valid C var name can be use.

 2. A 'config' section can be provided to describe the position and
    arguments of a program. Syntax is identical to 'perf probe'.

An example is pasted at the bottom of this cover letter. In that
example, mybpfprog is configured by string in config section, and will
be probed at __alloc_pages_nodemask. sample_bpf.o is generated using:

 $ $CLANG -I/usr/src/kernel/include -I/usr/src/kernel/usr/include -D__KERNEL__ \
	 -Wno-unused-value -Wno-pointer-sign \
	 -O2 -emit-llvm -c sample_bpf.c -o -| $LLC -march=bpf -filetype=obj -o \
	 sample_bpf.o

And can be loaded using:

 $ perf bpf sample_bpf.o

This series is only a limited functional. Following works are on the
todo list:

 1. Unprobe kprobe stubs used by eBPF programs when unloading;

 2. Enable eBPF programs to access local variables and arguments
    by utilizing debuginfo;

 3. Output data in perf way.

In this series:

Patch 1/22 is a bugfix in perf probe, and may be triggered by following
patches;

Patch 2-3/22 are preparation, add required macros and syscall
definition into perf source tree.

Patch 4/22 add 'perf bpf' command.

Patch 5-20/22 are labor works, which parse the ELF object file, collect
information in object files, create maps needed by programs, link map
and programs, config programs and load programs into kernel.

Patch 21-22/22 are the final work. Patch 21 creates kprobe points which
will be used by eBPF programs, patch 22 creates perf file descriptors
then attach eBPF programs on them.

 -------- EXAMPL --------
 ----- sample_bpf.c -----
 #include <uapi/linux/bpf.h>
 #include <linux/version.h>
 #include <uapi/linux/ptrace.h>

 #define SEC(NAME) __attribute__((section(NAME), used))

 static int (*bpf_map_delete_elem)(void *map, void *key) =
 	(void *) BPF_FUNC_map_delete_elem;
 static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
 	(void *) BPF_FUNC_trace_printk;

 struct bpf_map_def {
 	unsigned int type;
 	unsigned int key_size;
 	unsigned int value_size;
 	unsigned int max_entries;
 };

 struct pair {
 	u64 val;
 	u64 ip;
 };

 struct bpf_map_def SEC("maps") my_map = {
 	.type = BPF_MAP_TYPE_HASH,
 	.key_size = sizeof(long),
 	.value_size = sizeof(struct pair),
 	.max_entries = 1000000,
 };

 SEC("kprobe/kmem_cache_free")
 int bpf_prog1(struct pt_regs *ctx)
 {
 	long ptr = ctx->r14;
 	bpf_map_delete_elem(&my_map, &ptr);
 	return 0;
 }

 SEC("mybpfprog")
 int bpf_prog_my(void *ctx)
 {
 	char fmt[] = "Haha\n";
 	bpf_trace_printk(fmt, sizeof(fmt));
 	return 0;
 }

 char _license[] SEC("license") = "GPL";
 u32 _version SEC("version") = LINUX_VERSION_CODE;
 char _config[] SEC("config") = ""
 "mybpfprog=__alloc_pages_nodemask\n";

Wang Nan (22):
  perf: probe: avoid segfault if passed with ''.
  perf: bpf: prepare: add __aligned_u64 to types.h.
  perf: add bpf common operations.
  perf tools: Add new 'perf bpf' command.
  perf bpf: open eBPF object file and do basic validation.
  perf bpf: check swap according to EHDR.
  perf bpf: iterater over elf sections to collect information.
  perf bpf: collect version and license from ELF.
  perf bpf: collect map definitions.
  perf bpf: collect config section in object.
  perf bpf: collect symbol table in object files.
  perf bpf: collect bpf programs from object files.
  perf bpf: collects relocation sections from object file.
  perf bpf: config eBPF programs based on their names.
  perf bpf: config eBPF programs using config section.
  perf bpf: create maps needed by object file.
  perf bpf: relocation programs.
  perf bpf: load eBPF programs into kernel.
  perf bpf: dump eBPF program before loading.
  perf bpf: clean elf memory after loading.
  perf bpf: probe at kprobe points.
  perf bpf: attaches eBPF program to perf fd.

 tools/include/linux/types.h           |    5 +
 tools/perf/Build                      |    1 +
 tools/perf/Documentation/perf-bpf.txt |   18 +
 tools/perf/builtin-bpf.c              |   63 ++
 tools/perf/builtin.h                  |    1 +
 tools/perf/perf-sys.h                 |    6 +
 tools/perf/perf.c                     |    1 +
 tools/perf/util/Build                 |    2 +
 tools/perf/util/bpf-loader.c          | 1061 +++++++++++++++++++++++++++++++++
 tools/perf/util/bpf-loader.h          |   73 +++
 tools/perf/util/bpf.c                 |  195 ++++++
 tools/perf/util/bpf.h                 |   23 +
 tools/perf/util/probe-event.c         |    2 +
 13 files changed, 1451 insertions(+)
 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
 create mode 100644 tools/perf/util/bpf.c
 create mode 100644 tools/perf/util/bpf.h

-- 
1.8.3.4


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

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

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-30 10:52 [RFC PATCH 00/22] perf tools: introduce 'perf bpf' command to load eBPF programs Wang Nan
2015-04-30 10:52 ` [RFC PATCH 01/22] perf: probe: avoid segfault if passed with '' Wang Nan
2015-05-05 14:09   ` Masami Hiramatsu
2015-05-05 15:26     ` Arnaldo Carvalho de Melo
2015-05-05 16:33       ` Masami Hiramatsu
2015-04-30 10:52 ` [RFC PATCH 02/22] perf: bpf: prepare: add __aligned_u64 to types.h Wang Nan
2015-04-30 10:52 ` [RFC PATCH 03/22] perf: add bpf common operations Wang Nan
2015-04-30 10:52 ` [RFC PATCH 04/22] perf tools: Add new 'perf bpf' command Wang Nan
2015-05-11  6:28   ` Namhyung Kim
2015-04-30 10:52 ` [RFC PATCH 05/22] perf bpf: open eBPF object file and do basic validation Wang Nan
2015-04-30 10:52 ` [RFC PATCH 06/22] perf bpf: check swap according to EHDR Wang Nan
2015-04-30 10:52 ` [RFC PATCH 07/22] perf bpf: iterater over elf sections to collect information Wang Nan
2015-04-30 10:52 ` [RFC PATCH 08/22] perf bpf: collect version and license from ELF Wang Nan
2015-04-30 10:52 ` [RFC PATCH 09/22] perf bpf: collect map definitions Wang Nan
2015-05-11  6:32   ` Namhyung Kim
2015-04-30 10:52 ` [RFC PATCH 10/22] perf bpf: collect config section in object Wang Nan
2015-04-30 10:52 ` [RFC PATCH 11/22] perf bpf: collect symbol table in object files Wang Nan
2015-04-30 10:52 ` [RFC PATCH 12/22] perf bpf: collect bpf programs from " Wang Nan
2015-04-30 10:52 ` [RFC PATCH 13/22] perf bpf: collects relocation sections from object file Wang Nan
2015-04-30 10:52 ` [RFC PATCH 14/22] perf bpf: config eBPF programs based on their names Wang Nan
2015-04-30 10:52 ` [RFC PATCH 15/22] perf bpf: config eBPF programs using config section Wang Nan
2015-04-30 10:52 ` [RFC PATCH 16/22] perf bpf: create maps needed by object file Wang Nan
2015-04-30 10:52 ` [RFC PATCH 17/22] perf bpf: relocation programs Wang Nan
2015-04-30 10:52 ` [RFC PATCH 18/22] perf bpf: load eBPF programs into kernel Wang Nan
2015-04-30 10:52 ` [RFC PATCH 19/22] perf bpf: dump eBPF program before loading Wang Nan
2015-04-30 10:52 ` [RFC PATCH 20/22] perf bpf: clean elf memory after loading Wang Nan
2015-04-30 10:52 ` [RFC PATCH 21/22] perf bpf: probe at kprobe points Wang Nan
2015-05-05 16:34   ` Masami Hiramatsu
2015-05-06  2:36     ` Wang Nan
2015-04-30 10:52 ` [RFC PATCH 22/22] perf bpf: attaches eBPF program to perf fd Wang Nan
2015-05-01  4:37 ` [RFC PATCH 00/22] perf tools: introduce 'perf bpf' command to load eBPF programs Alexei Starovoitov
2015-05-01 11:06   ` Peter Zijlstra
2015-05-01 11:49     ` Ingo Molnar
2015-05-01 16:56       ` Alexei Starovoitov
2015-05-01 17:06         ` Ingo Molnar
2015-05-05 15:39         ` Arnaldo Carvalho de Melo
2015-05-02  7:19   ` Wang Nan
2015-05-05  3:02     ` Alexei Starovoitov
2015-05-05  4:41       ` Wang Nan
2015-05-05  5:49         ` Alexei Starovoitov
2015-05-05  6:14           ` Wang Nan
2015-05-06  4:46             ` Wang Nan
2015-05-06  4:56               ` Alexei Starovoitov
2015-05-06  5:00                 ` Wang Nan
2015-05-01  7:16 ` Ingo Molnar
2015-05-05 21:52 ` Brendan Gregg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.