Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Merge event counts from all hybrid PMUs

For hybrid events, by default stat aggregates and reports the event counts
per pmu.

# ./perf stat -e cycles -a sleep 1

Performance counter stats for 'system wide':

14,066,877,268 cpu_core/cycles/
6,814,443,147 cpu_atom/cycles/

1.002760625 seconds time elapsed

Sometimes, it's also useful to aggregate event counts from all PMUs.
Create a new option '--hybrid-merge' to enable that behavior and report
the counts without PMUs.

# ./perf stat -e cycles -a --hybrid-merge sleep 1

Performance counter stats for 'system wide':

20,732,982,512 cycles

1.002776793 seconds time elapsed

Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220422065635.767648-2-zhengjun.xing@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Zhengjun Xing and committed by
Arnaldo Carvalho de Melo
2c8e6451 60344f1a

+28 -2
+10
tools/perf/Documentation/perf-stat.txt
··· 454 454 2. Aliases, which are listed immediately after the Kernel PMU events 455 455 by perf list, are used. 456 456 457 + --hybrid-merge:: 458 + Merge the hybrid event counts from all PMUs. 459 + 460 + For hybrid events, by default, the stat aggregates and reports the event 461 + counts per PMU. But sometimes, it's also useful to aggregate event counts 462 + from all PMUs. This option enables that behavior and reports the counts 463 + without PMUs. 464 + 465 + For non-hybrid events, it should be no effect. 466 + 457 467 --smi-cost:: 458 468 Measure SMI cost if msr/aperf/ and msr/smi/ events are supported. 459 469
+2
tools/perf/builtin-stat.c
··· 1258 1258 OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, 1259 1259 "disable CPU count aggregation", AGGR_NONE), 1260 1260 OPT_BOOLEAN(0, "no-merge", &stat_config.no_merge, "Do not merge identical named events"), 1261 + OPT_BOOLEAN(0, "hybrid-merge", &stat_config.hybrid_merge, 1262 + "Merge identical named hybrid events"), 1261 1263 OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator", 1262 1264 "print counts with custom separator"), 1263 1265 OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
+15 -2
tools/perf/util/stat-display.c
··· 612 612 return perf_pmu__has_hybrid() && !is_uncore(evsel); 613 613 } 614 614 615 + static bool hybrid_merge(struct evsel *counter, struct perf_stat_config *config, 616 + bool check) 617 + { 618 + if (hybrid_uniquify(counter)) { 619 + if (check) 620 + return config && config->hybrid_merge; 621 + else 622 + return config && !config->hybrid_merge; 623 + } 624 + 625 + return false; 626 + } 627 + 615 628 static bool collect_data(struct perf_stat_config *config, struct evsel *counter, 616 629 void (*cb)(struct perf_stat_config *config, struct evsel *counter, void *data, 617 630 bool first), ··· 633 620 if (counter->merged_stat) 634 621 return false; 635 622 cb(config, counter, data, true); 636 - if (config->no_merge || hybrid_uniquify(counter)) 623 + if (config->no_merge || hybrid_merge(counter, config, false)) 637 624 uniquify_event_name(counter, config); 638 - else if (counter->auto_merge_stats) 625 + else if (counter->auto_merge_stats || hybrid_merge(counter, config, true)) 639 626 collect_all_aliases(config, counter, cb, data); 640 627 return true; 641 628 }
+1
tools/perf/util/stat.h
··· 127 127 bool ru_display; 128 128 bool big_num; 129 129 bool no_merge; 130 + bool hybrid_merge; 130 131 bool walltime_run_table; 131 132 bool all_kernel; 132 133 bool all_user;