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 9char _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 */ 15struct counter { 16 long value; 17} __attribute__((aligned(128))); 18 19struct counter hits[MAX_CPUS]; 20 21static __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 28SEC("?uprobe") 29int bench_trigger_uprobe(void *ctx) 30{ 31 inc_counter(); 32 return 0; 33} 34 35const volatile int batch_iters = 0; 36 37SEC("?raw_tp") 38int 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 48SEC("?raw_tp") 49int 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 59extern int bpf_modify_return_test_tp(int nonce) __ksym __weak; 60 61SEC("?raw_tp") 62int 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 72SEC("?kprobe/bpf_get_numa_node_id") 73int bench_trigger_kprobe(void *ctx) 74{ 75 inc_counter(); 76 return 0; 77} 78 79SEC("?kretprobe/bpf_get_numa_node_id") 80int bench_trigger_kretprobe(void *ctx) 81{ 82 inc_counter(); 83 return 0; 84} 85 86SEC("?kprobe.multi/bpf_get_numa_node_id") 87int bench_trigger_kprobe_multi(void *ctx) 88{ 89 inc_counter(); 90 return 0; 91} 92 93SEC("?kretprobe.multi/bpf_get_numa_node_id") 94int bench_trigger_kretprobe_multi(void *ctx) 95{ 96 inc_counter(); 97 return 0; 98} 99 100SEC("?fentry/bpf_get_numa_node_id") 101int bench_trigger_fentry(void *ctx) 102{ 103 inc_counter(); 104 return 0; 105} 106 107SEC("?fexit/bpf_get_numa_node_id") 108int bench_trigger_fexit(void *ctx) 109{ 110 inc_counter(); 111 return 0; 112} 113 114SEC("?fmod_ret/bpf_modify_return_test_tp") 115int bench_trigger_fmodret(void *ctx) 116{ 117 inc_counter(); 118 return -22; 119} 120 121SEC("?tp/bpf_test_run/bpf_trigger_tp") 122int bench_trigger_tp(void *ctx) 123{ 124 inc_counter(); 125 return 0; 126} 127 128SEC("?raw_tp/bpf_trigger_tp") 129int bench_trigger_rawtp(void *ctx) 130{ 131 inc_counter(); 132 return 0; 133} 134