mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 18:22:00 -04:00
Adding usdt trigger bench for usdt: trig-usdt-nop - usdt on top of nop1 instruction trig-usdt-nop5 - usdt on top of nop1/nop5 combo Adding it to benchs/run_bench_uprobes.sh script. Example run on x86_64 kernel with uprobe syscall: # ./benchs/run_bench_uprobes.sh usermode-count : 152.507 ± 0.098M/s syscall-count : 14.309 ± 0.093M/s uprobe-nop : 3.190 ± 0.012M/s uprobe-push : 3.057 ± 0.004M/s uprobe-ret : 1.095 ± 0.009M/s uprobe-nop5 : 7.305 ± 0.034M/s uretprobe-nop : 2.175 ± 0.005M/s uretprobe-push : 2.109 ± 0.003M/s uretprobe-ret : 0.945 ± 0.002M/s uretprobe-nop5 : 3.530 ± 0.006M/s usdt-nop : 3.235 ± 0.008M/s <-- added usdt-nop5 : 7.511 ± 0.045M/s <-- added Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20260224103915.1369690-6-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
191 lines
3.1 KiB
C
191 lines
3.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
// Copyright (c) 2020 Facebook
|
|
#include "vmlinux.h"
|
|
#include <asm/unistd.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
#include "bpf_misc.h"
|
|
#include "bpf/usdt.bpf.h"
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
#define CPU_MASK 255
|
|
#define MAX_CPUS (CPU_MASK + 1) /* should match MAX_BUCKETS in benchs/bench_trigger.c */
|
|
|
|
/* matches struct counter in bench.h */
|
|
struct counter {
|
|
long value;
|
|
} __attribute__((aligned(128)));
|
|
|
|
struct counter hits[MAX_CPUS];
|
|
|
|
static __always_inline void inc_counter(void)
|
|
{
|
|
int cpu = bpf_get_smp_processor_id();
|
|
|
|
__sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1);
|
|
}
|
|
|
|
volatile const int stacktrace;
|
|
|
|
typedef __u64 stack_trace_t[128];
|
|
|
|
struct {
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
__uint(max_entries, 1);
|
|
__type(key, __u32);
|
|
__type(value, stack_trace_t);
|
|
} stack_heap SEC(".maps");
|
|
|
|
static __always_inline void do_stacktrace(void *ctx)
|
|
{
|
|
if (!stacktrace)
|
|
return;
|
|
|
|
__u64 *ptr = bpf_map_lookup_elem(&stack_heap, &(__u32){0});
|
|
|
|
if (ptr)
|
|
bpf_get_stack(ctx, ptr, sizeof(stack_trace_t), 0);
|
|
}
|
|
|
|
static __always_inline void handle(void *ctx)
|
|
{
|
|
inc_counter();
|
|
do_stacktrace(ctx);
|
|
}
|
|
|
|
SEC("?uprobe")
|
|
int bench_trigger_uprobe(void *ctx)
|
|
{
|
|
inc_counter();
|
|
return 0;
|
|
}
|
|
|
|
SEC("?uprobe.multi")
|
|
int bench_trigger_uprobe_multi(void *ctx)
|
|
{
|
|
inc_counter();
|
|
return 0;
|
|
}
|
|
|
|
const volatile int batch_iters = 0;
|
|
|
|
SEC("?raw_tp")
|
|
int trigger_kernel_count(void *ctx)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < batch_iters; i++) {
|
|
inc_counter();
|
|
bpf_get_numa_node_id();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
SEC("?raw_tp")
|
|
int trigger_driver(void *ctx)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < batch_iters; i++)
|
|
(void)bpf_get_numa_node_id(); /* attach point for benchmarking */
|
|
|
|
return 0;
|
|
}
|
|
|
|
extern int bpf_modify_return_test_tp(int nonce) __ksym __weak;
|
|
|
|
SEC("?raw_tp")
|
|
int trigger_driver_kfunc(void *ctx)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < batch_iters; i++)
|
|
(void)bpf_modify_return_test_tp(0); /* attach point for benchmarking */
|
|
|
|
return 0;
|
|
}
|
|
|
|
SEC("?kprobe/bpf_get_numa_node_id")
|
|
int bench_trigger_kprobe(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?kretprobe/bpf_get_numa_node_id")
|
|
int bench_trigger_kretprobe(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?kprobe.multi/bpf_get_numa_node_id")
|
|
int bench_trigger_kprobe_multi(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?kprobe.multi/bpf_get_numa_node_id")
|
|
int bench_kprobe_multi_empty(void *ctx)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
SEC("?kretprobe.multi/bpf_get_numa_node_id")
|
|
int bench_trigger_kretprobe_multi(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?kretprobe.multi/bpf_get_numa_node_id")
|
|
int bench_kretprobe_multi_empty(void *ctx)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
SEC("?fentry/bpf_get_numa_node_id")
|
|
int bench_trigger_fentry(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?fexit/bpf_get_numa_node_id")
|
|
int bench_trigger_fexit(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?fmod_ret/bpf_modify_return_test_tp")
|
|
int bench_trigger_fmodret(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return -22;
|
|
}
|
|
|
|
SEC("?tp/bpf_test_run/bpf_trigger_tp")
|
|
int bench_trigger_tp(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?raw_tp/bpf_trigger_tp")
|
|
int bench_trigger_rawtp(void *ctx)
|
|
{
|
|
handle(ctx);
|
|
return 0;
|
|
}
|
|
|
|
SEC("?usdt")
|
|
int bench_trigger_usdt(void *ctx)
|
|
{
|
|
inc_counter();
|
|
return 0;
|
|
}
|