* [PATCH] rtla/tests: Get rtla PID correctly when system shell is not bash
@ 2026-10-30 14:51 Tomas Glozar
0 siblings, 0 replies; only message in thread
From: Tomas Glozar @ 2026-10-30 14:51 UTC (permalink / raw)
To: Steven Rostedt, Tomas Glozar
Cc: John Kacur, Luis Goncalves, Crystal Wood, Costa Shulyupin,
Wander Lairson Costa, LKML, linux-trace-kernel
There are several places where rtla runtime tests call a script with
"--on-threshold shell" to verify the trace configuration in the middle
of tracing. Some of these checks require the rtla pid.
Currently, the tests assume that rtla is the parent process of the
utility script. That is, however, only the case when the system shell is
bash, which optimizes the invokation of "sh -c script.sh" used by the
system() function into just one process executing script.sh. On systems
where the system shell is not bash (including all Debian-based systems),
the system shell is the parent of the script, not rtla, and the checks
fail.
Pass $PPID resolved in the system shell to rtla's --on-threshold option
and use it as the PID for rtla to make the tests pass on all
distributions.
Note that some of the tests (the cgroup test, for example) were
intending to use rtla's PID, but work with the system shell's PID as
well. For consistency, all scripts are updated to use $PPID.
Fixes: d18fd5a34ff3 ("rtla/tests: Add get_workload_pids() helper")
Fixes: 7f7ad23bced9 ("rtla/tests: Check -c/--cpus thread affinity")
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Closes: https://lore.kernel.org/linux-trace-kernel/20260810210425.61435b0b@robin/
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
tools/tracing/rtla/tests/osnoise.t | 8 ++++----
.../tracing/rtla/tests/scripts/check-cgroup-match.sh | 6 ++++--
tools/tracing/rtla/tests/scripts/check-cpus.sh | 4 +++-
.../rtla/tests/scripts/check-housekeeping-cpus.sh | 5 +++--
tools/tracing/rtla/tests/scripts/check-priority.sh | 10 +++++++---
.../rtla/tests/scripts/check-user-kernel-threads.sh | 5 ++++-
.../rtla/tests/scripts/lib/get_workload_pids.sh | 12 ++++++++----
tools/tracing/rtla/tests/timerlat.t | 12 ++++++------
8 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/tools/tracing/rtla/tests/osnoise.t b/tools/tracing/rtla/tests/osnoise.t
index 352b302372453..53a6a23514d73 100644
--- a/tools/tracing/rtla/tests/osnoise.t
+++ b/tools/tracing/rtla/tests/osnoise.t
@@ -16,15 +16,15 @@ check_top_q_hist "verify the --trace param" \
# Thread tests
check_top_q_hist "verify the --priority/-P param" \
- "osnoise TOOL -P F:1 -c 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=\"$testdir/scripts/check-priority.sh SCHED_FIFO 1\"" \
+ "osnoise TOOL -P F:1 -c 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=\"$testdir/scripts/check-priority.sh \\\$PPID SCHED_FIFO 1\"" \
2 "Priorities are set correctly"
check_top_q_hist "verify the -C/--cgroup param" \
- "osnoise TOOL -C -c 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=\"$testdir/scripts/check-cgroup-match.sh\"" \
+ "osnoise TOOL -C -c 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=\"$testdir/scripts/check-cgroup-match.sh \\\$PPID\"" \
2 "cgroup matches for all workload PIDs"
check_top_q_hist "verify the -c/--cpus param" \
- "osnoise TOOL -P F:1 -c 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=$testdir/scripts/check-cpus.sh" 2 "^Affinity of threads: 0$"
+ "osnoise TOOL -P F:1 -c 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=\"$testdir/scripts/check-cpus.sh \\\$PPID\"" 2 "^Affinity of threads: 0$"
check_top_q_hist "verify the -H/--house-keeping param" \
- "osnoise TOOL -P F:1 -H 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=$testdir/scripts/check-housekeeping-cpus.sh" 2 "^Affinity of threads: 0$"
+ "osnoise TOOL -P F:1 -H 0 -r 900000 -d 10s -S 1 --on-threshold shell,command=\"$testdir/scripts/check-housekeeping-cpus.sh \\\$PPID\"" 2 "^Affinity of threads: 0$"
# Histogram tests
check "hist with -b/--bucket-size" \
diff --git a/tools/tracing/rtla/tests/scripts/check-cgroup-match.sh b/tools/tracing/rtla/tests/scripts/check-cgroup-match.sh
index fdc2c68c5957a..dd9bcb6e43e22 100755
--- a/tools/tracing/rtla/tests/scripts/check-cgroup-match.sh
+++ b/tools/tracing/rtla/tests/scripts/check-cgroup-match.sh
@@ -1,10 +1,12 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
+# check-cgroup-match.sh <rtla_pid>
+# Check that all workload threads are in the same cgroup as rtla.
. "$(dirname $0)/lib/get_workload_pids.sh"
-rtla_pid=$(echo $(ps -o ppid= $$))
+rtla_pid=$1
rtla_cgroup=$(</proc/$rtla_pid/cgroup)
echo "RTLA cgroup: $rtla_cgroup"
-for pid in $(get_workload_pids)
+for pid in $(get_workload_pids $rtla_pid)
do
pid_cgroup=$(</proc/$pid/cgroup)
echo "PID $pid cgroup: $pid_cgroup"
diff --git a/tools/tracing/rtla/tests/scripts/check-cpus.sh b/tools/tracing/rtla/tests/scripts/check-cpus.sh
index 0b016d4a79459..dc0f146bf2dc5 100755
--- a/tools/tracing/rtla/tests/scripts/check-cpus.sh
+++ b/tools/tracing/rtla/tests/scripts/check-cpus.sh
@@ -1,8 +1,10 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
+# check-cpus.sh <rtla_pid> - print affinity of all rtla workload threads
. "$(dirname $0)/lib/get_workload_pids.sh"
+rtla_pid=$1
echo -n "Affinity of threads: "
-for pid in $(get_workload_pids)
+for pid in $(get_workload_pids $rtla_pid)
do
echo -n $(taskset -c -p $pid | cut -d ':' -f 2)
done
diff --git a/tools/tracing/rtla/tests/scripts/check-housekeeping-cpus.sh b/tools/tracing/rtla/tests/scripts/check-housekeeping-cpus.sh
index 4742f34efb494..3f282fdd7fbf6 100755
--- a/tools/tracing/rtla/tests/scripts/check-housekeeping-cpus.sh
+++ b/tools/tracing/rtla/tests/scripts/check-housekeeping-cpus.sh
@@ -1,4 +1,5 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
-pid=$(ps -o ppid= $$)
-echo "Affinity of threads:$(taskset -c -p $pid | cut -d ':' -f 2)"
+# check-housekeeping-cpus.sh <rtla_pid> - print affinity of the rtla process
+rtla_pid=$1
+echo "Affinity of threads:$(taskset -c -p $rtla_pid | cut -d ':' -f 2)"
diff --git a/tools/tracing/rtla/tests/scripts/check-priority.sh b/tools/tracing/rtla/tests/scripts/check-priority.sh
index b51d5232a8688..8896bde77fd5c 100755
--- a/tools/tracing/rtla/tests/scripts/check-priority.sh
+++ b/tools/tracing/rtla/tests/scripts/check-priority.sh
@@ -1,8 +1,12 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
+# check-priority.sh <rtla_pid> <sched_policy> <sched_priority>
+# Check that all rtla workload threads run with the given scheduling
+# policy and priority.
. "$(dirname $0)/lib/get_workload_pids.sh"
-for pid in $(get_workload_pids)
+rtla_pid=$1
+for pid in $(get_workload_pids $rtla_pid)
do
- chrt -p $pid | cut -d ':' -f 2 | head -n1 | grep "^ $1\$" >/dev/null
- chrt -p $pid | cut -d ':' -f 2 | tail -n1 | grep "^ $2\$" >/dev/null
+ chrt -p $pid | cut -d ':' -f 2 | head -n1 | grep "^ $2\$" >/dev/null
+ chrt -p $pid | cut -d ':' -f 2 | tail -n1 | grep "^ $3\$" >/dev/null
done && echo "Priorities are set correctly"
diff --git a/tools/tracing/rtla/tests/scripts/check-user-kernel-threads.sh b/tools/tracing/rtla/tests/scripts/check-user-kernel-threads.sh
index bb7ac510a7358..27064cb845e7e 100755
--- a/tools/tracing/rtla/tests/scripts/check-user-kernel-threads.sh
+++ b/tools/tracing/rtla/tests/scripts/check-user-kernel-threads.sh
@@ -1,10 +1,13 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
+# check-user-kernel-threads.sh <rtla_pid>
+# Print counts of kernel and user rtla workload threads
. "$(dirname $0)/lib/get_workload_pids.sh"
kthreadd_pid=$(pgrep ^kthreadd$)
+rtla_pid=$1
cnt_kernel=0
cnt_user=0
-for pid in $(get_workload_pids)
+for pid in $(get_workload_pids $rtla_pid)
do
if [ "$(echo $(ps -o ppid= $pid))" = "$kthreadd_pid" ]
then
diff --git a/tools/tracing/rtla/tests/scripts/lib/get_workload_pids.sh b/tools/tracing/rtla/tests/scripts/lib/get_workload_pids.sh
index d10a4e3b321dc..a18f6698dd413 100644
--- a/tools/tracing/rtla/tests/scripts/lib/get_workload_pids.sh
+++ b/tools/tracing/rtla/tests/scripts/lib/get_workload_pids.sh
@@ -1,11 +1,15 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
+# get_workload_pids <rtla_pid> - print PIDs of all rtla workload threads
+#
+# Kernel threads are children of kthreadd. User threads are children of
+# the rtla process itself, so its PID is needed to find them.
get_workload_pids() {
- local shell_pid=$$
- local rtla_pid=$(ps -o ppid= $shell_pid)
+ local rtla_pid=$1
# kernel threads
pgrep -P $(pgrep ^kthreadd$) -f '^\[?(osnoise|timerlat)/[0-9]+\]?$'
- # user threads
- pgrep -P $rtla_pid | grep -v "^$shell_pid$"
+ # user threads, excluding this script and the intermediate shell
+ # running it, if any
+ pgrep -P $rtla_pid | grep -vE "^($$|$PPID)$"
}
diff --git a/tools/tracing/rtla/tests/timerlat.t b/tools/tracing/rtla/tests/timerlat.t
index 1d317c851a0fa..6001c7a09be50 100644
--- a/tools/tracing/rtla/tests/timerlat.t
+++ b/tools/tracing/rtla/tests/timerlat.t
@@ -41,19 +41,19 @@ check_top_hist "disable auto-analysis" \
# Thread tests
check_top_hist "verify -P/--priority" \
- "timerlat TOOL -P F:1 -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-priority.sh SCHED_FIFO 1\"" \
+ "timerlat TOOL -P F:1 -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-priority.sh \\\$PPID SCHED_FIFO 1\"" \
2 "Priorities are set correctly"
check_top_hist "verify -C/--cgroup" \
- "timerlat TOOL -k -C -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-cgroup-match.sh\"" \
+ "timerlat TOOL -k -C -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-cgroup-match.sh \\\$PPID\"" \
2 "cgroup matches for all workload PIDs"
check_top_q_hist "verify -c/--cpus" \
- "timerlat TOOL -c 0 -d 10s -T 1 --on-threshold shell,command=$testdir/scripts/check-cpus.sh" 2 "^Affinity of threads: 0$"
+ "timerlat TOOL -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-cpus.sh \\\$PPID\"" 2 "^Affinity of threads: 0$"
check_top_q_hist "verify -H/--house-keeping" \
- "timerlat TOOL -H 0 -d 10s -T 1 --on-threshold shell,command=$testdir/scripts/check-housekeeping-cpus.sh" 2 "^Affinity of threads: 0$"
+ "timerlat TOOL -H 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-housekeeping-cpus.sh \\\$PPID\"" 2 "^Affinity of threads: 0$"
check_top_q_hist "verify -k/--kernel-threads" \
- "timerlat TOOL -k -c 0 -d 10s -T 1 --on-threshold shell,command=$testdir/scripts/check-user-kernel-threads.sh" 2 "1 kernel threads, 0 user threads"
+ "timerlat TOOL -k -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-user-kernel-threads.sh \\\$PPID\"" 2 "1 kernel threads, 0 user threads"
check_top_q_hist "verify -u/--user-threads" \
- "timerlat TOOL -u -c 0 -d 10s -T 1 --on-threshold shell,command=$testdir/scripts/check-user-kernel-threads.sh" 2 "0 kernel threads, 1 user threads"
+ "timerlat TOOL -u -c 0 -d 10s -T 1 --on-threshold shell,command=\"$testdir/scripts/check-user-kernel-threads.sh \\\$PPID\"" 2 "0 kernel threads, 1 user threads"
# Tracer option tests - verify that rtla correctly sets tracefs options
# Default tests: poison tracefs with wrong values, verify rtla resets to defaults
--
2.56.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-30 14:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 14:51 [PATCH] rtla/tests: Get rtla PID correctly when system shell is not bash Tomas Glozar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox