File Index
Files and directories
Sign in
FILE

trigger_bench.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/progs/trigger_bench.c C
  1// SPDX-License-Identifier: GPL-2.0
  2// Copyright (c) 2020 Facebook
  3#include <linux/bpf.h>
  4#include <asm/unistd.h>
  5#include <bpf/bpf_helpers.h>
  6#include <bpf/bpf_tracing.h>
  7#include "bpf_misc.h"
  8
  9char _license[] SEC("license") = "GPL";
 10
 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}
 27
 28SEC("?uprobe")
 29int bench_trigger_uprobe(void *ctx)
 30{
 31	inc_counter();
 32	return 0;
 33}
 34
 35SEC("?uprobe.multi")
 36int bench_trigger_uprobe_multi(void *ctx)
 37{
 38	inc_counter();
 39	return 0;
 40}
 41
 42const volatile int batch_iters = 0;
 43
 44SEC("?raw_tp")
 45int trigger_kernel_count(void *ctx)
 46{
 47	int i;
 48
 49	for (i = 0; i < batch_iters; i++) {
 50		inc_counter();
 51		bpf_get_numa_node_id();
 52	}
 53
 54	return 0;
 55}
 56
 57SEC("?raw_tp")
 58int trigger_driver(void *ctx)
 59{
 60	int i;
 61
 62	for (i = 0; i < batch_iters; i++)
 63		(void)bpf_get_numa_node_id(); /* attach point for benchmarking */
 64
 65	return 0;
 66}
 67
 68extern int bpf_modify_return_test_tp(int nonce) __ksym __weak;
 69
 70SEC("?raw_tp")
 71int trigger_driver_kfunc(void *ctx)
 72{
 73	int i;
 74
 75	for (i = 0; i < batch_iters; i++)
 76		(void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */
 77
 78	return 0;
 79}
 80
 81SEC("?kprobe/bpf_get_numa_node_id")
 82int bench_trigger_kprobe(void *ctx)
 83{
 84	inc_counter();
 85	return 0;
 86}
 87
 88SEC("?kretprobe/bpf_get_numa_node_id")
 89int bench_trigger_kretprobe(void *ctx)
 90{
 91	inc_counter();
 92	return 0;
 93}
 94
 95SEC("?kprobe.multi/bpf_get_numa_node_id")
 96int bench_trigger_kprobe_multi(void *ctx)
 97{
 98	inc_counter();
 99	return 0;
100}
101
102SEC("?kprobe.multi/bpf_get_numa_node_id")
103int bench_kprobe_multi_empty(void *ctx)
104{
105	return 0;
106}
107
108SEC("?kretprobe.multi/bpf_get_numa_node_id")
109int bench_trigger_kretprobe_multi(void *ctx)
110{
111	inc_counter();
112	return 0;
113}
114
115SEC("?kretprobe.multi/bpf_get_numa_node_id")
116int bench_kretprobe_multi_empty(void *ctx)
117{
118	return 0;
119}
120
121SEC("?fentry/bpf_get_numa_node_id")
122int bench_trigger_fentry(void *ctx)
123{
124	inc_counter();
125	return 0;
126}
127
128SEC("?fexit/bpf_get_numa_node_id")
129int bench_trigger_fexit(void *ctx)
130{
131	inc_counter();
132	return 0;
133}
134
135SEC("?fmod_ret/bpf_modify_return_test_tp")
136int bench_trigger_fmodret(void *ctx)
137{
138	inc_counter();
139	return -22;
140}
141
142SEC("?tp/bpf_test_run/bpf_trigger_tp")
143int bench_trigger_tp(void *ctx)
144{
145	inc_counter();
146	return 0;
147}
148
149SEC("?raw_tp/bpf_trigger_tp")
150int bench_trigger_rawtp(void *ctx)
151{
152	inc_counter();
153	return 0;
154}
~/ Read-only file preview.