diff options
author | Alexei Starovoitov <ast@kernel.org> | 2018-03-28 15:05:39 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-03-28 16:55:19 -0400 |
commit | 4662a4e53890badf4da17e441606a2885f29d56d (patch) | |
tree | f1a09047f3d67d5f6264e7f9b6d94b96eabf7111 | |
parent | a0fe3e574b50461c4811ce81811f0eaefda62871 (diff) |
samples/bpf: raw tracepoint test
add empty raw_tracepoint bpf program to test overhead similar
to kprobe and traditional tracepoint tests
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | samples/bpf/Makefile | 1 | ||||
-rw-r--r-- | samples/bpf/bpf_load.c | 14 | ||||
-rw-r--r-- | samples/bpf/test_overhead_raw_tp_kern.c | 17 | ||||
-rw-r--r-- | samples/bpf/test_overhead_user.c | 12 |
4 files changed, 44 insertions, 0 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 2c2a587e0942..4d6a6edd4bf6 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile | |||
@@ -119,6 +119,7 @@ always += offwaketime_kern.o | |||
119 | always += spintest_kern.o | 119 | always += spintest_kern.o |
120 | always += map_perf_test_kern.o | 120 | always += map_perf_test_kern.o |
121 | always += test_overhead_tp_kern.o | 121 | always += test_overhead_tp_kern.o |
122 | always += test_overhead_raw_tp_kern.o | ||
122 | always += test_overhead_kprobe_kern.o | 123 | always += test_overhead_kprobe_kern.o |
123 | always += parse_varlen.o parse_simple.o parse_ldabs.o | 124 | always += parse_varlen.o parse_simple.o parse_ldabs.o |
124 | always += test_cgrp2_tc_kern.o | 125 | always += test_cgrp2_tc_kern.o |
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c index b1a310c3ae89..bebe4188b4b3 100644 --- a/samples/bpf/bpf_load.c +++ b/samples/bpf/bpf_load.c | |||
@@ -61,6 +61,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size) | |||
61 | bool is_kprobe = strncmp(event, "kprobe/", 7) == 0; | 61 | bool is_kprobe = strncmp(event, "kprobe/", 7) == 0; |
62 | bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0; | 62 | bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0; |
63 | bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0; | 63 | bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0; |
64 | bool is_raw_tracepoint = strncmp(event, "raw_tracepoint/", 15) == 0; | ||
64 | bool is_xdp = strncmp(event, "xdp", 3) == 0; | 65 | bool is_xdp = strncmp(event, "xdp", 3) == 0; |
65 | bool is_perf_event = strncmp(event, "perf_event", 10) == 0; | 66 | bool is_perf_event = strncmp(event, "perf_event", 10) == 0; |
66 | bool is_cgroup_skb = strncmp(event, "cgroup/skb", 10) == 0; | 67 | bool is_cgroup_skb = strncmp(event, "cgroup/skb", 10) == 0; |
@@ -85,6 +86,8 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size) | |||
85 | prog_type = BPF_PROG_TYPE_KPROBE; | 86 | prog_type = BPF_PROG_TYPE_KPROBE; |
86 | } else if (is_tracepoint) { | 87 | } else if (is_tracepoint) { |
87 | prog_type = BPF_PROG_TYPE_TRACEPOINT; | 88 | prog_type = BPF_PROG_TYPE_TRACEPOINT; |
89 | } else if (is_raw_tracepoint) { | ||
90 | prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT; | ||
88 | } else if (is_xdp) { | 91 | } else if (is_xdp) { |
89 | prog_type = BPF_PROG_TYPE_XDP; | 92 | prog_type = BPF_PROG_TYPE_XDP; |
90 | } else if (is_perf_event) { | 93 | } else if (is_perf_event) { |
@@ -131,6 +134,16 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size) | |||
131 | return populate_prog_array(event, fd); | 134 | return populate_prog_array(event, fd); |
132 | } | 135 | } |
133 | 136 | ||
137 | if (is_raw_tracepoint) { | ||
138 | efd = bpf_raw_tracepoint_open(event + 15, fd); | ||
139 | if (efd < 0) { | ||
140 | printf("tracepoint %s %s\n", event + 15, strerror(errno)); | ||
141 | return -1; | ||
142 | } | ||
143 | event_fd[prog_cnt - 1] = efd; | ||
144 | return 0; | ||
145 | } | ||
146 | |||
134 | if (is_kprobe || is_kretprobe) { | 147 | if (is_kprobe || is_kretprobe) { |
135 | if (is_kprobe) | 148 | if (is_kprobe) |
136 | event += 7; | 149 | event += 7; |
@@ -587,6 +600,7 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map) | |||
587 | if (memcmp(shname, "kprobe/", 7) == 0 || | 600 | if (memcmp(shname, "kprobe/", 7) == 0 || |
588 | memcmp(shname, "kretprobe/", 10) == 0 || | 601 | memcmp(shname, "kretprobe/", 10) == 0 || |
589 | memcmp(shname, "tracepoint/", 11) == 0 || | 602 | memcmp(shname, "tracepoint/", 11) == 0 || |
603 | memcmp(shname, "raw_tracepoint/", 15) == 0 || | ||
590 | memcmp(shname, "xdp", 3) == 0 || | 604 | memcmp(shname, "xdp", 3) == 0 || |
591 | memcmp(shname, "perf_event", 10) == 0 || | 605 | memcmp(shname, "perf_event", 10) == 0 || |
592 | memcmp(shname, "socket", 6) == 0 || | 606 | memcmp(shname, "socket", 6) == 0 || |
diff --git a/samples/bpf/test_overhead_raw_tp_kern.c b/samples/bpf/test_overhead_raw_tp_kern.c new file mode 100644 index 000000000000..d2af8bc1c805 --- /dev/null +++ b/samples/bpf/test_overhead_raw_tp_kern.c | |||
@@ -0,0 +1,17 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* Copyright (c) 2018 Facebook */ | ||
3 | #include <uapi/linux/bpf.h> | ||
4 | #include "bpf_helpers.h" | ||
5 | |||
6 | SEC("raw_tracepoint/task_rename") | ||
7 | int prog(struct bpf_raw_tracepoint_args *ctx) | ||
8 | { | ||
9 | return 0; | ||
10 | } | ||
11 | |||
12 | SEC("raw_tracepoint/urandom_read") | ||
13 | int prog2(struct bpf_raw_tracepoint_args *ctx) | ||
14 | { | ||
15 | return 0; | ||
16 | } | ||
17 | char _license[] SEC("license") = "GPL"; | ||
diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_user.c index d291167fd3c7..e1d35e07a10e 100644 --- a/samples/bpf/test_overhead_user.c +++ b/samples/bpf/test_overhead_user.c | |||
@@ -158,5 +158,17 @@ int main(int argc, char **argv) | |||
158 | unload_progs(); | 158 | unload_progs(); |
159 | } | 159 | } |
160 | 160 | ||
161 | if (test_flags & 0xC0) { | ||
162 | snprintf(filename, sizeof(filename), | ||
163 | "%s_raw_tp_kern.o", argv[0]); | ||
164 | if (load_bpf_file(filename)) { | ||
165 | printf("%s", bpf_log_buf); | ||
166 | return 1; | ||
167 | } | ||
168 | printf("w/RAW_TRACEPOINT\n"); | ||
169 | run_perf_test(num_cpu, test_flags >> 6); | ||
170 | unload_progs(); | ||
171 | } | ||
172 | |||
161 | return 0; | 173 | return 0; |
162 | } | 174 | } |