rtla/tests: Get rtla PID correctly when system shell is not bash
Subsystems (2)
Tomas Glozar
maintainerPATCH 1/1 rtla/tests: Get rtla PID correctly when system shell is not bash
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.
--- 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(-)
tools/tracing/rtla/tests/osnoise.t +4 -4
@@ -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" \
tools/tracing/rtla/tests/scripts/check-cgroup-match.sh +4 -2
@@ -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"
tools/tracing/rtla/tests/scripts/check-cpus.sh +3 -1
@@ -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
tools/tracing/rtla/tests/scripts/check-housekeeping-cpus.sh +3 -2
@@ -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)"
tools/tracing/rtla/tests/scripts/check-priority.sh +7 -3
@@ -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"
tools/tracing/rtla/tests/scripts/check-user-kernel-threads.sh +4 -1
@@ -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
tools/tracing/rtla/tests/scripts/lib/get_workload_pids.sh +8 -4
@@ -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)$" }
tools/tracing/rtla/tests/timerlat.t +6 -6
@@ -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
Signature · 1 line
2.56.0