perf, tools: Add support for uncore events and updated Intel events
I added support for parsing Intel uncore event files to the perf JSON code. There are still a few things that could be improved, but it's fairly usable now.
This patchkit adds the required support, including better support for duplicated PMUs. This on top of of Sukadev's v14 patchkit
Available ingit://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/builtin-json-7
I also pushed a new version of the Intel event files togit://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/intel-json-files-5
This version includes uncore files for some server cpus, and a few updates to the Broadwell core file. Plus it fixes the mapfile to contain correct types. Please use this version.
_Andi
PATCH 1/5 perf, tools: Add support for parsing uncore json files
From: Andi Kleen <[email protected]>
Handle the Unit field, which is needed to find the right PMU for an event.
Handle the ExtSel field.
Handle the Filter field.
Filter out zero fields, except for the event itself.
--- tools/perf/pmu-events/jevents.c | 130 +++++++++++++++++++++++++++++++++++-- tools/perf/pmu-events/jevents.h | 2 +- tools/perf/pmu-events/pmu-events.h | 1 + 3 files changed, 126 insertions(+), 7 deletions(-)
tools/perf/pmu-events/jevents.c +124 -6
@@ -133,7 +133,6 @@ static struct field {const char *field;const char *kernel; } fields[] = { - { "EventCode", "event=" }, { "UMask", "umask=" }, { "CounterMask", "cmask=" }, { "Invert", "inv=" },
@@ -162,6 +161,9 @@ static int match_field(char *map, jsmntok_t *field, int nz,for (f = fields; f->field; f++)if (json_streq (map, field, f->field) && nz) { +if (json_streq (map, val,"0x00" ) || +json_streq (map, val,"0x0" )) +return 1 ;cut_comma (map, &newval);addfield (map, event,"," , f->kernel, &newval);return 1 ;
@@ -187,6 +189,62 @@ static struct msrmap *lookup_msr(char *map, jsmntok_t *val)return NULL ; } +static struct map { +const char *json; +const char *perf; +} unit_to_perf[] = { + {"CBO" ,"cbox" }, + {"QPI LL" ,"qpi" }, + {"SBO" ,"sbox" }, + {} +}; + +static struct map filter_to_perf[] = { +#if 0 + { "QPIMatch0[17:0]", "match0"}, + { "QPIMask0[17:0]", "mask0"}, + { "QPIMatch0[12:0]", "match0"}, + { "QPIMask0[12:0]", "mask_mc, match_opc, match_vnw"}, + { "QPIMatch0[12:0]", "match_mc, match_opc, match_vnw"}, +#endif + { "CBoFilter0[22:18]", "filter_state"}, + { "CBoFilter1[17:10]", "filter_nid"}, + { "CBoFilter[17:10]", "filter_nid"}, + { "PCUFilter[7:0]", "filter_band0"}, + { "PCUFilter[15:8]", "filter_band1"}, + { "PCUFilter[23:16]", "filter_band2"}, + { "PCUFilter[31:24]", "filter_band3"}, + { "QPIMask0[17:0]", "mask0"}, + { "QPIMask1[19:16]", "mask_rds"}, + { "QPIMatch0[17:0]", "match_mc, match_opc, match_vnw, match_dnid"}, + { "QPIMatch1[19:16]", "match_rds"}, + { "CBoFilter[31:23]", "filter_opc"}, + { "CBoFilter0[23:17]", "filter_state" }, +#if 0 + /* Missing in uncore driver currently? */ + CBoFilter1[15:0] + CBoFilter1[28:20] + HA_AddrMatch0[31:6] + HA_AddrMatch1[13:0] + HA_Opcod + HA_OpcodeMatch[5:0] + IRPFilter[4:0] + UBoxFilter[3:0] +#endif + {} +}; + +static const char *field_to_perf(struct map *table, char *map, jsmntok_t *val) +{ + int i; + + for (i = 0; table[i].json; i++) { + if (json_streq(map, val, table[i].json)) + return table[i].perf; + } + return NULL; +} + #define EXPECT(e, t, m) do { if (!(e)) { \ jsmntok_t *loc = (t); \ if (!(t)->start && (t) > tokens) \
@@ -203,7 +261,8 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) }static int print_events_table_entry (void *data,char *name,char *event, -char *desc,char *long_desc,char *topic) +char *desc,char *long_desc,char *topic, +char *unit) {FILE *outfp = data;/*
@@ -219,7 +278,8 @@ static int print_events_table_entry(void *data, char *name, char *event,fprintf (outfp,"\t.long_desc = \"%s\",\n" , long_desc);if (topic)fprintf (outfp,"\t.topic = \"%s\",\n" , topic); - +if (unit) +fprintf (outfp,"\t.unit = \"%s\",\n" , unit);fprintf (outfp,"},\n" );return 0 ;
@@ -240,7 +300,7 @@ static void print_events_table_suffix(FILE *outfp)/* Call func with each event in the json file */ int json_events (const char *fn,int (*func)(void *data,char *name,char *event,char *desc, -char *long_desc,char *topic), +char *long_desc,char *topic,char *unit),void *data) {int err = -EIO ;
@@ -248,6 +308,7 @@ int json_events(const char *fn,jsmntok_t *tokens, *tok;int i, j, len;char *map; +char buf[128 ];if (!fn)return -ENOENT ;
@@ -262,6 +323,9 @@ int json_events(const char *fn,char *long_desc =NULL ;char *extra_desc =NULL ;char *topic =NULL ; +char *unit =NULL ; +char *filter =NULL ; +unsigned long long eventcode =0 ;struct msrmap *msr =NULL ;jsmntok_t *msrval =NULL ;jsmntok_t *precise =NULL ;
@@ -282,6 +346,16 @@ int json_events(const char *fn, nz = !json_streq (map, val,"0" );if (match_field (map, field, nz, &event, val)) {/* ok */ + }else if (json_streq (map, field,"EventCode" )) { +char *code =NULL ; +addfield (map, &code,"" ,"" , val); + eventcode |=strtoul (code,NULL ,0 ); +free (code); + }else if (json_streq (map, field,"ExtSel" )) { +char *code =NULL ; +addfield (map, &code,"" ,"" , val); + eventcode |=strtoul (code,NULL ,0 ) <<21 ; +free (code); }else if (json_streq (map, field,"EventName" )) {addfield (map, &name,"" ,"" , val); }else if (json_streq (map, field,"BriefDescription" )) {
@@ -306,9 +380,46 @@ int json_events(const char *fn,addfield (map, &extra_desc,". " ," Supports address when precise" ,NULL ); + }else if (json_streq (map, field,"Unit" )) { +const char *punit; +char *s; + +addfield (map, &topic," " ,"Uncore " , val); + + punit =field_to_perf (unit_to_perf, map, val); +if (punit) { + unit =strdup (punit); + }else { +addfield (map, &unit,"" ,"" , val); +for (s = unit; *s; s++) + *s =tolower (*s); + } +addfield (map, &desc,". " ,"Unit: " ,NULL ); +addfield (map, &desc,"" , unit,NULL ); + }else if (json_streq (map, field,"Filter" )) { +jsmntok_t nt = *val; +const char *nf; + +do { +cut_comma (map, &nt); +while (nt.start < val->end &&isspace (map[nt.start])) + nt.start++; + nf =field_to_perf (filter_to_perf, map, &nt); +if (!nf) { +if (verbose >1 ) +printf ("no filter match %.*s\n" , +json_len (&nt), map + nt.start); +addfield (map, &filter," " ,"" , &nt); + }else +addfield (map, &filter," " , nf,NULL ); + nt.start = nt.end +1 ; + nt.end = val->end; + }while (nt.start < val->end); }/* ignore unknown fields */ } +if (verbose >1 && filter &&strchr (filter,'[' )) +printf ("%s\n" , name);if (precise && !strstr (desc,"(Precise Event)" )) {if (json_streq (map, precise,"2" )) addfield(map, &extra_desc, " ",
@@ -317,21 +428,28 @@ int json_events(const char *fn,addfield (map, &extra_desc," " ,"(Precise event)" ,NULL ); } +snprintf (buf,sizeof buf,"event=%#llx" , eventcode); +addfield (map, &event,"," , buf,NULL );if (desc && extra_desc)addfield (map, &desc," " , extra_desc,NULL );if (long_desc && extra_desc)addfield (map, &long_desc," " , extra_desc,NULL ); +if (filter) { +addfield (map, &desc,". " ,"Filter: " ,NULL ); +addfield (map, &desc,"" , filter,NULL ); + }if (msr !=NULL )addfield (map, &event,"," , msr->pname, msrval);fixname (name); - - err =func (data, name, event, desc, long_desc, topic); + err =func (data, name, event, desc, long_desc, topic, unit);free (event);free (desc);free (name);free (long_desc);free (extra_desc);free (topic); +free (unit); +free (filter);if (err)break ; tok += j;
tools/perf/pmu-events/jevents.h +1 -1
@@ -3,7 +3,7 @@int json_events (const char *fn,int (*func)(void *data,char *name,char *event,char *desc, -char *long_desc,char *topic), +char *long_desc,char *topic,char *unit),void *data);char *get_cpu_str (void );
tools/perf/pmu-events/pmu-events.h +1 -0
@@ -10,6 +10,7 @@ struct pmu_event {const char *desc;const char *long_desc;const char *topic; +const char *unit; };/*
Signature · 1 line
2.4.2
PATCH 2/5 perf, tools: Support per pmu json aliases
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add support for registering json aliases per PMU. Any alias with an unit matching the prefix is registered to the PMU. Uncore has are multiple instances of most units, so all these aliases get registered for each individual PMU (this is important later to run the event on every instance of the PMU).
To avoid printing the events multiple times in perf list filter out duplicated events during printing.
--- tools/perf/util/pmu.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)
tools/perf/util/pmu.c +24 -5
@@ -474,7 +474,8 @@ char * __weak get_cpuid_str(void)* to the current running CPU. Then, add all PMU events from that table * as aliases. */ -static int pmu_add_cpu_aliases (struct list_head *head) +static int pmu_add_cpu_aliases (struct list_head *head,const char *name, +const char *type) {int i;struct pmu_events_map *map;
@@ -497,6 +498,9 @@ static int pmu_add_cpu_aliases(struct list_head *head)if (!map->table) goto out; +if (strcmp (map->type, type)) +continue ; +if (!strcmp (map->cpuid, cpuid))break ; }
@@ -510,6 +514,9 @@ static int pmu_add_cpu_aliases(struct list_head *head)if (!pe->name)break ; +if (pe->unit &&strncmp (pe->unit, name,strlen (pe->unit))) +continue ; +/* need type casts to override 'const' */ __perf_pmu__new_alias(head, NULL, (char *)pe->name, (char *)pe->desc, (char *)pe->event,
@@ -533,6 +540,8 @@ static struct perf_pmu *pmu_lookup(const char *name)LIST_HEAD (format);LIST_HEAD (aliases);__u32 type; +const char *typename; +int noff =0 ;/* No support for intel_bts or intel_pt so disallow them */ if (!strcmp (name,"intel_bts" ) || !strcmp (name,"intel_pt" ))
@@ -546,15 +555,22 @@ static struct perf_pmu *pmu_lookup(const char *name)if (pmu_format (name, &format))return NULL ; +if (pmu_type (name, &type)) +return NULL ; +if (pmu_aliases (name, &aliases))return NULL ;if (!strcmp (name,"cpu" )) - (void )pmu_add_cpu_aliases (&aliases); - -if (pmu_type (name, &type)) -return NULL ; + typename ="core" ; +else if (!strncmp (name,"uncore_" ,7 )) { + typename ="uncore" ; + noff =7 ; + }else + typename =NULL ; +if (typename) +pmu_add_cpu_aliases (&aliases, name + noff, typename); pmu =zalloc (sizeof (*pmu));if (!pmu)return NULL ;
@@ -1113,6 +1129,9 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, len = j;qsort (aliases, len,sizeof (struct sevent ), cmp_sevent);for (j =0 ; j < len; j++) { +/* Skip duplicates */ +if (j >0 && !strcmp (aliases[j].name, aliases[j -1 ].name)) +continue ;if (name_only) {printf ("%s " , aliases[j].name);continue ;
Signature · 1 line
2.4.2
PATCH 3/5 perf, tools: Support event aliases for non cpu// pmus
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
The code for handling pmu aliases without specifying the PMU hardcoded only supported the cpu PMU.
This patch extends it to work for all PMUs. We always duplicate the event for all PMUs that have an matching alias. This allows to automatically expand an alias for all instances of a PMU (so for example you can monitor all cache boxes with a single event)
--- tools/perf/util/parse-events.c | 46 ++++++++++++++++++++++++------------------ tools/perf/util/parse-events.y | 19 ++++++++++++++++- 2 files changed, 44 insertions(+), 21 deletions(-)
tools/perf/util/parse-events.c +26 -20
@@ -940,35 +940,41 @@ static void perf_pmu__parse_init(void)struct perf_pmu_alias *alias;int len =0 ; - pmu =perf_pmu__find ("cpu" ); -if ((pmu ==NULL ) ||list_empty (&pmu->aliases)) { + pmu =NULL ; +while ((pmu =perf_pmu__scan (pmu)) !=NULL ) { +list_for_each_entry (alias, &pmu->aliases, list) { +if (strchr (alias->name,'-' )) + len++; + len++; + } + } + +if (len ==0 ) { perf_pmu_events_list_num =-1 ;return ; } -list_for_each_entry (alias, &pmu->aliases, list) { -if (strchr (alias->name,'-' )) - len++; - len++; - } perf_pmu_events_list =malloc (sizeof (struct perf_pmu_event_symbol ) * len);if (!perf_pmu_events_list)return ; perf_pmu_events_list_num = len; len =0 ; -list_for_each_entry (alias, &pmu->aliases, list) { -struct perf_pmu_event_symbol *p = perf_pmu_events_list + len; -char *tmp =strchr (alias->name,'-' ); - -if (tmp !=NULL ) { -SET_SYMBOL (strndup (alias->name, tmp - alias->name), -PMU_EVENT_SYMBOL_PREFIX ); - p++; -SET_SYMBOL (strdup (++tmp),PMU_EVENT_SYMBOL_SUFFIX ); - len +=2 ; - }else { -SET_SYMBOL (strdup (alias->name),PMU_EVENT_SYMBOL ); - len++; + pmu =NULL ; +while ((pmu =perf_pmu__scan (pmu)) !=NULL ) { +list_for_each_entry (alias, &pmu->aliases, list) { +struct perf_pmu_event_symbol *p = perf_pmu_events_list + len; +char *tmp =strchr (alias->name,'-' ); + +if (tmp !=NULL ) { +SET_SYMBOL (strndup (alias->name, tmp - alias->name), +PMU_EVENT_SYMBOL_PREFIX ); + p++; +SET_SYMBOL (strdup (++tmp),PMU_EVENT_SYMBOL_SUFFIX ); + len +=2 ; + }else { +SET_SYMBOL (strdup (alias->name),PMU_EVENT_SYMBOL ); + len++; + } } } qsort(perf_pmu_events_list, len,
tools/perf/util/parse-events.y +18 -1
@@ -12,6 +12,7 @@ #include <linux/list.h> #include <linux/types.h> #include "util.h" +#include "pmu.h" #include "parse-events.h" #include "parse-events-bison.h"
@@ -228,6 +229,8 @@ PE_KERNEL_PMU_EVENT sep_dc struct list_head *head; struct parse_events_term *term; struct list_head *list; + struct perf_pmu *pmu = NULL; + int ok = 0; ALLOC_LIST(head); ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
@@ -235,7 +238,21 @@ PE_KERNEL_PMU_EVENT sep_dc list_add_tail(&term->list, head); ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); + /* Add it for all PMUs that support the alias */ + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + struct perf_pmu_alias *alias; + + list_for_each_entry(alias, &pmu->aliases, list) { + if (!strcasecmp(alias->name, $1)) { + if (!parse_events_add_pmu(data, list, + pmu->name, head)) { + ok++; + } + } + } + } + if (!ok) + YYABORT; parse_events__free_terms(head); $$ = list; }
Signature · 1 line
2.4.2
PATCH 4/5 perf, tools: Add debug support for outputing alias string
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
For debugging and testing it is useful to see the converted alias string. Add support to perf stat/record and perf list to print the alias conversion. The text string is saved in the alias structure. For perf stat/record it is folded into the normal -v. For perf list -v was taken, so we use --debug.
--- tools/perf/builtin-list.c | 5 ++++- tools/perf/util/parse-events.y | 3 +++ tools/perf/util/pmu.c | 7 +++++++ tools/perf/util/pmu.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-)
tools/perf/builtin-list.c +4 -1
@@ -15,6 +15,7 @@#include "util/cache.h" #include "util/pmu.h" #include "util/parse-options.h" +#include "util/debug.h" static bool desc_flag = true;
@@ -29,10 +30,12 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) "Print extra event descriptions. --no-desc to not print."),OPT_BOOLEAN ('d' ,"long-desc" , &long_desc_flag,"Print longer event descriptions." ), +OPT_INCR (0 ,"debug" , &verbose, +"Enable debugging output" ), OPT_END() };const char *const list_usage[] = { -"perf list [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob]" , +"perf list [--no-desc] [-v] [hw|sw|cache|tracepoint|pmu|event_glob]" ,NULL };
tools/perf/util/parse-events.y +3 -0
@@ -13,6 +13,7 @@ #include <linux/types.h> #include "util.h" #include "pmu.h" +#include "debug.h" #include "parse-events.h" #include "parse-events-bison.h"
@@ -246,6 +247,8 @@ PE_KERNEL_PMU_EVENT sep_dc if (!strcasecmp(alias->name, $1)) { if (!parse_events_add_pmu(data, list, pmu->name, head)) { + pr_debug("%s -> %s/%s/\n", $1, + pmu->name, alias->str); ok++; } }
tools/perf/util/pmu.c +7 -0
@@ -247,6 +247,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, alias->long_desc = long_desc ?strdup (long_desc) : desc ?strdup (desc) :NULL ; alias->topic = topic ?strdup (topic) :NULL ; + alias->str =strdup (val);list_add_tail (&alias->list, list);
@@ -1023,6 +1024,8 @@ struct sevent {char *name;char *desc;char *topic; +char *str; +char *pmu; };static int cmp_sevent (const void *a,const void *b)
@@ -1116,6 +1119,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, aliases[j].desc = long_desc ? alias->long_desc : alias->desc; aliases[j].topic = alias->topic; + aliases[j].str = alias->str; + aliases[j].pmu = pmu->name; j++; }if (pmu->selectable) {
@@ -1149,6 +1154,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,printf ("%*s" ,8 ,"[" );wordwrap (aliases[j].desc,8 , columns,0 );printf ("]\n" ); +if (verbose) +printf ("%*s%s/%s/\n" ,8 ,"" , aliases[j].pmu, aliases[j].str); }else printf (" %-50s [Kernel PMU event]\n" , aliases[j].name); printed++;
tools/perf/util/pmu.h +1 -0
@@ -41,6 +41,7 @@ struct perf_pmu_alias {char *desc;char *long_desc;char *topic; +char *str;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
Signature · 1 line
2.4.2
PATCH 5/5 perf, tools: Expand PMU events by prefetch match
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
When the user specifies a pmu directly, expand it automatically with a prefix match, similar as we do for the normal aliases now. This allows to specify attributes for duplicated boxes quickly. For example uncore_cbox_{0,8}/.../ can be now specified as cbox/.../ and it gets automatically expanded.
--- tools/perf/util/parse-events.y | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.y +17 -1
@@ -209,7 +209,23 @@ PE_NAME '/' event_config '/' struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_add_pmu(data, list, $1, $3)); + if (parse_events_add_pmu(data, list, $1, $3)) { + struct perf_pmu *pmu = NULL; + int ok = 0; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + char *name = pmu->name; + + if (!strncmp(name, "uncore_", 7)) + name += 7; + if (!strncmp($1, name, strlen($1))) { + if (!parse_events_add_pmu(data, list, pmu->name, $3)) + ok++; + } + } + if (!ok) + YYABORT; + } parse_events__free_terms($3); $$ = list; }
Signature · 1 line
2.4.2