tools/testing/selftests/bpf/progs/linked_list_peek.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/linked_list_peek.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/linked_list_peek.c- Extension
.c- Size
- 2310 bytes
- Lines
- 114
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_helpers.hbpf_misc.hbpf_experimental.h
Detected Declarations
struct node_datafunction list_peek
Annotated Snippet
struct node_data {
struct bpf_list_node l;
int key;
};
#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
private(A) struct bpf_spin_lock glock;
private(A) struct bpf_list_head ghead __contains(node_data, l);
#define list_entry(ptr, type, member) container_of(ptr, type, member)
#define NR_NODES 16
int zero = 0;
SEC("syscall")
__retval(0)
long list_peek(void *ctx)
{
struct bpf_list_node *l_n;
struct node_data *n;
int i, err = 0;
bpf_spin_lock(&glock);
l_n = bpf_list_front(&ghead);
bpf_spin_unlock(&glock);
if (l_n)
return __LINE__;
bpf_spin_lock(&glock);
l_n = bpf_list_back(&ghead);
bpf_spin_unlock(&glock);
if (l_n)
return __LINE__;
for (i = zero; i < NR_NODES && can_loop; i++) {
n = bpf_obj_new(typeof(*n));
if (!n)
return __LINE__;
n->key = i;
bpf_spin_lock(&glock);
bpf_list_push_back(&ghead, &n->l);
bpf_spin_unlock(&glock);
}
bpf_spin_lock(&glock);
l_n = bpf_list_front(&ghead);
if (!l_n) {
err = __LINE__;
goto done;
}
n = list_entry(l_n, struct node_data, l);
if (n->key != 0) {
err = __LINE__;
goto done;
}
l_n = bpf_list_back(&ghead);
if (!l_n) {
err = __LINE__;
goto done;
}
n = list_entry(l_n, struct node_data, l);
if (n->key != NR_NODES - 1) {
err = __LINE__;
goto done;
}
done:
bpf_spin_unlock(&glock);
return err;
}
#define TEST_FB(op, dolock) \
SEC("syscall") \
__failure __msg(MSG) \
long test_##op##_spinlock_##dolock(void *ctx) \
{ \
struct bpf_list_node *l_n; \
__u64 jiffies = 0; \
\
if (dolock) \
bpf_spin_lock(&glock); \
l_n = bpf_list_##op(&ghead); \
if (l_n) \
jiffies = bpf_jiffies64(); \
if (dolock) \
bpf_spin_unlock(&glock); \
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `bpf_experimental.h`.
- Detected declarations: `struct node_data`, `function list_peek`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.