Message ID | 1587120084-18990-8-git-send-email-john.garry@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | perf pmu-events: Support event aliasing for system PMUs | expand |
On Fri, Apr 17, 2020 at 06:41:18PM +0800, John Garry wrote: > Add a function to read the PMU id sysfs entry. We only do it for uncore > PMUs where this would be relevant. > > Signed-off-by: John Garry <john.garry@huawei.com> > --- > tools/perf/util/pmu.c | 36 ++++++++++++++++++++++++++++++++++++ > tools/perf/util/pmu.h | 1 + > 2 files changed, 37 insertions(+) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index ef6a63f3d386..6a67c6a28d08 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -594,6 +594,7 @@ static struct perf_cpu_map *__pmu_cpumask(const char *path) > * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) > * may have a "cpus" file. > */ > +#define CPUS_TEMPLATE_ID "%s/bus/event_source/devices/%s/identifier" > #define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask" > #define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus" > > @@ -632,6 +633,39 @@ static bool pmu_is_uncore(const char *name) > return file_available(path); > } > > +static char *pmu_id(const char *name) > +{ > + char path[PATH_MAX], *id; > + const char *sysfs; > + FILE *file; > + int n; > + > + sysfs = sysfs__mountpoint(); > + snprintf(path, PATH_MAX, CPUS_TEMPLATE_ID, sysfs, name); > + > + id = malloc(PATH_MAX); > + if (!id) > + return NULL; > + > + file = fopen(path, "r"); > + if (!file) { > + free(id); > + return NULL; > + } > + > + n = fscanf(file, "%s", id); > + > + fclose(file); > + > + if (!n) { > + free(id); > + return NULL; > + } > + > + return id; > +} I still need to go through this patchset in more detail, but just quick note, that we have sysfs__read_str that you could use in here jirka
Wi On 22/04/2020 12:41, Jiri Olsa wrote: > On Fri, Apr 17, 2020 at 06:41:18PM +0800, John Garry wrote: >> Add a function to read the PMU id sysfs entry. We only do it for uncore >> PMUs where this would be relevant. >> >> Signed-off-by: John Garry <john.garry@huawei.com> >> --- >> tools/perf/util/pmu.c | 36 ++++++++++++++++++++++++++++++++++++ >> tools/perf/util/pmu.h | 1 + >> 2 files changed, 37 insertions(+) >> >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index ef6a63f3d386..6a67c6a28d08 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -594,6 +594,7 @@ static struct perf_cpu_map *__pmu_cpumask(const char *path) >> * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) >> * may have a "cpus" file. >> */ >> +#define CPUS_TEMPLATE_ID "%s/bus/event_source/devices/%s/identifier" >> #define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask" >> #define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus" >> >> @@ -632,6 +633,39 @@ static bool pmu_is_uncore(const char *name) >> return file_available(path); >> } >> >> +static char *pmu_id(const char *name) >> +{ >> + char path[PATH_MAX], *id; >> + const char *sysfs; >> + FILE *file; >> + int n; >> + >> + sysfs = sysfs__mountpoint(); >> + snprintf(path, PATH_MAX, CPUS_TEMPLATE_ID, sysfs, name); >> + >> + id = malloc(PATH_MAX); >> + if (!id) >> + return NULL; >> + >> + file = fopen(path, "r"); >> + if (!file) { >> + free(id); >> + return NULL; >> + } >> + >> + n = fscanf(file, "%s", id); >> + >> + fclose(file); >> + >> + if (!n) { >> + free(id); >> + return NULL; >> + } >> + >> + return id; >> +} > > I still need to go through this patchset in more detail, ok, great. But, could you check patch #1 also, as this *may* be fixing something broken in mainline? Not sure. Without it, we get a spew of warnings for metrics. > but just quick note, that we have sysfs__read_str that you > could use in here > ok, there may be more functions in current pmu.c then which can use this. I can check. Cheers, John
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ef6a63f3d386..6a67c6a28d08 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -594,6 +594,7 @@ static struct perf_cpu_map *__pmu_cpumask(const char *path) * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) * may have a "cpus" file. */ +#define CPUS_TEMPLATE_ID "%s/bus/event_source/devices/%s/identifier" #define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask" #define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus" @@ -632,6 +633,39 @@ static bool pmu_is_uncore(const char *name) return file_available(path); } +static char *pmu_id(const char *name) +{ + char path[PATH_MAX], *id; + const char *sysfs; + FILE *file; + int n; + + sysfs = sysfs__mountpoint(); + snprintf(path, PATH_MAX, CPUS_TEMPLATE_ID, sysfs, name); + + id = malloc(PATH_MAX); + if (!id) + return NULL; + + file = fopen(path, "r"); + if (!file) { + free(id); + return NULL; + } + + n = fscanf(file, "%s", id); + + fclose(file); + + if (!n) { + free(id); + return NULL; + } + + return id; +} + + /* * PMU CORE devices have different name other than cpu in sysfs on some * platforms. @@ -844,6 +878,8 @@ static struct perf_pmu *pmu_lookup(const char *name) pmu->name = strdup(name); pmu->type = type; pmu->is_uncore = pmu_is_uncore(name); + if (pmu->is_uncore) + pmu->id = pmu_id(name); pmu->max_precise = pmu_max_precise(name); pmu_add_cpu_aliases(&aliases, pmu); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 5fb3f16828df..62ebca9481fe 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -24,6 +24,7 @@ struct perf_event_attr; struct perf_pmu { char *name; + char *id; __u32 type; bool selectable; bool is_uncore;
Add a function to read the PMU id sysfs entry. We only do it for uncore PMUs where this would be relevant. Signed-off-by: John Garry <john.garry@huawei.com> --- tools/perf/util/pmu.c | 36 ++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.h | 1 + 2 files changed, 37 insertions(+)