summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/trigger_bench.c
blob: 2619ed193c65a5f46e315a9048d611e36a4a38c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Facebook
#include <linux/bpf.h>
#include <asm/unistd.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"

char _license[] SEC("license") = "GPL";

#define CPU_MASK 255
#define MAX_CPUS (CPU_MASK + 1) /* should match MAX_BUCKETS in benchs/bench_trigger.c */

/* matches struct counter in bench.h */
struct counter {
	long value;
} __attribute__((aligned(128)));

struct counter hits[MAX_CPUS];

static __always_inline void inc_counter(void)
{
	int cpu = bpf_get_smp_processor_id();

	__sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
}

SEC("?uprobe")
int bench_trigger_uprobe(void *ctx)
{
	inc_counter();
	return 0;
}

const volatile int batch_iters = 0;

SEC("?raw_tp")
int trigger_count(void *ctx)
{
	int i;

	for (i = 0; i < batch_iters; i++)
		inc_counter();

	return 0;
}

SEC("?raw_tp")
int trigger_driver(void *ctx)
{
	int i;

	for (i = 0; i < batch_iters; i++)
		(void)bpf_get_numa_node_id(); /* attach point for benchmarking */

	return 0;
}

extern int bpf_modify_return_test_tp(int nonce) __ksym __weak;

SEC("?raw_tp")
int trigger_driver_kfunc(void *ctx)
{
	int i;

	for (i = 0; i < batch_iters; i++)
		(void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */

	return 0;
}

SEC("?kprobe/bpf_get_numa_node_id")
int bench_trigger_kprobe(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?kretprobe/bpf_get_numa_node_id")
int bench_trigger_kretprobe(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?kprobe.multi/bpf_get_numa_node_id")
int bench_trigger_kprobe_multi(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?kretprobe.multi/bpf_get_numa_node_id")
int bench_trigger_kretprobe_multi(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?fentry/bpf_get_numa_node_id")
int bench_trigger_fentry(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?fexit/bpf_get_numa_node_id")
int bench_trigger_fexit(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?fmod_ret/bpf_modify_return_test_tp")
int bench_trigger_fmodret(void *ctx)
{
	inc_counter();
	return -22;
}

SEC("?tp/bpf_test_run/bpf_trigger_tp")
int bench_trigger_tp(void *ctx)
{
	inc_counter();
	return 0;
}

SEC("?raw_tp/bpf_trigger_tp")
int bench_trigger_rawtp(void *ctx)
{
	inc_counter();
	return 0;
}