Re: [PATCH v4 14/25] perf stat: Add default hybrid events

From: Jin, Yao
Date: Wed Apr 21 2021 - 22:13:16 EST


Hi Jiri,

On 4/22/2021 2:29 AM, Jiri Olsa wrote:
On Fri, Apr 16, 2021 at 10:05:06PM +0800, Jin Yao wrote:

SNIP

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1255af4751c2..0351b99d17a7 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1145,6 +1145,13 @@ static int parse_stat_cgroups(const struct option *opt,
return parse_cgroups(opt, str, unset);
}
+static int add_default_hybrid_events(struct evlist *evlist)
+{
+ struct parse_events_error err;
+
+ return parse_events(evlist, "cycles,instructions,branches,branch-misses", &err);
+}
+
static struct option stat_options[] = {
OPT_BOOLEAN('T', "transaction", &transaction_run,
"hardware transaction statistics"),
@@ -1626,6 +1633,12 @@ static int add_default_attributes(void)
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
{ .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_BRANCH_MISSES },
+};
+ struct perf_event_attr default_sw_attrs[] = {
+ { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK },
+ { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES },
+ { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS },
+ { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS },

hum, why not use default_attrs0, it's the same, no?


The default_attrs0 has one more item " {.type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES },"

So I have to only pick out the sw attrs and save them to default_sw_attrs.

};
/*
@@ -1863,6 +1876,14 @@ static int add_default_attributes(void)
}
if (!evsel_list->core.nr_entries) {
+ if (perf_pmu__has_hybrid()) {
+ if (evlist__add_default_attrs(evsel_list,
+ default_sw_attrs) < 0) {
+ return -1;
+ }
+ return add_default_hybrid_events(evsel_list);

please do it the same way like when topdown calls parse events,
we don't need to check for cycles, but please check result and
display the error


Something like this?

err = parse_events(evsel_list, "cycles,instructions,branches,branch-misses", &errinfo);
if (err) {
fprintf(stderr,...);
parse_events_print_error(&errinfo, ...);
return -1;
}


+ }
+
if (target__has_cpu(&target))
default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK;

also you still want this change for hybrid pmus as well


Yes, the default_sw_attr only uses 'PERF_COUNT_SW_TASK_CLOCK', we do need to change it to PERF_COUNT_SW_CPU_CLOCK for system wide.

thanks,
jirka


Thanks
Jin Yao

--
2.17.1