diff options
author | Alexei Starovoitov <ast@fb.com> | 2016-09-01 21:37:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-09-02 13:46:45 -0400 |
commit | 1c47910ef80135ac89e4d0b471d123572cee5535 (patch) | |
tree | 95066aef056b16a4e5e477c7f277cc69db418e5c /samples/bpf/bpf_load.c | |
parent | aa6a5f3cb2b2edc5b9aab0b4fdfdfa9c3b5096a8 (diff) |
samples/bpf: add perf_event+bpf example
The bpf program is called 50 times a second and does hashmap[kern&user_stackid]++
It's primary purpose to check that key bpf helpers like map lookup, update,
get_stackid, trace_printk and ctx access are all working.
It checks:
- PERF_COUNT_HW_CPU_CYCLES on all cpus
- PERF_COUNT_HW_CPU_CYCLES for current process and inherited perf_events to children
- PERF_COUNT_SW_CPU_CLOCK on all cpus
- PERF_COUNT_SW_CPU_CLOCK for current process
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf/bpf_load.c')
-rw-r--r-- | samples/bpf/bpf_load.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index 0cfda2320320..97913e109b14 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c | |||
@@ -51,6 +51,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size) | |||
51 | bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0; | 51 | bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0; |
52 | bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0; | 52 | bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0; |
53 | bool is_xdp = strncmp(event, "xdp", 3) == 0; | 53 | bool is_xdp = strncmp(event, "xdp", 3) == 0; |
54 | bool is_perf_event = strncmp(event, "perf_event", 10) == 0; | ||
54 | enum bpf_prog_type prog_type; | 55 | enum bpf_prog_type prog_type; |
55 | char buf[256]; | 56 | char buf[256]; |
56 | int fd, efd, err, id; | 57 | int fd, efd, err, id; |
@@ -69,6 +70,8 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size) | |||
69 | prog_type = BPF_PROG_TYPE_TRACEPOINT; | 70 | prog_type = BPF_PROG_TYPE_TRACEPOINT; |
70 | } else if (is_xdp) { | 71 | } else if (is_xdp) { |
71 | prog_type = BPF_PROG_TYPE_XDP; | 72 | prog_type = BPF_PROG_TYPE_XDP; |
73 | } else if (is_perf_event) { | ||
74 | prog_type = BPF_PROG_TYPE_PERF_EVENT; | ||
72 | } else { | 75 | } else { |
73 | printf("Unknown event '%s'\n", event); | 76 | printf("Unknown event '%s'\n", event); |
74 | return -1; | 77 | return -1; |
@@ -82,7 +85,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size) | |||
82 | 85 | ||
83 | prog_fd[prog_cnt++] = fd; | 86 | prog_fd[prog_cnt++] = fd; |
84 | 87 | ||
85 | if (is_xdp) | 88 | if (is_xdp || is_perf_event) |
86 | return 0; | 89 | return 0; |
87 | 90 | ||
88 | if (is_socket) { | 91 | if (is_socket) { |
@@ -326,6 +329,7 @@ int load_bpf_file(char *path) | |||
326 | memcmp(shname_prog, "kretprobe/", 10) == 0 || | 329 | memcmp(shname_prog, "kretprobe/", 10) == 0 || |
327 | memcmp(shname_prog, "tracepoint/", 11) == 0 || | 330 | memcmp(shname_prog, "tracepoint/", 11) == 0 || |
328 | memcmp(shname_prog, "xdp", 3) == 0 || | 331 | memcmp(shname_prog, "xdp", 3) == 0 || |
332 | memcmp(shname_prog, "perf_event", 10) == 0 || | ||
329 | memcmp(shname_prog, "socket", 6) == 0) | 333 | memcmp(shname_prog, "socket", 6) == 0) |
330 | load_and_attach(shname_prog, insns, data_prog->d_size); | 334 | load_and_attach(shname_prog, insns, data_prog->d_size); |
331 | } | 335 | } |
@@ -344,6 +348,7 @@ int load_bpf_file(char *path) | |||
344 | memcmp(shname, "kretprobe/", 10) == 0 || | 348 | memcmp(shname, "kretprobe/", 10) == 0 || |
345 | memcmp(shname, "tracepoint/", 11) == 0 || | 349 | memcmp(shname, "tracepoint/", 11) == 0 || |
346 | memcmp(shname, "xdp", 3) == 0 || | 350 | memcmp(shname, "xdp", 3) == 0 || |
351 | memcmp(shname, "perf_event", 10) == 0 || | ||
347 | memcmp(shname, "socket", 6) == 0) | 352 | memcmp(shname, "socket", 6) == 0) |
348 | load_and_attach(shname, data->d_buf, data->d_size); | 353 | load_and_attach(shname, data->d_buf, data->d_size); |
349 | } | 354 | } |