Commit | Line | Data |
---|---|---|
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 | |
9 | char _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 */ | |
15 | struct counter { | |
16 | long value; | |
17 | } __attribute__((aligned(128))); | |
18 | ||
19 | struct counter hits[MAX_CPUS]; | |
20 | ||
21 | static __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 | 28 | SEC("?uprobe") |
d41bc48b AN |
29 | int bench_trigger_uprobe(void *ctx) |
30 | { | |
520fad2e | 31 | inc_counter(); |
d41bc48b AN |
32 | return 0; |
33 | } | |
7df4e597 AN |
34 | |
35 | const volatile int batch_iters = 0; | |
36 | ||
b4ccf915 | 37 | SEC("?raw_tp") |
7df4e597 AN |
38 | int 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 | 48 | SEC("?raw_tp") |
7df4e597 AN |
49 | int 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 |
59 | extern int bpf_modify_return_test_tp(int nonce) __ksym __weak; |
60 | ||
61 | SEC("?raw_tp") | |
62 | int 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 | 72 | SEC("?kprobe/bpf_get_numa_node_id") |
208c4391 | 73 | int bench_trigger_kprobe(void *ctx) |
7df4e597 AN |
74 | { |
75 | inc_counter(); | |
76 | return 0; | |
77 | } | |
78 | ||
b4ccf915 | 79 | SEC("?kretprobe/bpf_get_numa_node_id") |
208c4391 | 80 | int bench_trigger_kretprobe(void *ctx) |
7df4e597 AN |
81 | { |
82 | inc_counter(); | |
83 | return 0; | |
84 | } | |
85 | ||
b4ccf915 | 86 | SEC("?kprobe.multi/bpf_get_numa_node_id") |
208c4391 | 87 | int bench_trigger_kprobe_multi(void *ctx) |
7df4e597 AN |
88 | { |
89 | inc_counter(); | |
90 | return 0; | |
91 | } | |
92 | ||
b4ccf915 | 93 | SEC("?kretprobe.multi/bpf_get_numa_node_id") |
208c4391 | 94 | int bench_trigger_kretprobe_multi(void *ctx) |
7df4e597 AN |
95 | { |
96 | inc_counter(); | |
97 | return 0; | |
98 | } | |
99 | ||
b4ccf915 | 100 | SEC("?fentry/bpf_get_numa_node_id") |
208c4391 | 101 | int bench_trigger_fentry(void *ctx) |
7df4e597 AN |
102 | { |
103 | inc_counter(); | |
104 | return 0; | |
105 | } | |
106 | ||
b4ccf915 | 107 | SEC("?fexit/bpf_get_numa_node_id") |
208c4391 | 108 | int bench_trigger_fexit(void *ctx) |
7df4e597 AN |
109 | { |
110 | inc_counter(); | |
111 | return 0; | |
112 | } | |
985d0681 AN |
113 | |
114 | SEC("?fmod_ret/bpf_modify_return_test_tp") | |
115 | int bench_trigger_fmodret(void *ctx) | |
116 | { | |
117 | inc_counter(); | |
118 | return -22; | |
119 | } | |
120 | ||
121 | SEC("?tp/bpf_test_run/bpf_trigger_tp") | |
122 | int bench_trigger_tp(void *ctx) | |
123 | { | |
124 | inc_counter(); | |
125 | return 0; | |
126 | } | |
127 | ||
128 | SEC("?raw_tp/bpf_trigger_tp") | |
129 | int bench_trigger_rawtp(void *ctx) | |
130 | { | |
131 | inc_counter(); | |
132 | return 0; | |
133 | } |