Skip to contentSkip to conversation

perf test: Increase load in lock contention test on low-activity systems

RFC PATCH In review Jan Polensky 3 participants 5 messages Jul 9, 2025 – Jul 26, 2025 perf events

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 perf test: Increase load in lock contention test on low-activity systems

On low-activity systems, the 'kernel lock contention analysis test' often fails due to insufficient system load. To address this, the test now increases load by using multiple groups and threads in 'perf bench sched messaging', scaled to the number of available CPUs.

---
 tools/perf/tests/shell/lock_contention.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lock_contention.sh +2 -1
index 30d195d4c62f..e859e1503b5c 100755
@@ -44,7 +44,8 @@ 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 \
+		--group "$(nproc)" --thread "$(nproc)" > /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

--
2.48.1

Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Jan Polensky

On low-activity systems, the 'kernel lock contention analysis test' often fails due to insufficient system load. To address this, the test now increases load by using multiple groups and threads in 'perf bench sched messaging', scaled to the number of available CPUs.

---
 tools/perf/tests/shell/lock_contention.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lock_contention.sh +2 -2
index 30d195d4c62f..e859e1503b5c 100755
@@ -44,7 +44,8 @@ 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 \
+		--group "$(nproc)" --thread "$(nproc)" > /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
--
Quoted 3 lines

2.48.1

Signature · 9 lines
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH

Vorsitzender des Aufsichtsrats: Wolfgang Wendt

Geschäftsführung: David Faller

Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
maintainer
#2 lore raw
In reply to Jan Polensky

Hello,

Quoted 15 lines · Jan Polensky

On low-activity systems, the 'kernel lock contention analysis test' often fails due to insufficient system load. To address this, the test now increases load by using multiple groups and threads in 'perf bench sched messaging', scaled to the number of available CPUs.

---
 tools/perf/tests/shell/lock_contention.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lock_contention.sh +0 -0
index 30d195d4c62f..e859e1503b5c 100755

tools/perf/tests/shell/lock_contention.sh check() { · line 48

Quoted 6 lines
tools/perf/tests/shell/lock_contention.sh +2 -1
@@ -44,7 +44,8 @@ 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 \
+		--group "$(nproc)" --thread "$(nproc)" > /dev/null 2>&1
  $ perf bench sched messaging -h
  # Running 'sched/messaging' benchmark:

Usage: perf bench sched messaging <options>

      -g, --group <n>       Specify number of groups
      -l, --nr_loops <n>    Specify the number of loops to run (default: 100)
      -p, --pipe            Use pipe() instead of socketpair()
      -t, --thread          Be multi thread instead of multi process

The default value of --group option is 10 so it can be smaller on tiny systems. Note that it'd create 20 tasks for each group (I don't think we have an option to control this).

Also --thread option doesn't take an argument so the number will be ignored.

More importantly, there are several instances of this workload. Probably we want to change all of them by introducing a shell variable. But I'm a bit afraid how much overhead it'd bring up.

Thanks,
Namhyung

Quoted 6 lines
tools/perf/tests/shell/lock_contention.sh +0 -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
--

2.48.1

#3 lore raw

Hello Namhyung,

Quoted 9 lines · Namhyung Kim

Hello,

Quoted 7 lines · Jan Polensky

On low-activity systems, the 'kernel lock contention analysis test' often fails due to insufficient system load. To address this, the test now increases load by using multiple groups and threads in 'perf bench sched messaging', scaled to the number of available CPUs.

---

[skip]

Quoted 3 lines

More importantly, there are several instances of this workload. Probably we want to change all of them by introducing a shell variable.

You're right — introducing a shell variable makes sense, especially since there are 13 identical calls. However, I’m slightly concerned that this might reduce readability. We might also consider an alternative solution to avoid this.

Quoted 1 line

But I'm a bit afraid how much overhead it'd bring up.

Indeed, using the --group parameter on large systems can lead to issues. For example:

[root@localhost perf]# ./perf stat -- perf bench sched messaging --group $(nproc) --thread # Running 'sched/messaging' benchmark:
perf: socketpair(): Too many open files

To avoid this, I suggest following the approach proposed by Thomas Richter ([email protected]), using the -p (pipe) mode instead:

perf bench sched messaging -p

The pipe-based solution generates sufficient load and lock contention for the test, while avoiding the use of sockets and their associated file descriptor limits.

I’ll incorporate these changes and send the next version shortly.

Thanks again for your feedback – it's much appreciated.

Best regards,
Jan

maintainer
#4 lore raw
Quoted 11 lines · Jan Polensky

Hello Namhyung,

Quoted 9 lines · Namhyung Kim

Hello,

Quoted 7 lines · Jan Polensky

On low-activity systems, the 'kernel lock contention analysis test' often fails due to insufficient system load. To address this, the test now increases load by using multiple groups and threads in 'perf bench sched messaging', scaled to the number of available CPUs.

---

Quoted 8 lines

[skip]

Quoted 3 lines

More importantly, there are several instances of this workload. Probably we want to change all of them by introducing a shell variable.

You're right — introducing a shell variable makes sense, especially since there are 13 identical calls. However, I’m slightly concerned that this might reduce readability. We might also consider an alternative solution to avoid this.

We already have similar code in other places like record.sh.

Thanks,
Namhyung

Quoted 23 lines
Quoted 1 line

But I'm a bit afraid how much overhead it'd bring up.

Indeed, using the --group parameter on large systems can lead to issues. For example:

[root@localhost perf]# ./perf stat -- perf bench sched messaging --group $(nproc) --thread # Running 'sched/messaging' benchmark:
perf: socketpair(): Too many open files

To avoid this, I suggest following the approach proposed by Thomas Richter ([email protected]), using the -p (pipe) mode instead:

perf bench sched messaging -p

The pipe-based solution generates sufficient load and lock contention for the test, while avoiding the use of sockets and their associated file descriptor limits.

I’ll incorporate these changes and send the next version shortly.

Thanks again for your feedback – it's much appreciated.

Best regards,
Jan