* [PATCH V2] perf test: Add a perf event fallback test
@ 2025-11-12 16:48 Zide Chen
2025-11-12 17:04 ` Ian Rogers
2025-11-14 18:35 ` Namhyung Kim
0 siblings, 2 replies; 3+ messages in thread
From: Zide Chen @ 2025-11-12 16:48 UTC (permalink / raw)
To: Namhyung Kim, Peter Zijlstra, Adrian Hunter, Ingo Molnar,
Jiri Olsa, Mark Rutland, Ian Rogers, Arnaldo Carvalho de Melo,
Alexander Shishkin
Cc: linux-kernel, linux-perf-users, thomas.falcon, dapeng1.mi,
xudong.hao, Zide Chen
This adds test cases to verify the precise ip fallback logic:
- If the system supports precise ip, for an event given with the maximum
precision level, it should be able to decrease precise_ip to find a
supported level.
- The same fallback behavior should also work in more complex scenarios,
such as event groups or when PEBS is involved
Additional fallback tests, such as those covering missing feature cases,
can be added in the future.
Suggested-by: Ian Rogers <irogers@google.com>
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.com>
---
v2:
- Incorporated Namhyung's suggestion to change cycles:ppp to cycles:P
.../tests/shell/test_event_open_fallback.sh | 86 +++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100755 tools/perf/tests/shell/test_event_open_fallback.sh
diff --git a/tools/perf/tests/shell/test_event_open_fallback.sh b/tools/perf/tests/shell/test_event_open_fallback.sh
new file mode 100755
index 000000000000..9c411153c01b
--- /dev/null
+++ b/tools/perf/tests/shell/test_event_open_fallback.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+# Perf event open fallback test
+# SPDX-License-Identifier: GPL-2.0
+
+skip_cnt=0
+ok_cnt=0
+err_cnt=0
+
+cleanup()
+{
+ rm -f perf.data
+ rm -f perf.data.old
+ trap - EXIT TERM INT
+}
+
+trap_cleanup()
+{
+ cleanup
+ exit 1
+}
+
+trap trap_cleanup EXIT TERM INT
+
+perf_record()
+{
+ perf record "$@" -- true 1>/dev/null 2>&1
+}
+
+test_decrease_precise_ip()
+{
+ echo "Decrease precise ip test"
+
+ perf list pmu | grep -q 'cycles' || return 2
+
+ if ! perf_record -e cycles; then
+ return 2
+ fi
+
+ # It should reduce precision level down to 0 if needed.
+ if ! perf_record -e cycles:P; then
+ return 1
+ fi
+ return 0
+}
+
+test_decrease_precise_ip_complicated()
+{
+ echo "Decrease precise ip test (complicated case)"
+
+ perf list pmu | grep -q 'mem-loads-aux' || return 2
+
+ if ! perf_record -e '{cpu/mem-loads-aux/S,cpu/mem-loads/PS}'; then
+ return 1
+ fi
+ return 0
+}
+
+count_result()
+{
+ if [ "$1" -eq 2 ] ; then
+ skip_cnt=$((skip_cnt + 1))
+ return
+ fi
+ if [ "$1" -eq 0 ] ; then
+ ok_cnt=$((ok_cnt + 1))
+ return
+ fi
+ err_cnt=$((err_cnt + 1))
+}
+
+ret=0
+test_decrease_precise_ip || ret=$? ; count_result $ret ; ret=0
+test_decrease_precise_ip_complicated || ret=$? ; count_result $ret ; ret=0
+
+cleanup
+
+if [ ${err_cnt} -gt 0 ] ; then
+ exit 1
+fi
+
+if [ ${ok_cnt} -gt 0 ] ; then
+ exit 0
+fi
+
+# Skip
+exit 2
--
2.51.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] perf test: Add a perf event fallback test
2025-11-12 16:48 [PATCH V2] perf test: Add a perf event fallback test Zide Chen
@ 2025-11-12 17:04 ` Ian Rogers
2025-11-14 18:35 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2025-11-12 17:04 UTC (permalink / raw)
To: Zide Chen
Cc: Namhyung Kim, Peter Zijlstra, Adrian Hunter, Ingo Molnar,
Jiri Olsa, Mark Rutland, Arnaldo Carvalho de Melo,
Alexander Shishkin, linux-kernel, linux-perf-users,
thomas.falcon, dapeng1.mi, xudong.hao
On Wed, Nov 12, 2025 at 8:55 AM Zide Chen <zide.chen@intel.com> wrote:
>
> This adds test cases to verify the precise ip fallback logic:
>
> - If the system supports precise ip, for an event given with the maximum
> precision level, it should be able to decrease precise_ip to find a
> supported level.
> - The same fallback behavior should also work in more complex scenarios,
> such as event groups or when PEBS is involved
>
> Additional fallback tests, such as those covering missing feature cases,
> can be added in the future.
>
> Suggested-by: Ian Rogers <irogers@google.com>
> Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
> Signed-off-by: Zide Chen <zide.chen@intel.com>
> ---
> v2:
> - Incorporated Namhyung's suggestion to change cycles:ppp to cycles:P
>
> .../tests/shell/test_event_open_fallback.sh | 86 +++++++++++++++++++
> 1 file changed, 86 insertions(+)
> create mode 100755 tools/perf/tests/shell/test_event_open_fallback.sh
>
> diff --git a/tools/perf/tests/shell/test_event_open_fallback.sh b/tools/perf/tests/shell/test_event_open_fallback.sh
> new file mode 100755
> index 000000000000..9c411153c01b
> --- /dev/null
> +++ b/tools/perf/tests/shell/test_event_open_fallback.sh
> @@ -0,0 +1,86 @@
> +#!/bin/bash
> +# Perf event open fallback test
> +# SPDX-License-Identifier: GPL-2.0
> +
> +skip_cnt=0
> +ok_cnt=0
> +err_cnt=0
> +
> +cleanup()
> +{
> + rm -f perf.data
> + rm -f perf.data.old
> + trap - EXIT TERM INT
> +}
> +
> +trap_cleanup()
> +{
> + cleanup
> + exit 1
> +}
> +
> +trap trap_cleanup EXIT TERM INT
> +
> +perf_record()
> +{
> + perf record "$@" -- true 1>/dev/null 2>&1
> +}
> +
> +test_decrease_precise_ip()
> +{
> + echo "Decrease precise ip test"
> +
> + perf list pmu | grep -q 'cycles' || return 2
nit: I don't think this test can ever fail.
Reviewed-by: Ian Rogers <irogers!@google.com>
Thanks,
Ian
> +
> + if ! perf_record -e cycles; then
> + return 2
> + fi
> +
> + # It should reduce precision level down to 0 if needed.
> + if ! perf_record -e cycles:P; then
> + return 1
> + fi
> + return 0
> +}
> +
> +test_decrease_precise_ip_complicated()
> +{
> + echo "Decrease precise ip test (complicated case)"
> +
> + perf list pmu | grep -q 'mem-loads-aux' || return 2
> +
> + if ! perf_record -e '{cpu/mem-loads-aux/S,cpu/mem-loads/PS}'; then
> + return 1
> + fi
> + return 0
> +}
> +
> +count_result()
> +{
> + if [ "$1" -eq 2 ] ; then
> + skip_cnt=$((skip_cnt + 1))
> + return
> + fi
> + if [ "$1" -eq 0 ] ; then
> + ok_cnt=$((ok_cnt + 1))
> + return
> + fi
> + err_cnt=$((err_cnt + 1))
> +}
> +
> +ret=0
> +test_decrease_precise_ip || ret=$? ; count_result $ret ; ret=0
> +test_decrease_precise_ip_complicated || ret=$? ; count_result $ret ; ret=0
> +
> +cleanup
> +
> +if [ ${err_cnt} -gt 0 ] ; then
> + exit 1
> +fi
> +
> +if [ ${ok_cnt} -gt 0 ] ; then
> + exit 0
> +fi
> +
> +# Skip
> +exit 2
> --
> 2.51.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] perf test: Add a perf event fallback test
2025-11-12 16:48 [PATCH V2] perf test: Add a perf event fallback test Zide Chen
2025-11-12 17:04 ` Ian Rogers
@ 2025-11-14 18:35 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-11-14 18:35 UTC (permalink / raw)
To: Peter Zijlstra, Adrian Hunter, Ingo Molnar, Jiri Olsa,
Mark Rutland, Ian Rogers, Arnaldo Carvalho de Melo,
Alexander Shishkin, Zide Chen
Cc: linux-kernel, linux-perf-users, thomas.falcon, dapeng1.mi, xudong.hao
On Wed, 12 Nov 2025 08:48:23 -0800, Zide Chen wrote:
> This adds test cases to verify the precise ip fallback logic:
>
> - If the system supports precise ip, for an event given with the maximum
> precision level, it should be able to decrease precise_ip to find a
> supported level.
> - The same fallback behavior should also work in more complex scenarios,
> such as event groups or when PEBS is involved
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-14 18:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-12 16:48 [PATCH V2] perf test: Add a perf event fallback test Zide Chen
2025-11-12 17:04 ` Ian Rogers
2025-11-14 18:35 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®