selftests/bpf: add batched tp/raw_tp/fmodret tests
[linux-block.git] / tools / testing / selftests / bpf / progs / trigger_bench.c
CommitLineData
c5d420c3
AN
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2020 Facebook
c5d420c3
AN
3#include <linux/bpf.h>
4#include <asm/unistd.h>
5#include <bpf/bpf_helpers.h>
6#include <bpf/bpf_tracing.h>
e91d280c 7#include "bpf_misc.h"
c5d420c3
AN
8
9char _license[] SEC("license") = "GPL";
10
520fad2e
AN
11#define CPU_MASK 255
12#define MAX_CPUS (CPU_MASK + 1) /* should match MAX_BUCKETS in benchs/bench_trigger.c */
13
14/* matches struct counter in bench.h */
15struct counter {
16 long value;
17} __attribute__((aligned(128)));
18
19struct counter hits[MAX_CPUS];
20
21static __always_inline void inc_counter(void)
22{
23 int cpu = bpf_get_smp_processor_id();
24
25 __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
26}
c5d420c3 27
b4ccf915 28SEC("?uprobe")
d41bc48b
AN
29int bench_trigger_uprobe(void *ctx)
30{
520fad2e 31 inc_counter();
d41bc48b
AN
32 return 0;
33}
7df4e597
AN
34
35const volatile int batch_iters = 0;
36
b4ccf915 37SEC("?raw_tp")
7df4e597
AN
38int trigger_count(void *ctx)
39{
40 int i;
41
42 for (i = 0; i < batch_iters; i++)
43 inc_counter();
44
45 return 0;
46}
47
b4ccf915 48SEC("?raw_tp")
7df4e597
AN
49int trigger_driver(void *ctx)
50{
51 int i;
52
53 for (i = 0; i < batch_iters; i++)
54 (void)bpf_get_numa_node_id(); /* attach point for benchmarking */
55
56 return 0;
57}
58
985d0681
AN
59extern int bpf_modify_return_test_tp(int nonce) __ksym __weak;
60
61SEC("?raw_tp")
62int trigger_driver_kfunc(void *ctx)
63{
64 int i;
65
66 for (i = 0; i < batch_iters; i++)
67 (void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */
68
69 return 0;
70}
71
b4ccf915 72SEC("?kprobe/bpf_get_numa_node_id")
208c4391 73int bench_trigger_kprobe(void *ctx)
7df4e597
AN
74{
75 inc_counter();
76 return 0;
77}
78
b4ccf915 79SEC("?kretprobe/bpf_get_numa_node_id")
208c4391 80int bench_trigger_kretprobe(void *ctx)
7df4e597
AN
81{
82 inc_counter();
83 return 0;
84}
85
b4ccf915 86SEC("?kprobe.multi/bpf_get_numa_node_id")
208c4391 87int bench_trigger_kprobe_multi(void *ctx)
7df4e597
AN
88{
89 inc_counter();
90 return 0;
91}
92
b4ccf915 93SEC("?kretprobe.multi/bpf_get_numa_node_id")
208c4391 94int bench_trigger_kretprobe_multi(void *ctx)
7df4e597
AN
95{
96 inc_counter();
97 return 0;
98}
99
b4ccf915 100SEC("?fentry/bpf_get_numa_node_id")
208c4391 101int bench_trigger_fentry(void *ctx)
7df4e597
AN
102{
103 inc_counter();
104 return 0;
105}
106
b4ccf915 107SEC("?fexit/bpf_get_numa_node_id")
208c4391 108int bench_trigger_fexit(void *ctx)
7df4e597
AN
109{
110 inc_counter();
111 return 0;
112}
985d0681
AN
113
114SEC("?fmod_ret/bpf_modify_return_test_tp")
115int bench_trigger_fmodret(void *ctx)
116{
117 inc_counter();
118 return -22;
119}
120
121SEC("?tp/bpf_test_run/bpf_trigger_tp")
122int bench_trigger_tp(void *ctx)
123{
124 inc_counter();
125 return 0;
126}
127
128SEC("?raw_tp/bpf_trigger_tp")
129int bench_trigger_rawtp(void *ctx)
130{
131 inc_counter();
132 return 0;
133}