From: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
To: igt-dev@lists.freedesktop.org
Cc: siqueira@igalia.com,
"Thadeu Lima de Souza Cascardo" <cascardo@igalia.com>,
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>,
"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
"Vitaly Prosyak" <vitaly.prosyak@amd.com>,
"Natalie Vock" <natalie.vock@gmx.de>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
kernel-dev@igalia.com
Subject: [PATCH i-g-t v7 2/9] tests/cgroup_dmem: add dmem cgroup controller test
Date: Wed, 23 Sep 2026 17:44:37 -0300 [thread overview]
Message-ID: <20260923-dmem_max-v7-2-194ea47bbb4d@igalia.com> (raw)
In-Reply-To: <20260923-dmem_max-v7-0-194ea47bbb4d@igalia.com>
From: Thomas Hellström <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.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
---
tests/cgroup_dmem.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 1 +
2 files changed, 92 insertions(+)
diff --git a/tests/cgroup_dmem.c b/tests/cgroup_dmem.c
new file mode 100644
index 000000000000..2ccd8bdb00ae
--- /dev/null
+++ b/tests/cgroup_dmem.c
@@ -0,0 +1,91 @@
+// 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);
+}
diff --git a/tests/meson.build b/tests/meson.build
index 4f5c9be7b458..65b9a230f935 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,4 +1,5 @@
test_progs = [
+ 'cgroup_dmem',
'core_auth',
'core_debugfs',
'core_getclient',
--
2.47.3
next prev parent reply other threads:[~2026-09-23 20:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 20:44 [PATCH i-g-t v7 0/9] add cgroup_dmem test Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 1/9] lib/igt_cgroup: add cgroup v2 and dmem controller helpers Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` Thadeu Lima de Souza Cascardo [this message]
2026-09-23 20:44 ` [PATCH i-g-t v7 3/9] lib/xe: add xe_cgroup_region_name() helper Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 4/9] lib/xe: Introduce dmem driver and implement Xe support Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 5/9] lib/amdgpu: add amdgpu_cgroup_region_name Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 6/9] lib/amdgpu: add amdgpu support to igt_dmem_driver Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 7/9] tests/cgroup_dmem: add dmem cgroup eviction test Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 8/9] tests/cgroup_dmem: add write_eviction_nonblock subtest Thadeu Lima de Souza Cascardo
2026-09-23 20:44 ` [PATCH i-g-t v7 9/9] tests/cgroup_dmem: add test for dmem.current Thadeu Lima de Souza Cascardo
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=20260923-dmem_max-v7-2-194ea47bbb4d@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=janusz.krzysztofik@linux.intel.com \
--cc=kamil.konieczny@linux.intel.com \
--cc=kernel-dev@igalia.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=natalie.vock@gmx.de \
--cc=siqueira@igalia.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tvrtko.ursulin@igalia.com \
--cc=vitaly.prosyak@amd.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