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
10 char _license[] SEC("license") = "GPL";
11
12 long hits = 0;
13
14 SEC("tp/syscalls/sys_enter_getpgid")
bench_trigger_tp(void * ctx)15 int bench_trigger_tp(void *ctx)
16 {
17 __sync_add_and_fetch(&hits, 1);
18 return 0;
19 }
20
21 SEC("raw_tp/sys_enter")
BPF_PROG(bench_trigger_raw_tp,struct pt_regs * regs,long id)22 int 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
29 SEC("kprobe/" SYS_PREFIX "sys_getpgid")
bench_trigger_kprobe(void * ctx)30 int bench_trigger_kprobe(void *ctx)
31 {
32 __sync_add_and_fetch(&hits, 1);
33 return 0;
34 }
35
36 SEC("fentry/" SYS_PREFIX "sys_getpgid")
bench_trigger_fentry(void * ctx)37 int bench_trigger_fentry(void *ctx)
38 {
39 __sync_add_and_fetch(&hits, 1);
40 return 0;
41 }
42
43 SEC("fentry.s/" SYS_PREFIX "sys_getpgid")
bench_trigger_fentry_sleep(void * ctx)44 int bench_trigger_fentry_sleep(void *ctx)
45 {
46 __sync_add_and_fetch(&hits, 1);
47 return 0;
48 }
49
50 SEC("fmod_ret/" SYS_PREFIX "sys_getpgid")
bench_trigger_fmodret(void * ctx)51 int bench_trigger_fmodret(void *ctx)
52 {
53 __sync_add_and_fetch(&hits, 1);
54 return -22;
55 }
56
57 SEC("uprobe")
bench_trigger_uprobe(void * ctx)58 int bench_trigger_uprobe(void *ctx)
59 {
60 __sync_add_and_fetch(&hits, 1);
61 return 0;
62 }
63