Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
To: igt-dev@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-xe@lists.freedesktop.org,
	"Christian Koenig" <christian.koenig@amd.com>,
	maarten.lankhorst@linux.intel.com,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Natalie Vock" <natalie.vock@gmx.de>,
	kernel-dev@igalia.com,
	"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
	"Thadeu Lima de Souza Cascardo" <cascardo@igalia.com>
Subject: [PATCH i-g-t 2/8] Adjust xe_cgroups test to use igt_dmem_driver
Date: Tue, 12 May 2026 18:51:49 -0300	[thread overview]
Message-ID: <20260512215156.4083082-3-cascardo@igalia.com> (raw)
In-Reply-To: <20260512215156.4083082-1-cascardo@igalia.com>

Using the driver should not have any functional changes.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
---
 tests/intel/xe_cgroups.c | 69 ++++++++--------------------------------
 1 file changed, 14 insertions(+), 55 deletions(-)

diff --git a/tests/intel/xe_cgroups.c b/tests/intel/xe_cgroups.c
index 08cf8e3bdc5b..9ff8d46570ab 100644
--- a/tests/intel/xe_cgroups.c
+++ b/tests/intel/xe_cgroups.c
@@ -25,6 +25,7 @@
 #include "igt.h"
 #include "igt_aux.h"
 #include "igt_cgroup.h"
+#include "igt_dmem_driver.h"
 #include "xe_drm.h"
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
@@ -110,27 +111,14 @@ static uint64_t wait_for_usage_drop(struct igt_cgroup *cg, const char *region,
 	return current;
 }
 
-static int fill_vram(int fd, uint32_t vm, uint64_t vram_region,
-		     uint32_t *handles, int max_bo)
+static int fill_vram(struct igt_dmem_driver *drv, void *ctx, int fd, int max_bo)
 {
-	uint32_t handle;
-	uint64_t addr = BIND_BASE;
 	int n_bo, err = 0;
 
 	for (n_bo = 0; n_bo < max_bo; n_bo++) {
-		err = __xe_bo_create(fd, 0, BO_SIZE, vram_region,
-				     DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING,
-				     NULL, &handle);
+		err = drv->allocate_vram(ctx, n_bo, BO_SIZE);
 		if (err)
 			break;
-
-		handles[n_bo] = handle;
-
-		err = __xe_vm_bind_lr_sync(fd, vm, handle, 0, addr, BO_SIZE, 0);
-		if (err)
-			break;
-
-		addr += BO_SIZE;
 	}
 
 	igt_assert_f(err == -ENOMEM || err == -ENOSPC,
@@ -140,47 +128,20 @@ static int fill_vram(int fd, uint32_t vm, uint64_t vram_region,
 	return n_bo;
 }
 
-static void unfill_vram(int fd, uint32_t vm, uint32_t *handles, int n_bo)
-{
-	uint64_t addr = BIND_BASE;
-	int i;
-
-	for (i = 0; i < n_bo; i++) {
-		if (handles[i]) {
-			xe_vm_unbind_lr_sync(fd, vm, 0, addr, BO_SIZE);
-			gem_close(fd, handles[i]);
-		}
-		addr += BO_SIZE;
-	}
-	free(handles);
-}
-
-static void test_write_eviction(int fd, unsigned int flags)
+static void test_write_eviction(int fd, unsigned int flags, struct igt_dmem_driver *drv)
 {
+	void *ctx;
 	struct igt_cgroup *cg;
 	char *cg_region;
-	uint32_t vm;
-	uint64_t vram_region = 0;
-	uint64_t region;
-	uint32_t *handles = NULL;
 	int n_bo = 0, max_bo;
 	uint64_t current, capacity, cg_max, limit, after;
-	int set_err;
+	int set_err, err;
 
 	/* Check dmem cgroup controller is available before doing anything else */
 	igt_require_f(igt_cgroup_dmem_available(),
 		      "dmem cgroup controller not available (no cgroup v2 or no registered regions)\n");
 
-	/* Find first VRAM region */
-	xe_for_each_mem_region(fd, all_memory_regions(fd), region) {
-		if (xe_region_class(fd, region) == DRM_XE_MEM_REGION_CLASS_VRAM) {
-			vram_region = region;
-			break;
-		}
-	}
-	igt_require_f(vram_region, "No VRAM region found on this device\n");
-
-	cg_region = xe_cgroup_region_name(fd, vram_region);
+	cg_region = drv->get_region_name(fd);
 	igt_require_f(cg_region, "Region not tracked by dmem cgroup controller\n");
 
 	igt_cgroup_dmem_get_capacity(cg_region, &capacity);
@@ -204,13 +165,12 @@ static void test_write_eviction(int fd, unsigned int flags)
 	igt_cgroup_move_current(cg);
 	igt_cgroup_dmem_set_max(cg, cg_region, cg_max);
 
-	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE, 0);
-
 	max_bo = (cg_max / BO_SIZE) + 8; /* headroom for overcommit */
-	handles = calloc(max_bo, sizeof(*handles));
-	igt_assert(handles);
 
-	n_bo = fill_vram(fd, vm, vram_region, handles, max_bo);
+	err = drv->init(&ctx, fd, max_bo);
+	igt_assert_f(!err, "Failed to initialize driver");
+
+	n_bo = fill_vram(drv, ctx, fd, max_bo);
 
 	igt_cgroup_dmem_get_current(cg, cg_region, &current);
 	igt_debug("After fill: cgroup current = %"PRIu64" MiB, "
@@ -261,9 +221,8 @@ static void test_write_eviction(int fd, unsigned int flags)
 
 	/* Cleanup */
 	igt_cgroup_dmem_set_max(cg, cg_region, IGT_CGROUP_DMEM_MAX);
-	unfill_vram(fd, vm, handles, n_bo);
-	handles = NULL;
-	xe_vm_destroy(fd, vm);
+	drv->free_vram(ctx, n_bo, BO_SIZE);
+	drv->deinit(ctx);
 	free(cg_region);
 	igt_cgroup_free(cg);
 }
@@ -288,7 +247,7 @@ int igt_main()
 
 	for (int i = 0; subtests[i].name; i++)
 		igt_subtest(subtests[i].name)
-			test_write_eviction(fd, subtests[i].flags);
+			test_write_eviction(fd, subtests[i].flags, &xe_dmem_driver);
 
 	igt_fixture() {
 		drm_close_driver(fd);
-- 
2.47.3


  parent reply	other threads:[~2026-05-12 21:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 21:51 [PATCH i-g-t 0/8] dmem: add amdgpu support and one more test Thadeu Lima de Souza Cascardo
2026-05-12 21:51 ` [PATCH i-g-t 1/8] Introduce dmem driver and implement Xe support Thadeu Lima de Souza Cascardo
2026-05-12 21:51 ` Thadeu Lima de Souza Cascardo [this message]
2026-05-13 15:18   ` [PATCH i-g-t 2/8] Adjust xe_cgroups test to use igt_dmem_driver Kamil Konieczny
2026-05-12 21:51 ` [PATCH i-g-t 3/8] Make xe_cgroup test a generic test Thadeu Lima de Souza Cascardo
2026-05-13 15:21   ` Kamil Konieczny
2026-05-12 21:51 ` [PATCH i-g-t 4/8] amdgpu: add amdgpu_cgroup_region_name Thadeu Lima de Souza Cascardo
2026-05-12 21:51 ` [PATCH i-g-t 5/8] igt_dmem_driver: add amdgpu support Thadeu Lima de Souza Cascardo
2026-05-13 15:26   ` Kamil Konieczny
2026-05-12 21:51 ` [PATCH i-g-t 6/8] dmem: add test for current/max Thadeu Lima de Souza Cascardo
2026-05-13 15:31   ` Kamil Konieczny
2026-05-12 21:51 ` [PATCH i-g-t 7/8] dmem: only check for dmem availability once Thadeu Lima de Souza Cascardo
2026-05-12 21:51 ` [PATCH i-g-t 8/8] dmem: get region once per driver Thadeu Lima de Souza Cascardo
2026-05-12 22:27 ` [PATCH i-g-t 0/8] dmem: add amdgpu support and one more test Thadeu Lima de Souza Cascardo
2026-05-13  8:06 ` Christian König
2026-05-13  8:54   ` Thomas Hellström

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=20260512215156.4083082-3-cascardo@igalia.com \
    --to=cascardo@igalia.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=kernel-dev@igalia.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=natalie.vock@gmx.de \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tvrtko.ursulin@igalia.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