Skip to content

Commit 3ca3877

Browse files
liu-song-6acmel
authored andcommitted
perf bpf: Process PERF_BPF_EVENT_PROG_LOAD for annotation
This patch adds processing of PERF_BPF_EVENT_PROG_LOAD, which sets proper DSO type/id/etc of memory regions mapped to BPF programs to DSO_BINARY_TYPE__BPF_PROG_INFO. Signed-off-by: Song Liu <songliubraving@fb.com> Reviewed-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stanislav Fomichev <sdf@google.com> Cc: kernel-team@fb.com Link: http://lkml.kernel.org/r/20190312053051.2690567-14-songliubraving@fb.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9b86d04 commit 3ca3877

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tools/perf/util/bpf-event.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "machine.h"
1313
#include "env.h"
1414
#include "session.h"
15+
#include "map.h"
1516

1617
#define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr))
1718

@@ -25,12 +26,65 @@ static int snprintf_hex(char *buf, size_t size, unsigned char *data, size_t len)
2526
return ret;
2627
}
2728

29+
static int machine__process_bpf_event_load(struct machine *machine,
30+
union perf_event *event,
31+
struct perf_sample *sample __maybe_unused)
32+
{
33+
struct bpf_prog_info_linear *info_linear;
34+
struct bpf_prog_info_node *info_node;
35+
struct perf_env *env = machine->env;
36+
int id = event->bpf_event.id;
37+
unsigned int i;
38+
39+
/* perf-record, no need to handle bpf-event */
40+
if (env == NULL)
41+
return 0;
42+
43+
info_node = perf_env__find_bpf_prog_info(env, id);
44+
if (!info_node)
45+
return 0;
46+
info_linear = info_node->info_linear;
47+
48+
for (i = 0; i < info_linear->info.nr_jited_ksyms; i++) {
49+
u64 *addrs = (u64 *)(info_linear->info.jited_ksyms);
50+
u64 addr = addrs[i];
51+
struct map *map;
52+
53+
map = map_groups__find(&machine->kmaps, addr);
54+
55+
if (map) {
56+
map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
57+
map->dso->bpf_prog.id = id;
58+
map->dso->bpf_prog.sub_id = i;
59+
map->dso->bpf_prog.env = env;
60+
}
61+
}
62+
return 0;
63+
}
64+
2865
int machine__process_bpf_event(struct machine *machine __maybe_unused,
2966
union perf_event *event,
3067
struct perf_sample *sample __maybe_unused)
3168
{
3269
if (dump_trace)
3370
perf_event__fprintf_bpf_event(event, stdout);
71+
72+
switch (event->bpf_event.type) {
73+
case PERF_BPF_EVENT_PROG_LOAD:
74+
return machine__process_bpf_event_load(machine, event, sample);
75+
76+
case PERF_BPF_EVENT_PROG_UNLOAD:
77+
/*
78+
* Do not free bpf_prog_info and btf of the program here,
79+
* as annotation still need them. They will be freed at
80+
* the end of the session.
81+
*/
82+
break;
83+
default:
84+
pr_debug("unexpected bpf_event type of %d\n",
85+
event->bpf_event.type);
86+
break;
87+
}
3488
return 0;
3589
}
3690

0 commit comments

Comments
 (0)