summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArunpravin <Arunpravin.PaneerSelvam@amd.com>2022-02-22 20:48:42 +0300
committerChristian König <christian.koenig@amd.com>2022-02-23 12:45:11 +0300
commit4010ce9fb634c6368ebb9dead9ef83d49c4dde96 (patch)
tree8f03c27fefed73fc5686dc18f091aa00d3f44c72
parent92937f170d3f49f41d7acb86243ee691a98eb2be (diff)
downloadlinux-4010ce9fb634c6368ebb9dead9ef83d49c4dde96.tar.xz
drm/selftests: add drm buddy optimistic testcase
create a mm with one block of each order available, and try to allocate them all. v2(Matthew Auld): - removed unnecessary test succeeded print - replace list_del()/list_add_tail() with list_move_tail() Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Acked-by: Christian König <christian.koenig@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220222174845.2175-4-Arunpravin.PaneerSelvam@amd.com Signed-off-by: Christian König <christian.koenig@amd.com>
-rw-r--r--drivers/gpu/drm/selftests/drm_buddy_selftests.h1
-rw-r--r--drivers/gpu/drm/selftests/test-drm_buddy.c80
2 files changed, 81 insertions, 0 deletions
diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h
index 3230bfd2770b..21a6bd38864f 100644
--- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h
@@ -9,3 +9,4 @@
selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */
selftest(buddy_alloc_limit, igt_buddy_alloc_limit)
selftest(buddy_alloc_range, igt_buddy_alloc_range)
+selftest(buddy_alloc_optimistic, igt_buddy_alloc_optimistic)
diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c
index 586e0673a67c..f20d3ad1ac65 100644
--- a/drivers/gpu/drm/selftests/test-drm_buddy.c
+++ b/drivers/gpu/drm/selftests/test-drm_buddy.c
@@ -17,6 +17,11 @@
static unsigned int random_seed;
+static inline u64 get_size(int order, u64 chunk_size)
+{
+ return (1 << order) * chunk_size;
+}
+
static inline const char *yesno(bool v)
{
return v ? "yes" : "no";
@@ -309,6 +314,81 @@ static void igt_mm_config(u64 *size, u64 *chunk_size)
*size = (u64)s << 12;
}
+static int igt_buddy_alloc_optimistic(void *arg)
+{
+ u64 mm_size, size, min_page_size, start = 0;
+ struct drm_buddy_block *block;
+ unsigned long flags = 0;
+ const int max_order = 16;
+ struct drm_buddy mm;
+ LIST_HEAD(blocks);
+ LIST_HEAD(tmp);
+ int order, err;
+
+ /*
+ * Create a mm with one block of each order available, and
+ * try to allocate them all.
+ */
+
+ mm_size = PAGE_SIZE * ((1 << (max_order + 1)) - 1);
+ err = drm_buddy_init(&mm,
+ mm_size,
+ PAGE_SIZE);
+ if (err) {
+ pr_err("buddy_init failed(%d)\n", err);
+ return err;
+ }
+
+ BUG_ON(mm.max_order != max_order);
+
+ for (order = 0; order <= max_order; order++) {
+ size = min_page_size = get_size(order, PAGE_SIZE);
+ err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags);
+ if (err) {
+ pr_info("buddy_alloc hit -ENOMEM with order=%d\n",
+ order);
+ goto err;
+ }
+
+ block = list_first_entry_or_null(&tmp,
+ struct drm_buddy_block,
+ link);
+ if (!block) {
+ pr_err("alloc_blocks has no blocks\n");
+ err = -EINVAL;
+ goto err;
+ }
+
+ list_move_tail(&block->link, &blocks);
+ }
+
+ /* Should be completely full! */
+ size = min_page_size = get_size(0, PAGE_SIZE);
+ err = drm_buddy_alloc_blocks(&mm, start, mm_size, size, min_page_size, &tmp, flags);
+ if (!err) {
+ pr_info("buddy_alloc unexpectedly succeeded, it should be full!");
+ block = list_first_entry_or_null(&tmp,
+ struct drm_buddy_block,
+ link);
+ if (!block) {
+ pr_err("alloc_blocks has no blocks\n");
+ err = -EINVAL;
+ goto err;
+ }
+
+ list_move_tail(&block->link, &blocks);
+ err = -EINVAL;
+ goto err;
+ } else {
+ err = 0;
+ }
+
+err:
+ drm_buddy_free_list(&mm, &blocks);
+ drm_buddy_fini(&mm);
+ return err;
+}
+
static int igt_buddy_alloc_range(void *arg)
{
unsigned long flags = DRM_BUDDY_RANGE_ALLOCATION;