Messages in this thread Patch in this message | | | Date | Mon, 13 Sep 2021 16:34:24 -0300 | From | Arnaldo Carvalho de Melo <> | Subject | Re: [PATCH v1 11/13] perf tools: improve IBS error handling |
| |
Em Thu, Sep 09, 2021 at 12:56:58AM -0700, Stephane Eranian escreveu: > From: Kim Phillips <kim.phillips@amd.com> > > This patch improves the error message returned on failed perf_event_open() on > AMD when using IBS. > > Signed-off-by: Kim Phillips <kim.phillips@amd.com> > --- > tools/perf/util/evsel.c | 42 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index f61e5dd53f5d..f203f178fdb9 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -2684,12 +2684,52 @@ static bool find_process(const char *name) > return ret ? false : true; > } > > +static bool is_amd; > + > +static char *fgrep(FILE *inf, const char *str) > +{ > + char line[256]; > + int slen = strlen(str); > + > + while (!feof(inf)) { > + if (!fgets(line, 256, inf)) > + break; > + if (strncmp(line, str, slen)) > + continue; > + > + return strdup(line); > + } > + > + return NULL; > +} > + > +static void detect_amd(void) > +{ > + FILE *inf = fopen("/proc/cpuinfo", "r"); > + char *res; > + > + if (!inf) > + return; > + > + res = fgrep(inf, "vendor_id"); > + > + if (res) { > + char *s = strchr(res, ':'); > + > + is_amd = s && !strcmp(s, ": AuthenticAMD\n"); > + free(res); > + } > + fclose(inf); > +} > +
We have perf_env for such details, for instance in tools/perf/util/sample-raw.c we have:o
const char *arch_pf = perf_env__arch(evlist->env); const char *cpuid = perf_env__cpuid(evlist->env);
else if (arch_pf && !strcmp("x86", arch_pf) && cpuid && strstarts(cpuid, "AuthenticAMD") && evlist__has_amd_ibs(evlist)) {
> int evsel__open_strerror(struct evsel *evsel, struct target *target, > int err, char *msg, size_t size) > { > char sbuf[STRERR_BUFSIZE]; > int printed = 0, enforced = 0; > > + detect_amd(); > + > switch (err) { > case EPERM: > case EACCES: > @@ -2782,6 +2822,8 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, > return scnprintf(msg, size, "wrong clockid (%d).", clockid); > if (perf_missing_features.aux_output) > return scnprintf(msg, size, "The 'aux_output' feature is not supported, update the kernel."); > + if (is_amd && (evsel->core.attr.precise_ip || !strncmp(evsel->pmu_name, "ibs", 3)) && (evsel->core.attr.exclude_kernel)) > + return scnprintf(msg, size, "AMD IBS can't exclude kernel events. Try running at a higher privilege level."); > break; > case ENODATA: > return scnprintf(msg, size, "Cannot collect data source with the load latency event alone. " > -- > 2.33.0.153.gba50c8fa24-goog
--
- Arnaldo
| |