All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sobin Thomas <sobin.thomas@intel.com>
To: igt-dev@lists.freedesktop.org, matthew.brost@intel.com
Cc: nishit.sharma@intel.com, priyanka.dandamudi@intel.com
Subject: [PATCH i-g-t v5 2/5] tests/intel: Add random-size BO leak tests
Date: Tue, 22 Sep 2026 11:04:35 +0000	[thread overview]
Message-ID: <20260922110438.2402109-3-sobin.thomas@intel.com> (raw)
In-Reply-To: <20260922110438.2402109-1-sobin.thomas@intel.com>

Add new RANDOM_SIZE subtests exercising randomly sized BO allocation
This test excercises allocation, execution, validation and cleanup
paths across a wider mix of BO size, helping to detect issues that
may only appear with specific size combinations.

Add the following subtests:
- rand-sizes-10
- rand-sizes-100
- rand-sizes-100-unaligned

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Sobin Thomas <sobin.thomas@intel.com>
---
 tests/intel/xe_bo_alloc.c | 126 ++++++++++++++++++++++++++++++++++----
 1 file changed, 115 insertions(+), 11 deletions(-)

diff --git a/tests/intel/xe_bo_alloc.c b/tests/intel/xe_bo_alloc.c
index 8680fe518..bd5bf5a33 100644
--- a/tests/intel/xe_bo_alloc.c
+++ b/tests/intel/xe_bo_alloc.c
@@ -34,6 +34,20 @@
  * SUBTEST: all-sizes-once
  * Description: Test all BO allocations sizes in test table
  * Test category: functionality test
+ *
+ * SUBTEST: rand-sizes-10
+ * Description: Test 10 random BO allocation sizes in test table
+ * Test category: functionality test
+ *
+ * SUBTEST: rand-sizes-100
+ * Description: Test 100 random BO allocation sizes in test table
+ * Test category: functionality test
+ *
+ * SUBTEST: rand-sizes-100-unaligned
+ * Description: Test 100 random BO allocation sizes in test table, unaligned bind addresses
+ * Test category: functionality test
+ *
+ *
  */
 
 #define GB(x) (1024ULL * 1024ULL * 1024ULL * (x))
@@ -45,7 +59,7 @@ static uint64_t *alloc_sizes;
 /*
  * Data-driven subtest matrix.
  *
- * TYPE_ALL_SIZES / TYPE_SINGLE / TYPE_ARRAY_BIND all exercise exactly one
+ * TYPE_ALL_SIZES / TYPE_RANDOM_SIZE / TYPE_ARRAY_BIND all exercise exactly one
  * engine per invocation, so they're wired up as a dynamic child subtest
  * per engine below (igt_subtest_with_dynamic_f() + igt_dynamic_f()).
  *
@@ -59,6 +73,7 @@ static uint64_t *alloc_sizes;
  */
 enum test_type {
 	TYPE_ALL_SIZES,
+	TYPE_RANDOM_SIZE,
 };
 
 struct test_case {
@@ -337,6 +352,15 @@ static void test_map_bos(int fd, struct bo_alloc *bos, int n_bos)
 	}
 }
 
+static void bo_release(int fd, struct bo_alloc *b)
+{
+	if (b->map)
+		munmap(b->map, b->bo_size);
+	if (b->bo)
+		gem_close(fd, b->bo);
+	bo_alloc_release_va(b);
+}
+
 /*
  * Build and submit one batch for every 4 KiB page of one BO.
  */
@@ -414,15 +438,6 @@ static void execute_multi_bos(int fd, uint32_t exec_queue,
 		execute_bo(fd, exec_queue, &bos[i]);
 }
 
-static void bo_release(int fd, struct bo_alloc *b)
-{
-	if (b->map)
-		munmap(b->map, b->bo_size);
-	if (b->bo)
-		gem_close(fd, b->bo);
-	bo_alloc_release_va(b);
-}
-
 /*
  * Runs prepare + bind + execute for n_bos BOs at once (n_bos == 1
  * reproduces the original single-BO behaviour). If LEAK_BINDING is not
@@ -488,6 +503,88 @@ static struct bo_alloc *test_alloc_size(int fd, uint32_t vm, uint32_t q,
 	return NULL;
 }
 
+static void validate_bo_leak(int fd, uint32_t vm, struct bo_alloc *bos,
+			     int n_bos, uint32_t flags)
+{
+	int i;
+
+	for (i = 0; i < n_bos; ++i)
+		check_exec_data(bos[i].map, bos[i].bo_size >> SZ_4K_SHIFT);
+
+	/* Migrate the whole group back into VRAM, recheck */
+	if (flags & EVICT) {
+		igt_assert_eq(test_bind(fd, vm, bos, n_bos, flags), 0);
+
+		for (i = 0; i < n_bos; ++i)
+			check_exec_data(bos[i].map, bos[i].bo_size >> SZ_4K_SHIFT);
+
+		test_unbind(fd, vm, bos, n_bos);
+	}
+
+	for (i = 0; i < n_bos; ++i)
+		bo_release(fd, &bos[i]);
+}
+
+static void check_leak_multi_group(int fd, uint32_t vm, struct bo_group **groups,
+				   int count, uint32_t flags)
+{
+	int i;
+
+	for (i = 0; i < count; ++i) {
+		if (!groups[i])
+			continue;
+
+		validate_bo_leak(fd, vm, groups[i]->bos, groups[i]->n_bos, flags);
+		free(groups[i]);
+	}
+}
+
+static void alloc_rand_size_bos(int fd, struct drm_xe_engine_class_instance *hwe,
+				int count, uint64_t vram_per_process, pthread_barrier_t *barrier,
+				uint32_t flags)
+{
+	struct bo_group **leaks = NULL;
+	uint32_t vm, q, bo_size;
+	uint64_t vram_used = 0;
+	int i, max_batches = (count == -1) ? MAX_ALLOCATIONS : count;
+
+	igt_assert(count > 0 || (flags & EVICT && flags & LEAK_BO));
+	leaks = malloc(sizeof(*leaks) * max_batches);
+	igt_assert(leaks);
+
+	vm = xe_vm_create(fd, 0, 0);
+	q =  xe_exec_queue_create(fd, vm, hwe, 0);
+
+	for (i = 0; i < count || vram_used < vram_per_process; ++i) {
+		struct bo_alloc *bo;
+
+		bo_size = alloc_sizes[rand() % N_ALLOC_SIZES];
+
+		igt_assert(i < max_batches);
+		bo = test_alloc_size(fd, vm, q, hwe->gt_id, bo_size, flags,
+				     BO_BIND_BASE_ADDR);
+		if (bo) {
+			leaks[i] = malloc(sizeof(*leaks[i]));
+			igt_assert(leaks[i]);
+
+			leaks[i]->bos = bo;
+			leaks[i]->n_bos = 1;
+
+			vram_used += bo->bo_size;
+		} else {
+			leaks[i] = NULL;
+		}
+	}
+
+	if (barrier)
+		pthread_barrier_wait(barrier);
+	check_leak_multi_group(fd, vm, leaks, i, flags);
+
+	xe_exec_queue_destroy(fd, q);
+	xe_vm_destroy(fd, vm);
+	free(leaks);
+}
+
 static void all_sizes_once(int fd, struct drm_xe_engine_class_instance *hwe)
 {
 	uint32_t vm, q;
@@ -544,6 +641,9 @@ static void run_gt_dynamic_subtests(int fd, const struct test_case *t)
 			case TYPE_ALL_SIZES:
 				all_sizes_once(fd, hwe);
 				break;
+			case TYPE_RANDOM_SIZE:
+				alloc_rand_size_bos(fd, hwe, t->count, 0, NULL, t->flags);
+				break;
 			default:
 				break;
 
@@ -555,7 +655,7 @@ static void run_gt_dynamic_subtests(int fd, const struct test_case *t)
 /*
  * Data-driven subtest matrix.
  *
- * TYPE_ALL_SIZES / TYPE_SINGLE / TYPE_ARRAY_BIND all exercise exactly one
+ * TYPE_ALL_SIZES / TYPE_RANDOM_SIZE / TYPE_ARRAY_BIND all exercise exactly one
  * engine per invocation, so they're wired up as a dynamic child subtest
  * per engine below (igt_subtest_with_dynamic_f() + igt_dynamic_f()).
  *
@@ -570,6 +670,9 @@ static void run_gt_dynamic_subtests(int fd, const struct test_case *t)
 
 static const struct test_case test_matrix[] = {
 	{ "all-sizes-once", 0, 0, TYPE_ALL_SIZES, false },
+	{ "rand-sizes-10", 10, 0, TYPE_RANDOM_SIZE, false },
+	{ "rand-sizes-100", 100, 0, TYPE_RANDOM_SIZE, false },
+	{ "rand-sizes-100-unaligned", 100, UNALIGNED, TYPE_RANDOM_SIZE, false },
 };
 
 int igt_main()
@@ -586,6 +689,7 @@ int igt_main()
 
 		switch (t->type) {
 		case TYPE_ALL_SIZES:
+		case TYPE_RANDOM_SIZE:
 			igt_subtest_with_dynamic_f("%s", t->name)
 				run_gt_dynamic_subtests(fd, t);
 		}
-- 
2.52.0


  parent reply	other threads:[~2026-09-22 11:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 11:04 [PATCH i-g-t v5 0/5] Add BO Allocation and VM Bind stress infra Sobin Thomas
2026-09-22 11:04 ` [PATCH i-g-t v5 1/5] tests/intel: add BO allocation stress coverage Sobin Thomas
2026-10-01  4:52   ` Dandamudi, Priyanka
2026-09-22 11:04 ` Sobin Thomas [this message]
2026-10-01  6:50   ` [PATCH i-g-t v5 2/5] tests/intel: Add random-size BO leak tests Dandamudi, Priyanka
2026-10-05  6:15     ` Dandamudi, Priyanka
2026-09-22 11:04 ` [PATCH i-g-t v5 3/5] tests/intel: Add array-of-binds random-size allocation tests Sobin Thomas
2026-10-05  6:20   ` Dandamudi, Priyanka
2026-10-08 13:17     ` Thomas, Sobin
2026-09-22 11:04 ` [PATCH i-g-t v5 4/5] tests/intel: Add threaded random-size allocation stress tests Sobin Thomas
2026-10-05  6:56   ` Dandamudi, Priyanka
2026-10-08 10:35     ` Thomas, Sobin
2026-09-22 11:04 ` [PATCH i-g-t v5 5/5] tests/intel: Add oversubscribe concurrent bind stress subtest Sobin Thomas
2026-09-29  5:17   ` Sharma, Nishit
2026-10-05 14:34   ` Sharma, Nishit
2026-10-08 10:12     ` Thomas, Sobin
2026-09-23  1:23 ` ✓ i915.CI.BAT: success for Add BO Allocation and VM Bind stress infra (rev4) Patchwork
2026-09-23  2:21 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-23 15:56 ` ✗ i915.CI.Full: failure " Patchwork
2026-09-23 18:40 ` ✗ Xe.CI.FULL: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260922110438.2402109-3-sobin.thomas@intel.com \
    --to=sobin.thomas@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=nishit.sharma@intel.com \
    --cc=priyanka.dandamudi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.