tools/testing/selftests/bpf/progs/pyperf.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/pyperf.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/pyperf.h- Extension
.h- Size
- 8679 bytes
- Lines
- 359
- 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
linux/sched.hlinux/ptrace.hstdint.hstddef.hstdbool.hlinux/bpf.hbpf/bpf_helpers.hbpf_misc.hbpf_compiler.h
Detected Declarations
struct process_frame_ctxfunction get_frame_datafunction process_frame_callbackfunction __on_eventfunction bpf_forfunction on_event
Annotated Snippet
struct process_frame_ctx {
int cur_cpu;
int32_t *symbol_counter;
void *frame_ptr;
FrameData *frame;
PidData *pidData;
Symbol *sym;
Event *event;
bool done;
};
static int process_frame_callback(__u32 i, struct process_frame_ctx *ctx)
{
int zero = 0;
void *frame_ptr = ctx->frame_ptr;
PidData *pidData = ctx->pidData;
FrameData *frame = ctx->frame;
int32_t *symbol_counter = ctx->symbol_counter;
int cur_cpu = ctx->cur_cpu;
Event *event = ctx->event;
Symbol *sym = ctx->sym;
if (frame_ptr && get_frame_data(frame_ptr, pidData, frame, sym)) {
int32_t new_symbol_id = *symbol_counter * 64 + cur_cpu;
int32_t *symbol_id = bpf_map_lookup_elem(&symbolmap, sym);
if (!symbol_id) {
bpf_map_update_elem(&symbolmap, sym, &zero, 0);
symbol_id = bpf_map_lookup_elem(&symbolmap, sym);
if (!symbol_id) {
ctx->done = true;
return 1;
}
}
if (*symbol_id == new_symbol_id)
(*symbol_counter)++;
barrier_var(i);
if (i >= STACK_MAX_LEN)
return 1;
event->stack[i] = *symbol_id;
event->stack_len = i + 1;
frame_ptr = frame->f_back;
}
return 0;
}
#endif /* USE_BPF_LOOP */
#ifdef GLOBAL_FUNC
__noinline
#elif defined(SUBPROGS)
static __noinline
#else
static __always_inline
#endif
int __on_event(struct bpf_raw_tracepoint_args *ctx)
{
uint64_t pid_tgid = bpf_get_current_pid_tgid();
pid_t pid = (pid_t)(pid_tgid >> 32);
PidData* pidData = bpf_map_lookup_elem(&pidmap, &pid);
if (!pidData)
return 0;
int zero = 0;
Event* event = bpf_map_lookup_elem(&eventmap, &zero);
if (!event)
return 0;
event->pid = pid;
event->tid = (pid_t)pid_tgid;
bpf_get_current_comm(&event->comm, sizeof(event->comm));
event->user_stack_id = bpf_get_stackid(ctx, &stackmap, BPF_F_USER_STACK);
event->kernel_stack_id = bpf_get_stackid(ctx, &stackmap, 0);
void* thread_state_current = (void*)0;
bpf_probe_read_user(&thread_state_current,
sizeof(thread_state_current),
(void*)(long)pidData->current_state_addr);
struct task_struct* task = (struct task_struct*)bpf_get_current_task();
void* tls_base = (void*)task;
void* thread_state = pidData->use_tls ? get_thread_state(tls_base, pidData)
: thread_state_current;
event->thread_current = thread_state == thread_state_current;
Annotation
- Immediate include surface: `linux/sched.h`, `linux/ptrace.h`, `stdint.h`, `stddef.h`, `stdbool.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `struct process_frame_ctx`, `function get_frame_data`, `function process_frame_callback`, `function __on_event`, `function bpf_for`, `function on_event`.
- 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.