diff options
author | Wang Nan <wangnan0@huawei.com> | 2015-10-14 08:41:16 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-10-28 12:09:50 -0400 |
commit | 1e5e3ee8ff3877db6943032b54a6ac21c095affd (patch) | |
tree | 1d6fbc9352d2595553e5b85654c821fedcef3b85 /tools/perf/util/bpf-loader.h | |
parent | aa3abf30bb28addcf593578d37447d42e3f65fc3 (diff) |
perf tools: Load eBPF object into kernel
This patch utilizes bpf_object__load() provided by libbpf to load all
objects into kernel.
Committer notes:
Testing it:
When using an incorrect kernel version number, i.e., having this in your
eBPF proggie:
int _version __attribute__((section("version"), used)) = 0x40100;
For a 4.3.0-rc6+ kernel, say, this happens and needs checking at event
parsing time, to provide a better error report to the user:
# perf record --event /tmp/foo.o sleep 1
libbpf: load bpf program failed: Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
libbpf: -- END LOG --
libbpf: failed to load program 'fork=_do_fork'
libbpf: failed to load object '/tmp/foo.o'
event syntax error: '/tmp/foo.o'
\___ Invalid argument: Are you root and runing a CONFIG_BPF_SYSCALL kernel?
(add -v to see detail)
Run 'perf list' for a list of valid events
Usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
If we instead make it match, i.e. use 0x40300 on this v4.3.0-rc6+
kernel, the whole process goes thru:
# perf record --event /tmp/foo.o -a usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.202 MB perf.data ]
# perf evlist -v
/tmp/foo.o: type: 1, size: 112, config: 0x9, { sample_period,
sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, disabled: 1,
inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, sample_id_all: 1,
exclude_guest: 1, mmap2: 1, comm_exec: 1
#
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1444826502-49291-6-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/bpf-loader.h')
-rw-r--r-- | tools/perf/util/bpf-loader.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index b819622dc7ce..b091ceb19c48 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h | |||
@@ -23,6 +23,9 @@ int bpf__unprobe(struct bpf_object *obj); | |||
23 | int bpf__strerror_probe(struct bpf_object *obj, int err, | 23 | int bpf__strerror_probe(struct bpf_object *obj, int err, |
24 | char *buf, size_t size); | 24 | char *buf, size_t size); |
25 | 25 | ||
26 | int bpf__load(struct bpf_object *obj); | ||
27 | int bpf__strerror_load(struct bpf_object *obj, int err, | ||
28 | char *buf, size_t size); | ||
26 | #else | 29 | #else |
27 | static inline struct bpf_object * | 30 | static inline struct bpf_object * |
28 | bpf__prepare_load(const char *filename __maybe_unused) | 31 | bpf__prepare_load(const char *filename __maybe_unused) |
@@ -35,6 +38,7 @@ static inline void bpf__clear(void) { } | |||
35 | 38 | ||
36 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} | 39 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} |
37 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} | 40 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} |
41 | static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } | ||
38 | 42 | ||
39 | static inline int | 43 | static inline int |
40 | __bpf_strerror(char *buf, size_t size) | 44 | __bpf_strerror(char *buf, size_t size) |
@@ -55,5 +59,12 @@ bpf__strerror_probe(struct bpf_object *obj __maybe_unused, | |||
55 | { | 59 | { |
56 | return __bpf_strerror(buf, size); | 60 | return __bpf_strerror(buf, size); |
57 | } | 61 | } |
62 | |||
63 | static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, | ||
64 | int err __maybe_unused, | ||
65 | char *buf, size_t size) | ||
66 | { | ||
67 | return __bpf_strerror(buf, size); | ||
68 | } | ||
58 | #endif | 69 | #endif |
59 | #endif | 70 | #endif |