]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf test: Ensure lock contention using pipe mode
authorJan Polensky <japo@linux.ibm.com>
Fri, 25 Jul 2025 17:08:01 +0000 (19:08 +0200)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 30 Jul 2025 20:38:53 +0000 (13:38 -0700)
The 'kernel lock contention analysis test' requires reliable triggering
of lock contention. On some systems, previous benchmark calls failed to
generate sufficient contention due to low system activity or resource
limits.

This patch adds the -p (pipe) option to all calls of perf bench sched
messaging, ensuring consistent lock contention without relying on
socket-based communication.

Suggested-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Link: https://lore.kernel.org/r/20250725170801.3176678-1-japo@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/tests/shell/lock_contention.sh

index dde5bc737eb26bf52be81719423610506300b91b..d33d9e4392b065ba50218a0b595f052f4c23a5b7 100755 (executable)
@@ -44,7 +44,7 @@ check() {
 test_record()
 {
        echo "Testing perf lock record and perf lock contention"
-       perf lock record -o ${perfdata} -- perf bench sched messaging > /dev/null 2>&1
+       perf lock record -o ${perfdata} -- perf bench sched messaging -p > /dev/null 2>&1
        # the output goes to the stderr and we expect only 1 output (-E 1)
        perf lock contention -i ${perfdata} -E 1 -q 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
@@ -64,7 +64,7 @@ test_bpf()
        fi
 
        # the perf lock contention output goes to the stderr
-       perf lock con -a -b -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
@@ -75,7 +75,7 @@ test_bpf()
 test_record_concurrent()
 {
        echo "Testing perf lock record and perf lock contention at the same time"
-       perf lock record -o- -- perf bench sched messaging 2> /dev/null | \
+       perf lock record -o- -- perf bench sched messaging -p 2> /dev/null | \
        perf lock contention -i- -E 1 -q 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l)"
@@ -99,7 +99,7 @@ test_aggr_task()
        fi
 
        # the perf lock contention output goes to the stderr
-       perf lock con -a -b -t -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -t -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
@@ -122,7 +122,7 @@ test_aggr_addr()
        fi
 
        # the perf lock contention output goes to the stderr
-       perf lock con -a -b -l -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -l -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
@@ -140,7 +140,7 @@ test_aggr_cgroup()
        fi
 
        # the perf lock contention output goes to the stderr
-       perf lock con -a -b -g -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -g -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result count is not 1:" "$(cat "${result}" | wc -l)"
                err=1
@@ -162,7 +162,7 @@ test_type_filter()
                return
        fi
 
-       perf lock con -a -b -Y spinlock -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -Y spinlock -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(grep -c -v spinlock "${result}")" != "0" ]; then
                echo "[Fail] BPF result should not have non-spinlocks:" "$(cat "${result}")"
                err=1
@@ -194,7 +194,7 @@ test_lock_filter()
                return
        fi
 
-       perf lock con -a -b -L tasklist_lock -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -L tasklist_lock -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(grep -c -v "${test_lock_filter_type}" "${result}")" != "0" ]; then
                echo "[Fail] BPF result should not have non-${test_lock_filter_type} locks:" "$(cat "${result}")"
                err=1
@@ -222,7 +222,7 @@ test_stack_filter()
                return
        fi
 
-       perf lock con -a -b -S unix_stream -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -S unix_stream -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result should have a lock from unix_stream:" "$(cat "${result}")"
                err=1
@@ -250,7 +250,7 @@ test_aggr_task_stack_filter()
                return
        fi
 
-       perf lock con -a -b -t -S unix_stream -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -t -S unix_stream -E 1 -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result should have a task from unix_stream:" "$(cat "${result}")"
                err=1
@@ -266,7 +266,7 @@ test_cgroup_filter()
                return
        fi
 
-       perf lock con -a -b -g -E 1 -F wait_total -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -g -E 1 -F wait_total -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result should have a cgroup result:" "$(cat "${result}")"
                err=1
@@ -274,7 +274,7 @@ test_cgroup_filter()
        fi
 
        cgroup=$(cat "${result}" | awk '{ print $3 }')
-       perf lock con -a -b -g -E 1 -G "${cgroup}" -q -- perf bench sched messaging > /dev/null 2> ${result}
+       perf lock con -a -b -g -E 1 -G "${cgroup}" -q -- perf bench sched messaging -p > /dev/null 2> ${result}
        if [ "$(cat "${result}" | wc -l)" != "1" ]; then
                echo "[Fail] BPF result should have a result with cgroup filter:" "$(cat "${cgroup}")"
                err=1
@@ -309,7 +309,7 @@ test_csv_output()
        fi
 
        # the perf lock contention output goes to the stderr
-       perf lock con -a -b -E 1 -x , --output ${result} -- perf bench sched messaging > /dev/null 2>&1
+       perf lock con -a -b -E 1 -x , --output ${result} -- perf bench sched messaging -p > /dev/null 2>&1
        output=$(grep -v "^#" ${result} | tr -d -c , | wc -c)
        if [ "${header}" != "${output}" ]; then
                echo "[Fail] BPF result does not match the number of commas: ${header} != ${output}"