perf stat: Allow no events to open if this is a "--null" run
Ian Rogers
reviewerPATCH 1/4 perf stat: Allow no events to open if this is a "--null" run
It is intended that a "--null" run doesn't open any events.
--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -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);
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH 2/4 libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map
Passing an empty map to perf_cpu_map__max triggered a SEGV. Explicitly test for the empty map.
--- tools/lib/perf/cpumap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tools/lib/perf/cpumap.c +6 -4
@@ -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'. */
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH 3/4 perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask
In reply to Ian RogersIf 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.
--- tools/perf/util/cpumap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/cpumap.c +7 -2
@@ -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 ) {
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH 4/4 perf tests stat: Add "--null" coverage
In reply to Ian RogersEnsure "--null" does a minimal run.
--- tools/perf/tests/shell/stat.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/perf/tests/shell/stat.sh +12 -0
@@ -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
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Quoted 13 lines · Ian Rogers
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 <[email protected]>--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/builtin-stat.c +0
-0
tools/perf/builtin-stat.c static int __run_perf_stat(int argc, const char **argv, int run_idx) · line 929
Quoted 8 lines
tools/perf/builtin-stat.c +1
-1@@ -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:
Thanks,
Ingo
Quoted 4 lines · Ingo Molnar
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
Ingo Molnar
Tested-byQuoted 11 lines · Ingo Molnar
Quoted 4 lines · Ingo Molnar
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.gitperf-tools-next
With all 4 patches applied to v6.18 'perf stat --null' works fine:
Thanks,
Ingo
Quoted 4 lines · Ingo Molnar
With all 4 patches applied to v6.18 'perf stat --null' works fine:
Tested-by Ingo Molnar <[email protected]>
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
Ian Rogers
reviewerQuoted 38 lines · Ingo Molnar
Quoted 4 lines · Ingo Molnar
With all 4 patches applied to v6.18 'perf stat --null' works fine:
Tested-by Ingo Molnar <[email protected]>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 1Performance 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: InterruptPerformance 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.
Quoted 4 lines
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/[email protected]/
Thanks,
Ian
Quoted 3 lines
Thanks,
Ingo