Re: [PATCHv2 4/5] perf stat: Add -a as a default target
From: Jiri Olsa
Date: Tue Feb 21 2017 - 06:05:05 EST
On Tue, Feb 21, 2017 at 08:54:37AM +0100, Jiri Olsa wrote:
> On Mon, Feb 20, 2017 at 11:47:16PM +0100, Borislav Petkov wrote:
> > On Mon, Feb 20, 2017 at 06:22:54PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Well, this one should be read (and written in the tool output as):
> > >
> > > <not supported in workload only mode, try system wide, using -a>
> >
> > Do you want to change that CNTR_NOT_SUPPORTED string unconditionally to
> > something like above?
> >
> > Because perf_evsel.supported seems like it means that counter is not
> > supported but not necessarily only because of the missing -a for an
> > uncore event, AFAICT. I could be wrong.
> >
> > > Right, the ENOTSUPP in this case needs to be properly expanded into
> > > something meaningful, as suggested above.
> >
> > I dumped errno in __run_perf_stat():
> >
> > ./perf stat -v -e amd_nb/event=0xe0,umask=0x1f/ sleep 1
> > Using CPUID AuthenticAMD-21-2
> > Warning:
> > amd_nb/event=0xe0,umask=0x1f/ event is not supported by the kernel: 22.
> >
> > It is -EINVAL and the syscall returns -EINVAL in bunch of places so I'm
> > guessing this might not be a good way to match the retval to the proper
> > error message.
> >
> > Peterz said something about scanning all events supplied by -e and if
> > all are uncore, to set -a automatically. Can we do that?
>
> right, so that's different from what we actually did.. ;-)
>
> I'll check on this one.. might not be as straight forward,
> because some uncore events might have already cpumask limit
could you please test this change?
thanks,
jirka
---
diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c
index 79fe07158d00..424055bf32c9 100644
--- a/tools/perf/arch/x86/util/pmu.c
+++ b/tools/perf/arch/x86/util/pmu.c
@@ -14,5 +14,6 @@ struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu __mayb
if (!strcmp(pmu->name, INTEL_BTS_PMU_NAME))
pmu->selectable = true;
#endif
+ pmu->system_wide = strcmp(pmu->name, "cpu");
return NULL;
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 13b54999ad79..e924d56f3232 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2339,6 +2339,27 @@ static int __cmd_report(int argc, const char **argv)
return 0;
}
+static void setup_system_wide(int argc)
+{
+ /*
+ * Make system wide (-a) the default target
+ * or change the target to system_wide if
+ * all the counters are system_ wide.
+ */
+ if (!argc && target__none(&target))
+ target.system_wide = true;
+ else {
+ struct perf_evsel *counter;
+
+ evlist__for_each_entry(evsel_list, counter) {
+ if (!counter->system_wide)
+ return;
+ }
+
+ target.system_wide = true;
+ }
+}
+
int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char * const stat_usage[] = {
@@ -2445,9 +2466,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
} else if (big_num_opt == 0) /* User passed --no-big-num */
big_num = false;
- /* Make system wide (-a) the default target. */
- if (!argc && target__none(&target))
- target.system_wide = true;
+ setup_system_wide(argc);
if (run_count < 0) {
pr_err("Run count must be a positive number\n");
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 67a8aebc67ab..8b06b21f1bbc 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1254,6 +1254,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
evsel->scale = info.scale;
evsel->per_pkg = info.per_pkg;
evsel->snapshot = info.snapshot;
+ evsel->system_wide = pmu->system_wide;
}
return evsel ? 0 : -ENOMEM;
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 00852ddc7741..0ce3ffacbf92 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -21,6 +21,7 @@ struct perf_pmu {
char *name;
__u32 type;
bool selectable;
+ bool system_wide;
struct perf_event_attr *default_config;
struct cpu_map *cpus;
struct list_head format; /* HEAD struct perf_pmu_format -> list */