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 9 char _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 */ 15 struct counter { 16 long value; 17 } __attribute__((aligned(128))); 18 19 struct counter hits[MAX_CPUS]; 20 21 static __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 28 SEC("?uprobe") 29 int bench_trigger_uprobe(void *ctx) 30 { 31 inc_counter(); 32 return 0; 33 } 34 35 SEC("?uprobe.multi") 36 int bench_trigger_uprobe_multi(void *ctx) 37 { 38 inc_counter(); 39 return 0; 40 } 41 42 const volatile int batch_iters = 0; 43 44 SEC("?raw_tp") 45 int 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 55 SEC("?raw_tp") 56 int 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 66 extern int bpf_modify_return_test_tp(int nonce) __ksym __weak; 67 68 SEC("?raw_tp") 69 int 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 79 SEC("?kprobe/bpf_get_numa_node_id") 80 int bench_trigger_kprobe(void *ctx) 81 { 82 inc_counter(); 83 return 0; 84 } 85 86 SEC("?kretprobe/bpf_get_numa_node_id") 87 int bench_trigger_kretprobe(void *ctx) 88 { 89 inc_counter(); 90 return 0; 91 } 92 93 SEC("?kprobe.multi/bpf_get_numa_node_id") 94 int bench_trigger_kprobe_multi(void *ctx) 95 { 96 inc_counter(); 97 return 0; 98 } 99 100 SEC("?kprobe.multi/bpf_get_numa_node_id") 101 int bench_kprobe_multi_empty(void *ctx) 102 { 103 return 0; 104 } 105 106 SEC("?kretprobe.multi/bpf_get_numa_node_id") 107 int bench_trigger_kretprobe_multi(void *ctx) 108 { 109 inc_counter(); 110 return 0; 111 } 112 113 SEC("?kretprobe.multi/bpf_get_numa_node_id") 114 int bench_kretprobe_multi_empty(void *ctx) 115 { 116 return 0; 117 } 118 119 SEC("?fentry/bpf_get_numa_node_id") 120 int bench_trigger_fentry(void *ctx) 121 { 122 inc_counter(); 123 return 0; 124 } 125 126 SEC("?fexit/bpf_get_numa_node_id") 127 int bench_trigger_fexit(void *ctx) 128 { 129 inc_counter(); 130 return 0; 131 } 132 133 SEC("?fmod_ret/bpf_modify_return_test_tp") 134 int bench_trigger_fmodret(void *ctx) 135 { 136 inc_counter(); 137 return -22; 138 } 139 140 SEC("?tp/bpf_test_run/bpf_trigger_tp") 141 int bench_trigger_tp(void *ctx) 142 { 143 inc_counter(); 144 return 0; 145 } 146 147 SEC("?raw_tp/bpf_trigger_tp") 148 int bench_trigger_rawtp(void *ctx) 149 { 150 inc_counter(); 151 return 0; 152 } 153