2022-09-24 00:46:30

by Namhyung Kim

[permalink] [raw]
Subject: [PATCH 3/3] perf test: Add kernel lock contention test

Add a new shell test to check if both normal perf lock record +
contention and BPF (with -b) option are working. Use perf bench
sched messaging as a workload since it'd create some contention for
sending and receiving messages.

Signed-off-by: Namhyung Kim <[email protected]>
---
tools/perf/tests/shell/lock_contention.sh | 73 +++++++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100755 tools/perf/tests/shell/lock_contention.sh

diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
new file mode 100755
index 000000000000..04bf604e3c6f
--- /dev/null
+++ b/tools/perf/tests/shell/lock_contention.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+# kernel lock contention analysis test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+result=$(mktemp /tmp/__perf_test.result.XXXXX)
+
+cleanup() {
+ rm -f ${perfdata}
+ rm -f ${result}
+ trap - exit term int
+}
+
+trap_cleanup() {
+ cleanup
+ exit ${err}
+}
+trap trap_cleanup exit term int
+
+check() {
+ if [ `id -u` != 0 ]; then
+ echo "[Skip] No root permission"
+ err=2
+ exit
+ fi
+
+ if ! perf list | grep -q lock:contention_begin; then
+ echo "[Skip] No lock contention tracepoints"
+ err=2
+ exit
+ fi
+}
+
+test_record()
+{
+ echo "Testing perf lock record and perf lock contention"
+ perf lock record -o ${perfdata} -- perf bench sched messaging > /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
+ echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
+ err=1
+ exit
+ fi
+}
+
+test_bpf()
+{
+ echo "Testing perf lock contention --use-bpf"
+
+ if ! perf lock con -b true > /dev/null 2>&1 ; then
+ echo "[Skip] No BPF support"
+ exit
+ 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}
+ if [ $(cat "${result}" | wc -l) != "1" ]; then
+ echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
+ err=1
+ exit
+ fi
+}
+
+check
+
+test_record
+test_bpf
+
+exit ${err}
--
2.37.3.998.g577e59143f-goog


2022-09-24 03:24:10

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH 3/3] perf test: Add kernel lock contention test

On Fri, Sep 23, 2022 at 5:42 PM Namhyung Kim <[email protected]> wrote:
>
> Add a new shell test to check if both normal perf lock record +
> contention and BPF (with -b) option are working. Use perf bench
> sched messaging as a workload since it'd create some contention for
> sending and receiving messages.
>
> Signed-off-by: Namhyung Kim <[email protected]>

Great!

Acked-by: Ian Rogers <[email protected]>

Thanks,
Ian


> ---
> tools/perf/tests/shell/lock_contention.sh | 73 +++++++++++++++++++++++
> 1 file changed, 73 insertions(+)
> create mode 100755 tools/perf/tests/shell/lock_contention.sh
>
> diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
> new file mode 100755
> index 000000000000..04bf604e3c6f
> --- /dev/null
> +++ b/tools/perf/tests/shell/lock_contention.sh
> @@ -0,0 +1,73 @@
> +#!/bin/sh
> +# kernel lock contention analysis test
> +# SPDX-License-Identifier: GPL-2.0
> +
> +set -e
> +
> +err=0
> +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +result=$(mktemp /tmp/__perf_test.result.XXXXX)
> +
> +cleanup() {
> + rm -f ${perfdata}
> + rm -f ${result}
> + trap - exit term int
> +}
> +
> +trap_cleanup() {
> + cleanup
> + exit ${err}
> +}
> +trap trap_cleanup exit term int
> +
> +check() {
> + if [ `id -u` != 0 ]; then
> + echo "[Skip] No root permission"
> + err=2
> + exit
> + fi
> +
> + if ! perf list | grep -q lock:contention_begin; then
> + echo "[Skip] No lock contention tracepoints"
> + err=2
> + exit
> + fi
> +}
> +
> +test_record()
> +{
> + echo "Testing perf lock record and perf lock contention"
> + perf lock record -o ${perfdata} -- perf bench sched messaging > /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
> + echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
> + err=1
> + exit
> + fi
> +}
> +
> +test_bpf()
> +{
> + echo "Testing perf lock contention --use-bpf"
> +
> + if ! perf lock con -b true > /dev/null 2>&1 ; then
> + echo "[Skip] No BPF support"
> + exit
> + 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}
> + if [ $(cat "${result}" | wc -l) != "1" ]; then
> + echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
> + err=1
> + exit
> + fi
> +}
> +
> +check
> +
> +test_record
> +test_bpf
> +
> +exit ${err}
> --
> 2.37.3.998.g577e59143f-goog
>

2022-09-24 08:21:00

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH 3/3] perf test: Add kernel lock contention test

On 24/09/22 03:42, Namhyung Kim wrote:
> Add a new shell test to check if both normal perf lock record +
> contention and BPF (with -b) option are working. Use perf bench
> sched messaging as a workload since it'd create some contention for
> sending and receiving messages.
>
> Signed-off-by: Namhyung Kim <[email protected]>

There are a few things below that don't need to be fixed but
are perhaps things to be aware of.

Nevertheless:

Acked-by: Adrian Hunter <[email protected]>


> ---
> tools/perf/tests/shell/lock_contention.sh | 73 +++++++++++++++++++++++
> 1 file changed, 73 insertions(+)
> create mode 100755 tools/perf/tests/shell/lock_contention.sh
>
> diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
> new file mode 100755
> index 000000000000..04bf604e3c6f
> --- /dev/null
> +++ b/tools/perf/tests/shell/lock_contention.sh
> @@ -0,0 +1,73 @@
> +#!/bin/sh
> +# kernel lock contention analysis test
> +# SPDX-License-Identifier: GPL-2.0

All the shell tests are like this, but checkpatch says:

WARNING: Missing or malformed SPDX-License-Identifier tag in line 2
#24: FILE: tools/perf/tests/shell/lock_contention.sh:2:
+# kernel lock contention analysis test

WARNING: Misplaced SPDX-License-Identifier tag - use line 2 instead
#25: FILE: tools/perf/tests/shell/lock_contention.sh:3:
+# SPDX-License-Identifier: GPL-2.0

> +
> +set -e
> +
> +err=0
> +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +result=$(mktemp /tmp/__perf_test.result.XXXXX)
> +
> +cleanup() {
> + rm -f ${perfdata}
> + rm -f ${result}
> + trap - exit term int
> +}
> +
> +trap_cleanup() {
> + cleanup

With "set -e", a command failure will end up here with err=0

> + exit ${err}
> +}
> +trap trap_cleanup exit term int

shellcheck -S warning tools/perf/tests/shell/lock_contention.sh

In tools/perf/tests/shell/lock_contention.sh line 14:
trap - exit term int
^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
^-^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.


In tools/perf/tests/shell/lock_contention.sh line 21:
trap trap_cleanup exit term int
^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
^-^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.


> +
> +check() {
> + if [ `id -u` != 0 ]; then
> + echo "[Skip] No root permission"
> + err=2
> + exit
> + fi
> +
> + if ! perf list | grep -q lock:contention_begin; then
> + echo "[Skip] No lock contention tracepoints"
> + err=2
> + exit
> + fi
> +}
> +
> +test_record()
> +{
> + echo "Testing perf lock record and perf lock contention"
> + perf lock record -o ${perfdata} -- perf bench sched messaging > /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
> + echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
> + err=1
> + exit
> + fi
> +}
> +
> +test_bpf()
> +{
> + echo "Testing perf lock contention --use-bpf"
> +
> + if ! perf lock con -b true > /dev/null 2>&1 ; then
> + echo "[Skip] No BPF support"
> + exit
> + 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}
> + if [ $(cat "${result}" | wc -l) != "1" ]; then
> + echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
> + err=1
> + exit
> + fi
> +}
> +
> +check
> +
> +test_record
> +test_bpf
> +
> +exit ${err}

2022-09-24 16:53:27

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH 3/3] perf test: Add kernel lock contention test

On Sat, Sep 24, 2022 at 1:10 AM Adrian Hunter <[email protected]> wrote:
>
> On 24/09/22 03:42, Namhyung Kim wrote:
> > Add a new shell test to check if both normal perf lock record +
> > contention and BPF (with -b) option are working. Use perf bench
> > sched messaging as a workload since it'd create some contention for
> > sending and receiving messages.
> >
> > Signed-off-by: Namhyung Kim <[email protected]>
>
> There are a few things below that don't need to be fixed but
> are perhaps things to be aware of.
>
> Nevertheless:
>
> Acked-by: Adrian Hunter <[email protected]>

Thanks Adrian, I'll install and run shellcheck next time.

Arnaldo, please let me know if you want me to resend it
with the suggested changes.

Thanks,
Namhyung