From: "Michal Koutný" <mkoutny@suse.com>
To: Tao Cui <cui.tao@linux.dev>
Cc: Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>,
Suren Baghdasaryan <surenb@google.com>,
Shuah Khan <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Ziyang Men <ziyang.meme@gmail.com>,
Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH v2] selftests/cgroup: add PSI pressure trigger and validation tests
Date: Thu, 6 Aug 2026 18:52:38 +0200 [thread overview]
Message-ID: <anS3saMkFog89yxy@localhost.localdomain> (raw)
In-Reply-To: <20260728083742.2359320-1-cui.tao@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 3115 bytes --]
Hi,
thanks for continuing with this.
On Tue, Jul 28, 2026 at 04:37:42PM +0800, Tao Cui <cui.tao@linux.dev> wrote:
> +/* Trigger smoke test: second on same fd -> EBUSY; IRQ rejects "some". */
> +static int test_proc_triggers(const char *root)
> +{
> + static const char *const resources[] = { "io", "memory", "cpu" };
> + int ret = KSFT_FAIL;
> + int fd = -1;
> + int i;
> +
> + (void)root;
WTH?
> +
> + for (i = 0; i < (int)ARRAY_SIZE(resources); i++) {
This (int) cast is quite uncommon, look around.
> +/* Induce deterministic CPU pressure (more hogs than CPUs). */
> +static int test_cgroup_trigger_fire(const char *root)
> +{
> + char *cg = NULL, *cpupress = NULL;
> + int fd = -1, ret = KSFT_FAIL;
> + struct pollfd pfd;
> + long ncpus, i;
> + pid_t pid;
> +
> + cg = cg_name(root, "psi_trigger_test");
> + if (!cg)
> + goto cleanup;
> + if (cg_create(cg))
> + goto cleanup;
> +
> + cpupress = cg_control(cg, "cpu.pressure");
> + if (!cpupress)
> + goto cleanup;
> + fd = open(cpupress, O_RDWR);
> + if (fd < 0) {
> + ksft_print_msg("open cpu.pressure: %s\n", strerror(errno));
> + goto cleanup;
> + }
> +
> + /* 1us threshold in a 1s window: any cpu stall fires it. */
> + errno = 0;
> + if (write_trigger(fd, "some 1 1000000") <= 0) {
> + ksft_print_msg("arming trigger failed: %s\n", strerror(errno));
> + goto cleanup;
> + }
When I see this, could you increase the window size to 2000000 (so that
it has potential to run for unprivileged users)?
> +
> + ncpus = sysconf(_SC_NPROCESSORS_ONLN);
> + if (ncpus <= 0)
> + ncpus = 1;
> +
> + pid = fork();
> + if (pid < 0) {
> + ksft_print_msg("fork: %s\n", strerror(errno));
> + goto cleanup;
> + }
> + if (pid == 0) {
> + /* Enter the cgroup, then over-subscribe it with CPU hogs. */
> + if (cg_enter_current(cg))
> + _exit(KSFT_FAIL);
> + for (i = 0; i < ncpus; i++) {
> + if (fork() == 0) {
> + for (;;)
> + asm volatile("" ::: "memory");
> + _exit(0);
> + }
> + }
> + for (;;)
> + asm volatile("" ::: "memory"); /* child is also a hog */
> + _exit(0);
> + }
This part could be replaced with generalized hog_cpus_timed() from
test_cpu.c (after move to cgroup_util.c).
> +int main(int argc, char **argv)
> +{
> + char root[PATH_MAX];
> + int mempress_fd;
> + int i;
> +
> + (void)argc;
What's up with this?
> +
> + ksft_print_header();
> + ksft_set_plan(ARRAY_SIZE(tests));
> +
> + if (cg_find_unified_root(root, sizeof(root), NULL))
> + ksft_exit_skip("cgroup v2 isn't mounted\n");
> +
> + /* PSI must be enabled (CONFIG_PSI=y, not default-disabled). */
> + mempress_fd = open("/proc/pressure/memory", O_RDONLY);
> + if (mempress_fd < 0)
> + ksft_exit_skip("PSI unavailable (CONFIG_PSI=n or psi=0)\n");
> + close(mempress_fd);
> +
> + if (cg_read_strstr(root, "cgroup.controllers", "memory"))
> + ksft_exit_skip("memory controller isn't available\n");
> + if (cg_read_strstr(root, "cgroup.subtree_control", "memory"))
> + if (cg_write(root, "cgroup.subtree_control", "+memory"))
> + ksft_exit_skip("failed to enable memory controller\n");
The memory controller is unnecessary now, right?
Regards,
Michal
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]
next prev parent reply other threads:[~2026-08-06 16:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 8:37 [PATCH v2] selftests/cgroup: add PSI pressure trigger and validation tests Tao Cui
2026-08-06 16:52 ` Michal Koutný [this message]
2026-08-06 17:12 ` Suren Baghdasaryan
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=anS3saMkFog89yxy@localhost.localdomain \
--to=mkoutny@suse.com \
--cc=cgroups@vger.kernel.org \
--cc=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=ziyang.meme@gmail.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