aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/test_perf_buffer.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-07-06 11:06:26 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2019-07-08 15:35:43 +0200
commitee5cf82ce04a60d71b0dc219804f6cf1e6ba6d14 (patch)
tree4deec4d2857b00221e53f75f9d64f62a7d95f672 /tools/testing/selftests/bpf/progs/test_perf_buffer.c
parentlibbpf: auto-set PERF_EVENT_ARRAY size to number of CPUs (diff)
downloadlinux-dev-ee5cf82ce04a60d71b0dc219804f6cf1e6ba6d14.tar.xz
linux-dev-ee5cf82ce04a60d71b0dc219804f6cf1e6ba6d14.zip
selftests/bpf: test perf buffer API
Add test verifying perf buffer API functionality. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to '')
-rw-r--r--tools/testing/selftests/bpf/progs/test_perf_buffer.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_perf_buffer.c b/tools/testing/selftests/bpf/progs/test_perf_buffer.c
new file mode 100644
index 000000000000..876c27deb65a
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_perf_buffer.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2019 Facebook
+
+#include <linux/ptrace.h>
+#include <linux/bpf.h>
+#include "bpf_helpers.h"
+
+struct {
+ __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+ __uint(key_size, sizeof(int));
+ __uint(value_size, sizeof(int));
+} perf_buf_map SEC(".maps");
+
+SEC("kprobe/sys_nanosleep")
+int handle_sys_nanosleep_entry(struct pt_regs *ctx)
+{
+ int cpu = bpf_get_smp_processor_id();
+
+ bpf_perf_event_output(ctx, &perf_buf_map, BPF_F_CURRENT_CPU,
+ &cpu, sizeof(cpu));
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
+__u32 _version SEC("version") = 1;