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

perf stat: Always keep perf metrics topdown events in a group

If any member in a group has a different cpu mask than the other
members, the current perf stat disables group. when the perf metrics
topdown events are part of the group, the below <not supported> error
will be triggered.

$ perf stat -e "{slots,topdown-retiring,uncore_imc_free_running_0/dclk/}" -a sleep 1
WARNING: grouped events cpus do not match, disabling group:
anon group { slots, topdown-retiring, uncore_imc_free_running_0/dclk/ }

Performance counter stats for 'system wide':

141,465,174 slots
<not supported> topdown-retiring
1,605,330,334 uncore_imc_free_running_0/dclk/

The perf metrics topdown events must always be grouped with a slots
event as leader.

Factor out evsel__remove_from_group() to only remove the regular events
from the group.

Remove evsel__must_be_in_group(), since no one use it anymore.

With the patch, the topdown events aren't broken from the group for the
splitting.

$ perf stat -e "{slots,topdown-retiring,uncore_imc_free_running_0/dclk/}" -a sleep 1
WARNING: grouped events cpus do not match, disabling group:
anon group { slots, topdown-retiring, uncore_imc_free_running_0/dclk/ }

Performance counter stats for 'system wide':

346,110,588 slots
124,608,256 topdown-retiring
1,606,869,976 uncore_imc_free_running_0/dclk/

1.003877592 seconds time elapsed

Fixes: a9a1790247bdcf3b ("perf stat: Ensure group is defined on top of the same cpu mask")
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20220518143900.1493980-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kan Liang and committed by
Arnaldo Carvalho de Melo
e8f4f794 39d5f412

+15 -13
+2 -5
tools/perf/builtin-stat.c
··· 272 272 pr_warning(" %s: %s\n", evsel->name, buf); 273 273 } 274 274 275 - for_each_group_evsel(pos, leader) { 276 - evsel__set_leader(pos, pos); 277 - pos->core.nr_members = 0; 278 - } 279 - evsel->core.leader->nr_members = 0; 275 + for_each_group_evsel(pos, leader) 276 + evsel__remove_from_group(pos, leader); 280 277 } 281 278 } 282 279
+1 -5
tools/perf/util/evlist.c
··· 1747 1747 * them. Some events, like Intel topdown, require being 1748 1748 * in a group and so keep these in the group. 1749 1749 */ 1750 - if (!evsel__must_be_in_group(c2) && c2 != leader) { 1751 - evsel__set_leader(c2, c2); 1752 - c2->core.nr_members = 0; 1753 - leader->core.nr_members--; 1754 - } 1750 + evsel__remove_from_group(c2, leader); 1755 1751 1756 1752 /* 1757 1753 * Set this for all former members of the group
+11 -2
tools/perf/util/evsel.c
··· 3109 3109 return false; 3110 3110 } 3111 3111 3112 - bool evsel__must_be_in_group(const struct evsel *evsel) 3112 + /* 3113 + * Remove an event from a given group (leader). 3114 + * Some events, e.g., perf metrics Topdown events, 3115 + * must always be grouped. Ignore the events. 3116 + */ 3117 + void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader) 3113 3118 { 3114 - return arch_evsel__must_be_in_group(evsel); 3119 + if (!arch_evsel__must_be_in_group(evsel) && evsel != leader) { 3120 + evsel__set_leader(evsel, evsel); 3121 + evsel->core.nr_members = 0; 3122 + leader->core.nr_members--; 3123 + } 3115 3124 }
+1 -1
tools/perf/util/evsel.h
··· 499 499 bool evsel__is_leader(struct evsel *evsel); 500 500 void evsel__set_leader(struct evsel *evsel, struct evsel *leader); 501 501 int evsel__source_count(const struct evsel *evsel); 502 - bool evsel__must_be_in_group(const struct evsel *evsel); 502 + void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader); 503 503 504 504 bool arch_evsel__must_be_in_group(const struct evsel *evsel); 505 505