perf: Support event alias in form foo-bar-baz
cover perf: Support event alias in form foo-bar-baz
Currently event aliases in the form foo-bar-baz are not supported.
The HiSilicon D06 platform has uncore event aliases in that form, and using those aliases fail:
$ ./perf list sdir-home-migrate
List of pre-defined events (to be used in -e):
uncore hha:
sdir-home-migrate
[Unit: hisi_sccl,hha]
$ sudo ./perf stat -e sdir-home-migrate
event syntax error: 'sdir-home-migrate'
\___ parser error
Run 'perf list' for a list of valid events Usage: perf stat [<options>] [<command>]
-e, --event <event>event selector. use 'perf list' to list available events
This series added support for such an event alias form.
I am no expert on l+y, so any and all review here would be appreciated, especially the last patch which is marked as RFC (for that same reason).
The series is based on acme perf/core @ 9bce13ea88f8.
John Garry (3):
perf parse-events: Support event alias in form foo-bar-baz perf test: Add pmu-events test for aliases with hyphens perf test: Add parse-events test for aliases with hyphens
.../arch/test/test_soc/cpu/uncore.json | 16 +++++ tools/perf/tests/parse-events.c | 49 ++++++++++++++ tools/perf/tests/pmu-events.c | 32 +++++++++ tools/perf/util/parse-events.c | 67 ++++++++++++++++--- tools/perf/util/parse-events.h | 1 + tools/perf/util/parse-events.l | 2 + tools/perf/util/parse-events.y | 17 ++++- 7 files changed, 171 insertions(+), 13 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/3 perf parse-events: Support event alias in form foo-bar-baz
Event aliasing for events whose name in the form foo-bar-baz is not supported, while foo-bar, foo_bar_baz, and other combinations are, i.e. two hyphens are not supported.
The HiSilicon D06 platform has events in such form:
$ ./perf list sdir-home-migrate
List of pre-defined events (to be used in -e):
uncore hha:
sdir-home-migrate
[Unit: hisi_sccl,hha]
$ sudo ./perf stat -e sdir-home-migrate
event syntax error: 'sdir-home-migrate'
\___ parser error
Run 'perf list' for a list of valid events Usage: perf stat [<options>] [<command>]
-e, --event <event>event selector. use 'perf list' to list available events
To support, add an extra PMU event symbol type for "baz", and add a new rule in the bison file.
--- tools/perf/util/parse-events.c | 25 +++++++++++++++++++++++-- tools/perf/util/parse-events.h | 1 + tools/perf/util/parse-events.l | 2 ++ tools/perf/util/parse-events.y | 17 +++++++++++++++-- 4 files changed, 41 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +23 -2
@@ -2098,8 +2098,17 @@ static void perf_pmu__parse_init(void) pmu =NULL ;while ((pmu =perf_pmu__scan (pmu)) !=NULL ) {list_for_each_entry (alias, &pmu->aliases, list) { -if (strchr (alias->name,'-' )) +char *tmp =strchr (alias->name,'-' ); + +if (tmp) { +char *tmp2 =NULL ; + + tmp2 =strchr (tmp +1 ,'-' ); len++; +if (tmp2) + len++; + } + len++; } }
@@ -2119,8 +2128,20 @@ static void perf_pmu__parse_init(void)list_for_each_entry (alias, &pmu->aliases, list) {struct perf_pmu_event_symbol *p = perf_pmu_events_list + len;char *tmp =strchr (alias->name,'-' ); +char *tmp2 =NULL ; -if (tmp !=NULL ) { +if (tmp) + tmp2 =strchr (tmp +1 ,'-' ); +if (tmp2) { +SET_SYMBOL (strndup (alias->name, tmp - alias->name), +PMU_EVENT_SYMBOL_PREFIX ); + p++; + tmp++; +SET_SYMBOL (strndup (tmp, tmp2 - tmp),PMU_EVENT_SYMBOL_SUFFIX ); + p++; +SET_SYMBOL (strdup (++tmp2),PMU_EVENT_SYMBOL_SUFFIX2 ); + len +=3 ; + }else if (tmp) {SET_SYMBOL (strndup (alias->name, tmp - alias->name),PMU_EVENT_SYMBOL_PREFIX ); p++;
tools/perf/util/parse-events.h +1 -0
@@ -53,6 +53,7 @@ enum perf_pmu_event_symbol_type {PMU_EVENT_SYMBOL ,/* normal style PMU event */ PMU_EVENT_SYMBOL_PREFIX ,/* prefix of pre-suf style event */ PMU_EVENT_SYMBOL_SUFFIX ,/* suffix of pre-suf style event */ + PMU_EVENT_SYMBOL_SUFFIX2, /* suffix of pre-suf2 style event */ }; struct perf_pmu_event_symbol {
tools/perf/util/parse-events.l +2 -0
@@ -149,6 +149,8 @@ static int pmu_str_check(yyscan_t scanner, struct parse_events_state *parse_stat return PE_PMU_EVENT_PRE; case PMU_EVENT_SYMBOL_SUFFIX: return PE_PMU_EVENT_SUF; + case PMU_EVENT_SYMBOL_SUFFIX2: + return PE_PMU_EVENT_SUF2; case PMU_EVENT_SYMBOL: return parse_state->fake_pmu ? PE_PMU_EVENT_FAKE : PE_KERNEL_PMU_EVENT;
tools/perf/util/parse-events.y +15 -2
@@ -69,7 +69,7 @@ static void inc_group_count(struct list_head *list, %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP %token PE_ERROR -%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE +%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_PMU_EVENT_SUF2 PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE %token PE_ARRAY_ALL PE_ARRAY_RANGE %token PE_DRV_CFG_TERM %type <num> PE_VALUE
@@ -87,7 +87,7 @@ static void inc_group_count(struct list_head *list, %type <str> PE_MODIFIER_EVENT %type <str> PE_MODIFIER_BP %type <str> PE_EVENT_NAME -%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE +%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_PMU_EVENT_SUF2 PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE %type <str> PE_DRV_CFG_TERM %type <str> event_pmu_name %destructor { free ($$); } <str>
@@ -372,6 +372,19 @@ PE_KERNEL_PMU_EVENT opt_pmu_config $$ = list; } | +PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF '-' PE_PMU_EVENT_SUF2 sep_dc +{ + struct list_head *list; + char pmu_name[128]; + snprintf(pmu_name, sizeof(pmu_name), "%s-%s-%s", $1, $3, $5); + free($1); + free($3); + free($5); + if (parse_events_multi_pmu_add(_parse_state, pmu_name, NULL, &list) < 0) + YYABORT; + $$ = list; +} +| PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc { struct list_head *list;
Signature · 1 line
2.26.2
PATCH 2/3 perf test: Add pmu-events test for aliases with hyphens
In reply to John GarryAdd a test for aliases with hyphens in the name to ensure that the pmu-events tables are as expects. There should be no reason why these sort of aliases would be treated differently, but no harm in checking.
--- .../arch/test/test_soc/cpu/uncore.json | 16 ++++++++++ tools/perf/tests/pmu-events.c | 32 +++++++++++++++++++ 2 files changed, 48 insertions(+)
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json +16 -0
@@ -18,6 +18,22 @@ "Invert": "0", "EdgeDetect": "0" }, + { + "Unit": "CBO", + "EventCode": "0xE0", + "UMask": "0x00", + "EventName": "event-hyphen", + "BriefDescription": "UNC_CBO_HYPHEN", + "PublicDescription": "UNC_CBO_HYPHEN" + }, + { + "Unit": "CBO", + "EventCode": "0xC0", + "UMask": "0x00", + "EventName": "event-two-hyph", + "BriefDescription": "UNC_CBO_TWO_HYPH", + "PublicDescription": "UNC_CBO_TWO_HYPH" + }, { "EventCode": "0x7", "EventName": "uncore_hisi_l3c.rd_hit_cpipe",
tools/perf/tests/pmu-events.c +32 -0
@@ -143,6 +143,34 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = { .matching_pmu = "uncore_cbox_0", }; +static const struct perf_pmu_test_event uncore_hyphen = { + .event = { + .name ="event-hyphen" , + .event ="umask=0x00,event=0xe0" , + .desc ="Unit: uncore_cbox UNC_CBO_HYPHEN" , + .topic ="uncore" , + .long_desc ="UNC_CBO_HYPHEN" , + .pmu ="uncore_cbox" , + }, + .alias_str ="umask=0,event=0xe0" , + .alias_long_desc ="UNC_CBO_HYPHEN" , + .matching_pmu ="uncore_cbox_0" , +}; + +static const struct perf_pmu_test_event uncore_two_hyph = { + .event = { + .name ="event-two-hyph" , + .event ="umask=0x00,event=0xc0" , + .desc ="Unit: uncore_cbox UNC_CBO_TWO_HYPH" , + .topic ="uncore" , + .long_desc ="UNC_CBO_TWO_HYPH" , + .pmu ="uncore_cbox" , + }, + .alias_str ="umask=0,event=0xc0" , + .alias_long_desc ="UNC_CBO_TWO_HYPH" , + .matching_pmu ="uncore_cbox_0" , +}; +static const struct perf_pmu_test_event uncore_hisi_l3c_rd_hit_cpipe = { .event = { .name ="uncore_hisi_l3c.rd_hit_cpipe" ,
@@ -188,6 +216,8 @@ static const struct perf_pmu_test_event uncore_imc_cache_hits = {static const struct perf_pmu_test_event *uncore_events[] = { &uncore_hisi_ddrc_flux_wcmd, &unc_cbo_xsnp_response_miss_eviction, + &uncore_hyphen, + &uncore_two_hyph, &uncore_hisi_l3c_rd_hit_cpipe, &uncore_imc_free_running_cache_miss, &uncore_imc_cache_hits,
@@ -654,6 +684,8 @@ static struct perf_pmu_test_pmu test_pmus[] = { }, .aliases = { &unc_cbo_xsnp_response_miss_eviction, + &uncore_hyphen, + &uncore_two_hyph, }, }, {
Signature · 1 line
2.26.2
PATCH 3/3 perf test: Add parse-events test for aliases with hyphens
In reply to John GarryAdd a test which allows us to test parsing an event alias with hyphens.
Since these events typically do not exist on most host systems, add the alias to the fake pmu.
Function perf_pmu__test_parse_init() has terms added to match known test aliases.
--- tools/perf/tests/parse-events.c | 49 +++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.c | 42 ++++++++++++++++++++++------ 2 files changed, 82 insertions(+), 9 deletions(-)
tools/perf/tests/parse-events.c +49 -0
@@ -2069,6 +2069,31 @@ static int test_event(struct evlist_test *e)return ret; } +static int test_event_fake_pmu (const char *str) +{ +struct parse_events_error err; +struct evlist *evlist; +int ret; + + evlist =evlist__new (); +if (!evlist) +return -ENOMEM ; + +parse_events_error__init (&err); +perf_pmu__test_parse_init (); + ret =__parse_events (evlist, str, &err, &perf_pmu__fake); +if (ret) { +pr_debug ("failed to parse event '%s', err %d, str '%s'\n" , + str, ret, err.str); +parse_events_error__print (&err, str); + } + +parse_events_error__exit (&err); +evlist__delete (evlist); + +return ret; +} +static int test_events (struct evlist_test *events,unsigned cnt) {int ret1, ret2 =0 ;
@@ -2276,6 +2301,26 @@ static int test_pmu_events_alias(char *event, char *alias)return test_event (&e); } +static int test_pmu_events_alias2 (void ) +{ +static const char events[][30 ] = { +"event-hyphen" , +"event-two-hyph" , + }; +unsigned long i; +int ret =0 ; + +for (i =0 ; i <ARRAY_SIZE (events); i++) { + ret =test_event_fake_pmu (&events[i][0 ]); +if (ret) { +pr_err ("check_parse_fake %s failed\n" , &events[i][0 ]); +break ; + } + } + +return ret; +} +static int test__parse_events (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) {int ret1, ret2 =0 ;
@@ -2313,6 +2358,10 @@ do { \return ret; } + ret1 =test_pmu_events_alias2 (); +if (!ret2) + ret2 = ret1; + ret1 =test_terms (test__terms,ARRAY_SIZE (test__terms));if (!ret2) ret2 = ret1;
tools/perf/util/parse-events.c +33 -9
62 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 28 lines · John Garry
Currently event aliases in the form foo-bar-baz are not supported.
The HiSilicon D06 platform has uncore event aliases in that form, and using those aliases fail:
$ ./perf list sdir-home-migrateList of pre-defined events (to be used in -e):
uncore hha:
sdir-home-migrate
[Unit: hisi_sccl,hha]$ sudo ./perf stat -e sdir-home-migrate event syntax error: 'sdir-home-migrate' \___ parser error Run 'perf list' for a list of valid eventsUsage: perf stat [<options>] [<command>]
-e, --event <event>event selector. use 'perf list' to list available events
This series added support for such an event alias form.
I am no expert on l+y, so any and all review here would be appreciated, especially the last patch which is marked as RFC (for that same reason).
Quoted 6 lines
The series is based on acme perf/core @
9bce13ea88f8.John Garry (3):
perf parse-events: Support event alias in form foo-bar-baz perf test: Add pmu-events test for aliases with hyphens perf test: Add parse-events test for aliases with hyphens
The whole set:
The additional code is no worse than the existing code. The testing is a great addition!
Thanks,
Ian
Quoted 12 lines
.../arch/test/test_soc/cpu/uncore.json | 16 +++++ tools/perf/tests/parse-events.c | 49 ++++++++++++++ tools/perf/tests/pmu-events.c | 32 +++++++++ tools/perf/util/parse-events.c | 67 ++++++++++++++++--- tools/perf/util/parse-events.h | 1 + tools/perf/util/parse-events.l | 2 + tools/perf/util/parse-events.y | 17 ++++- 7 files changed, 171 insertions(+), 13 deletions(-)--
2.26.2
Em Mon, Jan 17, 2022 at 08:21:42AM -0800, Ian Rogers escreveu:
Quoted 36 lines · John Garry
Quoted 28 lines
Currently event aliases in the form foo-bar-baz are not supported.
The HiSilicon D06 platform has uncore event aliases in that form, and using those aliases fail:
$ ./perf list sdir-home-migrateList of pre-defined events (to be used in -e):
uncore hha:
sdir-home-migrate
[Unit: hisi_sccl,hha]$ sudo ./perf stat -e sdir-home-migrate event syntax error: 'sdir-home-migrate' \___ parser error Run 'perf list' for a list of valid eventsUsage: perf stat [<options>] [<command>]
-e, --event <event>event selector. use 'perf list' to list available events
This series added support for such an event alias form.
I am no expert on l+y, so any and all review here would be appreciated, especially the last patch which is marked as RFC (for that same reason).
Quoted 6 lines
The series is based on acme perf/core @
9bce13ea88f8.John Garry (3):
perf parse-events: Support event alias in form foo-bar-baz perf test: Add pmu-events test for aliases with hyphens perf test: Add parse-events test for aliases with hyphens
Quoted 6 lines
The whole set:
Acked-by Ian Rogers <[email protected]>The additional code is no worse than the existing code. The testing is a great addition!
Indeed, thanks a lot!
Thanks, applied.
- Arnaldo
Quoted 15 lines
Thanks,
IanQuoted 12 lines
.../arch/test/test_soc/cpu/uncore.json | 16 +++++ tools/perf/tests/parse-events.c | 49 ++++++++++++++ tools/perf/tests/pmu-events.c | 32 +++++++++ tools/perf/util/parse-events.c | 67 ++++++++++++++++--- tools/perf/util/parse-events.h | 1 + tools/perf/util/parse-events.l | 2 + tools/perf/util/parse-events.y | 17 ++++- 7 files changed, 171 insertions(+), 13 deletions(-)--
2.26.2
Signature · 1 line
- Arnaldo