2023-10-23 13:17:22

by James Clark

[permalink] [raw]
Subject: [PATCH] perf tests: test_arm_coresight: Simplify source iteration

There are two reasons to do this, firstly there is a shellcheck warning
in cs_etm_dev_name(), which can be completely deleted. And secondly the
current iteration method doesn't support systems with both ETE and ETM
because it picks one or the other. There isn't a known system with this
configuration, but it could happen in the future.

Iterating over all the sources for each CPU can be done by going through
/sys/bus/event_source/devices/cs_etm/cpu* and following the symlink back
to the Coresight device in /sys/bus/coresight/devices. This will work
whether the device is ETE, ETM or any future name, and is much simpler
and doesn't require any hard coded version numbers

Suggested-by: Suzuki K Poulose <[email protected]>
Signed-off-by: James Clark <[email protected]>
---

This was discussed here previously:
https://lore.kernel.org/all/[email protected]/

I chose not to add a fixes tag like the original because shellcheck
isn't part of the build so it doesn't really fix any real issue yet and
is just a refactor.

tools/perf/tests/shell/test_arm_coresight.sh | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/tools/perf/tests/shell/test_arm_coresight.sh b/tools/perf/tests/shell/test_arm_coresight.sh
index fe78c4626e45..65dd85207125 100755
--- a/tools/perf/tests/shell/test_arm_coresight.sh
+++ b/tools/perf/tests/shell/test_arm_coresight.sh
@@ -11,19 +11,6 @@

glb_err=0

-cs_etm_dev_name() {
- cs_etm_path=$(find /sys/bus/event_source/devices/cs_etm/ -name cpu* -print -quit)
- trcdevarch=$(cat ${cs_etm_path}/mgmt/trcdevarch)
- archhver=$((($trcdevarch >> 12) & 0xf))
- archpart=$(($trcdevarch & 0xfff))
-
- if [ $archhver -eq 5 -a "$(printf "0x%X\n" $archpart)" = "0xA13" ] ; then
- echo "ete"
- else
- echo "etm"
- fi
-}
-
skip_if_no_cs_etm_event() {
perf list | grep -q 'cs_etm//' && return 0

@@ -149,7 +136,9 @@ arm_cs_iterate_devices() {

arm_cs_etm_traverse_path_test() {
# Iterate for every ETM device
- for dev in /sys/bus/coresight/devices/$(cs_etm_dev_name)*; do
+ for dev in /sys/bus/event_source/devices/cs_etm/cpu*; do
+ # Canonicalize the path
+ dev=`readlink -f $dev`

# Find the ETM device belonging to which CPU
cpu=`cat $dev/cpu`
--
2.34.1


2023-10-26 04:14:37

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH] perf tests: test_arm_coresight: Simplify source iteration

On Mon, Oct 23, 2023 at 6:17 AM James Clark <[email protected]> wrote:
>
> There are two reasons to do this, firstly there is a shellcheck warning
> in cs_etm_dev_name(), which can be completely deleted. And secondly the
> current iteration method doesn't support systems with both ETE and ETM
> because it picks one or the other. There isn't a known system with this
> configuration, but it could happen in the future.
>
> Iterating over all the sources for each CPU can be done by going through
> /sys/bus/event_source/devices/cs_etm/cpu* and following the symlink back
> to the Coresight device in /sys/bus/coresight/devices. This will work
> whether the device is ETE, ETM or any future name, and is much simpler
> and doesn't require any hard coded version numbers
>
> Suggested-by: Suzuki K Poulose <[email protected]>
> Signed-off-by: James Clark <[email protected]>

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

Thanks,
Ian

> ---
>
> This was discussed here previously:
> https://lore.kernel.org/all/[email protected]/
>
> I chose not to add a fixes tag like the original because shellcheck
> isn't part of the build so it doesn't really fix any real issue yet and
> is just a refactor.
>
> tools/perf/tests/shell/test_arm_coresight.sh | 17 +++--------------
> 1 file changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/tools/perf/tests/shell/test_arm_coresight.sh b/tools/perf/tests/shell/test_arm_coresight.sh
> index fe78c4626e45..65dd85207125 100755
> --- a/tools/perf/tests/shell/test_arm_coresight.sh
> +++ b/tools/perf/tests/shell/test_arm_coresight.sh
> @@ -11,19 +11,6 @@
>
> glb_err=0
>
> -cs_etm_dev_name() {
> - cs_etm_path=$(find /sys/bus/event_source/devices/cs_etm/ -name cpu* -print -quit)
> - trcdevarch=$(cat ${cs_etm_path}/mgmt/trcdevarch)
> - archhver=$((($trcdevarch >> 12) & 0xf))
> - archpart=$(($trcdevarch & 0xfff))
> -
> - if [ $archhver -eq 5 -a "$(printf "0x%X\n" $archpart)" = "0xA13" ] ; then
> - echo "ete"
> - else
> - echo "etm"
> - fi
> -}
> -
> skip_if_no_cs_etm_event() {
> perf list | grep -q 'cs_etm//' && return 0
>
> @@ -149,7 +136,9 @@ arm_cs_iterate_devices() {
>
> arm_cs_etm_traverse_path_test() {
> # Iterate for every ETM device
> - for dev in /sys/bus/coresight/devices/$(cs_etm_dev_name)*; do
> + for dev in /sys/bus/event_source/devices/cs_etm/cpu*; do
> + # Canonicalize the path
> + dev=`readlink -f $dev`
>
> # Find the ETM device belonging to which CPU
> cpu=`cat $dev/cpu`
> --
> 2.34.1
>

2023-10-26 05:33:00

by Leo Yan

[permalink] [raw]
Subject: Re: [PATCH] perf tests: test_arm_coresight: Simplify source iteration

On Mon, Oct 23, 2023 at 02:15:49PM +0100, James Clark wrote:
> There are two reasons to do this, firstly there is a shellcheck warning
> in cs_etm_dev_name(), which can be completely deleted. And secondly the
> current iteration method doesn't support systems with both ETE and ETM
> because it picks one or the other. There isn't a known system with this
> configuration, but it could happen in the future.
>
> Iterating over all the sources for each CPU can be done by going through
> /sys/bus/event_source/devices/cs_etm/cpu* and following the symlink back
> to the Coresight device in /sys/bus/coresight/devices. This will work
> whether the device is ETE, ETM or any future name, and is much simpler
> and doesn't require any hard coded version numbers
>
> Suggested-by: Suzuki K Poulose <[email protected]>
> Signed-off-by: James Clark <[email protected]>

Looks good to me. And I did a test for it:

Tested-by: Leo Yan <[email protected]>

2023-10-30 18:59:47

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH] perf tests: test_arm_coresight: Simplify source iteration

On Mon, 23 Oct 2023 14:15:49 +0100, James Clark wrote:
> There are two reasons to do this, firstly there is a shellcheck warning
> in cs_etm_dev_name(), which can be completely deleted. And secondly the
> current iteration method doesn't support systems with both ETE and ETM
> because it picks one or the other. There isn't a known system with this
> configuration, but it could happen in the future.
>
> Iterating over all the sources for each CPU can be done by going through
> /sys/bus/event_source/devices/cs_etm/cpu* and following the symlink back
> to the Coresight device in /sys/bus/coresight/devices. This will work
> whether the device is ETE, ETM or any future name, and is much simpler
> and doesn't require any hard coded version numbers
>
> [...]

Applied to perf-tools-next, thanks!