Message ID | 1433265135-20426-4-git-send-email-sukadev@linux.vnet.ibm.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Tue, Jun 02, 2015 at 10:12:03AM -0700, Sukadev Bhattiprolu wrote: SNIP > + > +/* > + * From the pmu_events_map, find the table of PMU events that corresponds > + * to the current running CPU. Then, add all PMU events from that table > + * as aliases. > + */ > +static int pmu_add_cpu_aliases(void *data) any reason why the argument is not 'head' directly? jirka > +{ > + struct list_head *head = (struct list_head *)data; > + int i; > + struct pmu_events_map *map; > + struct pmu_event *pe; > + char *cpuid; > + > + cpuid = get_cpuid_str(); > + if (!cpuid) > + return 0; > + > + i = 0; > + while (1) { > + map = &pmu_events_map[i++]; > + if (!map->table) { > + goto out; > + } > + > + if (!strcmp(map->cpuid, cpuid)) > + break; > + } > + > + /* > + * Found a matching PMU events table. Create aliases > + */ > + i = 0; > + while (1) { > + pe = &map->table[i++]; > + if (!pe->name) > + break; > + > + /* need type casts to override 'const' */ > + __perf_pmu__new_alias(head, (char *)pe->name, NULL, > + (char *)pe->desc, (char *)pe->event); > + } > + > +out: > + free(cpuid); > + return 0; > +} > + > + > static struct perf_pmu *pmu_lookup(const char *name) > { > struct perf_pmu *pmu; > @@ -464,6 +540,8 @@ static struct perf_pmu *pmu_lookup(const char *name) > if (pmu_aliases(name, &aliases)) > return NULL; > > + if (!strcmp(name, "cpu")) > + (void)pmu_add_cpu_aliases(&aliases); > if (pmu_type(name, &type)) > return NULL; > > -- > 1.7.9.5 >
On Tue, Jun 02, 2015 at 10:12:03AM -0700, Sukadev Bhattiprolu wrote: SNIP > > +/* > + * Return the CPU id as a raw string. > + * > + * Each architecture should provide a more precise id string that > + * can be use to match the architecture's "mapfile". > + */ > +char *__attribute__((weak))get_cpuid_str(void) we have '__weak' define in <linux/compiler.h> include jirka
On Tue, Jun 02, 2015 at 10:12:03AM -0700, Sukadev Bhattiprolu wrote: > At run time, (i.e when perf is starting up), locate the specific events > table for the current CPU and create event aliases for each of the events. > > Use these aliases to parse user's specified perf event. > > Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com> > > Changelog[v3] > [Jiri Olsa] Fix a memory leak with cpuid. > > Changelog[v2] > [Andi Kleen] Replace the pmu_events_map->vfm field with a simple > generic "cpuid" string and use that string to find the > matching mapfile entry. > --- > tools/perf/arch/powerpc/util/header.c | 11 ++++ > tools/perf/util/header.h | 3 +- > tools/perf/util/pmu.c | 104 ++++++++++++++++++++++++++++----- > 3 files changed, 104 insertions(+), 14 deletions(-) I think this patch is doing too much, it should be split into 3 pieces: - introduce get_cpuid_str for powerpc - introducing __perf_pmu__new_alias/perf_pmu__new_alias functions split - adding pmu_add_cpu_aliases functionality jirka
On Tue, Jun 02, 2015 at 10:12:03AM -0700, Sukadev Bhattiprolu wrote: SNIP > @@ -225,26 +221,47 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI > alias->unit[0] = '\0'; > alias->per_pkg = false; > > - ret = parse_events_terms(&alias->terms, buf); > + ret = parse_events_terms(&alias->terms, val); > if (ret) { > + pr_err("Cannot parse alias %s: %d\n", val, ret); > free(alias); > return ret; > } > > alias->name = strdup(name); > + if (dir) { > + /* > + * load unit name and scale if available > + */ > + perf_pmu__parse_unit(alias, dir, name); > + perf_pmu__parse_scale(alias, dir, name); > + perf_pmu__parse_per_pkg(alias, dir, name); > + perf_pmu__parse_snapshot(alias, dir, name); > + } > + > /* > - * load unit name and scale if available > + * TODO: pickup description from Andi's patchset > */ > - perf_pmu__parse_unit(alias, dir, name); > - perf_pmu__parse_scale(alias, dir, name); > - perf_pmu__parse_per_pkg(alias, dir, name); > - perf_pmu__parse_snapshot(alias, dir, name); > + //alias->desc = desc ? strdpu(desc) : NULL; please remove the TODO line and above commented code, it is addressed later in this patchset jirka
diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c index 6c1b8a7..65f9391 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -32,3 +32,14 @@ get_cpuid(char *buffer, size_t sz) } return -1; } + +char * +get_cpuid_str(void) +{ + char *bufp; + + if (asprintf(&bufp, "%.8lx", mfspr(SPRN_PVR)) < 0) + bufp = NULL; + + return bufp; +} diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index d4d5796..bb2ef5e 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -8,7 +8,6 @@ #include <linux/types.h> #include "event.h" - enum { HEADER_RESERVED = 0, /* always cleared */ HEADER_FIRST_FEATURE = 1, @@ -157,4 +156,6 @@ int write_padded(int fd, const void *bf, size_t count, size_t count_aligned); */ int get_cpuid(char *buffer, size_t sz); +char *get_cpuid_str(void); + #endif /* __PERF_HEADER_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0fcc624..0932323 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -10,7 +10,9 @@ #include "util.h" #include "pmu.h" #include "parse-events.h" +#include "pmu-events/pmu-events.h" #include "cpumap.h" +#include "header.h" struct perf_pmu_format { char *name; @@ -205,17 +207,11 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, return 0; } -static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) +static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir, char *desc __maybe_unused, char *val) { struct perf_pmu_alias *alias; - char buf[256]; int ret; - ret = fread(buf, 1, sizeof(buf), file); - if (ret == 0) - return -EINVAL; - buf[ret] = 0; - alias = malloc(sizeof(*alias)); if (!alias) return -ENOMEM; @@ -225,26 +221,47 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI alias->unit[0] = '\0'; alias->per_pkg = false; - ret = parse_events_terms(&alias->terms, buf); + ret = parse_events_terms(&alias->terms, val); if (ret) { + pr_err("Cannot parse alias %s: %d\n", val, ret); free(alias); return ret; } alias->name = strdup(name); + if (dir) { + /* + * load unit name and scale if available + */ + perf_pmu__parse_unit(alias, dir, name); + perf_pmu__parse_scale(alias, dir, name); + perf_pmu__parse_per_pkg(alias, dir, name); + perf_pmu__parse_snapshot(alias, dir, name); + } + /* - * load unit name and scale if available + * TODO: pickup description from Andi's patchset */ - perf_pmu__parse_unit(alias, dir, name); - perf_pmu__parse_scale(alias, dir, name); - perf_pmu__parse_per_pkg(alias, dir, name); - perf_pmu__parse_snapshot(alias, dir, name); + //alias->desc = desc ? strdpu(desc) : NULL; list_add_tail(&alias->list, list); return 0; } +static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file) +{ + char buf[256]; + int ret; + + ret = fread(buf, 1, sizeof(buf), file); + if (ret == 0) + return -EINVAL; + buf[ret] = 0; + + return __perf_pmu__new_alias(list, name, dir, NULL, buf); +} + static inline bool pmu_alias_info_file(char *name) { size_t len; @@ -442,6 +459,65 @@ perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) return NULL; } +/* + * Return the CPU id as a raw string. + * + * Each architecture should provide a more precise id string that + * can be use to match the architecture's "mapfile". + */ +char *__attribute__((weak))get_cpuid_str(void) +{ + return NULL; +} + +/* + * From the pmu_events_map, find the table of PMU events that corresponds + * to the current running CPU. Then, add all PMU events from that table + * as aliases. + */ +static int pmu_add_cpu_aliases(void *data) +{ + struct list_head *head = (struct list_head *)data; + int i; + struct pmu_events_map *map; + struct pmu_event *pe; + char *cpuid; + + cpuid = get_cpuid_str(); + if (!cpuid) + return 0; + + i = 0; + while (1) { + map = &pmu_events_map[i++]; + if (!map->table) { + goto out; + } + + if (!strcmp(map->cpuid, cpuid)) + break; + } + + /* + * Found a matching PMU events table. Create aliases + */ + i = 0; + while (1) { + pe = &map->table[i++]; + if (!pe->name) + break; + + /* need type casts to override 'const' */ + __perf_pmu__new_alias(head, (char *)pe->name, NULL, + (char *)pe->desc, (char *)pe->event); + } + +out: + free(cpuid); + return 0; +} + + static struct perf_pmu *pmu_lookup(const char *name) { struct perf_pmu *pmu; @@ -464,6 +540,8 @@ static struct perf_pmu *pmu_lookup(const char *name) if (pmu_aliases(name, &aliases)) return NULL; + if (!strcmp(name, "cpu")) + (void)pmu_add_cpu_aliases(&aliases); if (pmu_type(name, &type)) return NULL;
At run time, (i.e when perf is starting up), locate the specific events table for the current CPU and create event aliases for each of the events. Use these aliases to parse user's specified perf event. Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com> Changelog[v3] [Jiri Olsa] Fix a memory leak with cpuid. Changelog[v2] [Andi Kleen] Replace the pmu_events_map->vfm field with a simple generic "cpuid" string and use that string to find the matching mapfile entry. --- tools/perf/arch/powerpc/util/header.c | 11 ++++ tools/perf/util/header.h | 3 +- tools/perf/util/pmu.c | 104 ++++++++++++++++++++++++++++----- 3 files changed, 104 insertions(+), 14 deletions(-)