Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A473EC61DD3 for ; Thu, 3 Sep 2026 22:01:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 41B5110F7BD; Thu, 3 Sep 2026 22:01:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="Ze94zwxp"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 70ADB10F7BD; Thu, 3 Sep 2026 22:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=KRnl0PvwKZond8VGA1vqUOunbtS1TeIiSK7sEbkWm4c=; b=Ze94zwxpYa3dqCEHqchutlp87a PWZYe43USKF0fG+rugsFSyqVtsCKJO/SOsLnesiYIuzzGlp2SMtZbN8jVSWGQ0N6R/ERUcO12v0ef RkgtfHD5BsFDHim4RmXrGJMhUmSk+uTouJIZyiqlVAzk+qUnSon6djVrIke4nSzHvpEU99AKQ9f1b 3ZJGwXcrkVZOP+TxnQWqOrtLP7GtgSG+r7TaKGQND3bYx57m1tu3eWgI4tb6bkhLbUpvhPC2v1zOn KK6XCH9HTPptQfZEaolcxZ42nqwRfRyylcnqxWLUqm3U1fk09wT3hOSA1aaQi5tYmPEsrGLEL91+G jcNZMXJw==; Received: from [187.43.152.48] (helo=[127.0.0.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1x2FUL-00EbUz-59; Fri, 04 Sep 2026 00:00:53 +0200 From: Thadeu Lima de Souza Cascardo Date: Thu, 03 Sep 2026 19:00:24 -0300 Subject: [PATCH i-g-t v6 2/9] tests/cgroup_dmem: add dmem cgroup controller test MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260903-dmem_max-v6-2-61dc62970fae@igalia.com> References: <20260903-dmem_max-v6-0-61dc62970fae@igalia.com> In-Reply-To: <20260903-dmem_max-v6-0-61dc62970fae@igalia.com> To: igt-dev@lists.freedesktop.org Cc: siqueira@igalia.com, Thadeu Lima de Souza Cascardo , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Christian Koenig , maarten.lankhorst@linux.intel.com, =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Kamil Konieczny , Janusz Krzysztofik , Vitaly Prosyak , Natalie Vock , Tvrtko Ursulin , kernel-dev@igalia.com X-Mailer: b4 0.16-dev-62088 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" From: Thomas Hellström 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 --- tests/cgroup_dmem.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 1 + 2 files changed, 93 insertions(+) diff --git a/tests/cgroup_dmem.c b/tests/cgroup_dmem.c new file mode 100644 index 000000000000..442c965f9bbf --- /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 + +#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 1ac89bab7e15..c362d42888ba 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