tools/testing/selftests/bpf/progs/rbtree.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/rbtree.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/rbtree.c- Extension
.c- Size
- 6830 bytes
- Lines
- 324
- 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_tracing.hbpf/bpf_helpers.hbpf/bpf_core_read.hbpf_experimental.h
Detected Declarations
struct node_datastruct root_nested_innerstruct root_nestedfunction lessfunction __add_threefunction rbtree_add_nodesfunction rbtree_add_nodes_nestedfunction rbtree_add_and_removefunction rbtree_add_and_remove_arrayfunction rbtree_first_and_removefunction rbtree_api_release_aliasing
Annotated Snippet
struct node_data {
long key;
long data;
struct bpf_rb_node node;
};
struct root_nested_inner {
struct bpf_spin_lock glock;
struct bpf_rb_root root __contains(node_data, node);
};
struct root_nested {
struct root_nested_inner inner;
};
long less_callback_ran = -1;
long removed_key = -1;
long first_data[2] = {-1, -1};
#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
private(A) struct bpf_spin_lock glock;
private(A) struct bpf_rb_root groot __contains(node_data, node);
private(A) struct bpf_rb_root groot_array[2] __contains(node_data, node);
private(A) struct bpf_rb_root groot_array_one[1] __contains(node_data, node);
private(B) struct root_nested groot_nested;
static bool less(struct bpf_rb_node *a, const struct bpf_rb_node *b)
{
struct node_data *node_a;
struct node_data *node_b;
node_a = container_of(a, struct node_data, node);
node_b = container_of(b, struct node_data, node);
less_callback_ran = 1;
return node_a->key < node_b->key;
}
static long __add_three(struct bpf_rb_root *root, struct bpf_spin_lock *lock)
{
struct node_data *n, *m;
n = bpf_obj_new(typeof(*n));
if (!n)
return 1;
n->key = 5;
m = bpf_obj_new(typeof(*m));
if (!m) {
bpf_obj_drop(n);
return 2;
}
m->key = 1;
bpf_spin_lock(lock);
bpf_rbtree_add(root, &n->node, less);
bpf_rbtree_add(root, &m->node, less);
bpf_spin_unlock(lock);
n = bpf_obj_new(typeof(*n));
if (!n)
return 3;
n->key = 3;
bpf_spin_lock(lock);
bpf_rbtree_add(root, &n->node, less);
bpf_spin_unlock(lock);
return 0;
}
SEC("tc")
long rbtree_add_nodes(void *ctx)
{
return __add_three(&groot, &glock);
}
SEC("tc")
long rbtree_add_nodes_nested(void *ctx)
{
return __add_three(&groot_nested.inner.root, &groot_nested.inner.glock);
}
SEC("tc")
long rbtree_add_and_remove(void *ctx)
{
struct bpf_rb_node *res = NULL;
struct node_data *n, *m = NULL;
n = bpf_obj_new(typeof(*n));
if (!n)
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `bpf/bpf_core_read.h`, `bpf_experimental.h`.
- Detected declarations: `struct node_data`, `struct root_nested_inner`, `struct root_nested`, `function less`, `function __add_three`, `function rbtree_add_nodes`, `function rbtree_add_nodes_nested`, `function rbtree_add_and_remove`, `function rbtree_add_and_remove_array`, `function rbtree_first_and_remove`.
- 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.