tools/testing/selftests/bpf/progs/trigger_bench.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/trigger_bench.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/trigger_bench.c- Extension
.c- Size
- 3210 bytes
- Lines
- 191
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hasm/unistd.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf_misc.hbpf/usdt.bpf.h
Detected Declarations
struct counterfunction inc_counterfunction do_stacktracefunction handlefunction bench_trigger_uprobefunction bench_trigger_uprobe_multifunction trigger_kernel_countfunction trigger_driverfunction trigger_driver_kfuncfunction bench_trigger_kprobefunction bench_trigger_kretprobefunction bench_trigger_kprobe_multifunction bench_kprobe_multi_emptyfunction bench_trigger_kretprobe_multifunction bench_kretprobe_multi_emptyfunction bench_trigger_fentryfunction bench_trigger_fexitfunction bench_trigger_fmodretfunction bench_trigger_tpfunction bench_trigger_rawtpfunction bench_trigger_usdt
Annotated Snippet
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 */
Annotation
- Immediate include surface: `vmlinux.h`, `asm/unistd.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`, `bpf/usdt.bpf.h`.
- Detected declarations: `struct counter`, `function inc_counter`, `function do_stacktrace`, `function handle`, `function bench_trigger_uprobe`, `function bench_trigger_uprobe_multi`, `function trigger_kernel_count`, `function trigger_driver`, `function trigger_driver_kfunc`, `function bench_trigger_kprobe`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.