Skip to content

Commit 4662a4e

Browse files
Alexei Starovoitovborkmann
authored andcommitted
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>
1 parent a0fe3e5 commit 4662a4e

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎samples/bpf/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ always += offwaketime_kern.o
119119
always += spintest_kern.o
120120
always += map_perf_test_kern.o
121121
always += test_overhead_tp_kern.o
122+
always += test_overhead_raw_tp_kern.o
122123
always += test_overhead_kprobe_kern.o
123124
always += parse_varlen.o parse_simple.o parse_ldabs.o
124125
always += test_cgrp2_tc_kern.o

‎samples/bpf/bpf_load.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
6161
bool is_kprobe = strncmp(event, "kprobe/", 7) == 0;
6262
bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0;
6363
bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0;
64+
bool is_raw_tracepoint = strncmp(event, "raw_tracepoint/", 15) == 0;
6465
bool is_xdp = strncmp(event, "xdp", 3) == 0;
6566
bool is_perf_event = strncmp(event, "perf_event", 10) == 0;
6667
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)
8586
prog_type = BPF_PROG_TYPE_KPROBE;
8687
} else if (is_tracepoint) {
8788
prog_type = BPF_PROG_TYPE_TRACEPOINT;
89+
} else if (is_raw_tracepoint) {
90+
prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT;
8891
} else if (is_xdp) {
8992
prog_type = BPF_PROG_TYPE_XDP;
9093
} else if (is_perf_event) {
@@ -131,6 +134,16 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
131134
return populate_prog_array(event, fd);
132135
}
133136

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+
134147
if (is_kprobe || is_kretprobe) {
135148
if (is_kprobe)
136149
event += 7;
@@ -587,6 +600,7 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map)
587600
if (memcmp(shname, "kprobe/", 7) == 0 ||
588601
memcmp(shname, "kretprobe/", 10) == 0 ||
589602
memcmp(shname, "tracepoint/", 11) == 0 ||
603+
memcmp(shname, "raw_tracepoint/", 15) == 0 ||
590604
memcmp(shname, "xdp", 3) == 0 ||
591605
memcmp(shname, "perf_event", 10) == 0 ||
592606
memcmp(shname, "socket", 6) == 0 ||
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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";

‎samples/bpf/test_overhead_user.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,17 @@ int main(int argc, char **argv)
158158
unload_progs();
159159
}
160160

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+
161173
return 0;
162174
}

0 commit comments

Comments
 (0)