From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: dev@lankhorst.se, "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: [PATCH i-g-t 2/5] tests/cgroup_dmem: add dmem cgroup controller test
Date: Thu, 26 Mar 2026 17:10:04 +0100 [thread overview]
Message-ID: <20260326161007.39294-3-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20260326161007.39294-1-thomas.hellstrom@linux.intel.com>
Add a test that exercises the cgroup v2 dmem controller interface using
the new igt_cgroup library.
The test uses igt_simple_main and:
- Skips if no dmem regions are registered (no cgroup v2 or no
dmem-capable device).
- Creates a sub-cgroup and moves the test process into it.
- Enumerates all registered device memory regions and prints their
capacity, system-wide current usage, per-cgroup current usage, and
configured min, low and max limits.
- Destroys the cgroup on completion.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
tests/cgroup_dmem.c | 92 +++++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 93 insertions(+)
create mode 100644 tests/cgroup_dmem.c
diff --git a/tests/cgroup_dmem.c b/tests/cgroup_dmem.c
new file mode 100644
index 000000000..442c965f9
--- /dev/null
+++ b/tests/cgroup_dmem.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+/**
+ * TEST: cgroup dmem
+ * Description: Exercises the cgroup v2 dmem controller interface. Creates a
+ * cgroup, moves the process into it, enumerates all dmem regions,
+ * prints their capacity, system-wide current usage, per-cgroup
+ * current usage and configured limits, then destroys the cgroup.
+ * Category: Core
+ * Mega feature: General Core features
+ * Sub-category: uapi
+ * Functionality: cgroup
+ * Feature: dmem
+ * Test category: uapi
+ */
+
+#include <inttypes.h>
+
+#include "igt.h"
+#include "igt_cgroup.h"
+
+IGT_TEST_DESCRIPTION("Exercises the cgroup v2 dmem controller interface.");
+
+static void fmt_bytes(uint64_t v, char *buf, size_t len)
+{
+ if (v == IGT_CGROUP_DMEM_MAX)
+ snprintf(buf, len, "max");
+ else
+ snprintf(buf, len, "%" PRIu64, v);
+}
+
+int igt_simple_main()
+{
+ struct igt_cgroup *cg;
+ const char *region;
+ char **regions;
+ uint64_t capacity, sys_current, cg_current, min, low, max;
+ char cap_s[32], sys_s[32], cg_s[32];
+ char min_s[32], low_s[32], max_s[32];
+ int i;
+
+ igt_require_f(igt_cgroup_dmem_available(),
+ "No dmem regions found; is cgroup v2 with the "
+ "dmem controller available?\n");
+
+ cg = igt_cgroup_new("igt-cgroup-dmem-test");
+ igt_assert_f(cg, "Failed to create cgroup\n");
+
+ igt_cgroup_move_current(cg);
+
+ regions = igt_cgroup_dmem_regions();
+ igt_assert_f(regions, "Failed to enumerate dmem regions\n");
+
+ igt_info("%-40s %16s %16s %16s %16s %16s %16s\n",
+ "region", "capacity", "system-current",
+ "cgroup-current", "min", "low", "max");
+ igt_info("%-40s %16s %16s %16s %16s %16s %16s\n",
+ "------", "--------", "--------------",
+ "--------------", "---", "---", "---");
+
+ for (i = 0; regions[i]; i++) {
+ region = regions[i];
+
+ igt_cgroup_dmem_get_capacity(region, &capacity);
+ fmt_bytes(capacity, cap_s, sizeof(cap_s));
+
+ igt_cgroup_dmem_get_system_current(region, &sys_current);
+ fmt_bytes(sys_current, sys_s, sizeof(sys_s));
+
+ igt_cgroup_dmem_get_current(cg, region, &cg_current);
+ fmt_bytes(cg_current, cg_s, sizeof(cg_s));
+
+ igt_cgroup_dmem_get_min(cg, region, &min);
+ fmt_bytes(min, min_s, sizeof(min_s));
+
+ igt_cgroup_dmem_get_low(cg, region, &low);
+ fmt_bytes(low, low_s, sizeof(low_s));
+
+ igt_cgroup_dmem_get_max(cg, region, &max);
+ fmt_bytes(max, max_s, sizeof(max_s));
+
+ igt_info("%-40s %16s %16s %16s %16s %16s %16s\n",
+ region, cap_s, sys_s, cg_s,
+ min_s, low_s, max_s);
+ }
+
+ igt_cgroup_dmem_regions_free(regions);
+ igt_cgroup_free(cg);
+}
diff --git a/tests/meson.build b/tests/meson.build
index cecb4a8ae..f2326d293 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,4 +1,5 @@
test_progs = [
+ 'cgroup_dmem',
'core_auth',
'core_debugfs',
'core_getclient',
--
2.53.0
next prev parent reply other threads:[~2026-03-26 16:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 16:10 [PATCH i-g-t 0/5] Initial dmem cgroup support Thomas Hellström
2026-03-26 16:10 ` [PATCH i-g-t 1/5] lib/igt_cgroup: add cgroup v2 and dmem controller helpers Thomas Hellström
2026-03-26 16:10 ` Thomas Hellström [this message]
2026-03-26 16:10 ` [PATCH i-g-t 3/5] lib/xe: add xe_cgroup_region_name() helper Thomas Hellström
2026-03-26 16:10 ` [PATCH i-g-t 4/5] lib/xe: add __xe_vm_bind_lr_sync() failable bind helper Thomas Hellström
2026-03-26 16:10 ` [PATCH i-g-t 5/5] tests/xe_cgroups: add dmem cgroup eviction test Thomas Hellström
2026-03-26 23:42 ` ✓ Xe.CI.BAT: success for Initial dmem cgroup support Patchwork
2026-03-27 0:00 ` ✓ i915.CI.BAT: " Patchwork
2026-03-27 17:49 ` ✓ Xe.CI.FULL: " Patchwork
2026-03-28 0:45 ` ✗ i915.CI.Full: 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=20260326161007.39294-3-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=dev@lankhorst.se \
--cc=igt-dev@lists.freedesktop.org \
/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.