Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 431c590

Browse files
arunpravin24airlied
authored andcommitted
drm/tests: Add a unit test for range bias allocation
Allocate cleared blocks in the bias range when the DRM buddy's clear avail is zero. This will validate the bias range allocation in scenarios like system boot when no cleared blocks are available and exercise the fallback path too. The resulting blocks should always be dirty. v1:(Matthew) - move the size to the variable declaration section. - move the mm.clear_avail init to allocator init. Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Signed-off-by: Dave Airlie <airlied@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240514145636.16253-2-Arunpravin.PaneerSelvam@amd.com
1 parent bb21700 commit 431c590

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

drivers/gpu/drm/tests/drm_buddy_test.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ static inline u64 get_size(int order, u64 chunk_size)
2323

2424
static void drm_test_buddy_alloc_range_bias(struct kunit *test)
2525
{
26-
u32 mm_size, ps, bias_size, bias_start, bias_end, bias_rem;
26+
u32 mm_size, size, ps, bias_size, bias_start, bias_end, bias_rem;
2727
DRM_RND_STATE(prng, random_seed);
2828
unsigned int i, count, *order;
29+
struct drm_buddy_block *block;
30+
unsigned long flags;
2931
struct drm_buddy mm;
3032
LIST_HEAD(allocated);
3133

@@ -222,6 +224,38 @@ static void drm_test_buddy_alloc_range_bias(struct kunit *test)
222224

223225
drm_buddy_free_list(&mm, &allocated, 0);
224226
drm_buddy_fini(&mm);
227+
228+
/*
229+
* Allocate cleared blocks in the bias range when the DRM buddy's clear avail is
230+
* zero. This will validate the bias range allocation in scenarios like system boot
231+
* when no cleared blocks are available and exercise the fallback path too. The resulting
232+
* blocks should always be dirty.
233+
*/
234+
235+
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_init(&mm, mm_size, ps),
236+
"buddy_init failed\n");
237+
238+
bias_start = round_up(prandom_u32_state(&prng) % (mm_size - ps), ps);
239+
bias_end = round_up(bias_start + prandom_u32_state(&prng) % (mm_size - bias_start), ps);
240+
bias_end = max(bias_end, bias_start + ps);
241+
bias_rem = bias_end - bias_start;
242+
243+
flags = DRM_BUDDY_CLEAR_ALLOCATION | DRM_BUDDY_RANGE_ALLOCATION;
244+
size = max(round_up(prandom_u32_state(&prng) % bias_rem, ps), ps);
245+
246+
KUNIT_ASSERT_FALSE_MSG(test,
247+
drm_buddy_alloc_blocks(&mm, bias_start,
248+
bias_end, size, ps,
249+
&allocated,
250+
flags),
251+
"buddy_alloc failed with bias(%x-%x), size=%u, ps=%u\n",
252+
bias_start, bias_end, size, ps);
253+
254+
list_for_each_entry(block, &allocated, link)
255+
KUNIT_EXPECT_EQ(test, drm_buddy_block_is_clear(block), false);
256+
257+
drm_buddy_free_list(&mm, &allocated, 0);
258+
drm_buddy_fini(&mm);
225259
}
226260

227261
static void drm_test_buddy_alloc_clear(struct kunit *test)

0 commit comments

Comments
 (0)