public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: maarten.lankhorst@linux.intel.com,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: [PATCH i-g-t 6/6] tests/xe_cgroups: add write_eviction_nonblock subtest
Date: Tue, 28 Apr 2026 08:54:11 +0200	[thread overview]
Message-ID: <20260428065411.4222-7-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20260428065411.4222-1-thomas.hellstrom@linux.intel.com>

Add write_eviction_nonblock to exercise the O_NONBLOCK path of the dmem
cgroup max interface.  After filling VRAM to the cgroup limit, each
limit-lowering step writes dmem.max with O_NONBLOCK so that synchronous
eviction is skipped.  The test then verifies that usage has not yet
dropped below the new limit, allocates a small BO to trigger eviction
explicitly, and finally confirms that usage falls within bounds.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 tests/intel/xe_cgroups.c | 43 ++++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/tests/intel/xe_cgroups.c b/tests/intel/xe_cgroups.c
index 8b0f4381f..aa7a8c3b2 100644
--- a/tests/intel/xe_cgroups.c
+++ b/tests/intel/xe_cgroups.c
@@ -35,6 +35,7 @@
 #define BIND_BASE		0x100000000ULL	/* 4 GiB VA base */
 
 #define TEST_INTERRUPTIBLE	(1 << 0)
+#define TEST_NONBLOCK		(1 << 1)
 
 /**
  * SUBTEST: write_eviction
@@ -62,6 +63,18 @@
  * REQUIREMENTS: must run as root; xe device with at least one VRAM region
  */
 
+/**
+ * SUBTEST: write_eviction_nonblock
+ * DESCRIPTION:
+ *   Same fill phase as write_eviction.  In the limit-lowering phase dmem.max
+ *   is written with O_NONBLOCK, which causes the kernel to skip synchronous
+ *   eviction.  After each nonblock write the test verifies that usage has not
+ *   yet dropped below the new limit, then triggers eviction explicitly by
+ *   allocating a small BO.  Finally verifies that usage falls within bounds
+ *   after the forced eviction.
+ * REQUIREMENTS: must run as root; xe device with at least one VRAM region
+ */
+
 static atomic_int signal_count;
 static struct sigaction sigcont_oldact;
 
@@ -146,7 +159,7 @@ static void test_write_eviction(int fd, unsigned int flags)
 	uint64_t region;
 	uint32_t *handles = NULL;
 	int n_bo = 0, max_bo;
-	uint64_t current, capacity, cg_max, limit, after;
+	uint64_t current, capacity, cg_max, limit, after, before;
 
 	/* Check dmem cgroup controller is available before doing anything else */
 	igt_require_f(igt_cgroup_dmem_available(),
@@ -207,18 +220,35 @@ static void test_write_eviction(int fd, unsigned int flags)
 	while (limit >= EVICT_STEP) {
 
 		limit -= EVICT_STEP;
-		igt_cgroup_dmem_set_max(cg, cg_region, limit, false);
+
+		if (flags & TEST_NONBLOCK)
+			igt_cgroup_dmem_get_current(cg, cg_region, &before);
+
+		igt_cgroup_dmem_set_max(cg, cg_region, limit,
+					!!(flags & TEST_NONBLOCK));
 
 		igt_cgroup_dmem_get_current(cg, cg_region, &after);
 		igt_debug("Lowered max to %"PRIu64" MiB: usage = %"PRIu64" MiB\n",
 			  limit / SZ_1M, after / SZ_1M);
 
+		if (flags & TEST_NONBLOCK) {
+			/*
+			 * O_NONBLOCK skips eviction: verify usage has not
+			 * dropped below the new limit yet.
+			 */
+			igt_assert_f(after == before,
+				     "Expected no eviction with O_NONBLOCK, but "
+				     "usage dropped from %"PRIu64" MiB to %"PRIu64" MiB "
+				     "(limit %"PRIu64" MiB)\n",
+				     before / SZ_1M, after / SZ_1M, limit / SZ_1M);
+		}
+
 		if (limit > EVICT_STEP) {
-			if ((flags & TEST_INTERRUPTIBLE) && after > limit) {
+			if ((flags & (TEST_INTERRUPTIBLE | TEST_NONBLOCK)) && after > limit) {
 				uint32_t handle;
 
-				/* Let a new bo creation trigger eviction. */
-				handle = xe_bo_create(fd, 0, BO_SIZE / 8, vram_region, 0);
+				handle = xe_bo_create(fd, 0, BO_SIZE / 8,
+						      vram_region, 0);
 				gem_close(fd, handle);
 
 				igt_cgroup_dmem_get_current(cg, cg_region, &after);
@@ -252,8 +282,9 @@ static const struct {
 	const char *name;
 	unsigned int flags;
 } subtests[] = {
-	{ "write_eviction",		0 },
+	{ "write_eviction",			0 },
 	{ "write_eviction_interruptible",	TEST_INTERRUPTIBLE },
+	{ "write_eviction_nonblock",		TEST_NONBLOCK },
 	{ }
 };
 
-- 
2.53.0


  parent reply	other threads:[~2026-04-28  6:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28  6:54 [PATCH i-g-t 0/6] Initial dmem cgroup support Thomas Hellström
2026-04-28  6:54 ` [PATCH i-g-t 1/6] lib/igt_cgroup: add cgroup v2 and dmem controller helpers Thomas Hellström
2026-04-28  6:54 ` [PATCH i-g-t 2/6] tests/cgroup_dmem: add dmem cgroup controller test Thomas Hellström
2026-04-28  6:54 ` [PATCH i-g-t 3/6] lib/xe: add xe_cgroup_region_name() helper Thomas Hellström
2026-04-28  6:54 ` [PATCH i-g-t 4/6] lib/xe: Add failable variant of xe_vm_bind_lr_sync() Thomas Hellström
2026-04-28  6:54 ` [PATCH i-g-t 5/6] tests/xe_cgroups: add dmem cgroup eviction test Thomas Hellström
2026-04-28  6:54 ` Thomas Hellström [this message]
2026-04-28  7:59 ` ✓ Xe.CI.BAT: success for Initial dmem cgroup support (rev2) Patchwork
2026-04-28  8:19 ` ✗ i915.CI.BAT: failure " 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=20260428065411.4222-7-thomas.hellstrom@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=maarten.lankhorst@linux.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