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

perf stat: Support --cputype option for hybrid events

In previous patch, we have supported the syntax which enables
the event on a specified pmu, such as:

cpu_core/<event>/
cpu_atom/<event>/

While this syntax is not very easy for applying on a set of
events or applying on a group. In following example, we have to
explicitly assign the pmu prefix.

# ./perf stat -e '{cpu_core/cycles/,cpu_core/instructions/}' -- sleep 1

Performance counter stats for 'sleep 1':

1,158,545 cpu_core/cycles/
1,003,113 cpu_core/instructions/

1.002428712 seconds time elapsed

A much easier way is:

# ./perf stat --cputype core -e '{cycles,instructions}' -- sleep 1

Performance counter stats for 'sleep 1':

1,101,071 cpu_core/cycles/
939,892 cpu_core/instructions/

1.002363142 seconds time elapsed

For this example, the '--cputype' enables the events from specified
pmu (cpu_core).

If '--cputype' conflicts with pmu prefix, '--cputype' is ignored.

# ./perf stat --cputype core -e cycles,cpu_atom/instructions/ -a -- sleep 1

Performance counter stats for 'system wide':

21,003,407 cpu_core/cycles/
367,886 cpu_atom/instructions/

1.002203520 seconds time elapsed

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20210909062215.10278-1-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jin Yao and committed by
Arnaldo Carvalho de Melo
e69dc842 ed17b191

+35 -3
+4
tools/perf/Documentation/perf-stat.txt
··· 495 495 496 496 $ perf config stat.no-csv-summary=true 497 497 498 + --cputype:: 499 + Only enable events on applying cpu with this type for hybrid platform 500 + (e.g. core or atom)" 501 + 498 502 EXAMPLES 499 503 -------- 500 504
+24
tools/perf/builtin-stat.c
··· 1168 1168 return parse_cgroups(opt, str, unset); 1169 1169 } 1170 1170 1171 + static int parse_hybrid_type(const struct option *opt, 1172 + const char *str, 1173 + int unset __maybe_unused) 1174 + { 1175 + struct evlist *evlist = *(struct evlist **)opt->value; 1176 + 1177 + if (!list_empty(&evlist->core.entries)) { 1178 + fprintf(stderr, "Must define cputype before events/metrics\n"); 1179 + return -1; 1180 + } 1181 + 1182 + evlist->hybrid_pmu_name = perf_pmu__hybrid_type_to_pmu(str); 1183 + if (!evlist->hybrid_pmu_name) { 1184 + fprintf(stderr, "--cputype %s is not supported!\n", str); 1185 + return -1; 1186 + } 1187 + 1188 + return 0; 1189 + } 1190 + 1171 1191 static struct option stat_options[] = { 1172 1192 OPT_BOOLEAN('T', "transaction", &transaction_run, 1173 1193 "hardware transaction statistics"), ··· 1302 1282 "don't print 'summary' for CSV summary output"), 1303 1283 OPT_BOOLEAN(0, "quiet", &stat_config.quiet, 1304 1284 "don't print output (useful with record)"), 1285 + OPT_CALLBACK(0, "cputype", &evsel_list, "hybrid cpu type", 1286 + "Only enable events on applying cpu with this type " 1287 + "for hybrid platform (e.g. core or atom)", 1288 + parse_hybrid_type), 1305 1289 #ifdef HAVE_LIBPFM 1306 1290 OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", 1307 1291 "libpfm4 event selector. use 'perf list' to list available events",
+1
tools/perf/util/evlist.h
··· 64 64 struct evsel *selected; 65 65 struct events_stats stats; 66 66 struct perf_env *env; 67 + const char *hybrid_pmu_name; 67 68 void (*trace_event_sample_raw)(struct evlist *evlist, 68 69 union perf_event *event, 69 70 struct perf_sample *sample);
+6 -3
tools/perf/util/parse-events-hybrid.c
··· 63 63 static int pmu_cmp(struct parse_events_state *parse_state, 64 64 struct perf_pmu *pmu) 65 65 { 66 - if (!parse_state->hybrid_pmu_name) 67 - return 0; 66 + if (parse_state->evlist && parse_state->evlist->hybrid_pmu_name) 67 + return strcmp(parse_state->evlist->hybrid_pmu_name, pmu->name); 68 68 69 - return strcmp(parse_state->hybrid_pmu_name, pmu->name); 69 + if (parse_state->hybrid_pmu_name) 70 + return strcmp(parse_state->hybrid_pmu_name, pmu->name); 71 + 72 + return 0; 70 73 } 71 74 72 75 static int add_hw_hybrid(struct parse_events_state *parse_state,