samples/bpf: raw tracepoint test
authorAlexei Starovoitov <ast@kernel.org>
Wed, 28 Mar 2018 19:05:39 +0000 (12:05 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 28 Mar 2018 20:55:19 +0000 (22:55 +0200)
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>
samples/bpf/Makefile
samples/bpf/bpf_load.c
samples/bpf/test_overhead_raw_tp_kern.c [new file with mode: 0644]
samples/bpf/test_overhead_user.c

index 2c2a587e0942b9d714539521d413ae96e01bfaf0..4d6a6edd4bf6e9200f5be30c7c78ff0e26854731 100644 (file)
@@ -119,6 +119,7 @@ always += offwaketime_kern.o
 always += spintest_kern.o
 always += map_perf_test_kern.o
 always += test_overhead_tp_kern.o
+always += test_overhead_raw_tp_kern.o
 always += test_overhead_kprobe_kern.o
 always += parse_varlen.o parse_simple.o parse_ldabs.o
 always += test_cgrp2_tc_kern.o
index b1a310c3ae899b043c70085fc71a08b698ea0308..bebe4188b4b36cbf42fe39f1f5c61c43ea1bf8a9 100644 (file)
@@ -61,6 +61,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
        bool is_kprobe = strncmp(event, "kprobe/", 7) == 0;
        bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0;
        bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0;
+       bool is_raw_tracepoint = strncmp(event, "raw_tracepoint/", 15) == 0;
        bool is_xdp = strncmp(event, "xdp", 3) == 0;
        bool is_perf_event = strncmp(event, "perf_event", 10) == 0;
        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)
                prog_type = BPF_PROG_TYPE_KPROBE;
        } else if (is_tracepoint) {
                prog_type = BPF_PROG_TYPE_TRACEPOINT;
+       } else if (is_raw_tracepoint) {
+               prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT;
        } else if (is_xdp) {
                prog_type = BPF_PROG_TYPE_XDP;
        } else if (is_perf_event) {
@@ -131,6 +134,16 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
                return populate_prog_array(event, fd);
        }
 
+       if (is_raw_tracepoint) {
+               efd = bpf_raw_tracepoint_open(event + 15, fd);
+               if (efd < 0) {
+                       printf("tracepoint %s %s\n", event + 15, strerror(errno));
+                       return -1;
+               }
+               event_fd[prog_cnt - 1] = efd;
+               return 0;
+       }
+
        if (is_kprobe || is_kretprobe) {
                if (is_kprobe)
                        event += 7;
@@ -587,6 +600,7 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map)
                if (memcmp(shname, "kprobe/", 7) == 0 ||
                    memcmp(shname, "kretprobe/", 10) == 0 ||
                    memcmp(shname, "tracepoint/", 11) == 0 ||
+                   memcmp(shname, "raw_tracepoint/", 15) == 0 ||
                    memcmp(shname, "xdp", 3) == 0 ||
                    memcmp(shname, "perf_event", 10) == 0 ||
                    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 (file)
index 0000000..d2af8bc
--- /dev/null
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018 Facebook */
+#include <uapi/linux/bpf.h>
+#include "bpf_helpers.h"
+
+SEC("raw_tracepoint/task_rename")
+int prog(struct bpf_raw_tracepoint_args *ctx)
+{
+       return 0;
+}
+
+SEC("raw_tracepoint/urandom_read")
+int prog2(struct bpf_raw_tracepoint_args *ctx)
+{
+       return 0;
+}
+char _license[] SEC("license") = "GPL";
index d291167fd3c78c8649c07ad6b1023f9a3ad7bb19..e1d35e07a10ec13feaba88f5276612ff5a35b0ae 100644 (file)
@@ -158,5 +158,17 @@ int main(int argc, char **argv)
                unload_progs();
        }
 
+       if (test_flags & 0xC0) {
+               snprintf(filename, sizeof(filename),
+                        "%s_raw_tp_kern.o", argv[0]);
+               if (load_bpf_file(filename)) {
+                       printf("%s", bpf_log_buf);
+                       return 1;
+               }
+               printf("w/RAW_TRACEPOINT\n");
+               run_perf_test(num_cpu, test_flags >> 6);
+               unload_progs();
+       }
+
        return 0;
 }