1c5d420c3SAndrii Nakryiko // SPDX-License-Identifier: GPL-2.0 2c5d420c3SAndrii Nakryiko // Copyright (c) 2020 Facebook 3c5d420c3SAndrii Nakryiko #include <linux/bpf.h> 4c5d420c3SAndrii Nakryiko #include <asm/unistd.h> 5c5d420c3SAndrii Nakryiko #include <bpf/bpf_helpers.h> 6c5d420c3SAndrii Nakryiko #include <bpf/bpf_tracing.h> 7e91d280cSNaveen N. Rao #include "bpf_misc.h" 8c5d420c3SAndrii Nakryiko 9c5d420c3SAndrii Nakryiko char _license[] SEC("license") = "GPL"; 10c5d420c3SAndrii Nakryiko 11520fad2eSAndrii Nakryiko #define CPU_MASK 255 12520fad2eSAndrii Nakryiko #define MAX_CPUS (CPU_MASK + 1) /* should match MAX_BUCKETS in benchs/bench_trigger.c */ 13520fad2eSAndrii Nakryiko 14520fad2eSAndrii Nakryiko /* matches struct counter in bench.h */ 15520fad2eSAndrii Nakryiko struct counter { 16520fad2eSAndrii Nakryiko long value; 17520fad2eSAndrii Nakryiko } __attribute__((aligned(128))); 18520fad2eSAndrii Nakryiko 19520fad2eSAndrii Nakryiko struct counter hits[MAX_CPUS]; 20520fad2eSAndrii Nakryiko 21520fad2eSAndrii Nakryiko static __always_inline void inc_counter(void) 22520fad2eSAndrii Nakryiko { 23520fad2eSAndrii Nakryiko int cpu = bpf_get_smp_processor_id(); 24520fad2eSAndrii Nakryiko 25520fad2eSAndrii Nakryiko __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1); 26520fad2eSAndrii Nakryiko } 27c5d420c3SAndrii Nakryiko 28b4ccf915SAndrii Nakryiko SEC("?uprobe") 29d41bc48bSAndrii Nakryiko int bench_trigger_uprobe(void *ctx) 30d41bc48bSAndrii Nakryiko { 31520fad2eSAndrii Nakryiko inc_counter(); 32d41bc48bSAndrii Nakryiko return 0; 33d41bc48bSAndrii Nakryiko } 347df4e597SAndrii Nakryiko 357df4e597SAndrii Nakryiko const volatile int batch_iters = 0; 367df4e597SAndrii Nakryiko 37b4ccf915SAndrii Nakryiko SEC("?raw_tp") 387df4e597SAndrii Nakryiko int trigger_count(void *ctx) 397df4e597SAndrii Nakryiko { 407df4e597SAndrii Nakryiko int i; 417df4e597SAndrii Nakryiko 427df4e597SAndrii Nakryiko for (i = 0; i < batch_iters; i++) 437df4e597SAndrii Nakryiko inc_counter(); 447df4e597SAndrii Nakryiko 457df4e597SAndrii Nakryiko return 0; 467df4e597SAndrii Nakryiko } 477df4e597SAndrii Nakryiko 48b4ccf915SAndrii Nakryiko SEC("?raw_tp") 497df4e597SAndrii Nakryiko int trigger_driver(void *ctx) 507df4e597SAndrii Nakryiko { 517df4e597SAndrii Nakryiko int i; 527df4e597SAndrii Nakryiko 537df4e597SAndrii Nakryiko for (i = 0; i < batch_iters; i++) 547df4e597SAndrii Nakryiko (void)bpf_get_numa_node_id(); /* attach point for benchmarking */ 557df4e597SAndrii Nakryiko 567df4e597SAndrii Nakryiko return 0; 577df4e597SAndrii Nakryiko } 587df4e597SAndrii Nakryiko 59*985d0681SAndrii Nakryiko extern int bpf_modify_return_test_tp(int nonce) __ksym __weak; 60*985d0681SAndrii Nakryiko 61*985d0681SAndrii Nakryiko SEC("?raw_tp") 62*985d0681SAndrii Nakryiko int trigger_driver_kfunc(void *ctx) 63*985d0681SAndrii Nakryiko { 64*985d0681SAndrii Nakryiko int i; 65*985d0681SAndrii Nakryiko 66*985d0681SAndrii Nakryiko for (i = 0; i < batch_iters; i++) 67*985d0681SAndrii Nakryiko (void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */ 68*985d0681SAndrii Nakryiko 69*985d0681SAndrii Nakryiko return 0; 70*985d0681SAndrii Nakryiko } 71*985d0681SAndrii Nakryiko 72b4ccf915SAndrii Nakryiko SEC("?kprobe/bpf_get_numa_node_id") 73208c4391SAndrii Nakryiko int bench_trigger_kprobe(void *ctx) 747df4e597SAndrii Nakryiko { 757df4e597SAndrii Nakryiko inc_counter(); 767df4e597SAndrii Nakryiko return 0; 777df4e597SAndrii Nakryiko } 787df4e597SAndrii Nakryiko 79b4ccf915SAndrii Nakryiko SEC("?kretprobe/bpf_get_numa_node_id") 80208c4391SAndrii Nakryiko int bench_trigger_kretprobe(void *ctx) 817df4e597SAndrii Nakryiko { 827df4e597SAndrii Nakryiko inc_counter(); 837df4e597SAndrii Nakryiko return 0; 847df4e597SAndrii Nakryiko } 857df4e597SAndrii Nakryiko 86b4ccf915SAndrii Nakryiko SEC("?kprobe.multi/bpf_get_numa_node_id") 87208c4391SAndrii Nakryiko int bench_trigger_kprobe_multi(void *ctx) 887df4e597SAndrii Nakryiko { 897df4e597SAndrii Nakryiko inc_counter(); 907df4e597SAndrii Nakryiko return 0; 917df4e597SAndrii Nakryiko } 927df4e597SAndrii Nakryiko 93b4ccf915SAndrii Nakryiko SEC("?kretprobe.multi/bpf_get_numa_node_id") 94208c4391SAndrii Nakryiko int bench_trigger_kretprobe_multi(void *ctx) 957df4e597SAndrii Nakryiko { 967df4e597SAndrii Nakryiko inc_counter(); 977df4e597SAndrii Nakryiko return 0; 987df4e597SAndrii Nakryiko } 997df4e597SAndrii Nakryiko 100b4ccf915SAndrii Nakryiko SEC("?fentry/bpf_get_numa_node_id") 101208c4391SAndrii Nakryiko int bench_trigger_fentry(void *ctx) 1027df4e597SAndrii Nakryiko { 1037df4e597SAndrii Nakryiko inc_counter(); 1047df4e597SAndrii Nakryiko return 0; 1057df4e597SAndrii Nakryiko } 1067df4e597SAndrii Nakryiko 107b4ccf915SAndrii Nakryiko SEC("?fexit/bpf_get_numa_node_id") 108208c4391SAndrii Nakryiko int bench_trigger_fexit(void *ctx) 1097df4e597SAndrii Nakryiko { 1107df4e597SAndrii Nakryiko inc_counter(); 1117df4e597SAndrii Nakryiko return 0; 1127df4e597SAndrii Nakryiko } 113*985d0681SAndrii Nakryiko 114*985d0681SAndrii Nakryiko SEC("?fmod_ret/bpf_modify_return_test_tp") 115*985d0681SAndrii Nakryiko int bench_trigger_fmodret(void *ctx) 116*985d0681SAndrii Nakryiko { 117*985d0681SAndrii Nakryiko inc_counter(); 118*985d0681SAndrii Nakryiko return -22; 119*985d0681SAndrii Nakryiko } 120*985d0681SAndrii Nakryiko 121*985d0681SAndrii Nakryiko SEC("?tp/bpf_test_run/bpf_trigger_tp") 122*985d0681SAndrii Nakryiko int bench_trigger_tp(void *ctx) 123*985d0681SAndrii Nakryiko { 124*985d0681SAndrii Nakryiko inc_counter(); 125*985d0681SAndrii Nakryiko return 0; 126*985d0681SAndrii Nakryiko } 127*985d0681SAndrii Nakryiko 128*985d0681SAndrii Nakryiko SEC("?raw_tp/bpf_trigger_tp") 129*985d0681SAndrii Nakryiko int bench_trigger_rawtp(void *ctx) 130*985d0681SAndrii Nakryiko { 131*985d0681SAndrii Nakryiko inc_counter(); 132*985d0681SAndrii Nakryiko return 0; 133*985d0681SAndrii Nakryiko } 134