tools/testing/selftests/bpf/libarena/src/rbtree.bpf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/libarena/src/rbtree.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/libarena/src/rbtree.bpf.c- Extension
.c- Size
- 22879 bytes
- Lines
- 1048
- 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
libarena/common.hlibarena/asan.hlibarena/rbtree.h
Detected Declarations
enum rb_print_statefunction directlyfunction rb_destroyfunction rbnode_dirfunction rbnode_rotatefunction rb_findfunction rb_node_freefunction rb_node_insertfunction rb_insert_nodefunction rb_insertfunction rb_leastfunction rbnode_fixup_pointersfunction rbnode_swap_valuesfunction rbnode_adjust_neighborsfunction rbnode_replacefunction rbnode_switchfunction rbnode_remove_node_single_childfunction rbnode_has_red_childrenfunction rb_node_removefunction rb_remove_nodefunction rb_removefunction rb_popfunction rbnode_printfunction rb_print_next_statefunction rb_print_pop_upfunction rb_printfunction rb_integrity_check
Annotated Snippet
if (rbtree->root) {
arena_stderr("WARNING: Destroying RB_NOALLOC tree with > 0 nodes");
return -EBUSY;
}
goto out;
}
while (rbtree->root && can_loop) {
ret = rb_remove(rbtree, rbtree->root->key);
if (ret)
break;
}
out:
arena_free(rbtree);
return ret;
}
static inline int rbnode_dir(struct rbnode __arena *node)
{
/* Arbitrarily choose a direction for the root. */
if (unlikely(!node->parent))
return 0;
return (node->parent->left == node) ? 0 : 1;
}
/*
* The __noinline is to prevent inlining from bloating the add
* remove calls, in turn causing register splits and increasing
* stack usage above what is permitted.
*/
__noinline
int rbnode_rotate(struct rbtree __arena *rbtree,
struct rbnode __arena *node, int dir)
{
struct rbnode __arena *tmp, *parent;
int parentdir;
parent = node->parent;
if (parent)
parentdir = rbnode_dir(node);
/* If we're doing a root change, are we the root? */
if (unlikely(!parent && rbtree->root != node))
return -EINVAL;
/*
* Does the node we're turning into the root into exist?
* Note that the new root is on the opposite side of the
* rotation's direction.
*/
tmp = node->child[1 - dir];
if (unlikely(!tmp))
return -EINVAL;
/* Steal the closest child of the new root. */
node->child[1 - dir] = tmp->child[dir];
if (node->child[1 - dir])
node->child[1 - dir]->parent = node;
/* Put the node below the new root.*/
tmp->child[dir] = node;
node->parent = tmp;
tmp->parent = parent;
if (parent)
parent->child[parentdir] = tmp;
else
rbtree->root = tmp;
return 0;
}
static
struct rbnode __arena *rbnode_find(struct rbnode __arena *subtree, u64 key)
{
struct rbnode __arena *node = subtree;
int dir;
if (!subtree)
return NULL;
while (can_loop) {
if (node->key == key)
break;
dir = (key < node->key) ? 0 : 1;
Annotation
- Immediate include surface: `libarena/common.h`, `libarena/asan.h`, `libarena/rbtree.h`.
- Detected declarations: `enum rb_print_state`, `function directly`, `function rb_destroy`, `function rbnode_dir`, `function rbnode_rotate`, `function rb_find`, `function rb_node_free`, `function rb_node_insert`, `function rb_insert_node`, `function rb_insert`.
- 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.