* [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run
@ 2025-12-01 23:09 Ian Rogers
2025-12-01 23:09 ` [PATCH v1 2/4] libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map Ian Rogers
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Ian Rogers @ 2025-12-01 23:09 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, linux-perf-users, linux-kernel
It is intended that a "--null" run doesn't open any events.
Fixes: 2cc7aa995ce9 ("perf stat: Refactor retry/skip/fatal error handling")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-stat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 5c06e9b61821..6410115ed9c5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -923,7 +923,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
goto err_out;
}
}
- if (!has_supported_counters) {
+ if (!has_supported_counters && !stat_config.null_run) {
evsel__open_strerror(evlist__first(evsel_list), &target, open_err,
msg, sizeof(msg));
ui__error("No supported events found.\n%s\n", msg);
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 2/4] libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map
2025-12-01 23:09 [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ian Rogers
@ 2025-12-01 23:09 ` Ian Rogers
2025-12-01 23:09 ` [PATCH v1 3/4] perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask Ian Rogers
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2025-12-01 23:09 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, linux-perf-users, linux-kernel
Cc: Ingo Molnar
Passing an empty map to perf_cpu_map__max triggered a SEGV. Explicitly
test for the empty map.
Reported-by: Ingo Molnar <mingo@kernel.org>
Closes: https://lore.kernel.org/linux-perf-users/aSwt7yzFjVJCEmVp@gmail.com/
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/lib/perf/cpumap.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
index 7e88417ba84d..4160e7d2e120 100644
--- a/tools/lib/perf/cpumap.c
+++ b/tools/lib/perf/cpumap.c
@@ -368,10 +368,12 @@ struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map)
.cpu = -1
};
- // cpu_map__trim_new() qsort()s it, cpu_map__default_new() sorts it as well.
- return __perf_cpu_map__nr(map) > 0
- ? __perf_cpu_map__cpu(map, __perf_cpu_map__nr(map) - 1)
- : result;
+ if (!map)
+ return result;
+
+ // The CPUs are always sorted and nr is always > 0 as 0 length map is
+ // encoded as NULL.
+ return __perf_cpu_map__cpu(map, __perf_cpu_map__nr(map) - 1);
}
/** Is 'b' a subset of 'a'. */
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 3/4] perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask
2025-12-01 23:09 [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ian Rogers
2025-12-01 23:09 ` [PATCH v1 2/4] libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map Ian Rogers
@ 2025-12-01 23:09 ` Ian Rogers
2025-12-01 23:09 ` [PATCH v1 4/4] perf tests stat: Add "--null" coverage Ian Rogers
2025-12-02 4:38 ` [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ingo Molnar
3 siblings, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2025-12-01 23:09 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, linux-perf-users, linux-kernel
If the perf_cpu_map is empty or is just the any CPU value, then early
return. Don't process the "any" CPU when creating the bitmap.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/cpumap.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 89570397a4b3..a80845038a5e 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -684,16 +684,21 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size)
unsigned char *bitmap;
struct perf_cpu c, last_cpu = perf_cpu_map__max(map);
- if (buf == NULL)
+ if (buf == NULL || size == 0)
return 0;
+ if (last_cpu.cpu < 0) {
+ buf[0] = '\0';
+ return 0;
+ }
+
bitmap = zalloc(last_cpu.cpu / 8 + 1);
if (bitmap == NULL) {
buf[0] = '\0';
return 0;
}
- perf_cpu_map__for_each_cpu(c, idx, map)
+ perf_cpu_map__for_each_cpu_skip_any(c, idx, map)
bitmap[c.cpu / 8] |= 1 << (c.cpu % 8);
for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) {
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 4/4] perf tests stat: Add "--null" coverage
2025-12-01 23:09 [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ian Rogers
2025-12-01 23:09 ` [PATCH v1 2/4] libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map Ian Rogers
2025-12-01 23:09 ` [PATCH v1 3/4] perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask Ian Rogers
@ 2025-12-01 23:09 ` Ian Rogers
2025-12-02 4:38 ` [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ingo Molnar
3 siblings, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2025-12-01 23:09 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, James Clark, linux-perf-users, linux-kernel
Cc: Ingo Molnar
Ensure "--null" does a minimal run.
Reported-by: Ingo Molnar <mingo@kernel.org>
Closes: https://lore.kernel.org/linux-perf-users/aSwt7yzFjVJCEmVp@gmail.com/
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/tests/shell/stat.sh | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh
index 985adc02749e..7885e875caf4 100755
--- a/tools/perf/tests/shell/stat.sh
+++ b/tools/perf/tests/shell/stat.sh
@@ -16,6 +16,17 @@ test_default_stat() {
echo "Basic stat command test [Success]"
}
+test_null_stat() {
+ echo "Null stat command test"
+ if ! perf stat --null true 2>&1 | grep -E -q "Performance counter stats for 'true':"
+ then
+ echo "Null stat command test [Failed]"
+ err=1
+ return
+ fi
+ echo "Null stat command test [Success]"
+}
+
test_stat_record_report() {
echo "stat record and report test"
if ! perf stat record -e task-clock -o - true | perf stat report -i - 2>&1 | \
@@ -212,6 +223,7 @@ test_hybrid() {
}
test_default_stat
+test_null_stat
test_stat_record_report
test_stat_record_script
test_stat_repeat_weak_groups
--
2.52.0.158.g65b55ccf14-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run
2025-12-01 23:09 [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ian Rogers
` (2 preceding siblings ...)
2025-12-01 23:09 ` [PATCH v1 4/4] perf tests stat: Add "--null" coverage Ian Rogers
@ 2025-12-02 4:38 ` Ingo Molnar
2025-12-02 4:41 ` Ingo Molnar
3 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2025-12-02 4:38 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
James Clark, linux-perf-users, linux-kernel
* Ian Rogers <irogers@google.com> wrote:
> It is intended that a "--null" run doesn't open any events.
>
> Fixes: 2cc7aa995ce9 ("perf stat: Refactor retry/skip/fatal error handling")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/builtin-stat.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 5c06e9b61821..6410115ed9c5 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -923,7 +923,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
> goto err_out;
> }
> }
> - if (!has_supported_counters) {
> + if (!has_supported_counters && !stat_config.null_run) {
> evsel__open_strerror(evlist__first(evsel_list), &target, open_err,
> msg, sizeof(msg));
> ui__error("No supported events found.\n%s\n", msg);
Note that without the cpumask workaround patch I sent
'perf stat --null' still segfaults on perf-tools-next
even with the above patch applied - I suppose that's
expected, right?
Other than that:
Tested-by: Ingo Molnar <mingo@kernel.org>
Thanks,
Ingo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run
2025-12-02 4:38 ` [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ingo Molnar
@ 2025-12-02 4:41 ` Ingo Molnar
2025-12-02 4:45 ` Ingo Molnar
0 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2025-12-02 4:41 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
James Clark, linux-perf-users, linux-kernel
* Ingo Molnar <mingo@kernel.org> wrote:
> Note that without the cpumask workaround patch I sent
> 'perf stat --null' still segfaults on perf-tools-next
> even with the above patch applied - I suppose that's
> expected, right?
Ignore me, I just saw your fix series:
git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
Thanks,
Ingo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run
2025-12-02 4:41 ` Ingo Molnar
@ 2025-12-02 4:45 ` Ingo Molnar
2025-12-02 4:52 ` Ingo Molnar
0 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2025-12-02 4:45 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
James Clark, linux-perf-users, linux-kernel
* Ingo Molnar <mingo@kernel.org> wrote:
>
> * Ingo Molnar <mingo@kernel.org> wrote:
>
> > Note that without the cpumask workaround patch I sent
> > 'perf stat --null' still segfaults on perf-tools-next
> > even with the above patch applied - I suppose that's
> > expected, right?
>
> Ignore me, I just saw your fix series:
>
> git git://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
With all 4 patches applied to v6.18 'perf stat --null'
works fine:
Tested-by: Ingo Molnar <mingo@kernel.org>
Thanks,
Ingo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run
2025-12-02 4:45 ` Ingo Molnar
@ 2025-12-02 4:52 ` Ingo Molnar
2025-12-03 21:49 ` Ian Rogers
0 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2025-12-02 4:52 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
James Clark, linux-perf-users, linux-kernel
* Ingo Molnar <mingo@kernel.org> wrote:
> With all 4 patches applied to v6.18 'perf stat --null'
> works fine:
>
> Tested-by: Ingo Molnar <mingo@kernel.org>
BTW., there's a long-standing perf-stat --repeat bug
where signals don't seem to get properly propagated.
The following command takes 10 seconds to run, as
expected:
starship:~/tip> perf stat --null --repeat 10 sleep 1
Performance counter stats for 'sleep 1' (10 runs):
1.0026669 +- 0.0000503 seconds time elapsed ( +- 0.01% )
But if I try to interrupt the test:
starship:~/tip> perf stat --null --repeat 10 sleep 1
^Csleep: Interrupt
^Csleep: Interrupt
Performance counter stats for 'sleep 1' (10 runs):
0.9250 +- 0.0543 seconds time elapsed ( +- 5.87% )
The Ctrl-C only propagates to the <command>, interrupts
it (as can be seen from the shortened total runtime
that is less than 10 seconds), and otherwise results in
both an incorrect measurement and a misleading output
of the partial results.
Furthermore, the test runs to full completion - which
can be annoying if you happen to use high --repeat
counts like I sometimes do. I have to Ctrl-Z and
killall -9 perf to kill such instances.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run
2025-12-02 4:52 ` Ingo Molnar
@ 2025-12-03 21:49 ` Ian Rogers
0 siblings, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2025-12-03 21:49 UTC (permalink / raw)
To: Ingo Molnar
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
James Clark, linux-perf-users, linux-kernel
On Mon, Dec 1, 2025 at 8:52 PM Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * Ingo Molnar <mingo@kernel.org> wrote:
>
> > With all 4 patches applied to v6.18 'perf stat --null'
> > works fine:
> >
> > Tested-by: Ingo Molnar <mingo@kernel.org>
>
> BTW., there's a long-standing perf-stat --repeat bug
> where signals don't seem to get properly propagated.
>
> The following command takes 10 seconds to run, as
> expected:
>
> starship:~/tip> perf stat --null --repeat 10 sleep 1
>
> Performance counter stats for 'sleep 1' (10 runs):
>
> 1.0026669 +- 0.0000503 seconds time elapsed ( +- 0.01% )
>
> But if I try to interrupt the test:
>
> starship:~/tip> perf stat --null --repeat 10 sleep 1
> ^Csleep: Interrupt
> ^Csleep: Interrupt
>
> Performance counter stats for 'sleep 1' (10 runs):
>
> 0.9250 +- 0.0543 seconds time elapsed ( +- 5.87% )
>
>
> The Ctrl-C only propagates to the <command>, interrupts
> it (as can be seen from the shortened total runtime
> that is less than 10 seconds), and otherwise results in
> both an incorrect measurement and a misleading output
> of the partial results.
>
> Furthermore, the test runs to full completion - which
> can be annoying if you happen to use high --repeat
> counts like I sometimes do. I have to Ctrl-Z and
> killall -9 perf to kill such instances.
I've added a patch that hopefully fixes this in the v2 patch series:
https://lore.kernel.org/lkml/20251203214706.112174-8-irogers@google.com/
Thanks,
Ian
> Thanks,
>
> Ingo
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-12-03 21:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-01 23:09 [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ian Rogers
2025-12-01 23:09 ` [PATCH v1 2/4] libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map Ian Rogers
2025-12-01 23:09 ` [PATCH v1 3/4] perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask Ian Rogers
2025-12-01 23:09 ` [PATCH v1 4/4] perf tests stat: Add "--null" coverage Ian Rogers
2025-12-02 4:38 ` [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ingo Molnar
2025-12-02 4:41 ` Ingo Molnar
2025-12-02 4:45 ` Ingo Molnar
2025-12-02 4:52 ` Ingo Molnar
2025-12-03 21:49 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).