Linux Audio

Check our new training course

Loading...
v6.13.7
  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_count(void *ctx)
 46{
 47	int i;
 48
 49	for (i = 0; i < batch_iters; i++)
 50		inc_counter();
 51
 52	return 0;
 53}
 54
 55SEC("?raw_tp")
 56int trigger_driver(void *ctx)
 57{
 58	int i;
 59
 60	for (i = 0; i < batch_iters; i++)
 61		(void)bpf_get_numa_node_id(); /* attach point for benchmarking */
 62
 63	return 0;
 64}
 65
 66extern int bpf_modify_return_test_tp(int nonce) __ksym __weak;
 67
 68SEC("?raw_tp")
 69int trigger_driver_kfunc(void *ctx)
 70{
 71	int i;
 72
 73	for (i = 0; i < batch_iters; i++)
 74		(void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */
 75
 76	return 0;
 77}
 78
 79SEC("?kprobe/bpf_get_numa_node_id")
 80int bench_trigger_kprobe(void *ctx)
 81{
 82	inc_counter();
 83	return 0;
 84}
 85
 86SEC("?kretprobe/bpf_get_numa_node_id")
 87int bench_trigger_kretprobe(void *ctx)
 88{
 89	inc_counter();
 90	return 0;
 91}
 92
 93SEC("?kprobe.multi/bpf_get_numa_node_id")
 94int bench_trigger_kprobe_multi(void *ctx)
 95{
 96	inc_counter();
 97	return 0;
 98}
 99
100SEC("?kretprobe.multi/bpf_get_numa_node_id")
101int bench_trigger_kretprobe_multi(void *ctx)
102{
103	inc_counter();
104	return 0;
105}
106
107SEC("?fentry/bpf_get_numa_node_id")
108int bench_trigger_fentry(void *ctx)
109{
110	inc_counter();
111	return 0;
112}
113
114SEC("?fexit/bpf_get_numa_node_id")
115int bench_trigger_fexit(void *ctx)
116{
117	inc_counter();
118	return 0;
119}
120
121SEC("?fmod_ret/bpf_modify_return_test_tp")
122int bench_trigger_fmodret(void *ctx)
123{
124	inc_counter();
125	return -22;
126}
127
128SEC("?tp/bpf_test_run/bpf_trigger_tp")
129int bench_trigger_tp(void *ctx)
130{
131	inc_counter();
132	return 0;
133}
134
135SEC("?raw_tp/bpf_trigger_tp")
136int bench_trigger_rawtp(void *ctx)
137{
138	inc_counter();
139	return 0;
140}
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2// Copyright (c) 2020 Facebook
 3
 4#include <linux/bpf.h>
 5#include <asm/unistd.h>
 6#include <bpf/bpf_helpers.h>
 7#include <bpf/bpf_tracing.h>
 8#include "bpf_misc.h"
 9
10char _license[] SEC("license") = "GPL";
11
12long hits = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
14SEC("tp/syscalls/sys_enter_getpgid")
15int bench_trigger_tp(void *ctx)
16{
17	__sync_add_and_fetch(&hits, 1);
 
 
 
 
18	return 0;
19}
20
21SEC("raw_tp/sys_enter")
22int BPF_PROG(bench_trigger_raw_tp, struct pt_regs *regs, long id)
23{
24	if (id == __NR_getpgid)
25		__sync_add_and_fetch(&hits, 1);
 
 
 
26	return 0;
27}
28
29SEC("kprobe/" SYS_PREFIX "sys_getpgid")
 
 
 
 
 
 
 
 
 
 
 
 
 
30int bench_trigger_kprobe(void *ctx)
31{
32	__sync_add_and_fetch(&hits, 1);
 
 
 
 
 
 
 
33	return 0;
34}
35
36SEC("fentry/" SYS_PREFIX "sys_getpgid")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37int bench_trigger_fentry(void *ctx)
38{
39	__sync_add_and_fetch(&hits, 1);
40	return 0;
41}
42
43SEC("fentry.s/" SYS_PREFIX "sys_getpgid")
44int bench_trigger_fentry_sleep(void *ctx)
45{
46	__sync_add_and_fetch(&hits, 1);
47	return 0;
48}
49
50SEC("fmod_ret/" SYS_PREFIX "sys_getpgid")
51int bench_trigger_fmodret(void *ctx)
52{
53	__sync_add_and_fetch(&hits, 1);
54	return -22;
55}
56
57SEC("uprobe")
58int bench_trigger_uprobe(void *ctx)
 
 
 
 
 
 
 
59{
60	__sync_add_and_fetch(&hits, 1);
61	return 0;
62}