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 const volatile int batch_iters = 0; 36 37 SEC("?raw_tp") 38 int trigger_count(void *ctx) 39 { 40 int i; 41 42 for (i = 0; i < batch_iters; i++) 43 inc_counter(); 44 45 return 0; 46 } 47 48 SEC("?raw_tp") 49 int trigger_driver(void *ctx) 50 { 51 int i; 52 53 for (i = 0; i < batch_iters; i++) 54 (void)bpf_get_numa_node_id(); /* attach point for benchmarking */ 55 56 return 0; 57 } 58 59 extern int bpf_modify_return_test_tp(int nonce) __ksym __weak; 60 61 SEC("?raw_tp") 62 int trigger_driver_kfunc(void *ctx) 63 { 64 int i; 65 66 for (i = 0; i < batch_iters; i++) 67 (void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */ 68 69 return 0; 70 } 71 72 SEC("?kprobe/bpf_get_numa_node_id") 73 int bench_trigger_kprobe(void *ctx) 74 { 75 inc_counter(); 76 return 0; 77 } 78 79 SEC("?kretprobe/bpf_get_numa_node_id") 80 int bench_trigger_kretprobe(void *ctx) 81 { 82 inc_counter(); 83 return 0; 84 } 85 86 SEC("?kprobe.multi/bpf_get_numa_node_id") 87 int bench_trigger_kprobe_multi(void *ctx) 88 { 89 inc_counter(); 90 return 0; 91 } 92 93 SEC("?kretprobe.multi/bpf_get_numa_node_id") 94 int bench_trigger_kretprobe_multi(void *ctx) 95 { 96 inc_counter(); 97 return 0; 98 } 99 100 SEC("?fentry/bpf_get_numa_node_id") 101 int bench_trigger_fentry(void *ctx) 102 { 103 inc_counter(); 104 return 0; 105 } 106 107 SEC("?fexit/bpf_get_numa_node_id") 108 int bench_trigger_fexit(void *ctx) 109 { 110 inc_counter(); 111 return 0; 112 } 113 114 SEC("?fmod_ret/bpf_modify_return_test_tp") 115 int bench_trigger_fmodret(void *ctx) 116 { 117 inc_counter(); 118 return -22; 119 } 120 121 SEC("?tp/bpf_test_run/bpf_trigger_tp") 122 int bench_trigger_tp(void *ctx) 123 { 124 inc_counter(); 125 return 0; 126 } 127 128 SEC("?raw_tp/bpf_trigger_tp") 129 int bench_trigger_rawtp(void *ctx) 130 { 131 inc_counter(); 132 return 0; 133 } 134
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.