<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/tools/testing/selftests/cgroup/test_cpu.c, branch v6.18.22</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.18.22</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.18.22'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-10-15T15:00:59+00:00</updated>
<entry>
<title>selftests: cgroup: Use values_close_report in test_cpu</title>
<updated>2025-10-15T15:00:59+00:00</updated>
<author>
<name>Sebastian Chlad</name>
<email>sebastianchlad@gmail.com</email>
</author>
<published>2025-10-15T10:33:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=4cdde87d723a0552f475c8c6b0db472a6945125f'/>
<id>urn:sha1:4cdde87d723a0552f475c8c6b0db472a6945125f</id>
<content type='text'>
Convert test_cpu to use the newly added values_close_report() helper
to print detailed diagnostics when a tolerance check fails. This
provides clearer insight into deviations while run in the CI.

Signed-off-by: Sebastian Chlad &lt;sebastian.chlad@suse.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>selftests/cgroup: fix cpu.max tests</title>
<updated>2025-07-17T18:12:19+00:00</updated>
<author>
<name>Shashank Balaji</name>
<email>shashank.mahadasyam@sony.com</email>
</author>
<published>2025-07-04T11:08:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=954bacce36d976fe472090b55987df66da00c49b'/>
<id>urn:sha1:954bacce36d976fe472090b55987df66da00c49b</id>
<content type='text'>
Current cpu.max tests (both the normal one and the nested one) are broken.

They setup cpu.max with 1000 us quota and the default period (100,000 us).
A cpu hog is run for a duration of 1s as per wall clock time. This corresponds
to 10 periods, hence an expected usage of 10,000 us. We want the measured
usage (as per cpu.stat) to be close to 10,000 us.

Previously, this approximate equality test was done by
`!values_close(usage_usec, expected_usage_usec, 95)`: if the absolute
difference between usage_usec and expected_usage_usec is greater than 95% of
their sum, then we pass. And expected_usage_usec was set to 1,000,000 us.
Mathematically, this translates to the following being true for pass:

	|usage - expected_usage| &gt; (usage + expected_usage)*0.95

	If usage &gt; expected_usage:
		usage - expected_usage &gt; (usage + expected_usage)*0.95
		0.05*usage &gt; 1.95*expected_usage
		usage &gt; 39*expected_usage = 39s

	If usage &lt; expected_usage:
		expected_usage - usage &gt; (usage + expected_usage)*0.95
		0.05*expected_usage &gt; 1.95*usage
		usage &lt; 0.0256*expected_usage = 25,600 us

Combined,

	Pass if usage &lt; 25,600 us or &gt; 39 s,

which makes no sense given that all we need is for usage_usec to be close to
10,000 us.

Fix this by explicitly calcuating the expected usage duration based on the
configured quota, default period, and the duration, and compare usage_usec
and expected_usage_usec using values_close() with a 10% error margin.

Also, use snprintf to get the quota string to write to cpu.max instead of
hardcoding the quota, ensuring a single source of truth.

Remove the check comparing user_usec and expected_usage_usec, since on running
this test modified with printfs, it's seen that user_usec and usage_usec can
regularly exceed the theoretical expected_usage_usec:

	$ sudo ./test_cpu
	user: 10485, usage: 10485, expected: 10000
	ok 1 test_cpucg_max
	user: 11127, usage: 11127, expected: 10000
	ok 2 test_cpucg_max_nested
	$ sudo ./test_cpu
	user: 10286, usage: 10286, expected: 10000
	ok 1 test_cpucg_max
	user: 10404, usage: 11271, expected: 10000
	ok 2 test_cpucg_max_nested

Hence, a values_close() check of usage_usec and expected_usage_usec is
sufficient.

Fixes: a79906570f9646ae17 ("cgroup: Add test_cpucg_max_nested() testcase")
Fixes: 889ab8113ef1386c57 ("cgroup: Add test_cpucg_max() testcase")
Acked-by: Michal Koutný &lt;mkoutny@suse.com&gt;
Signed-off-by: Shashank Balaji &lt;shashank.mahadasyam@sony.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>selftests/cgroup: Fix compile error in test_cpu.c</title>
<updated>2024-10-15T01:05:39+00:00</updated>
<author>
<name>Xiu Jianfeng</name>
<email>xiujianfeng@huawei.com</email>
</author>
<published>2024-10-11T06:11:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=11312c86f9d7d1bffe0587185934a7070ce9ec33'/>
<id>urn:sha1:11312c86f9d7d1bffe0587185934a7070ce9ec33</id>
<content type='text'>
When compiling the cgroup selftests with the following command:

make -C tools/testing/selftests/cgroup/

the compiler complains as below:

test_cpu.c: In function ‘test_cpucg_nice’:
test_cpu.c:284:39: error: incompatible type for argument 2 of ‘hog_cpus_timed’
  284 |                 hog_cpus_timed(cpucg, param);
      |                                       ^~~~~
      |                                       |
      |                                       struct cpu_hog_func_param
test_cpu.c:132:53: note: expected ‘void *’ but argument is of type ‘struct cpu_hog_func_param’
  132 | static int hog_cpus_timed(const char *cgroup, void *arg)
      |                                               ~~~~~~^~~

Fix it by passing the address of param to hog_cpus_timed().

Fixes: 2e82c0d4562a ("cgroup/rstat: Selftests for niced CPU statistics")
Signed-off-by: Xiu Jianfeng &lt;xiujianfeng@huawei.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>cgroup/rstat: Selftests for niced CPU statistics</title>
<updated>2024-10-08T18:50:54+00:00</updated>
<author>
<name>Joshua Hahn</name>
<email>joshua.hahn6@gmail.com</email>
</author>
<published>2024-10-02T18:47:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=2e82c0d4562a4b8292af83577b70af888a93d16d'/>
<id>urn:sha1:2e82c0d4562a4b8292af83577b70af888a93d16d</id>
<content type='text'>
Creates a cgroup with a single nice CPU hog process running.
fork() is called to generate the nice process because un-nicing is
not possible (see man nice(3)). If fork() was not used to generate
the CPU hog, we would run the rest of the cgroup selftest suite as a
nice process.

Signed-off-by: Joshua Hahn &lt;joshua.hahnjy@gmail.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>Revert "selftests/cgroup: Drop define _GNU_SOURCE"</title>
<updated>2024-05-20T15:00:15+00:00</updated>
<author>
<name>Shuah Khan</name>
<email>skhan@linuxfoundation.org</email>
</author>
<published>2024-05-17T02:22:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a97853f25b06f71c23b2d7a59fbd40f3f42d55ac'/>
<id>urn:sha1:a97853f25b06f71c23b2d7a59fbd40f3f42d55ac</id>
<content type='text'>
This reverts commit c1457d9aad5ee2feafcf85aa9a58ab50500159d2.

The framework change to add D_GNU_SOURCE to KHDR_INCLUDES
to Makefile, lib.mk, and kselftest_harness.h is reverted
as it is causing build failures and warnings.

Revert this change as this change depends on the framework
change.

Reported-by: Mark Brown &lt;broonie@kernel.org&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>selftests/cgroup: Drop define _GNU_SOURCE</title>
<updated>2024-05-13T17:02:36+00:00</updated>
<author>
<name>Edward Liaw</name>
<email>edliaw@google.com</email>
</author>
<published>2024-05-10T00:06:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c1457d9aad5ee2feafcf85aa9a58ab50500159d2'/>
<id>urn:sha1:c1457d9aad5ee2feafcf85aa9a58ab50500159d2</id>
<content type='text'>
_GNU_SOURCE is provided by lib.mk, so it should be dropped to prevent
redefinition warnings.

Signed-off-by: Edward Liaw &lt;edliaw@google.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>selftests/cgroup: cpu_hogger init: use {} instead of {NULL}</title>
<updated>2024-05-03T19:06:09+00:00</updated>
<author>
<name>John Hubbard</name>
<email>jhubbard@nvidia.com</email>
</author>
<published>2024-05-03T03:51:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3309ca6f47f11b5d817ce1e5d8b2f1637b93243e'/>
<id>urn:sha1:3309ca6f47f11b5d817ce1e5d8b2f1637b93243e</id>
<content type='text'>
First of all, in order to build with clang at all, one must first apply
Valentin Obst's build fix for LLVM [1]. Once that is done, then when
building with clang, via:

    make LLVM=1 -C tools/testing/selftests

...clang generates warning here, because struct cpu_hogger has multiple
fields, and the code is initializing an array of these structs, and it
is incorrect to specify a single NULL value as the initializer.

Fix this by initializing with {}, so that the compiler knows to use
default initializer values for all fields in each array entry.

[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c49f@valentinobst.de/

Signed-off-by: John Hubbard &lt;jhubbard@nvidia.com&gt;
Reviewed-by: Roman Gushchin &lt;roman.gushchin@linux.dev&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>selftests: cgroup: skip test_cgcore_lesser_ns_open when cgroup2 mounted without nsdelegate</title>
<updated>2024-04-03T19:42:13+00:00</updated>
<author>
<name>Tianchen Ding</name>
<email>dtcccc@linux.alibaba.com</email>
</author>
<published>2024-03-27T02:44:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=4793cb599b1bdc3d356f0374c2c99ffe890ae876'/>
<id>urn:sha1:4793cb599b1bdc3d356f0374c2c99ffe890ae876</id>
<content type='text'>
The test case test_cgcore_lesser_ns_open only tasks effect when cgroup2
is mounted with "nsdelegate" mount option. If it misses this option, or
is remounted without "nsdelegate", the test case will fail. For example,
running bpf/test_cgroup_storage first, and then run cgroup/test_core will
fail on test_cgcore_lesser_ns_open. Skip it if "nsdelegate" is not
detected in cgroup2 mount options.

Fixes: bf35a7879f1d ("selftests: cgroup: Test open-time cgroup namespace usage for migration checks")
Signed-off-by: Tianchen Ding &lt;dtcccc@linux.alibaba.com&gt;
Reviewed-by: Muhammad Usama Anjum &lt;usama.anjum@collabora.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>cgroup: Add test_cpucg_max_nested() testcase</title>
<updated>2022-04-25T17:27:31+00:00</updated>
<author>
<name>David Vernet</name>
<email>void@manifault.com</email>
</author>
<published>2022-04-23T12:30:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a79906570f9646ae174dd0899ea54cc2eeffd788'/>
<id>urn:sha1:a79906570f9646ae174dd0899ea54cc2eeffd788</id>
<content type='text'>
The cgroup cpu controller selftests have a test_cpucg_max() testcase
that validates the behavior of the cpu.max knob. Let's also add a
testcase that verifies that the behavior works correctly when set on a
nested cgroup.

Signed-off-by: David Vernet &lt;void@manifault.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
<entry>
<title>cgroup: Add test_cpucg_max() testcase</title>
<updated>2022-04-25T17:27:31+00:00</updated>
<author>
<name>David Vernet</name>
<email>void@manifault.com</email>
</author>
<published>2022-04-23T12:30:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=889ab8113ef1386c57d64da106b850e752949f07'/>
<id>urn:sha1:889ab8113ef1386c57d64da106b850e752949f07</id>
<content type='text'>
The cgroup cpu controller test suite has a number of testcases that
validate the expected behavior of the cpu.weight knob, but none for
cpu.max. This testcase fixes that by adding a testcase for cpu.max as well.

Signed-off-by: David Vernet &lt;void@manifault.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
</entry>
</feed>
