tools/testing/selftests/bpf/progs/local_storage_rcu_tasks_trace_bench.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/local_storage_rcu_tasks_trace_bench.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/local_storage_rcu_tasks_trace_bench.c- Extension
.c- Size
- 1424 bytes
- Lines
- 68
- 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.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
function get_localfunction pregp_stepfunction postgp
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
struct {
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, int);
} task_storage SEC(".maps");
long hits;
long gp_hits;
long gp_times;
long current_gp_start;
long unexpected;
bool postgp_seen;
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int get_local(void *ctx)
{
struct task_struct *task;
int idx;
int *s;
idx = 0;
task = bpf_get_current_task_btf();
s = bpf_task_storage_get(&task_storage, task, &idx,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!s)
return 0;
*s = 3;
bpf_task_storage_delete(&task_storage, task);
__sync_add_and_fetch(&hits, 1);
return 0;
}
SEC("fentry/rcu_tasks_trace_pregp_step")
int pregp_step(struct pt_regs *ctx)
{
current_gp_start = bpf_ktime_get_ns();
return 0;
}
SEC("fentry/rcu_tasks_trace_postgp")
int postgp(struct pt_regs *ctx)
{
if (!current_gp_start && postgp_seen) {
/* Will only happen if prog tracing rcu_tasks_trace_pregp_step doesn't
* execute before this prog
*/
__sync_add_and_fetch(&unexpected, 1);
return 0;
}
__sync_add_and_fetch(&gp_times, bpf_ktime_get_ns() - current_gp_start);
__sync_add_and_fetch(&gp_hits, 1);
current_gp_start = 0;
postgp_seen = true;
return 0;
}
char _license[] SEC("license") = "GPL";
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `function get_local`, `function pregp_step`, `function postgp`.
- 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.