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}
v5.14.15
 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
 9char _license[] SEC("license") = "GPL";
10
11long hits = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13SEC("tp/syscalls/sys_enter_getpgid")
14int bench_trigger_tp(void *ctx)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15{
16	__sync_add_and_fetch(&hits, 1);
 
 
 
 
17	return 0;
18}
19
20SEC("raw_tp/sys_enter")
21int BPF_PROG(bench_trigger_raw_tp, struct pt_regs *regs, long id)
22{
23	if (id == __NR_getpgid)
24		__sync_add_and_fetch(&hits, 1);
 
 
 
25	return 0;
26}
27
28SEC("kprobe/__x64_sys_getpgid")
 
 
 
 
 
 
 
 
 
 
 
 
 
29int bench_trigger_kprobe(void *ctx)
30{
31	__sync_add_and_fetch(&hits, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32	return 0;
33}
34
35SEC("fentry/__x64_sys_getpgid")
36int bench_trigger_fentry(void *ctx)
37{
38	__sync_add_and_fetch(&hits, 1);
39	return 0;
40}
41
42SEC("fentry.s/__x64_sys_getpgid")
43int bench_trigger_fentry_sleep(void *ctx)
44{
45	__sync_add_and_fetch(&hits, 1);
46	return 0;
47}
48
49SEC("fmod_ret/__x64_sys_getpgid")
50int bench_trigger_fmodret(void *ctx)
51{
52	__sync_add_and_fetch(&hits, 1);
53	return -22;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54}