perf parse-events: Fixes relating to no_value terms
Ian Rogers
reviewerPATCH 1/6 perf parse-events: Fixes relating to no_value terms
A term may have no value in which case it is assumed to have a value of 1. It doesn't just apply to alias/event terms so change the parse_events_term__to_strbuf assert.
Commit 99e7138eb789 ("perf tools: Fail on using multiple bits long terms without value") made it so that no_value terms could only be for a single bit. Prior to commit 64199ae4b8a3 ("perf parse-events: Fix propagation of term's no_value when cloning") this missed a test case where config1 had no_value.
--- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/tests/parse-events.c +1 -1
@@ -2170,7 +2170,7 @@ static const struct evlist_test test__events[] = {static const struct evlist_test test__events_pmu[] = { { - .name ="cpu/config=10,config1,config2=3,period=1000/u" , + .name ="cpu/config=10,config1=1,config2=3,period=1000/u" , .valid = test__pmu_cpu_valid, .check = test__checkevent_pmu,/* 0 */
tools/perf/util/parse-events.c +1 -1
@@ -2607,7 +2607,7 @@ int parse_events_term__to_strbuf(struct list_head *term_list, struct strbuf *sb)if (term->type_val ==PARSE_EVENTS__TERM_TYPE_NUM )if (term->no_value) { -assert (term->type_term ==PARSE_EVENTS__TERM_TYPE_USER ); +assert (term->val.num ==1 ); ret =strbuf_addf (sb,"%s" , term->config); }else ret =strbuf_addf (sb,"%s=%#" PRIx64, term->config, term->val.num);
tools/perf/util/parse-events.h +2 -2
@@ -124,8 +124,8 @@ struct parse_events_term {*/ bool weak;/** -* @no_value: Is there no value. TODO: this should really be part of -* type_val. +* @no_value: Is there no value. If a numeric term has no value then the +* value is assumed to be 1. An event name also has no value. */ bool no_value; };
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Ian Rogers
reviewerPATCH 2/6 perf parse-events: Remove unnecessary __maybe_unused
The parameter head_terms is always used in get_config_terms.
--- tools/perf/util/parse-events.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.c +2 -4
@@ -34,8 +34,7 @@#ifdef PARSER_DEBUG extern int parse_events_debug;#endif -static int get_config_terms (struct list_head *head_config, -struct list_head *head_terms__maybe_unused ); +static int get_config_terms (struct list_head *head_config,struct list_head *head_terms);struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX ] = { [PERF_COUNT_HW_CPU_CYCLES ] = {
@@ -1079,8 +1078,7 @@ static int config_attr(struct perf_event_attr *attr,return 0 ; } -static int get_config_terms (struct list_head *head_config, -struct list_head *head_terms__maybe_unused ) +static int get_config_terms (struct list_head *head_config,struct list_head *head_terms) {#define ADD_CONFIG_TERM (__type, __weak) \ struct evsel_config_term *__t; \
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Ian Rogers
reviewerPATCH 3/6 perf parse-events: Tidy up str parameter
In reply to Ian RogersAdd a const and rename str to event_name.
--- tools/perf/util/parse-events.c | 13 +++++++------ tools/perf/util/parse-events.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/parse-events.c +7 -6
@@ -1482,7 +1482,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, }int parse_events_multi_pmu_add (struct parse_events_state *parse_state, -char *str,struct list_head *head, +const char *event_name,struct list_head *head,struct list_head **listp,void *loc_) {struct parse_events_term *term;
@@ -1502,7 +1502,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,INIT_LIST_HEAD (head); } - config =strdup (str); + + config =strdup (event_name);if (!config) goto out_err;
@@ -1528,7 +1529,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,if (parse_events__filter_pmu (parse_state, pmu))continue ; -if (!perf_pmu__have_event (pmu, str)) +if (!perf_pmu__have_event (pmu, event_name))continue ; auto_merge_stats =perf_pmu__auto_merge_stats (pmu);
@@ -1539,7 +1540,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,strbuf_init (&sb,/*hint=*/ 0 );parse_events_term__to_strbuf (orig_head, &sb); -pr_debug ("%s -> %s/%s/\n" , str, pmu->name, sb.buf); +pr_debug ("%s -> %s/%s/\n" , event_name, pmu->name, sb.buf);strbuf_release (&sb); ok++; }
@@ -1547,13 +1548,13 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, }if (parse_state->fake_pmu) { -if (!parse_events_add_pmu (parse_state, list, str, head, +if (!parse_events_add_pmu (parse_state, list, event_name, head,/*auto_merge_stats=*/ true, loc)) {struct strbuf sb;strbuf_init (&sb,/*hint=*/ 0 );parse_events_term__to_strbuf (head, &sb); -pr_debug ("%s -> %s/%s/\n" , str,"fake_pmu" , sb.buf); +pr_debug ("%s -> %s/%s/\n" , event_name,"fake_pmu" , sb.buf);strbuf_release (&sb); ok++; }
tools/perf/util/parse-events.h +1 -1
@@ -217,7 +217,7 @@ struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, struct perf_pmu *pmu);int parse_events_multi_pmu_add (struct parse_events_state *parse_state, -char *str, +const char *event_name,struct list_head *head_config,struct list_head **listp,void *loc);
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Ian Rogers
reviewerPATCH 4/6 perf parse-events: Avoid enum casts
In reply to Ian RogersAdd term_type to union of values returned by the lexer to avoid casts to and from an integer.
--- tools/perf/util/parse-events.l | 2 +- tools/perf/util/parse-events.y | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-)
tools/perf/util/parse-events.l +1 -1
@@ -120,7 +120,7 @@ static int term(yyscan_t scanner, enum parse_events__term_type type) { YYSTYPE *yylval = parse_events_get_lval(scanner); - yylval->num = type; + yylval->term_type = type; return PE_TERM; }
tools/perf/util/parse-events.y +11 -14
@@ -70,7 +70,7 @@ static void free_list_evsel(struct list_head* list_evsel) %type <num> PE_VALUE_SYM_HW %type <num> PE_VALUE_SYM_SW %type <num> PE_VALUE_SYM_TOOL -%type <num> PE_TERM +%type <term_type> PE_TERM %type <num> value_sym %type <str> PE_RAW %type <str> PE_NAME
@@ -111,6 +111,7 @@ static void free_list_evsel(struct list_head* list_evsel) { char *str; u64 num; + enum parse_events__term_type term_type; struct list_head *list_evsel; struct list_head *list_terms; struct parse_events_term *term;
@@ -778,8 +779,7 @@ PE_TERM_HW PE_TERM '=' name_or_legacy { struct parse_events_term *term; - int err = parse_events_term__str(&term, (enum parse_events__term_type)$1, - /*config=*/NULL, $3, &@1, &@3); + int err = parse_events_term__str(&term, $1, /*config=*/NULL, $3, &@1, &@3); if (err) { free($3);
@@ -791,8 +791,7 @@ PE_TERM '=' name_or_legacy PE_TERM '=' PE_TERM_HW { struct parse_events_term *term; - int err = parse_events_term__str(&term, (enum parse_events__term_type)$1, - /*config=*/NULL, $3.str, &@1, &@3); + int err = parse_events_term__str(&term, $1, /*config=*/NULL, $3.str, &@1, &@3); if (err) { free($3.str);
@@ -804,10 +803,7 @@ PE_TERM '=' PE_TERM_HW PE_TERM '=' PE_TERM { struct parse_events_term *term; - int err = parse_events_term__term(&term, - (enum parse_events__term_type)$1, - (enum parse_events__term_type)$3, - &@1, &@3); + int err = parse_events_term__term(&term, $1, $3, &@1, &@3); if (err) PE_ABORT(err);
@@ -818,8 +814,9 @@ PE_TERM '=' PE_TERM PE_TERM '=' PE_VALUE { struct parse_events_term *term; - int err = parse_events_term__num(&term, (enum parse_events__term_type)$1, - /*config=*/NULL, $3, /*novalue=*/false, &@1, &@3); + int err = parse_events_term__num(&term, $1, + /*config=*/NULL, $3, /*novalue=*/false, + &@1, &@3); if (err) PE_ABORT(err);
@@ -830,9 +827,9 @@ PE_TERM '=' PE_VALUE PE_TERM { struct parse_events_term *term; - int err = parse_events_term__num(&term, (enum parse_events__term_type)$1, - /*config=*/NULL, /*num=*/1, /*novalue=*/true, - &@1, /*loc_val=*/NULL); + int err = parse_events_term__num(&term, $1, + /*config=*/NULL, /*num=*/1, /*novalue=*/true, + &@1, /*loc_val=*/NULL); if (err) PE_ABORT(err);
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Ian Rogers
reviewerPATCH 5/6 perf parse-events: Copy fewer term lists
In reply to Ian RogersWhen trying to add events to multiple PMUs the term list is copied first as adding the event will rewrite the event's name term into the sysfs and/or json encoding terms (see perf_pmu__check_alias). Change the parse events add API so the passed in term list is const, then copy the list when modification is necessary.
--- tools/perf/util/parse-events.c | 108 ++++++++++++++++++--------------- tools/perf/util/parse-events.h | 7 +-- tools/perf/util/parse-events.y | 17 +----- 3 files changed, 65 insertions(+), 67 deletions(-)
tools/perf/util/parse-events.c +60 -48
@@ -35,6 +35,7 @@extern int parse_events_debug;#endif static int get_config_terms (struct list_head *head_config,struct list_head *head_terms); +static int parse_events_terms__copy (const struct list_head *src,struct list_head *dest);struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX ] = { [PERF_COUNT_HW_CPU_CYCLES ] = {
@@ -1367,7 +1368,7 @@ static bool config_term_percore(struct list_head *config_terms)int parse_events_add_pmu (struct parse_events_state *parse_state,struct list_head *list,const char *name, -struct list_head *head_config, +const struct list_head *const_head_terms,bool auto_merge_stats,void *loc_) {struct perf_event_attr attr;
@@ -1377,6 +1378,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,struct parse_events_error *err = parse_state->error;YYLTYPE *loc = loc_;LIST_HEAD (config_terms); +LIST_HEAD (head_terms); pmu = parse_state->fake_pmu ?:perf_pmus__find (name);
@@ -1390,32 +1392,37 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,return -EINVAL ; } +if (const_head_terms) { +int ret =parse_events_terms__copy (const_head_terms, &head_terms); + +if (ret) +return ret; + } +if (verbose >1 ) {struct strbuf sb;strbuf_init (&sb,/*hint=*/ 0 ); -if (pmu->selectable && !head_config) { +if (pmu->selectable &&list_empty (&head_terms)) {strbuf_addf (&sb,"%s//" , name); }else {strbuf_addf (&sb,"%s/" , name); -parse_events_term__to_strbuf (head_config, &sb); +parse_events_term__to_strbuf (&head_terms, &sb);strbuf_addch (&sb,'/' ); }fprintf (stderr,"Attempt to add: %s\n" , sb.buf);strbuf_release (&sb); } -if (head_config) -fix_raw (head_config, pmu); +fix_raw (&head_terms, pmu);if (pmu->default_config) { -memcpy (&attr, pmu->default_config, -sizeof (struct perf_event_attr )); +memcpy (&attr, pmu->default_config,sizeof (struct perf_event_attr )); }else {memset (&attr,0 ,sizeof (attr)); } attr.type = pmu->type; -if (!head_config) { +if (list_empty (&head_terms)) { evsel = __add_event(list, &parse_state->idx, &attr, /*init_attr=*/true, /*name=*/NULL, /*metric_id=*/NULL, pmu,
@@ -1424,14 +1431,16 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,return evsel ?0 : -ENOMEM ; } -if (!parse_state->fake_pmu &&perf_pmu__check_alias (pmu, head_config, &info, err)) +if (!parse_state->fake_pmu &&perf_pmu__check_alias (pmu, &head_terms, &info, err)) { +parse_events_terms__purge (&head_terms);return -EINVAL ; + }if (verbose >1 ) {struct strbuf sb;strbuf_init (&sb,/*hint=*/ 0 ); -parse_events_term__to_strbuf (head_config, &sb); +parse_events_term__to_strbuf (&head_terms, &sb);fprintf (stderr,"..after resolving event: %s/%s/\n" , name, sb.buf);strbuf_release (&sb); }
@@ -1440,39 +1449,52 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,* Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ -if (config_attr (&attr, head_config, parse_state->error, config_term_pmu)) +if (config_attr (&attr, &head_terms, parse_state->error, config_term_pmu)) { +parse_events_terms__purge (&head_terms);return -EINVAL ; + } -if (get_config_terms (head_config, &config_terms)) +if (get_config_terms (&head_terms, &config_terms)) { +parse_events_terms__purge (&head_terms);return -ENOMEM ; + }/* * When using default config, record which bits of attr->config were * changed by the user. */ -if (pmu->default_config &&get_config_chgs (pmu, head_config, &config_terms)) +if (pmu->default_config &&get_config_chgs (pmu, &head_terms, &config_terms)) { +parse_events_terms__purge (&head_terms);return -ENOMEM ; + } -if (!parse_state->fake_pmu &&perf_pmu__config (pmu, &attr, head_config, parse_state->error)) { +if (!parse_state->fake_pmu && +perf_pmu__config (pmu, &attr, &head_terms, parse_state->error)) {free_config_terms (&config_terms); +parse_events_terms__purge (&head_terms);return -EINVAL ; } evsel =__add_event (list, &parse_state->idx, &attr,/*init_attr=*/ true, -get_config_name (head_config), -get_config_metric_id (head_config), pmu, +get_config_name (&head_terms), +get_config_metric_id (&head_terms), pmu, &config_terms, auto_merge_stats,/*cpu_list=*/ NULL ); -if (!evsel) +if (!evsel) { +parse_events_terms__purge (&head_terms);return -ENOMEM ; + }if (evsel->name) evsel->use_config_name = true; evsel->percore =config_term_percore (&evsel->config_terms); -if (parse_state->fake_pmu) +if (parse_state->fake_pmu) { +parse_events_terms__purge (&head_terms);return 0 ; + } +parse_events_terms__purge (&head_terms);free ((char *)evsel->unit); evsel->unit =strdup (info.unit); evsel->scale = info.scale;
@@ -1482,25 +1504,25 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, }int parse_events_multi_pmu_add (struct parse_events_state *parse_state, -const char *event_name,struct list_head *head, +const char *event_name, +const struct list_head *const_head_terms,struct list_head **listp,void *loc_) {struct parse_events_term *term;struct list_head *list =NULL ; -struct list_head *orig_head =NULL ;struct perf_pmu *pmu =NULL ;YYLTYPE *loc = loc_;int ok =0 ;const char *config; +LIST_HEAD (head_terms); *listp =NULL ; -if (!head) { - head =malloc (sizeof (struct list_head )); -if (!head) - goto out_err; +if (const_head_terms) { +int ret =parse_events_terms__copy (const_head_terms, &head_terms); -INIT_LIST_HEAD (head); +if (ret) +return ret; } config =strdup (event_name);
@@ -1514,7 +1536,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,zfree (&config); goto out_err; } -list_add_tail (&term->list, head); +list_add_tail (&term->list, &head_terms);/* Add it for all PMUs that support the alias */ list =malloc (sizeof (struct list_head ));
@@ -1533,27 +1555,25 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,continue ; auto_merge_stats =perf_pmu__auto_merge_stats (pmu); -parse_events_copy_term_list (head, &orig_head);if (!parse_events_add_pmu (parse_state, list, pmu->name, - orig_head, auto_merge_stats, loc)) { + &head_terms, auto_merge_stats, loc)) {struct strbuf sb;strbuf_init (&sb,/*hint=*/ 0 ); -parse_events_term__to_strbuf (orig_head, &sb); +parse_events_term__to_strbuf (&head_terms, &sb);pr_debug ("%s -> %s/%s/\n" , event_name, pmu->name, sb.buf);strbuf_release (&sb); ok++; } -parse_events_terms__delete (orig_head); }if (parse_state->fake_pmu) { -if (!parse_events_add_pmu (parse_state, list, event_name, head, +if (!parse_events_add_pmu (parse_state, list, event_name, &head_terms,/*auto_merge_stats=*/ true, loc)) {struct strbuf sb;strbuf_init (&sb,/*hint=*/ 0 ); -parse_events_term__to_strbuf (head, &sb); +parse_events_term__to_strbuf (&head_terms, &sb);pr_debug ("%s -> %s/%s/\n" , event_name,"fake_pmu" , sb.buf);strbuf_release (&sb); ok++;
@@ -1561,12 +1581,12 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, } out_err: +parse_events_terms__purge (&head_terms);if (ok) *listp = list;else free (list); -parse_events_terms__delete (head);return ok ?0 :-1 ; }
@@ -2543,27 +2563,19 @@ void parse_events_term__delete(struct parse_events_term *term)free (term); } -int parse_events_copy_term_list (struct list_head *old, -struct list_head **new) +static int parse_events_terms__copy (const struct list_head *src,struct list_head *dest) { -struct parse_events_term *term, *n; -int ret; - -if (!old) { - *new =NULL ; -return 0 ; - } +struct parse_events_term *term; - *new =malloc (sizeof (struct list_head )); -if (!*new) -return -ENOMEM ; -INIT_LIST_HEAD (*new); + list_for_each_entry (term, src, list) { +struct parse_events_term *n; +int ret; - list_for_each_entry (term, old, list) { ret =parse_events_term__clone (&n, term);if (ret)return ret; -list_add_tail (&n->list, *new); + +list_add_tail (&n->list, dest); }return 0 ; }
tools/perf/util/parse-events.h +2 -5
@@ -209,7 +209,7 @@ int parse_events_add_breakpoint(struct parse_events_state *parse_state, struct list_head *head_config);int parse_events_add_pmu (struct parse_events_state *parse_state,struct list_head *list,const char *name, -struct list_head *head_config, +const struct list_head *const_head_terms,bool auto_merge_stats,void *loc); struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr,
@@ -218,12 +218,9 @@ struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr,int parse_events_multi_pmu_add (struct parse_events_state *parse_state,const char *event_name, -struct list_head *head_config, +const struct list_head *head_terms,struct list_head **listp,void *loc); -int parse_events_copy_term_list (struct list_head *old, -struct list_head **new); -void parse_events__set_leader (char *name,struct list_head *list);void parse_events_update_lists (struct list_head *list_event,struct list_head *list_all);
tools/perf/util/parse-events.y +3 -14
@@ -274,23 +274,18 @@ event_pmu: PE_NAME opt_pmu_config { struct parse_events_state *parse_state = _parse_state; - struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL; + /* List of created evsels. */ + struct list_head *list = NULL; char *pattern = NULL; #define CLEANUP \ do { \ parse_events_terms__delete($2); \ - parse_events_terms__delete(orig_terms); \ free(list); \ free($1); \ free(pattern); \ } while(0) - if (parse_events_copy_term_list($2, &orig_terms)) { - CLEANUP; - YYNOMEM; - } - list = alloc_list(); if (!list) { CLEANUP;
@@ -320,16 +315,11 @@ PE_NAME opt_pmu_config !perf_pmu__match(pattern, pmu->alias_name, $1)) { bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); - if (parse_events_copy_term_list(orig_terms, &terms)) { - CLEANUP; - YYNOMEM; - } - if (!parse_events_add_pmu(parse_state, list, pmu->name, terms, + if (!parse_events_add_pmu(parse_state, list, pmu->name, $2, auto_merge_stats, &@1)) { ok++; parse_state->wild_card_pmus = true; } - parse_events_terms__delete(terms); } }
@@ -337,7 +327,6 @@ PE_NAME opt_pmu_config /* Failure to add, assume $1 is an event name. */ zfree(&list); ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list, &@1); - $2 = NULL; } if (!ok) { struct parse_events_error *error = parse_state->error;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Ian Rogers
reviewerPATCH 6/6 perf parse-events: Add struct parse_events_terms
In reply to Ian Rogersparse_events_terms existed in function names but was passed a list_head. As many parse_events functions take an evsel_config list as well as a parse_event_term list, and the naming head_terms and head_config is inconsistent, there's a potential to switch the lists and get errors. Introduce a struct parse_events_terms, that just wraps a list_head, to avoid this. Add the regular init/exit functions and transition the code to use them.
--- tools/perf/arch/x86/util/intel-pt.c | 15 +-- tools/perf/tests/parse-events.c | 12 +-- tools/perf/tests/pmu.c | 23 ++-- tools/perf/util/parse-events.c | 158 +++++++++++++++------------- tools/perf/util/parse-events.h | 29 +++-- tools/perf/util/parse-events.y | 12 +-- tools/perf/util/pmu.c | 49 ++++----- tools/perf/util/pmu.h | 6 +- 8 files changed, 160 insertions(+), 144 deletions(-)
tools/perf/arch/x86/util/intel-pt.c +5 -10
@@ -64,28 +64,23 @@ static int intel_pt_parse_terms_with_default(struct perf_pmu *pmu,const char *str, u64 *config) { - struct list_head *terms; + struct parse_events_terms terms;struct perf_event_attr attr = { .size =0 , };int err; - terms =malloc (sizeof (struct list_head )); -if (!terms) -return -ENOMEM ; - -INIT_LIST_HEAD (terms); - - err =parse_events_terms (terms, str,/*input=*/ NULL ); +parse_events_terms__init (&terms); + err =parse_events_terms (&terms, str,/*input=*/ NULL );if (err) goto out_free; attr.config = *config; - err =perf_pmu__config_terms (pmu, &attr, terms,/*zero=*/ true,/*err=*/ NULL ); + err =perf_pmu__config_terms (pmu, &attr, &terms,/*zero=*/ true,/*err=*/ NULL );if (err) goto out_free; *config = attr.config; out_free: -parse_events_terms__delete (terms); +parse_events_terms__exit (&terms);return err; }
tools/perf/tests/parse-events.c +6 -6
@@ -771,12 +771,12 @@ static int test__checkevent_pmu_events_mix(struct evlist *evlist)return TEST_OK ; } -static int test__checkterms_simple (struct list_head *terms) +static int test__checkterms_simple (struct parse_events_terms *terms) {struct parse_events_term *term;/* config=10 */ - term = list_entry(terms->next, struct parse_events_term, list); + term = list_entry(terms->terms.next, struct parse_events_term, list);TEST_ASSERT_VAL ("wrong type term" , term->type_term ==PARSE_EVENTS__TERM_TYPE_CONFIG ); TEST_ASSERT_VAL("wrong type val",
@@ -2363,7 +2363,7 @@ static const struct evlist_test test__events_pmu[] = {struct terms_test {const char *str; -int (*check)(struct list_head *terms); +int (*check)(struct parse_events_terms *terms); };static const struct terms_test test__terms[] = {
@@ -2467,11 +2467,11 @@ static int test__events2(struct test_suite *test __maybe_unused, int subtest __mstatic int test_term (const struct terms_test *t) { -struct list_head terms; +struct parse_events_terms terms;int ret; -INIT_LIST_HEAD (&terms); +parse_events_terms__init (&terms); ret =parse_events_terms (&terms, t->str,/*input=*/ NULL );if (ret) { pr_debug("failed to parse terms '%s', err %d\n",
@@ -2480,7 +2480,7 @@ static int test_term(const struct terms_test *t) } ret = t->check (&terms); -parse_events_terms__purge (&terms); +parse_events_terms__exit (&terms);return ret; }
tools/perf/tests/pmu.c +15 -8
@@ -128,30 +128,35 @@ static int test_format_dir_put(char *dir)return system (buf); } -static struct list_head *test_terms_list (void ) +static void add_test_terms (struct parse_events_terms *terms) { -static LIST_HEAD (terms);unsigned int i; -for (i =0 ; i <ARRAY_SIZE (test_terms); i++) -list_add_tail (&test_terms[i].list, &terms); +for (i =0 ; i <ARRAY_SIZE (test_terms); i++) { +struct parse_events_term *clone; -return &terms; +parse_events_term__clone (&clone, &test_terms[i]); +list_add_tail (&clone->list, &terms->terms); + } }static int test__pmu (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) {char dir[PATH_MAX ];char *format; -struct list_head *terms =test_terms_list (); +struct parse_events_terms terms;struct perf_event_attr attr;struct perf_pmu *pmu;int fd;int ret; +parse_events_terms__init (&terms); +add_test_terms (&terms); pmu =zalloc (sizeof (*pmu)); -if (!pmu) +if (!pmu) { +parse_events_terms__exit (&terms);return -ENOMEM ; + }INIT_LIST_HEAD (&pmu->format);INIT_LIST_HEAD (&pmu->aliases);
@@ -159,6 +164,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe format =test_format_dir_get (dir,sizeof (dir));if (!format) {free (pmu); +parse_events_terms__exit (&terms);return -EINVAL ; }
@@ -175,7 +181,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybeif (ret) goto out; - ret =perf_pmu__config_terms (pmu, &attr, terms,/*zero=*/ false,/*err=*/ NULL ); + ret =perf_pmu__config_terms (pmu, &attr, &terms,/*zero=*/ false,/*err=*/ NULL );if (ret) goto out;
@@ -191,6 +197,7 @@ static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe out:test_format_dir_put (format);perf_pmu__delete (pmu); +parse_events_terms__exit (&terms);return ret; }
tools/perf/util/parse-events.c +82 -76
473 lines not on this page · raw message
tools/perf/util/parse-events.h +18 -11
@@ -44,7 +44,6 @@ static inline int parse_events(struct evlist *evlist, const char *str,int parse_event (struct evlist *evlist,const char *str); -int parse_events_terms (struct list_head *terms,const char *str,FILE *input);int parse_filter (const struct option *opt,const char *str,int unset);int exclude_perf (const struct option *opt,const char *arg,int unset);
@@ -140,6 +139,11 @@ struct parse_events_error {char *first_help; }; +/* A wrapper around a list of terms for the sake of better type safety. */ +struct parse_events_terms { +struct list_head terms; +}; +struct parse_events_state {/* The list parsed events are placed on. */ struct list_head list;
@@ -148,7 +152,7 @@ struct parse_events_state {/* Error information. */ struct parse_events_error *error;/* Holds returned terms for term parsing. */ -struct list_head *terms; +struct parse_events_terms *terms;/* Start token. */ int stoken;/* Special fake PMU marker for testing. */
@@ -181,35 +185,38 @@ int parse_events_term__term(struct parse_events_term **term,int parse_events_term__clone (struct parse_events_term **new,struct parse_events_term *term);void parse_events_term__delete (struct parse_events_term *term); -void parse_events_terms__delete (struct list_head *terms); -void parse_events_terms__purge (struct list_head *terms); -int parse_events_term__to_strbuf (struct list_head *term_list,struct strbuf *sb); + +void parse_events_terms__delete (struct parse_events_terms *terms); +void parse_events_terms__init (struct parse_events_terms *terms); +void parse_events_terms__exit (struct parse_events_terms *terms); +int parse_events_terms (struct parse_events_terms *terms,const char *str,FILE *input); +int parse_events_terms__to_strbuf (const struct parse_events_terms *terms,struct strbuf *sb);int parse_events__modifier_event (struct list_head *list,char *str,bool add);int parse_events__modifier_group (struct list_head *list,char *event_mod);int parse_events_name (struct list_head *list,const char *name);int parse_events_add_tracepoint (struct list_head *list,int *idx,const char *sys,const char *event,struct parse_events_error *error, -struct list_head *head_config,void *loc); +struct parse_events_terms *head_config,void *loc);int parse_events_add_numeric (struct parse_events_state *parse_state,struct list_head *list,u32 type,u64 config, -struct list_head *head_config, +struct parse_events_terms *head_config,bool wildcard);int parse_events_add_tool (struct parse_events_state *parse_state,struct list_head *list,int tool_event);int parse_events_add_cache (struct list_head *list,int *idx,const char *name,struct parse_events_state *parse_state, -struct list_head *head_config); +struct parse_events_terms *head_config);int parse_events__decode_legacy_cache (const char *name,int pmu_type,__u64 *config);int parse_events_add_breakpoint (struct parse_events_state *parse_state,struct list_head *list,u64 addr,char *type,u64 len, -struct list_head *head_config); +struct parse_events_terms *head_config);int parse_events_add_pmu (struct parse_events_state *parse_state,struct list_head *list,const char *name, -const struct list_head *const_head_terms, +const struct parse_events_terms *const_parsed_terms,bool auto_merge_stats,void *loc); struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr,
@@ -218,7 +225,7 @@ struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr,int parse_events_multi_pmu_add (struct parse_events_state *parse_state,const char *event_name, -const struct list_head *head_terms, +const struct parse_events_terms *const_parsed_terms,struct list_head **listp,void *loc);void parse_events__set_leader (char *name,struct list_head *list);
tools/perf/util/parse-events.y +6 -6
@@ -113,7 +113,7 @@ static void free_list_evsel(struct list_head* list_evsel) u64 num; enum parse_events__term_type term_type; struct list_head *list_evsel; - struct list_head *list_terms; + struct parse_events_terms *list_terms; struct parse_events_term *term; struct tracepoint_name { char *sys;
@@ -644,26 +644,26 @@ start_terms: event_config event_config: event_config ',' event_term { - struct list_head *head = $1; + struct parse_events_terms *head = $1; struct parse_events_term *term = $3; if (!head) { parse_events_term__delete(term); YYABORT; } - list_add_tail(&term->list, head); + list_add_tail(&term->list, &head->terms); $$ = $1; } | event_term { - struct list_head *head = malloc(sizeof(*head)); + struct parse_events_terms *head = malloc(sizeof(*head)); struct parse_events_term *term = $1; if (!head) YYNOMEM; - INIT_LIST_HEAD(head); - list_add_tail(&term->list, head); + parse_events_terms__init(head); + list_add_tail(&term->list, &head->terms); $$ = head; }
tools/perf/util/pmu.c +25 -24
146 lines not on this page · raw message
tools/perf/util/pmu.h +3 -3
@@ -191,15 +191,15 @@ typedef int (*pmu_event_callback)(void *state, struct pmu_event_info *info);void pmu_add_sys_aliases (struct perf_pmu *pmu);int perf_pmu__config (struct perf_pmu *pmu,struct perf_event_attr *attr, -struct list_head *head_terms, +struct parse_events_terms *head_terms,struct parse_events_error *error);int perf_pmu__config_terms (struct perf_pmu *pmu,struct perf_event_attr *attr, -struct list_head *head_terms, +struct parse_events_terms *terms,bool zero,struct parse_events_error *error);__u64 perf_pmu__format_bits (struct perf_pmu *pmu,const char *name);int perf_pmu__format_type (struct perf_pmu *pmu,const char *name); -int perf_pmu__check_alias (struct perf_pmu *pmu,struct list_head *head_terms, +int perf_pmu__check_alias (struct perf_pmu *pmu,struct parse_events_terms *head_terms,struct perf_pmu_info *info,struct parse_events_error *err);int perf_pmu__find_event (struct perf_pmu *pmu,const char *event,void *state,pmu_event_callback cb);
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Arnaldo Carvalho de Melo
maintainerEm Fri, Sep 01, 2023 at 04:39:44PM -0700, Ian Rogers escreveu:
Quoted 4 lines
A term may have no value in which case it is assumed to have a value of 1. It doesn't just apply to alias/event terms so change the
parse_events_term__to_strbufassert.
Quoted 8 lines
Commit
99e7138eb789("perf tools: Fail on using multiple bits long terms without value") made it so thatno_valueterms could only be for a single bit. Prior to commit64199ae4b8a3("perf parse-events: Fix propagation of term'sno_valuewhen cloning") this missed a test case where config1 hadno_value.Fixes 64199ae4b8a3 ("perf parse-events: Fix propagation of term's no_value when cloning")Signed-off-by Ian Rogers <[email protected]>
I'm trying to minimize the number of patches that aren't strict fixes this late in the process for v6.6, so I think I'll get just this first one and defer the other cleanups/improvements for v6.7, ok?
Thanks,
- Arnaldo
Quoted 50 lines
--- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/tests/parse-events.c +1
-1@@ -2170,7 +2170,7 @@ static const struct evlist_test test__events[] = {static const struct evlist_test test__events_pmu[] = { { - .name ="cpu/config=10,config1,config2=3,period=1000/u" , + .name ="cpu/config=10,config1=1,config2=3,period=1000/u" , .valid = test__pmu_cpu_valid, .check = test__checkevent_pmu,/* 0 */ tools/perf/util/parse-events.c +1
-1@@ -2607,7 +2607,7 @@ int parse_events_term__to_strbuf(struct list_head *term_list, struct strbuf *sb)if (term->type_val ==PARSE_EVENTS__TERM_TYPE_NUM )if (term->no_value) { -assert (term->type_term ==PARSE_EVENTS__TERM_TYPE_USER ); +assert (term->val.num ==1 ); ret =strbuf_addf (sb,"%s" , term->config); }else ret =strbuf_addf (sb,"%s=%#" PRIx64, term->config, term->val.num);tools/perf/util/parse-events.h +2
-2@@ -124,8 +124,8 @@ struct parse_events_term {*/ bool weak;/** -* @no_value: Is there no value. TODO: this should really be part of -* type_val. +* @no_value: Is there no value. If a numeric term has no value then the +* value is assumed to be 1. An event name also has no value. */ bool no_value; };Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Signature · 1 line
- Arnaldo
Ian Rogers
reviewerQuoted 12 lines · Arnaldo Carvalho de Melo
Em Fri, Sep 01, 2023 at 04:39:44PM -0700, Ian Rogers escreveu:
Quoted 10 lines
A term may have no value in which case it is assumed to have a value of 1. It doesn't just apply to alias/event terms so change the
parse_events_term__to_strbufassert.Commit
99e7138eb789("perf tools: Fail on using multiple bits long terms without value") made it so thatno_valueterms could only be for a single bit. Prior to commit64199ae4b8a3("perf parse-events: Fix propagation of term'sno_valuewhen cloning") this missed a test case where config1 hadno_value.
Quoted 6 lines
Quoted 2 lines
Fixes 64199ae4b8a3 ("perf parse-events: Fix propagation of term's no_value when cloning")Signed-off-by Ian Rogers <[email protected]>I'm trying to minimize the number of patches that aren't strict fixes this late in the process for v6.6, so I think I'll get just this first one and defer the other cleanups/improvements for v6.7, ok?
Makes sense, this is why I put the fix first in the series.
Thanks,
Ian
Quoted 58 lines
Thanks,
- Arnaldo
Quoted 48 lines
--- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/tests/parse-events.c +1
-1@@ -2170,7 +2170,7 @@ static const struct evlist_test test__events[] = {static const struct evlist_test test__events_pmu[] = { { - .name ="cpu/config=10,config1,config2=3,period=1000/u" , + .name ="cpu/config=10,config1=1,config2=3,period=1000/u" , .valid = test__pmu_cpu_valid, .check = test__checkevent_pmu,/* 0 */ tools/perf/util/parse-events.c +1
-1@@ -2607,7 +2607,7 @@ int parse_events_term__to_strbuf(struct list_head *term_list, struct strbuf *sb)if (term->type_val ==PARSE_EVENTS__TERM_TYPE_NUM )if (term->no_value) { -assert (term->type_term ==PARSE_EVENTS__TERM_TYPE_USER ); +assert (term->val.num ==1 ); ret =strbuf_addf (sb,"%s" , term->config); }else ret =strbuf_addf (sb,"%s=%#" PRIx64, term->config, term->val.num);tools/perf/util/parse-events.h +2
-3@@ -124,8 +124,8 @@ struct parse_events_term {*/ bool weak;/** -* @no_value: Is there no value. TODO: this should really be part of -* type_val. +* @no_value: Is there no value. If a numeric term has no value then the +* value is assumed to be 1. An event name also has no value. */ bool no_value; }; --Quoted 2 lines
2.42.0.283.g2d96d420d3-goog
--
- Arnaldo
Quoted 4 lines · Ian Rogers
A term may have no value in which case it is assumed to have a value of 1. It doesn't just apply to alias/event terms so change the
parse_events_term__to_strbufassert.
Quoted 8 lines
Commit
99e7138eb789("perf tools: Fail on using multiple bits long terms without value") made it so thatno_valueterms could only be for a single bit. Prior to commit64199ae4b8a3("perf parse-events: Fix propagation of term'sno_valuewhen cloning") this missed a test case where config1 hadno_value.Fixes 64199ae4b8a3 ("perf parse-events: Fix propagation of term's no_value when cloning")Signed-off-by Ian Rogers <[email protected]>
For the whole set:
Quoted 47 lines
--- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/tests/parse-events.c +1
-1@@ -2170,7 +2170,7 @@ static const struct evlist_test test__events[] = {static const struct evlist_test test__events_pmu[] = { { - .name ="cpu/config=10,config1,config2=3,period=1000/u" , + .name ="cpu/config=10,config1=1,config2=3,period=1000/u" , .valid = test__pmu_cpu_valid, .check = test__checkevent_pmu,/* 0 */ tools/perf/util/parse-events.c +1
-1@@ -2607,7 +2607,7 @@ int parse_events_term__to_strbuf(struct list_head *term_list, struct strbuf *sb)if (term->type_val ==PARSE_EVENTS__TERM_TYPE_NUM )if (term->no_value) { -assert (term->type_term ==PARSE_EVENTS__TERM_TYPE_USER ); +assert (term->val.num ==1 ); ret =strbuf_addf (sb,"%s" , term->config); }else ret =strbuf_addf (sb,"%s=%#" PRIx64, term->config, term->val.num);tools/perf/util/parse-events.h +2
-2@@ -124,8 +124,8 @@ struct parse_events_term {*/ bool weak;/** -* @no_value: Is there no value. TODO: this should really be part of -* type_val. +* @no_value: Is there no value. If a numeric term has no value then the +* value is assumed to be 1. An event name also has no value. */ bool no_value; };
Arnaldo Carvalho de Melo
maintainerEm Tue, Sep 05, 2023 at 10:39:38AM +0100, James Clark escreveu:
Quoted 13 lines · Ian Rogers
Quoted 10 lines
A term may have no value in which case it is assumed to have a value of 1. It doesn't just apply to alias/event terms so change the
parse_events_term__to_strbufassert.Commit
99e7138eb789("perf tools: Fail on using multiple bits long terms without value") made it so thatno_valueterms could only be for a single bit. Prior to commit64199ae4b8a3("perf parse-events: Fix propagation of term'sno_valuewhen cloning") this missed a test case where config1 hadno_value.
Quoted 6 lines
Quoted 2 lines
Fixes 64199ae4b8a3 ("perf parse-events: Fix propagation of term's no_value when cloning")Signed-off-by Ian Rogers <[email protected]>For the whole set:
Reviewed-by James Clark <[email protected]>
Thanks for providing it, in the future please consider replying to the cover letter (0/6) to do that, so that b4 can collect it, doing it for the 1st patch it will collect just for it, not for the whole set as you intended.
- Arnaldo
Quoted 47 lines
Quoted 47 lines
--- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/tests/parse-events.c +1
-1@@ -2170,7 +2170,7 @@ static const struct evlist_test test__events[] = {static const struct evlist_test test__events_pmu[] = { { - .name ="cpu/config=10,config1,config2=3,period=1000/u" , + .name ="cpu/config=10,config1=1,config2=3,period=1000/u" , .valid = test__pmu_cpu_valid, .check = test__checkevent_pmu,/* 0 */ tools/perf/util/parse-events.c +1
-1@@ -2607,7 +2607,7 @@ int parse_events_term__to_strbuf(struct list_head *term_list, struct strbuf *sb)if (term->type_val ==PARSE_EVENTS__TERM_TYPE_NUM )if (term->no_value) { -assert (term->type_term ==PARSE_EVENTS__TERM_TYPE_USER ); +assert (term->val.num ==1 ); ret =strbuf_addf (sb,"%s" , term->config); }else ret =strbuf_addf (sb,"%s=%#" PRIx64, term->config, term->val.num);tools/perf/util/parse-events.h +2
-2@@ -124,8 +124,8 @@ struct parse_events_term {*/ bool weak;/** -* @no_value: Is there no value. TODO: this should really be part of -* type_val. +* @no_value: Is there no value. If a numeric term has no value then the +* value is assumed to be 1. An event name also has no value. */ bool no_value; };
Signature · 1 line
- Arnaldo
Em Tue, Sep 05, 2023 at 10:39:38AM +0100, James Clark escreveu:
Quoted 13 lines · Ian Rogers
Quoted 10 lines
A term may have no value in which case it is assumed to have a value of 1. It doesn't just apply to alias/event terms so change the
parse_events_term__to_strbufassert.Commit
99e7138eb789("perf tools: Fail on using multiple bits long terms without value") made it so thatno_valueterms could only be for a single bit. Prior to commit64199ae4b8a3("perf parse-events: Fix propagation of term'sno_valuewhen cloning") this missed a test case where config1 hadno_value.
Quoted 6 lines
Quoted 2 lines
Fixes 64199ae4b8a3 ("perf parse-events: Fix propagation of term's no_value when cloning")Signed-off-by Ian Rogers <[email protected]>For the whole set:
Reviewed-by James Clark <[email protected]>
Thanks, applied.
- Arnaldo
Quoted 47 lines
Quoted 47 lines
--- tools/perf/tests/parse-events.c | 2 +- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/tests/parse-events.c +1
-1@@ -2170,7 +2170,7 @@ static const struct evlist_test test__events[] = {static const struct evlist_test test__events_pmu[] = { { - .name ="cpu/config=10,config1,config2=3,period=1000/u" , + .name ="cpu/config=10,config1=1,config2=3,period=1000/u" , .valid = test__pmu_cpu_valid, .check = test__checkevent_pmu,/* 0 */ tools/perf/util/parse-events.c +1
-1@@ -2607,7 +2607,7 @@ int parse_events_term__to_strbuf(struct list_head *term_list, struct strbuf *sb)if (term->type_val ==PARSE_EVENTS__TERM_TYPE_NUM )if (term->no_value) { -assert (term->type_term ==PARSE_EVENTS__TERM_TYPE_USER ); +assert (term->val.num ==1 ); ret =strbuf_addf (sb,"%s" , term->config); }else ret =strbuf_addf (sb,"%s=%#" PRIx64, term->config, term->val.num);tools/perf/util/parse-events.h +2
-2@@ -124,8 +124,8 @@ struct parse_events_term {*/ bool weak;/** -* @no_value: Is there no value. TODO: this should really be part of -* type_val. +* @no_value: Is there no value. If a numeric term has no value then the +* value is assumed to be 1. An event name also has no value. */ bool no_value; };
Signature · 1 line
- Arnaldo