tools/testing/selftests/bpf/progs/get_branch_snapshot.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/get_branch_snapshot.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/get_branch_snapshot.c- Extension
.c- Size
- 907 bytes
- Lines
- 41
- 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/bpf_tracing.h
Detected Declarations
function gbs_in_rangefunction BPF_PROG
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
char _license[] SEC("license") = "GPL";
__u64 test1_hits = 0;
__u64 address_low = 0;
__u64 address_high = 0;
int wasted_entries = 0;
long total_entries = 0;
#define ENTRY_CNT 32
struct perf_branch_entry entries[ENTRY_CNT] = {};
static inline bool gbs_in_range(__u64 val)
{
return (val >= address_low) && (val < address_high);
}
SEC("fexit/bpf_testmod_loop_test")
int BPF_PROG(test1, int n, int ret)
{
long i;
total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
total_entries /= sizeof(struct perf_branch_entry);
for (i = 0; i < ENTRY_CNT; i++) {
if (i >= total_entries)
break;
if (gbs_in_range(entries[i].from) && gbs_in_range(entries[i].to))
test1_hits++;
else if (!test1_hits)
wasted_entries++;
}
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `function gbs_in_range`, `function BPF_PROG`.
- 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.