From: Sobin Thomas <sobin.thomas@intel.com>
To: igt-dev@lists.freedesktop.org, nishit.sharma@intel.com
Cc: priyanka.dandamudi@intel.com, matthew.brost@intel.com,
kamil.konieczny@intel.com
Subject: [PATCH i-g-t v8 4/5] tests/intel: Add threaded random-size allocation stress tests
Date: Tue, 24 Nov 2026 12:12:02 +0000 [thread overview]
Message-ID: <20261124121203.592758-5-sobin.thomas@intel.com> (raw)
In-Reply-To: <20261124121203.592758-1-sobin.thomas@intel.com>
Add a new TYPE_THREAD test mode that creates a worker thread per
available engine and performs random-sized BO allocations concurrently.
Each thread creates its own VM and execution queue and exercises the
existing allocation path with both aligned and unaligned bind addresses.
Additional variants cover leaked bindings.
These tests provide additional stress coverage for concurrent BO
allocation and VM bind activity across multiple engines.
v6:
- Use rand_r(seed) instead of rand(). (Priyanka)
- Advance bind VA per transaction. (Priyanka)
- Use engines[i] instead of engines [i%n_found]. (Priyanka)
Signed-off-by: Sobin Thomas <sobin.thomas@intel.com>
---
tests/intel/xe_bo_alloc.c | 184 ++++++++++++++++++++++++++++++++++++--
1 file changed, 178 insertions(+), 6 deletions(-)
diff --git a/tests/intel/xe_bo_alloc.c b/tests/intel/xe_bo_alloc.c
index c2cc0a301..cf75ae111 100644
--- a/tests/intel/xe_bo_alloc.c
+++ b/tests/intel/xe_bo_alloc.c
@@ -29,6 +29,8 @@
#define SZ_4K_SHIFT 12
#define MAX_ALLOCATIONS 50000
#define N_BOS_PER_BIND 10
+#define GB(x) (1024ULL * 1024ULL * 1024ULL * (x))
+#define THREAD_VA_STRIDE GB(1)
/**
* SUBTEST: all-sizes-once
@@ -69,6 +71,25 @@
* Description: Allocate and retain batches of 10 random-sized BOs, each bound
* as a single array of binds, until VRAM is overcommited, then validate them.
* Test category: functionality test
+ *
+ * SUBTEST: threads-rand-sizes-50
+ * Description: Test 50 random BO allocation sizes in test table with a thread per engine
+ * Test category: stress test
+ *
+ * SUBTEST: threads-rand-sizes-50-unaligned
+ * Description: Test 50 random BO allocation sizes in test table with a thread per engine,
+ * with bind addresses unaligned to BO size
+ * Test category: stress test
+ *
+ * SUBTEST: threads-leak-binding-rand-sizes-50
+ * Description: Test 50 random BO allocation sizes in test table with a thread per engine,
+ * leak the binding
+ * Test category: stress test
+ *
+ * SUBTEST: threads-leak-binding-rand-sizes-50-unaligned
+ * Description: Test 50 random BO allocation sizes in test table with a thread per engine,
+ * leak the binding, with bind addresses unaligned to BO size
+ * Test category: stress test
*/
#define N_ALLOC_SIZES 256
@@ -83,6 +104,7 @@ enum test_type {
TYPE_ALL_SIZES,
TYPE_RANDOM_SIZE,
TYPE_ARRAY_BIND,
+ TYPE_THREAD,
};
struct test_case {
@@ -129,6 +151,20 @@ struct batch_data {
uint32_t data;
};
+struct thread_data {
+ uint64_t va_base;
+ pthread_t thread;
+ pthread_mutex_t *mutex;
+ pthread_cond_t *cond;
+ struct drm_xe_engine_class_instance *hwe;
+ int fd;
+ int count;
+ uint32_t vm;
+ uint32_t flags;
+ unsigned int seed;
+ bool *go;
+};
+
/*
* Reserve a chunk of process address space to use as the VM bind address
* for a BO, and hand back a pointer inside it aligned either to bo_size
@@ -701,6 +737,112 @@ static void all_sizes_once(int fd, struct drm_xe_engine_class_instance *hwe)
}
+static void *bo_alloc_thread_fn(void *data)
+{
+ struct thread_data *t = data;
+ uint32_t q;
+ uint64_t va = t->va_base;
+ int i;
+
+ igt_assert(!(t->flags & LEAK_BO));
+
+ pthread_mutex_lock(t->mutex);
+ while (!*t->go)
+ pthread_cond_wait(t->cond, t->mutex);
+ pthread_mutex_unlock(t->mutex);
+
+ q = xe_exec_queue_create(t->fd, t->vm, t->hwe, 0);
+
+ for (i = 0; i < t->count; ++i) {
+ uint64_t size = alloc_sizes[rand_r(&t->seed) % N_ALLOC_SIZES];
+
+ test_alloc_size(t->fd, t->vm, q, t->hwe->gt_id,
+ size, t->flags, va);
+ va += size;
+ }
+
+ xe_exec_queue_destroy(t->fd, q);
+
+ return NULL;
+}
+
+static void run_threaded_bo_alloc_test(int fd, int count, uint32_t flags)
+{
+ struct drm_xe_engine_class_instance *hwe;
+ struct drm_xe_engine_class_instance **engines;
+ struct thread_data *threads_data;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ bool begin_work = false;
+ int n_found = 0, n_threads = 0, i, ret;
+
+ xe_for_each_engine(fd, hwe)
+ n_found++;
+
+ igt_assert(n_found > 0);
+
+ engines = calloc(n_found, sizeof(*engines));
+ igt_assert(engines);
+
+ i = 0;
+ xe_for_each_engine(fd, hwe)
+ engines[i++] = hwe;
+
+ threads_data = calloc(n_found, sizeof(*threads_data));
+ igt_assert(threads_data);
+
+ pthread_mutex_init(&mutex, NULL);
+ pthread_cond_init(&cond, NULL);
+
+ for (i = 0; i < n_found; ++i) {
+ threads_data[i].mutex = &mutex;
+ threads_data[i].cond = &cond;
+ /* reuse engine 0 if only one exists */
+ threads_data[i].hwe = engines[i];
+ threads_data[i].fd = fd;
+ threads_data[i].count = count;
+ threads_data[i].vm = xe_vm_create(fd, 0, 0);
+ threads_data[i].flags = flags;
+ threads_data[i].go = &begin_work;
+ threads_data[i].seed = i + 1;
+ threads_data[i].va_base = BO_BIND_BASE_ADDR + (uint64_t)i * THREAD_VA_STRIDE;
+ ret = pthread_create(&threads_data[i].thread, 0, bo_alloc_thread_fn,
+ &threads_data[i]);
+ if (ret) {
+ igt_warn("Thread creation failed for engine %d: %s, Continuing with %d threads\n",
+ i, strerror(ret), n_threads);
+ break;
+ }
+ n_threads++;
+ }
+ igt_assert_f(n_threads > 0, "No worker threads could be created\n");
+ ret = pthread_mutex_lock(&mutex);
+ igt_assert_eq(ret, 0);
+ begin_work = true;
+ ret = pthread_cond_broadcast(&cond);
+ igt_assert_eq(ret, 0);
+ ret = pthread_mutex_unlock(&mutex);
+ igt_assert_eq(ret, 0);
+
+ for (i = 0; i < n_threads; ++i) {
+ ret = pthread_join(threads_data[i].thread, NULL);
+ igt_assert_eq(ret, 0);
+ }
+
+ /* VM destroy will be done for successful threads */
+ for (i = 0; i < n_found; ++i) {
+ if (threads_data[i].vm)
+ xe_vm_destroy(fd, threads_data[i].vm);
+ }
+
+ ret = pthread_cond_destroy(&cond);
+ igt_assert_eq(ret, 0);
+ ret = pthread_mutex_destroy(&mutex);
+ igt_assert_eq(ret, 0);
+ free(threads_data);
+ free(engines);
+}
+
static void run_gt_dynamic_subtests(int fd, const struct test_case *t)
{
struct drm_xe_engine_class_instance *hwe;
@@ -763,10 +905,19 @@ static void run_gt_dynamic_subtests(int fd, const struct test_case *t)
}
/*
- * Data-driven subtest matrix.
- *
- * Each entry becomes a subtest with one dynamic child per GT.
- */
+* Data-driven subtest matrix.
+* Each entry becomes a subtest with one dynamic child per GT.
+* 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()).
+*
+* TYPE_THREAD are deliberately NOT split per engine here:
+* threads() already do their own xe_for_each_engine() to spawn one thread per
+* engine internally. Wrapping those in a second, outer per-engine loop would
+* run the full all-engine fan-out once for every engine on the machine,
+* multiplying the runtime by the engine count and re-exercising every engine
+* N times over. So these stay flat, single subtests.
+*/
static const struct test_case test_matrix[] = {
{ "all-sizes-once", 0, 0, TYPE_ALL_SIZES, false },
@@ -779,6 +930,11 @@ static const struct test_case test_matrix[] = {
{ "array-binds-rand-sizes-10-unaligned", 10, ARRAY_BIND | LEAK_BO | UNALIGNED,
TYPE_ARRAY_BIND, true },
{ "array-binds-rand-sizes-evict", -1, ARRAY_BIND | LEAK_BO | EVICT, TYPE_ARRAY_BIND, true },
+ { "threads-rand-sizes-50", 50, 0, TYPE_THREAD, false },
+ { "threads-rand-sizes-50-unaligned", 50, UNALIGNED, TYPE_THREAD, false },
+ { "threads-leak-binding-rand-sizes-50", 50, LEAK_BINDING, TYPE_THREAD, false },
+ { "threads-leak-binding-rand-sizes-50-unaligned", 50, LEAK_BINDING | UNALIGNED,
+ TYPE_THREAD, false },
};
int igt_main()
@@ -792,8 +948,24 @@ int igt_main()
for (i = 0; i < ARRAY_SIZE(test_matrix); ++i) {
const struct test_case *t = &test_matrix[i];
- igt_subtest_with_dynamic_f("%s", t->name)
- run_gt_dynamic_subtests(fd, t);
+
+ switch (t->type) {
+ case TYPE_THREAD:
+ igt_subtest_f("%s", t->name) {
+ if (t->requires_evict_ram) {
+ igt_require(xe_has_vram(fd));
+ igt_require(igt_get_avail_ram_mb() >=
+ (xe_visible_vram_size(fd, 0) >> 20) / 2);
+ }
+ run_threaded_bo_alloc_test(fd, t->count, t->flags);
+ }
+ break;
+ case TYPE_ALL_SIZES:
+ case TYPE_RANDOM_SIZE:
+ case TYPE_ARRAY_BIND:
+ igt_subtest_with_dynamic_f("%s", t->name)
+ run_gt_dynamic_subtests(fd, t);
+ }
}
igt_fixture() {
--
2.55.0
next prev parent reply other threads:[~2026-11-24 12:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:11 [PATCH i-g-t v8 0/5] Add BO Allocation and VM Bind stress infra Sobin Thomas
2026-11-24 12:11 ` [PATCH i-g-t v8 1/5] tests/intel: Add BO allocation stress coverage Sobin Thomas
2026-11-24 12:12 ` [PATCH i-g-t v8 2/5] tests/intel: Add random-size BO leak tests Sobin Thomas
2026-11-24 12:12 ` [PATCH i-g-t v8 3/5] tests/intel: Add array-of-binds random-size allocation tests Sobin Thomas
2026-11-24 12:12 ` Sobin Thomas [this message]
2026-11-24 12:12 ` [PATCH i-g-t v8 5/5] tests/intel: Add oversubscribe concurrent bind stress subtest Sobin Thomas
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=20261124121203.592758-5-sobin.thomas@intel.com \
--to=sobin.thomas@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@intel.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox