1c5d420c3SAndrii Nakryiko // SPDX-License-Identifier: GPL-2.0 2c5d420c3SAndrii Nakryiko // Copyright (c) 2020 Facebook 3c5d420c3SAndrii Nakryiko 4c5d420c3SAndrii Nakryiko #include <linux/bpf.h> 5c5d420c3SAndrii Nakryiko #include <asm/unistd.h> 6c5d420c3SAndrii Nakryiko #include <bpf/bpf_helpers.h> 7c5d420c3SAndrii Nakryiko #include <bpf/bpf_tracing.h> 8e91d280cSNaveen N. Rao #include "bpf_misc.h" 9c5d420c3SAndrii Nakryiko 10c5d420c3SAndrii Nakryiko char _license[] SEC("license") = "GPL"; 11c5d420c3SAndrii Nakryiko 12*520fad2eSAndrii Nakryiko #define CPU_MASK 255 13*520fad2eSAndrii Nakryiko #define MAX_CPUS (CPU_MASK + 1) /* should match MAX_BUCKETS in benchs/bench_trigger.c */ 14*520fad2eSAndrii Nakryiko 15*520fad2eSAndrii Nakryiko /* matches struct counter in bench.h */ 16*520fad2eSAndrii Nakryiko struct counter { 17*520fad2eSAndrii Nakryiko long value; 18*520fad2eSAndrii Nakryiko } __attribute__((aligned(128))); 19*520fad2eSAndrii Nakryiko 20*520fad2eSAndrii Nakryiko struct counter hits[MAX_CPUS]; 21*520fad2eSAndrii Nakryiko 22*520fad2eSAndrii Nakryiko static __always_inline void inc_counter(void) 23*520fad2eSAndrii Nakryiko { 24*520fad2eSAndrii Nakryiko int cpu = bpf_get_smp_processor_id(); 25*520fad2eSAndrii Nakryiko 26*520fad2eSAndrii Nakryiko __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1); 27*520fad2eSAndrii Nakryiko } 28c5d420c3SAndrii Nakryiko 29c5d420c3SAndrii Nakryiko SEC("tp/syscalls/sys_enter_getpgid") 30c5d420c3SAndrii Nakryiko int bench_trigger_tp(void *ctx) 31c5d420c3SAndrii Nakryiko { 32*520fad2eSAndrii Nakryiko inc_counter(); 33c5d420c3SAndrii Nakryiko return 0; 34c5d420c3SAndrii Nakryiko } 35c5d420c3SAndrii Nakryiko 36c5d420c3SAndrii Nakryiko SEC("raw_tp/sys_enter") 37c5d420c3SAndrii Nakryiko int BPF_PROG(bench_trigger_raw_tp, struct pt_regs *regs, long id) 38c5d420c3SAndrii Nakryiko { 39c5d420c3SAndrii Nakryiko if (id == __NR_getpgid) 40*520fad2eSAndrii Nakryiko inc_counter(); 41c5d420c3SAndrii Nakryiko return 0; 42c5d420c3SAndrii Nakryiko } 43c5d420c3SAndrii Nakryiko 44e91d280cSNaveen N. Rao SEC("kprobe/" SYS_PREFIX "sys_getpgid") 45c5d420c3SAndrii Nakryiko int bench_trigger_kprobe(void *ctx) 46c5d420c3SAndrii Nakryiko { 47*520fad2eSAndrii Nakryiko inc_counter(); 48c5d420c3SAndrii Nakryiko return 0; 49c5d420c3SAndrii Nakryiko } 50c5d420c3SAndrii Nakryiko 51365c2b32SAndrii Nakryiko SEC("kretprobe/" SYS_PREFIX "sys_getpgid") 52365c2b32SAndrii Nakryiko int bench_trigger_kretprobe(void *ctx) 53365c2b32SAndrii Nakryiko { 54*520fad2eSAndrii Nakryiko inc_counter(); 55365c2b32SAndrii Nakryiko return 0; 56365c2b32SAndrii Nakryiko } 57365c2b32SAndrii Nakryiko 58379b97bbSJiri Olsa SEC("kprobe.multi/" SYS_PREFIX "sys_getpgid") 59379b97bbSJiri Olsa int bench_trigger_kprobe_multi(void *ctx) 60379b97bbSJiri Olsa { 61*520fad2eSAndrii Nakryiko inc_counter(); 62379b97bbSJiri Olsa return 0; 63379b97bbSJiri Olsa } 64379b97bbSJiri Olsa 65379b97bbSJiri Olsa SEC("kretprobe.multi/" SYS_PREFIX "sys_getpgid") 66379b97bbSJiri Olsa int bench_trigger_kretprobe_multi(void *ctx) 67379b97bbSJiri Olsa { 68*520fad2eSAndrii Nakryiko inc_counter(); 69379b97bbSJiri Olsa return 0; 70379b97bbSJiri Olsa } 71379b97bbSJiri Olsa 72e91d280cSNaveen N. Rao SEC("fentry/" SYS_PREFIX "sys_getpgid") 73c5d420c3SAndrii Nakryiko int bench_trigger_fentry(void *ctx) 74c5d420c3SAndrii Nakryiko { 75*520fad2eSAndrii Nakryiko inc_counter(); 76c5d420c3SAndrii Nakryiko return 0; 77c5d420c3SAndrii Nakryiko } 78c5d420c3SAndrii Nakryiko 79365c2b32SAndrii Nakryiko SEC("fexit/" SYS_PREFIX "sys_getpgid") 80365c2b32SAndrii Nakryiko int bench_trigger_fexit(void *ctx) 81365c2b32SAndrii Nakryiko { 82*520fad2eSAndrii Nakryiko inc_counter(); 83365c2b32SAndrii Nakryiko return 0; 84365c2b32SAndrii Nakryiko } 85365c2b32SAndrii Nakryiko 86e91d280cSNaveen N. Rao SEC("fentry.s/" SYS_PREFIX "sys_getpgid") 87e68a1445SAlexei Starovoitov int bench_trigger_fentry_sleep(void *ctx) 88e68a1445SAlexei Starovoitov { 89*520fad2eSAndrii Nakryiko inc_counter(); 90e68a1445SAlexei Starovoitov return 0; 91e68a1445SAlexei Starovoitov } 92e68a1445SAlexei Starovoitov 93e91d280cSNaveen N. Rao SEC("fmod_ret/" SYS_PREFIX "sys_getpgid") 94c5d420c3SAndrii Nakryiko int bench_trigger_fmodret(void *ctx) 95c5d420c3SAndrii Nakryiko { 96*520fad2eSAndrii Nakryiko inc_counter(); 97c5d420c3SAndrii Nakryiko return -22; 98c5d420c3SAndrii Nakryiko } 99d41bc48bSAndrii Nakryiko 10039f8dc43SAlan Maguire SEC("uprobe") 101d41bc48bSAndrii Nakryiko int bench_trigger_uprobe(void *ctx) 102d41bc48bSAndrii Nakryiko { 103*520fad2eSAndrii Nakryiko inc_counter(); 104d41bc48bSAndrii Nakryiko return 0; 105d41bc48bSAndrii Nakryiko } 106