Files
linux/tools/testing/selftests/bpf/progs/trigger_bench.c
Menglong Dong f2cb0660ac selftests/bpf: Call bpf_get_numa_node_id() in trigger_count()
The bench test "trig-kernel-count" can be used as a baseline comparison
for fentry and other benchmarks, and the calling to bpf_get_numa_node_id()
should be considered as composition of the baseline. So, let's call it in
trigger_count(). Meanwhile, rename trigger_count() to
trigger_kernel_count() to make it easier understand.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20251116014242.151110-1-dongml2@chinatelecom.cn
2025-11-25 14:32:50 -08:00

155 lines
2.5 KiB
C

// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Facebook
#include <linux/bpf.h>
#include <asm/unistd.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.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);
}
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)
{
inc_counter();
return 0;
}
SEC("?kretprobe/bpf_get_numa_node_id")
int bench_trigger_kretprobe(void *ctx)
{
inc_counter();
return 0;
}
SEC("?kprobe.multi/bpf_get_numa_node_id")
int bench_trigger_kprobe_multi(void *ctx)
{
inc_counter();
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)
{
inc_counter();
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)
{
inc_counter();
return 0;
}
SEC("?fexit/bpf_get_numa_node_id")
int bench_trigger_fexit(void *ctx)
{
inc_counter();
return 0;
}
SEC("?fmod_ret/bpf_modify_return_test_tp")
int bench_trigger_fmodret(void *ctx)
{
inc_counter();
return -22;
}
SEC("?tp/bpf_test_run/bpf_trigger_tp")
int bench_trigger_tp(void *ctx)
{
inc_counter();
return 0;
}
SEC("?raw_tp/bpf_trigger_tp")
int bench_trigger_rawtp(void *ctx)
{
inc_counter();
return 0;
}