From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BE37606A31A for ; Wed, 2 Dec 2026 04:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SY2INjEw Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E95AE10E02B; Wed, 2 Dec 2026 04:23:04 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9AB5C10E60E for ; Wed, 2 Dec 2026 04:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796185100; x=1827721100; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZFZ+Zd6qh424dpBuPu+FDSu6p2Cqy9tpoTeuToTL+uU=; b=SY2INjEwk3HVfKbjTYKLcjWK274wSXCxI+PRUJDEAw7bzHQxWJO/avdj 84ElZbVPM1AcSdXcwz0yv3/WpPuRM0RvR/JXGDu4YX95ijgCpgGluKpTD K/okHmjjeKuC89YO0nLsO3Fw9igPxPG2jDWL45BXhTKfBF0B4PBZHnWQG P0nvqh9IU2Ps+A3v451cJ2494PYSZiSCnZYIZ7ZHJz2JJh12iwdNBXipU SOQEwI4PA39Wssad2mTOAJMQwcl+A3PLl3+EoJH1P+1nYMRrLvN4nEmRx StqxC25MMBkyrDIoa5WghxaG4M17R6t+jau5w3oLi8wSVI2eDqdW+D0zI Q==; X-CSE-ConnectionGUID: N6MLEIZOQTaAtdJ0ysv1cg== X-CSE-MsgGUID: m8qjqBEhQECs0cxd1UYgSA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4996798" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="4996798" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 20:18:11 -0800 X-CSE-ConnectionGUID: ZCltiERnSgWej/SbXtT+WQ== X-CSE-MsgGUID: eh8sTEpNQR+bdFTfl3yowA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13288865" Received: from dut6245dg2frd.fm.intel.com ([10.36.24.131]) by orviesa003.jf.intel.com with ESMTP; 01 Dec 2026 20:18:11 -0800 From: Sobin Thomas To: igt-dev@lists.freedesktop.org, nishit.sharma@intel.com, priyanka.dandamudi@intel.com Cc: matthew.brost@intel.com, kamil.konieczny@intel.com Subject: [PATCH i-g-t v9 5/6] tests/intel: Add threaded random-size allocation stress tests Date: Wed, 2 Dec 2026 04:18:08 +0000 Message-ID: <20261202041809.713401-6-sobin.thomas@intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261202041809.713401-1-sobin.thomas@intel.com> References: <20261202041809.713401-1-sobin.thomas@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "igt-dev" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- tests/intel/xe_bo_alloc.c | 167 +++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 3 deletions(-) diff --git a/tests/intel/xe_bo_alloc.c b/tests/intel/xe_bo_alloc.c index 2183dad16..bb87c20fd 100644 --- a/tests/intel/xe_bo_alloc.c +++ b/tests/intel/xe_bo_alloc.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "igt.h" @@ -30,6 +31,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 +72,27 @@ * Description: Allocate and retain batches of 10 random-sized BOs, each bound * as a single array of binds, until VRAM is overcommitted, then validate them. * Test category: functionality test + * + * SUBTEST: threads-rand-sizes-50 + * Description: Create and bind 50 random-sized BOs from the size table on each + * engine, one thread per engine. + * Test category: stress test + * + * SUBTEST: threads-rand-sizes-50-unaligned + * Description: Create and bind 50 random-sized BOs from the size table on each + * engine, one thread per engine, with bind addresses unaligned to BO size. + * Test category: stress test + * + * SUBTEST: threads-leak-binding-rand-sizes-50 + * Description: Create and bind 50 random-sized BOs from the size table on + * each engine, one thread per engine, leaving the binding in place. + * Test category: stress test + * + * SUBTEST: threads-leak-binding-rand-sizes-50-unaligned + * Description: Create and bind 50 random-sized BOs from the size table on + * each engine, one thread per engine, leaving the binding in place, with + * bind address unaligned to BO size. + * Test category: stress test */ #define N_ALLOC_SIZES 256 @@ -83,6 +107,7 @@ enum test_type { TYPE_ALL_SIZES, TYPE_RANDOM_SIZE, TYPE_ARRAY_BIND, + TYPE_THREAD, }; struct test_case { @@ -129,6 +154,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 @@ -687,6 +726,106 @@ static void all_sizes_once(int fd, struct drm_xe_engine_class_instance *hwe) xe_vm_destroy(fd, vm); } +static void *bo_alloc_thread_fn(void *data) +{ + struct thread_data *t = data; + uint32_t q; + uint64_t va = t->va_base; + int i; + + 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; + + igt_assert(!(flags & LEAK_BO)); + 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); + + ret = pthread_mutex_init(&mutex, NULL); + igt_assert_eq(ret, 0); + ret = pthread_cond_init(&cond, NULL); + igt_assert_eq(ret, 0); + + for (i = 0; i < n_found; ++i) { + threads_data[i].mutex = &mutex; + threads_data[i].cond = &cond; + 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, NULL, bo_alloc_thread_fn, + &threads_data[i]); + igt_assert_eq(ret, 0); + n_threads++; + } + 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); + } + + 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; @@ -750,7 +889,12 @@ 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. + * TYPE_ALL_SIZES / TYPE_RANDOM_SIZE / TYPE_ARRAY_BIND entries become a + * subtest with one dynamic child per GT + * + * TYPE_THREAD entries are plain subtests: run_threaded_bo_alloc_test() + * already spawn one thread per engine, so it covers every engine + * by itself. */ static const struct test_case test_matrix[] = { @@ -764,6 +908,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() @@ -778,8 +927,20 @@ 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) + 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); + break; + default: + igt_assert_f(0, "Unhandled test type %d\n", t->type); + } } igt_fixture() { -- 2.55.0