drivers/gpu/tests/gpu_buddy_test.c
Source file repositories/reference/linux-study-clean/drivers/gpu/tests/gpu_buddy_test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/tests/gpu_buddy_test.c- Extension
.c- Size
- 45745 bytes
- Lines
- 1422
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/prime_numbers.hlinux/sched/signal.hlinux/sizes.hlinux/gpu_buddy.hgpu_random.h
Detected Declarations
function get_sizefunction gpu_test_buddy_subtree_offset_alignment_stressfunction gpu_test_buddy_offset_aligned_allocationfunction list_for_each_entryfunction list_for_each_entryfunction gpu_test_buddy_fragmentation_performancefunction list_for_each_entry_safefunction list_for_each_entry_safefunction gpu_test_buddy_alloc_range_biasfunction gpu_test_buddy_alloc_rangefunction list_for_each_entryfunction gpu_test_buddy_alloc_clearfunction list_for_each_entryfunction gpu_test_buddy_alloc_contiguousfunction gpu_test_buddy_alloc_pathologicalfunction gpu_test_buddy_alloc_pessimisticfunction gpu_test_buddy_alloc_optimisticfunction gpu_test_buddy_alloc_limitfunction gpu_test_buddy_alloc_exceeds_max_orderfunction gpu_buddy_suite_init
Annotated Snippet
if (node) {
root = container_of(node,
struct gpu_buddy_block,
rb);
break;
}
}
}
KUNIT_ASSERT_NOT_NULL(test, root);
KUNIT_EXPECT_EQ(test, root->subtree_max_alignment, expected);
}
for (i = ARRAY_SIZE(alignments); i-- > 0; ) {
gpu_buddy_free_list(&mm, &allocated[i], 0);
for (order = 0; order <= mm.max_order; order++) {
for (tree = 0; tree < 2; tree++) {
node = mm.free_trees[tree][order].rb_node;
if (!node)
continue;
block = container_of(node, struct gpu_buddy_block, rb);
max_subtree_align = max(max_subtree_align,
block->subtree_max_alignment);
}
}
KUNIT_EXPECT_GE(test, max_subtree_align, ilog2(alignments[i]));
}
gpu_buddy_fini(&mm);
}
static void gpu_test_buddy_offset_aligned_allocation(struct kunit *test)
{
struct gpu_buddy_block *block, *tmp;
int num_blocks, i, count = 0;
LIST_HEAD(allocated);
struct gpu_buddy mm;
u64 mm_size = SZ_4M;
LIST_HEAD(freed);
KUNIT_ASSERT_FALSE_MSG(test, gpu_buddy_init(&mm, mm_size, SZ_4K),
"buddy_init failed\n");
num_blocks = mm_size / SZ_256K;
/*
* Allocate multiple sizes under a fixed offset alignment.
* Ensures alignment handling is independent of allocation size and
* exercises subtree max-alignment pruning for small requests.
*/
for (i = 0; i < num_blocks; i++)
KUNIT_ASSERT_FALSE_MSG(test, gpu_buddy_alloc_blocks(&mm, 0, mm_size, SZ_8K, SZ_256K,
&allocated, 0),
"buddy_alloc hit an error size=%u\n", SZ_8K);
list_for_each_entry(block, &allocated, link) {
/* Ensure the allocated block uses the expected 8 KB size */
KUNIT_EXPECT_EQ(test, gpu_buddy_block_size(&mm, block), SZ_8K);
/* Ensure the block starts at a 256 KB-aligned offset for proper alignment */
KUNIT_EXPECT_TRUE(test, IS_ALIGNED(gpu_buddy_block_offset(block), SZ_256K));
}
gpu_buddy_free_list(&mm, &allocated, 0);
for (i = 0; i < num_blocks; i++)
KUNIT_ASSERT_FALSE_MSG(test, gpu_buddy_alloc_blocks(&mm, 0, mm_size, SZ_16K, SZ_256K,
&allocated, 0),
"buddy_alloc hit an error size=%u\n", SZ_16K);
list_for_each_entry(block, &allocated, link) {
/* Ensure the allocated block uses the expected 16 KB size */
KUNIT_EXPECT_EQ(test, gpu_buddy_block_size(&mm, block), SZ_16K);
/* Ensure the block starts at a 256 KB-aligned offset for proper alignment */
KUNIT_EXPECT_TRUE(test, IS_ALIGNED(gpu_buddy_block_offset(block), SZ_256K));
}
/*
* Free alternating aligned blocks to introduce fragmentation.
* Ensures offset-aligned allocations remain valid after frees and
* verifies subtree max-alignment metadata is correctly maintained.
*/
list_for_each_entry_safe(block, tmp, &allocated, link) {
if (count % 2 == 0)
list_move_tail(&block->link, &freed);
count++;
}
gpu_buddy_free_list(&mm, &freed, 0);
for (i = 0; i < num_blocks / 2; i++)
Annotation
- Immediate include surface: `kunit/test.h`, `linux/prime_numbers.h`, `linux/sched/signal.h`, `linux/sizes.h`, `linux/gpu_buddy.h`, `gpu_random.h`.
- Detected declarations: `function get_size`, `function gpu_test_buddy_subtree_offset_alignment_stress`, `function gpu_test_buddy_offset_aligned_allocation`, `function list_for_each_entry`, `function list_for_each_entry`, `function gpu_test_buddy_fragmentation_performance`, `function list_for_each_entry_safe`, `function list_for_each_entry_safe`, `function gpu_test_buddy_alloc_range_bias`, `function gpu_test_buddy_alloc_range`.
- Atlas domain: Driver Families / drivers/gpu.
- 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.