From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Wake Liu <wakel@google.com>
Subject: [LTP] [PATCH] controllers/cpuacct: Dynamically adjust cpuacct_task execution time
Date: Mon, 10 Aug 2026 04:17:38 +0000 [thread overview]
Message-ID: <20260810041738.1714971-1-wakel@google.com> (raw)
The test helper cpuacct_task currently runs for 10ms (virtual time)
before exiting. On some systems (e.g. fast virtual machines or under
heavy load), this short duration can lead to 0 usage being recorded in
cpuacct.usage cgroup file due to timing resolution or scheduling delay,
especially when running small configurations like cpuacct_1_1.
However, unconditionally increasing the duration for all runs (e.g. to
100ms) would cause large stress tests like cpuacct_100_100 (which runs
10,000 tasks) to timeout on systems with few CPUs.
Resolve this by:
1. Modifying cpuacct_task to accept an optional duration argument.
2. Modifying cpuacct.sh to calculate the duration dynamically based on
nbprocess, ensuring each subgroup gets at least 100ms of aggregate
CPU time, while clamping the per-process duration to a minimum of
10ms to avoid timeouts in large stress tests.
Signed-off-by: Wake Liu <wakel@google.com>
---
.../kernel/controllers/cpuacct/cpuacct.sh | 7 ++++++-
.../kernel/controllers/cpuacct/cpuacct_task.c | 20 ++++++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/controllers/cpuacct/cpuacct.sh b/testcases/kernel/controllers/cpuacct/cpuacct.sh
index 97a395cd5..efabe6cab 100755
--- a/testcases/kernel/controllers/cpuacct/cpuacct.sh
+++ b/testcases/kernel/controllers/cpuacct/cpuacct.sh
@@ -139,10 +139,15 @@ do_test()
{
tst_res TINFO "Creating $max subgroups each with $nbprocess processes"
+ local duration=$((100000 / nbprocess))
+ if [ $duration -lt 10000 ]; then
+ duration=10000
+ fi
+
# create and attach process to subgroups
for i in `seq 1 $max`; do
for j in `seq 1 $nbprocess`; do
- cpuacct_task $testpath/subgroup_$i/tasks &
+ cpuacct_task $testpath/subgroup_$i/tasks $duration &
echo $! >> task_pids
done
done
diff --git a/testcases/kernel/controllers/cpuacct/cpuacct_task.c b/testcases/kernel/controllers/cpuacct/cpuacct_task.c
index 677d6d401..caeecf064 100644
--- a/testcases/kernel/controllers/cpuacct/cpuacct_task.c
+++ b/testcases/kernel/controllers/cpuacct/cpuacct_task.c
@@ -38,12 +38,21 @@ int main(int argc, char **argv)
{
FILE *f;
struct sigaction sa;
+ int duration_us = 10000;
- if (argc != 2) {
- fprintf(stderr, "Usage: %s /cgroup/.../tasks\n", argv[0]);
+ if (argc < 2 || argc > 3) {
+ fprintf(stderr, "Usage: %s /cgroup/.../tasks [duration_us]\n", argv[0]);
return 1;
}
+ if (argc == 3) {
+ duration_us = atoi(argv[2]);
+ if (duration_us <= 0) {
+ fprintf(stderr, "Invalid duration: %s\n", argv[2]);
+ return 1;
+ }
+ }
+
f = fopen(argv[1], "a");
if (!f) {
perror("fopen failed");
@@ -62,7 +71,12 @@ int main(int argc, char **argv)
return 1;
}
- struct itimerval it = {.it_value = {.tv_sec = 0, .tv_usec = 10000}};
+ struct itimerval it = {
+ .it_value = {
+ .tv_sec = duration_us / 1000000,
+ .tv_usec = duration_us % 1000000
+ }
+ };
setitimer(ITIMER_VIRTUAL, &it, NULL);
for (;;);
--
2.55.0.654.g21b8a5bc05-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2026-08-10 4:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 4:17 Wake Liu via ltp [this message]
2026-08-10 5:28 ` [LTP] controllers/cpuacct: Dynamically adjust cpuacct_task execution time linuxtestproject.agent
2026-08-10 8:30 ` [LTP] [PATCH] " Wake Liu via ltp
2026-08-10 9:22 ` [LTP] " linuxtestproject.agent
2026-08-11 10:15 ` [LTP] [PATCH] " Andrea Cervesato via ltp
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=20260810041738.1714971-1-wakel@google.com \
--to=ltp@lists.linux.it \
--cc=wakel@google.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