parse-events clean up
Subsystems (3)
Ian Rogers
reviewerv2 cover parse-events clean up
Remove some tokens the lexer never produces. Ensure abort paths set an error. Previously scanning all PMUs meant bad events could fail with an invalid token, detect this at the point parsing for a PMU fails and add error strings. Try to be consistent in using YYNOMEM for memory failures and YYABORT for bad input.
v2. Fix build error when building without libtraceevent.
Ian Rogers (13):
perf parse-events: Remove unused PE_PMU_EVENT_FAKE token perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token perf parse-events: Remove two unused tokens
perf parse-events: Add more comments to parse_events_state perf parse-events: Avoid regrouped warning for wild card events perf parse-event: Add memory allocation test for name terms perf parse-events: Separate YYABORT and YYNOMEM cases perf parse-events: Move instances of YYABORT to YYNOMEM perf parse-events: Separate ENOMEM memory handling
perf parse-events: Additional error reporting
perf parse-events: Populate error column for BPF/tracepoint events perf parse-events: Improve location for add pmu
perf parse-events: Remove ABORT_ON
tools/perf/tests/bpf.c | 2 +- tools/perf/util/parse-events.c | 98 +++++---- tools/perf/util/parse-events.h | 20 +- tools/perf/util/parse-events.y | 351 +++++++++++++++++---------------- 4 files changed, 258 insertions(+), 213 deletions(-)
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 1/13 perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning PMUs before parsing").
--- tools/perf/util/parse-events.y | 42 ++-------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-)
tools/perf/util/parse-events.y +2 -40
@@ -63,7 +63,7 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_LEGACY_CACHE %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP %token PE_ERROR -%token PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE +%token PE_KERNEL_PMU_EVENT %token PE_ARRAY_ALL PE_ARRAY_RANGE %token PE_DRV_CFG_TERM %token PE_TERM_HW
@@ -81,7 +81,7 @@ static void free_list_evsel(struct list_head* list_evsel) %type <str> PE_MODIFIER_EVENT %type <str> PE_MODIFIER_BP %type <str> PE_EVENT_NAME -%type <str> PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE +%type <str> PE_KERNEL_PMU_EVENT %type <str> PE_DRV_CFG_TERM %type <str> name_or_raw name_or_legacy %destructor { free ($$); } <str>
@@ -394,44 +394,6 @@ PE_KERNEL_PMU_EVENT opt_pmu_config YYABORT; $$ = list; } -| -PE_PMU_EVENT_FAKE sep_dc -{ - struct list_head *list; - int err; - - list = alloc_list(); - if (!list) - YYABORT; - - err = parse_events_add_pmu(_parse_state, list, $1, /*head_config=*/NULL, - /*auto_merge_stats=*/false); - free($1); - if (err < 0) { - free(list); - YYABORT; - } - $$ = list; -} -| -PE_PMU_EVENT_FAKE opt_pmu_config -{ - struct list_head *list; - int err; - - list = alloc_list(); - if (!list) - YYABORT; - - err = parse_events_add_pmu(_parse_state, list, $1, $2, /*auto_merge_stats=*/false); - free($1); - parse_events_terms__delete($2); - if (err < 0) { - free(list); - YYABORT; - } - $$ = list; -} value_sym: PE_VALUE_SYM_HW
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Re: [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 2 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").
Will the chances ever grow to add another imperative change suggestion?
Regards,
Markus
Ian Rogers
reviewerRe: [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 8 lines · Markus Elfring
Quoted 3 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").Will the chances ever grow to add another imperative change suggestion?
Sorry, I can't parse this.
Thanks,
Ian
Quoted 2 lines
Regards,
Markus
Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").Will the chances ever grow to add another imperative change suggestion?
Sorry, I can't parse this.
Can you take the requirement “Describe your changes in imperative mood” into account for any more descriptions?
Regards,
Markus
Ian Rogers
reviewerRe: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 6 lines · Markus Elfring
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").Will the chances ever grow to add another imperative change suggestion?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Sorry, I can't parse this.
Can you take the requirement “Describe your changes in imperative mood” into account for any more descriptions?
Yep, still doesn't parse.
Thanks,
Ian
Quoted 2 lines
Regards,
Markus
Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").Will the chances ever grow to add another imperative change suggestion?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Sorry, I can't parse this.
Can you take the requirement “Describe your changes in imperative mood” into account for any more descriptions?
Yep, still doesn't parse.
Does this feedback really indicate that you stumble still on understanding difficulties for the linked development documentation?
Can the mentioned patch review concern be adjusted with wording alternatives for improved commit messages?
Regards,
Markus
Ian Rogers
reviewerRe: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 15 lines · Markus Elfring
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").Will the chances ever grow to add another imperative change suggestion?
Sorry, I can't parse this.
Can you take the requirement “Describe your changes in imperative mood” into account for any more descriptions?
Quoted 7 lines
Quoted 1 line
Yep, still doesn't parse.
Does this feedback really indicate that you stumble still on understanding difficulties for the linked development documentation?
Can the mentioned patch review concern be adjusted with wording alternatives for improved commit messages?
Sorry, checked with a colleague and kernel contributor, we don't know what is being requested here, "imperative mood" makes no sense, as such I don't have a fix for what you're requesting.
Thanks,
Ian
Quoted 2 lines
Regards,
Markus
Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 4 lines
Quoted 2 lines
Can the mentioned patch review concern be adjusted with wording alternatives for improved commit messages?
Sorry, checked with a colleague and kernel contributor,
Interesting …
Quoted 1 line
we don't know what is being requested here,
Another bit of attention for a known information source:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94
Quoted 1 line
"imperative mood" makes no sense,
How does such an opinion fit to the Linux development documentation?
Quoted 1 line
as such I don't have a fix for what you're requesting.
I got the impression that further possibilities can be taken better into account also for improved change descriptions.
Regards,
Markus
Ian Rogers
reviewerRe: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 17 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
Can the mentioned patch review concern be adjusted with wording alternatives for improved commit messages?
Sorry, checked with a colleague and kernel contributor,
Interesting …
Quoted 1 line
we don't know what is being requested here,
Another bit of attention for a known information source:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94Quoted 1 line
"imperative mood" makes no sense,
Quoted 7 lines
How does such an opinion fit to the Linux development documentation?
Quoted 1 line
as such I don't have a fix for what you're requesting.
I got the impression that further possibilities can be taken better into account also for improved change descriptions.
Thanks Markus, I appreciate you feel you have a real point here, I'm just not getting it. Perhaps you can write a commit message that fulfils requirements like being in the correct "imperative mood" and I will learn and improve.
Thanks,
Ian
Quoted 2 lines
Regards,
Markus
Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 5 lines
Quoted 2 lines
I got the impression that further possibilities can be taken better into account also for improved change descriptions.
Thanks Markus, I appreciate you feel you have a real point here, I'm just not getting it.
I hope that remaining communication difficulties can be resolved somehow.
Quoted 1 line
Perhaps you can write a commit message that fulfils requirements
Let us take another look.
Quoted 1 line
like being in the correct "imperative mood"
You chose some imperative wordings already for other changes while the description for this update step is still improvable.
Quoted 1 line
and I will learn and improve.
I hope also that further contributors and patch reviewers will “get into the mood” to share any additional ideas for more desirable change descriptions.
How do you think about a wording approach like the following?
Token specifications were adjusted by the commit 70c90e4a6b2fbe775b662eafefae51f64d627790 ("perf parse-events: Avoid scanning PMUs before parsing").
It was noticed that the token “PE_PMU_EVENT_FAKE” was not so useful any more. Thus delete its usage here.
Regards,
Markus
Re: [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
In reply to Ian RogersQuoted 5 lines · Ian Rogers
Quoted 4 lines · Markus Elfring
Quoted 3 lines
Removed by commit
70c90e4a6b2f("perf parse-events: Avoid scanning PMUs before parsing").
Quoted 7 lines
Quoted 4 lines
Will the chances ever grow to add another imperative change suggestion?
Sorry, I can't parse this.
Markus is banned from vger. Just ignore him.
regards,
dan carpenter
Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Sorry, I can't parse this.
Markus is banned from vger. Just ignore him.
I hope that further chances will picked up for desirable improvements despite of questionable communication difficulties.
Regards,
Markus
Ian Rogers
reviewerPATCH v2 2/13 perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token
In reply to Ian RogersRemoved by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning PMUs before parsing").
--- tools/perf/util/parse-events.y | 27 --------------------------- 1 file changed, 27 deletions(-)
tools/perf/util/parse-events.y +0 -27
@@ -63,7 +63,6 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_LEGACY_CACHE %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP %token PE_ERROR -%token PE_KERNEL_PMU_EVENT %token PE_ARRAY_ALL PE_ARRAY_RANGE %token PE_DRV_CFG_TERM %token PE_TERM_HW
@@ -81,7 +80,6 @@ static void free_list_evsel(struct list_head* list_evsel) %type <str> PE_MODIFIER_EVENT %type <str> PE_MODIFIER_BP %type <str> PE_EVENT_NAME -%type <str> PE_KERNEL_PMU_EVENT %type <str> PE_DRV_CFG_TERM %type <str> name_or_raw name_or_legacy %destructor { free ($$); } <str>
@@ -358,18 +356,6 @@ PE_NAME opt_pmu_config #undef CLEANUP_YYABORT } | -PE_KERNEL_PMU_EVENT sep_dc -{ - struct list_head *list; - int err; - - err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list); - free($1); - if (err < 0) - YYABORT; - $$ = list; -} -| PE_NAME sep_dc { struct list_head *list;
@@ -381,19 +367,6 @@ PE_NAME sep_dc YYABORT; $$ = list; } -| -PE_KERNEL_PMU_EVENT opt_pmu_config -{ - struct list_head *list; - int err; - - /* frees $2 */ - err = parse_events_multi_pmu_add(_parse_state, $1, $2, &list); - free($1); - if (err < 0) - YYABORT; - $$ = list; -} value_sym: PE_VALUE_SYM_HW
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 3/13 perf parse-events: Remove two unused tokens
In reply to Ian RogersThe tokens PE_PREFIX_RAW and PE_PREFIX_GROUP are unused so remove them.
--- tools/perf/util/parse-events.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/parse-events.y +1 -1
@@ -61,7 +61,7 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_BPF_OBJECT PE_BPF_SOURCE %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH %token PE_LEGACY_CACHE -%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP +%token PE_PREFIX_MEM %token PE_ERROR %token PE_ARRAY_ALL PE_ARRAY_RANGE %token PE_DRV_CFG_TERM
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 4/13 perf parse-events: Add more comments to parse_events_state
In reply to Ian RogersImprove documentation of struct parse_events_state.
--- tools/perf/util/parse-events.h | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/parse-events.h +8 -0
@@ -121,17 +121,25 @@ struct parse_events_error { };struct parse_events_state { +/* The list parsed events are placed on. */ struct list_head list; +/* The updated index used by entries as they are added. */ int idx; +/* Error information. */ struct parse_events_error *error; +/* Used by BPF event creation. */ struct evlist *evlist; +/* Holds returned terms for term parsing. */ struct list_head *terms; +/* Start token. */ int stoken; +/* Special fake PMU marker for testing. */ struct perf_pmu *fake_pmu;/* If non-null, when wildcard matching only match the given PMU. */ const char *pmu_filter;/* Should PE_LEGACY_NAME tokens be generated for config terms? */ bool match_legacy_cache_terms; +/* Were multiple PMUs scanned to find events? */ bool wild_card_pmus; };
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 5/13 perf parse-events: Avoid regrouped warning for wild card events
In reply to Ian RogersThere is logic to avoid printing the regrouping warning for wild card PMUs, this logic also needs to apply for wild card events.
Before:
```
$ perf stat -e '{data_read,data_write}' -a sleep 1
WARNING: events were regrouped to match PMUs
Performance counter stats for 'system wide':
2,979.16 MiB data_read
410.26 MiB data_write
1.001541923 seconds time elapsed
```
After:
```
$ perf stat -e '{data_read,data_write}' -a sleep 1
Performance counter stats for 'system wide':
2,975.94 MiB data_read
432.05 MiB data_write
1.001119499 seconds time elapsed
```--- tools/perf/util/parse-events.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/parse-events.c +1 -0
@@ -1722,6 +1722,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, auto_merge_stats)) {pr_debug ("%s -> %s/%s/\n" , str, pmu->name, alias->str); + parse_state->wild_card_pmus = true; ok++; }parse_events_terms__delete (orig_head);
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 6/13 perf parse-event: Add memory allocation test for name terms
In reply to Ian RogersIf the name memory allocation fails then propagate to the parser.
--- tools/perf/util/parse-events.c | 5 ++++- tools/perf/util/parse-events.y | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/parse-events.c +4 -1
@@ -1965,8 +1965,11 @@ int parse_events_name(struct list_head *list, const char *name)struct evsel *evsel;__evlist__for_each_entry (list, evsel) { -if (!evsel->name) +if (!evsel->name) { evsel->name =strdup (name); +if (!evsel->name) +return -ENOMEM ; + } }return 0 ;
tools/perf/util/parse-events.y +1 -1
@@ -263,7 +263,7 @@ PE_EVENT_NAME event_def free($1); if (err) { free_list_evsel($2); - YYABORT; + YYNOMEM; } $$ = $2; }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 7/13 perf parse-events: Separate YYABORT and YYNOMEM cases
In reply to Ian RogersSplit cases in event_pmu for greater accuracy.
--- tools/perf/util/parse-events.y | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-)
tools/perf/util/parse-events.y +26 -19
@@ -283,37 +283,42 @@ event_pmu: PE_NAME opt_pmu_config { struct parse_events_state *parse_state = _parse_state; - struct parse_events_error *error = parse_state->error; struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL; + struct parse_events_error *error = parse_state->error; char *pattern = NULL; -#define CLEANUP_YYABORT \ +#define CLEANUP \ do { \ parse_events_terms__delete($2); \ parse_events_terms__delete(orig_terms); \ free(list); \ free($1); \ free(pattern); \ - YYABORT; \ } while(0) - if (parse_events_copy_term_list($2, &orig_terms)) - CLEANUP_YYABORT; - if (error) error->idx = @1.first_column; + if (parse_events_copy_term_list($2, &orig_terms)) { + CLEANUP; + YYNOMEM; + } + list = alloc_list(); - if (!list) - CLEANUP_YYABORT; + if (!list) { + CLEANUP; + YYNOMEM; + } /* Attempt to add to list assuming $1 is a PMU name. */ if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false)) { struct perf_pmu *pmu = NULL; int ok = 0; /* Failure to add, try wildcard expansion of $1 as a PMU name. */ - if (asprintf(&pattern, "%s*", $1) < 0) - CLEANUP_YYABORT; + if (asprintf(&pattern, "%s*", $1) < 0) { + CLEANUP; + YYNOMEM; + } while ((pmu = perf_pmus__scan(pmu)) != NULL) { char *name = pmu->name;
@@ -328,8 +333,10 @@ 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_YYABORT; + if (parse_events_copy_term_list(orig_terms, &terms)) { + CLEANUP; + YYNOMEM; + } if (!parse_events_add_pmu(parse_state, list, pmu->name, terms, auto_merge_stats)) { ok++;
@@ -345,15 +352,15 @@ PE_NAME opt_pmu_config ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list); $2 = NULL; } - if (!ok) - CLEANUP_YYABORT; + if (!ok) { + CLEANUP; + YYABORT; + } } - parse_events_terms__delete($2); - parse_events_terms__delete(orig_terms); - free(pattern); - free($1); $$ = list; -#undef CLEANUP_YYABORT + list = NULL; + CLEANUP; +#undef CLEANUP } | PE_NAME sep_dc
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 8/13 perf parse-events: Move instances of YYABORT to YYNOMEM
In reply to Ian RogersMigration to improve error reporting as YYABORT cases should carry event parsing errors.
--- tools/perf/util/parse-events.y | 58 +++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 18 deletions(-)
tools/perf/util/parse-events.y +40 -18
@@ -390,7 +390,8 @@ value_sym '/' event_config '/' bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard); parse_events_terms__delete($3); if (err) {
@@ -408,7 +409,8 @@ value_sym sep_slash_slash_dc bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard)); $$ = list;
@@ -419,7 +421,8 @@ PE_VALUE_SYM_TOOL sep_slash_slash_dc struct list_head *list; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; ABORT_ON(parse_events_add_tool(_parse_state, list, $1)); $$ = list; }
@@ -432,7 +435,9 @@ PE_LEGACY_CACHE opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; + err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2); parse_events_terms__delete($2);
@@ -451,7 +456,9 @@ PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; + err = parse_events_add_breakpoint(_parse_state, list, $2, $6, $4, $7); parse_events_terms__delete($7);
@@ -469,7 +476,9 @@ PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; + err = parse_events_add_breakpoint(_parse_state, list, $2, NULL, $4, $5); parse_events_terms__delete($5);
@@ -486,7 +495,9 @@ PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; + err = parse_events_add_breakpoint(_parse_state, list, $2, $4, 0, $5); parse_events_terms__delete($5);
@@ -504,7 +515,8 @@ PE_PREFIX_MEM PE_VALUE opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; err = parse_events_add_breakpoint(_parse_state, list, $2, NULL, 0, $3); parse_events_terms__delete($3);
@@ -524,7 +536,8 @@ tracepoint_name opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; if (error) error->idx = @1.first_column;
@@ -556,7 +569,8 @@ PE_VALUE ':' PE_VALUE opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4, /*wildcard=*/false); parse_events_terms__delete($4);
@@ -575,7 +589,8 @@ PE_RAW opt_event_config u64 num; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; errno = 0; num = strtoull($1 + 1, NULL, 16); ABORT_ON(errno);
@@ -598,7 +613,8 @@ PE_BPF_OBJECT opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; err = parse_events_load_bpf(parse_state, list, $1, false, $2); parse_events_terms__delete($2); free($1);
@@ -615,7 +631,8 @@ PE_BPF_SOURCE opt_event_config int err; list = alloc_list(); - ABORT_ON(!list); + if (!list) + YYNOMEM; err = parse_events_load_bpf(_parse_state, list, $1, true, $2); parse_events_terms__delete($2); if (err) {
@@ -680,7 +697,8 @@ event_term struct list_head *head = malloc(sizeof(*head)); struct parse_events_term *term = $1; - ABORT_ON(!head); + if (!head) + YYNOMEM; INIT_LIST_HEAD(head); list_add_tail(&term->list, head); $$ = head;
@@ -857,7 +875,8 @@ PE_DRV_CFG_TERM struct parse_events_term *term; char *config = strdup($1); - ABORT_ON(!config); + if (!config) + YYNOMEM; if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, config, $1, &@1, NULL)) { free($1);
@@ -888,7 +907,8 @@ array_terms ',' array_term new_array.ranges = realloc($1.ranges, sizeof(new_array.ranges[0]) * new_array.nr_ranges); - ABORT_ON(!new_array.ranges); + if (!new_array.ranges) + YYNOMEM; memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, $3.nr_ranges * sizeof(new_array.ranges[0])); free($3.ranges);
@@ -904,7 +924,8 @@ PE_VALUE array.nr_ranges = 1; array.ranges = malloc(sizeof(array.ranges[0])); - ABORT_ON(!array.ranges); + if (!array.ranges) + YYNOMEM; array.ranges[0].start = $1; array.ranges[0].length = 1; $$ = array;
@@ -917,7 +938,8 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE ABORT_ON($3 < $1); array.nr_ranges = 1; array.ranges = malloc(sizeof(array.ranges[0])); - ABORT_ON(!array.ranges); + if (!array.ranges) + YYNOMEM; array.ranges[0].start = $1; array.ranges[0].length = $3 - $1 + 1; $$ = array;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 9/13 perf parse-events: Separate ENOMEM memory handling
In reply to Ian RogersAdd PE_ABORT that will YYNOMEM or YYABORT accordingly.
--- tools/perf/util/parse-events.y | 134 ++++++++++++++++++++------------- 1 file changed, 82 insertions(+), 52 deletions(-)
tools/perf/util/parse-events.y +82 -52
@@ -28,6 +28,13 @@ do { \ YYABORT; \ } while (0) +#define PE_ABORT(val) \ +do { \ + if (val == -ENOMEM) \ + YYNOMEM; \ + YYABORT; \ +} while (0) + static struct list_head* alloc_list(void) { struct list_head *list;
@@ -371,7 +378,7 @@ PE_NAME sep_dc err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list); free($1); if (err < 0) - YYABORT; + PE_ABORT(err); $$ = list; }
@@ -396,7 +403,7 @@ value_sym '/' event_config '/' parse_events_terms__delete($3); if (err) { free_list_evsel(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -407,23 +414,28 @@ value_sym sep_slash_slash_dc int type = $1 >> 16; int config = $1 & 255; bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); + int err; list = alloc_list(); if (!list) YYNOMEM; - ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, - /*head_config=*/NULL, wildcard)); + err = parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard); + if (err) + PE_ABORT(err); $$ = list; } | PE_VALUE_SYM_TOOL sep_slash_slash_dc { struct list_head *list; + int err; list = alloc_list(); if (!list) YYNOMEM; - ABORT_ON(parse_events_add_tool(_parse_state, list, $1)); + err = parse_events_add_tool(_parse_state, list, $1); + if (err) + YYNOMEM; $$ = list; }
@@ -444,7 +456,7 @@ PE_LEGACY_CACHE opt_event_config free($1); if (err) { free_list_evsel(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -465,7 +477,7 @@ PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event free($6); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -484,7 +496,7 @@ PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config parse_events_terms__delete($5); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -504,7 +516,7 @@ PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config free($4); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -522,7 +534,7 @@ PE_PREFIX_MEM PE_VALUE opt_event_config parse_events_terms__delete($3); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -549,7 +561,7 @@ tracepoint_name opt_event_config free($1.event); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -576,7 +588,7 @@ PE_VALUE ':' PE_VALUE opt_event_config parse_events_terms__delete($4); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -600,7 +612,7 @@ PE_RAW opt_event_config parse_events_terms__delete($2); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -620,7 +632,7 @@ PE_BPF_OBJECT opt_event_config free($1); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -637,7 +649,7 @@ PE_BPF_SOURCE opt_event_config parse_events_terms__delete($2); if (err) { free(list); - YYABORT; + PE_ABORT(err); } $$ = list; }
@@ -712,11 +724,12 @@ event_term: PE_RAW { struct parse_events_term *term; + int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW, + strdup("raw"), $1, &@1, &@1); - if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW, - strdup("raw"), $1, &@1, &@1)) { + if (err) { free($1); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -724,12 +737,12 @@ PE_RAW name_or_raw '=' name_or_legacy { struct parse_events_term *term; + int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $3, &@1, &@3); - if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3, &@1, &@3)) { + if (err) { free($1); free($3); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -737,11 +750,12 @@ name_or_raw '=' name_or_legacy name_or_raw '=' PE_VALUE { struct parse_events_term *term; + int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, $3, false, &@1, &@3); - if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3, false, &@1, &@3)) { + if (err) { free($1); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -749,12 +763,13 @@ name_or_raw '=' PE_VALUE name_or_raw '=' PE_TERM_HW { struct parse_events_term *term; + int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, $3.str, &@1, &@3); - if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3.str, &@1, &@3)) { + if (err) { free($1); free($3.str); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -762,11 +777,12 @@ name_or_raw '=' PE_TERM_HW PE_LEGACY_CACHE { struct parse_events_term *term; + int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE, + $1, 1, true, &@1, NULL); - if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE, - $1, 1, true, &@1, NULL)) { + if (err) { free($1); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -774,11 +790,12 @@ PE_LEGACY_CACHE PE_NAME { struct parse_events_term *term; + int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, 1, true, &@1, NULL); - if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, 1, true, &@1, NULL)) { + if (err) { free($1); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -786,11 +803,12 @@ PE_NAME PE_TERM_HW { struct parse_events_term *term; + int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE, + $1.str, $1.num & 255, false, &@1, NULL); - if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE, - $1.str, $1.num & 255, false, &@1, NULL)) { + if (err) { free($1.str); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -798,10 +816,11 @@ PE_TERM_HW PE_TERM '=' name_or_legacy { struct parse_events_term *term; + int err = parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3); - if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) { + if (err) { free($3); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -809,10 +828,11 @@ PE_TERM '=' name_or_legacy PE_TERM '=' PE_TERM_HW { struct parse_events_term *term; + int err = parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3); - if (parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3)) { + if (err) { free($3.str); - YYABORT; + PE_ABORT(err); } $$ = term; }
@@ -820,37 +840,46 @@ PE_TERM '=' PE_TERM_HW PE_TERM '=' PE_TERM { struct parse_events_term *term; + int err = parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3); + + if (err) + PE_ABORT(err); - ABORT_ON(parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3)); $$ = term; } | PE_TERM '=' PE_VALUE { struct parse_events_term *term; + int err = parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3); + + if (err) + PE_ABORT(err); - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3)); $$ = term; } | PE_TERM { struct parse_events_term *term; + int err = parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL); + + if (err) + PE_ABORT(err); - ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL)); $$ = term; } | name_or_raw array '=' name_or_legacy { struct parse_events_term *term; + int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, &@1, &@4); - if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $4, &@1, &@4)) { + if (err) { free($1); free($4); free($2.ranges); - YYABORT; + PE_ABORT(err); } term->array = $2; $$ = term;
@@ -859,12 +888,12 @@ name_or_raw array '=' name_or_legacy name_or_raw array '=' PE_VALUE { struct parse_events_term *term; + int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, false, &@1, &@4); - if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $4, false, &@1, &@4)) { + if (err) { free($1); free($2.ranges); - YYABORT; + PE_ABORT(err); } term->array = $2; $$ = term;
@@ -874,14 +903,15 @@ PE_DRV_CFG_TERM { struct parse_events_term *term; char *config = strdup($1); + int err; if (!config) YYNOMEM; - if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, - config, $1, &@1, NULL)) { + err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, config, $1, &@1, NULL); + if (err) { free($1); free(config); - YYABORT; + PE_ABORT(err); } $$ = term; }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 10/13 perf parse-events: Additional error reporting
In reply to Ian RogersWhen no events or PMUs match report an error for event_pmu:
Before:
```
$ perf stat -e 'asdfasdf' -a sleep 1
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
```After:
```
$ perf stat -e 'asdfasdf' -a sleep 1
event syntax error: 'asdfasdf'
\___ Bad event name
Unabled to find PMU or event on a PMU of 'asdfasdf'
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
```Fixes the inadvertent removal when hybrid parsing was modified.
--- tools/perf/util/parse-events.y | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
tools/perf/util/parse-events.y +19 -6
@@ -291,7 +291,6 @@ PE_NAME opt_pmu_config { struct parse_events_state *parse_state = _parse_state; struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL; - struct parse_events_error *error = parse_state->error; char *pattern = NULL; #define CLEANUP \
@@ -303,9 +302,6 @@ PE_NAME opt_pmu_config free(pattern); \ } while(0) - if (error) - error->idx = @1.first_column; - if (parse_events_copy_term_list($2, &orig_terms)) { CLEANUP; YYNOMEM;
@@ -360,6 +356,14 @@ PE_NAME opt_pmu_config $2 = NULL; } if (!ok) { + struct parse_events_error *error = parse_state->error; + char *help; + + if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0) + help = NULL; + parse_events_error__handle(error, @1.first_column, + strdup("Bad event or PMU"), + help); CLEANUP; YYABORT; }
@@ -376,9 +380,18 @@ PE_NAME sep_dc int err; err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list); - free($1); - if (err < 0) + if (err < 0) { + struct parse_events_state *parse_state = _parse_state; + struct parse_events_error *error = parse_state->error; + char *help; + + if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0) + help = NULL; + parse_events_error__handle(error, @1.first_column, strdup("Bad event name"), help); + free($1); PE_ABORT(err); + } + free($1); $$ = list; }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 11/13 perf parse-events: Populate error column for BPF/tracepoint events
In reply to Ian RogersFollow convention from parse_events_terms__num/str and pass the YYLTYPE for the location.
--- tools/perf/tests/bpf.c | 2 +- tools/perf/util/parse-events.c | 80 ++++++++++++++++++++-------------- tools/perf/util/parse-events.h | 8 ++-- tools/perf/util/parse-events.y | 6 +-- 4 files changed, 57 insertions(+), 39 deletions(-)
tools/perf/tests/bpf.c +1 -1
@@ -124,7 +124,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void), parse_state.error = &parse_error;INIT_LIST_HEAD (&parse_state.list); - err =parse_events_load_bpf_obj (&parse_state, &parse_state.list, obj,NULL ); + err =parse_events_load_bpf_obj (&parse_state, &parse_state.list, obj,NULL ,NULL );parse_events_error__exit (&parse_error);if (err == -ENODATA ) {pr_debug ("Failed to add events selected by BPF, debuginfo package not installed\n" );
tools/perf/util/parse-events.c +48 -32
241 lines not on this page · raw message
tools/perf/util/parse-events.h +5 -3
@@ -169,18 +169,20 @@ 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); +struct list_head *head_config,void *loc);int parse_events_load_bpf (struct parse_events_state *parse_state,struct list_head *list,char *bpf_file_name,bool source, -struct list_head *head_config); +struct list_head *head_config, +void *loc);/* Provide this function for perf test */ struct bpf_object ;int parse_events_load_bpf_obj (struct parse_events_state *parse_state,struct list_head *list,struct bpf_object *obj, -struct list_head *head_config); +struct list_head *head_config, +void *loc); int parse_events_add_numeric(struct parse_events_state *parse_state, struct list_head *list, u32 type, u64 config,
tools/perf/util/parse-events.y +3 -3
@@ -567,7 +567,7 @@ tracepoint_name opt_event_config error->idx = @1.first_column; err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, - error, $2); + error, $2, &@1); parse_events_terms__delete($2); free($1.sys);
@@ -640,7 +640,7 @@ PE_BPF_OBJECT opt_event_config list = alloc_list(); if (!list) YYNOMEM; - err = parse_events_load_bpf(parse_state, list, $1, false, $2); + err = parse_events_load_bpf(parse_state, list, $1, false, $2, &@1); parse_events_terms__delete($2); free($1); if (err) {
@@ -658,7 +658,7 @@ PE_BPF_SOURCE opt_event_config list = alloc_list(); if (!list) YYNOMEM; - err = parse_events_load_bpf(_parse_state, list, $1, true, $2); + err = parse_events_load_bpf(_parse_state, list, $1, true, $2, &@1); parse_events_terms__delete($2); if (err) { free(list);
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 12/13 perf parse-events: Improve location for add pmu
In reply to Ian RogersImprove the location for add PMU for cases when PMUs aren't found.
--- tools/perf/util/parse-events.c | 12 +++++++----- tools/perf/util/parse-events.h | 4 ++-- tools/perf/util/parse-events.y | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-)
tools/perf/util/parse-events.c +7 -5
@@ -1567,13 +1567,14 @@ 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,char *name,struct list_head *head_config, -bool auto_merge_stats) +bool auto_merge_stats,void *loc_) {struct perf_event_attr attr;struct perf_pmu_info info;struct perf_pmu *pmu;struct evsel *evsel;struct parse_events_error *err = parse_state->error; +YYLTYPE *loc = loc_;LIST_HEAD (config_terms); pmu = parse_state->fake_pmu ?:perf_pmus__find (name);
@@ -1597,7 +1598,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,if (asprintf (&err_str,"Cannot find PMU `%s'. Missing kernel support?" , name) >=0 ) -parse_events_error__handle (err,0 , err_str,NULL ); +parse_events_error__handle (err, loc->first_column, err_str,NULL );return -EINVAL ; }if (head_config)
@@ -1683,12 +1684,13 @@ 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, -struct list_head **listp) +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 ;char *config;
@@ -1735,7 +1737,7 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,parse_events_copy_term_list (head, &orig_head);if (!parse_events_add_pmu (parse_state, list, pmu->name, orig_head, - auto_merge_stats)) { + auto_merge_stats, loc)) {pr_debug ("%s -> %s/%s/\n" , str, pmu->name, alias->str); parse_state->wild_card_pmus = true;
@@ -1748,7 +1750,7 @@ 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, -/*auto_merge_stats=*/ true)) { +/*auto_merge_stats=*/ true, loc)) {pr_debug ("%s -> %s/%s/\n" , str,"fake_pmu" , str); ok++; }
tools/perf/util/parse-events.h +2 -2
@@ -202,7 +202,7 @@ int parse_events_add_breakpoint(struct parse_events_state *parse_state,int parse_events_add_pmu (struct parse_events_state *parse_state,struct list_head *list,char *name,struct list_head *head_config, -bool auto_merge_stats); +bool auto_merge_stats,void *loc); struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, const char *name, const char *metric_id,
@@ -211,7 +211,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,char *str,struct list_head *head_config, -struct list_head **listp); +struct list_head **listp,void *loc);int parse_events_copy_term_list (struct list_head *old,struct list_head **new);
tools/perf/util/parse-events.y +4 -4
@@ -313,7 +313,7 @@ PE_NAME opt_pmu_config YYNOMEM; } /* Attempt to add to list assuming $1 is a PMU name. */ - if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false)) { + if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false, &@1)) { struct perf_pmu *pmu = NULL; int ok = 0;
@@ -341,7 +341,7 @@ PE_NAME opt_pmu_config YYNOMEM; } if (!parse_events_add_pmu(parse_state, list, pmu->name, terms, - auto_merge_stats)) { + auto_merge_stats, &@1)) { ok++; parse_state->wild_card_pmus = true; }
@@ -352,7 +352,7 @@ PE_NAME opt_pmu_config if (!ok) { /* Failure to add, assume $1 is an event name. */ zfree(&list); - ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list); + ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list, &@1); $2 = NULL; } if (!ok) {
@@ -379,7 +379,7 @@ PE_NAME sep_dc struct list_head *list; int err; - err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list); + err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); if (err < 0) { struct parse_events_state *parse_state = _parse_state; struct parse_events_error *error = parse_state->error;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerPATCH v2 13/13 perf parse-events: Remove ABORT_ON
In reply to Ian RogersPrefer informative messages rather than none with ABORT_ON. Document one failure mode and add an error message for another.
--- tools/perf/util/parse-events.y | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
tools/perf/util/parse-events.y +14 -8
@@ -22,12 +22,6 @@ void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); -#define ABORT_ON(val) \ -do { \ - if (val) \ - YYABORT; \ -} while (0) - #define PE_ABORT(val) \ do { \ if (val == -ENOMEM) \
@@ -618,7 +612,9 @@ PE_RAW opt_event_config YYNOMEM; errno = 0; num = strtoull($1 + 1, NULL, 16); - ABORT_ON(errno); + /* Given the lexer will only give [a-fA-F0-9]+ a failure here should be impossible. */ + if (errno) + YYABORT; free($1); err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, /*wildcard=*/false);
@@ -978,7 +974,17 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE { struct parse_events_array array; - ABORT_ON($3 < $1); + if ($3 < $1) { + struct parse_events_state *parse_state = _parse_state; + struct parse_events_error *error = parse_state->error; + char *err_str; + + if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0) + err_str = NULL; + + parse_events_error__handle(error, @1.first_column, err_str, NULL); + YYABORT; + } array.nr_ranges = 1; array.ranges = malloc(sizeof(array.ranges[0])); if (!array.ranges)
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
Namhyung Kim
maintainerRe: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 38 lines · Ian Rogers
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/parse-events.y | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)tools/perf/util/parse-events.y +3
-7@@ -22,12 +22,6 @@ void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); -#define ABORT_ON(val) \ -do { \ - if (val) \ - YYABORT; \ -} while (0) - #define PE_ABORT(val) \ do { \ if (val == -ENOMEM) \@@ -618,7 +612,9 @@ PE_RAW opt_event_config YYNOMEM; errno = 0; num = strtoull($1 + 1, NULL, 16); - ABORT_ON(errno); + /* Given the lexer will only give [a-fA-F0-9]+ a failure here should be impossible. */ + if (errno) + YYABORT; free($1); err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, /*wildcard=*/false);
tools/perf/util/parse-events.y PE_VALUE PE_ARRAY_RANGE PE_VALUE · line 982
Quoted 10 lines
tools/perf/util/parse-events.y +6
-1@@ -978,7 +974,17 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE { struct parse_events_array array; - ABORT_ON($3 < $1); + if ($3 < $1) { + struct parse_events_state *parse_state = _parse_state; + struct parse_events_error *error = parse_state->error; + char *err_str; + + if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0)
Isn't it to be "greater-than or equal" ?
Thanks,
Namhyung
Quoted 11 lines
tools/perf/util/parse-events.y +5
-1+ err_str = NULL; + + parse_events_error__handle(error, @1.first_column, err_str, NULL); + YYABORT; + } array.nr_ranges = 1; array.ranges = malloc(sizeof(array.ranges[0])); if (!array.ranges) --2.41.0.162.gfafddb0af9-goog
Ian Rogers
reviewerRe: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 43 lines · Namhyung Kim
Quoted 41 lines · Ian Rogers
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/parse-events.y | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)tools/perf/util/parse-events.y +3
-7@@ -22,12 +22,6 @@ void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); -#define ABORT_ON(val) \ -do { \ - if (val) \ - YYABORT; \ -} while (0) - #define PE_ABORT(val) \ do { \ if (val == -ENOMEM) \@@ -618,7 +612,9 @@ PE_RAW opt_event_config YYNOMEM; errno = 0; num = strtoull($1 + 1, NULL, 16); - ABORT_ON(errno); + /* Given the lexer will only give [a-fA-F0-9]+ a failure here should be impossible. */ + if (errno) + YYABORT; free($1); err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, /*wildcard=*/false);@@ -978,7 +974,17 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE { struct parse_events_array array;
Quoted 9 lines
tools/perf/util/parse-events.y PE_VALUE PE_ARRAY_RANGE PE_VALUE · line 982
Quoted 7 lines
tools/perf/util/parse-events.y +6
-1- ABORT_ON($3 < $1); + if ($3 < $1) { + struct parse_events_state *parse_state = _parse_state; + struct parse_events_error *error = parse_state->error; + char *err_str; + + if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0)Isn't it to be "greater-than or equal" ?
I think the order is right. From the man page:
When successful, these functions return the number of bytes printed, just like sprintf(3). If memory allocation wasn't possible, or some other error occurs, these functions will return -1, and the contents of strp are undefined.
So here we need to catch -1 and ensure strp (&err_str) is NULL before passing it to parse_events_error__handle.
Thanks,
Ian
Quoted 15 lines
Thanks,
NamhyungQuoted 11 lines
tools/perf/util/parse-events.y +5
-1+ err_str = NULL; + + parse_events_error__handle(error, @1.first_column, err_str, NULL); + YYABORT; + } array.nr_ranges = 1; array.ranges = malloc(sizeof(array.ranges[0])); if (!array.ranges) --2.41.0.162.gfafddb0af9-goog
Namhyung Kim
maintainerRe: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 57 lines · Ian Rogers
Quoted 43 lines · Namhyung Kim
Quoted 41 lines · Ian Rogers
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/parse-events.y | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)tools/perf/util/parse-events.y +3
-7@@ -22,12 +22,6 @@ void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); -#define ABORT_ON(val) \ -do { \ - if (val) \ - YYABORT; \ -} while (0) - #define PE_ABORT(val) \ do { \ if (val == -ENOMEM) \@@ -618,7 +612,9 @@ PE_RAW opt_event_config YYNOMEM; errno = 0; num = strtoull($1 + 1, NULL, 16); - ABORT_ON(errno); + /* Given the lexer will only give [a-fA-F0-9]+ a failure here should be impossible. */ + if (errno) + YYABORT; free($1); err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, /*wildcard=*/false);@@ -978,7 +974,17 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE { struct parse_events_array array;Quoted 9 lines
tools/perf/util/parse-events.y PE_VALUE PE_ARRAY_RANGE PE_VALUE · line 982
Quoted 7 lines
tools/perf/util/parse-events.y +6
-1- ABORT_ON($3 < $1); + if ($3 < $1) { + struct parse_events_state *parse_state = _parse_state; + struct parse_events_error *error = parse_state->error; + char *err_str; + + if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0)Isn't it to be "greater-than or equal" ?
I think the order is right. From the man page:
Quoted 7 lines
When successful, these functions return the number of bytes printed, just like sprintf(3). If memory allocation wasn't possible, or some other error occurs, these functions will return -1, and the contents of strp are undefined.
So here we need to catch -1 and ensure strp (
&err_str) is NULL before passing it toparse_events_error__handle.
Oh, I meant the message not the condition in the if statement. It seems it aborts if $3 < $1, then it expects $3 >= $1 in the normal condition, right?
Thanks,
Namhyung
Ian Rogers
reviewerRe: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 64 lines · Namhyung Kim
Quoted 62 lines · Ian Rogers
Quoted 43 lines · Namhyung Kim
Quoted 41 lines · Ian Rogers
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/parse-events.y | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)tools/perf/util/parse-events.y +3
-7@@ -22,12 +22,6 @@ void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); -#define ABORT_ON(val) \ -do { \ - if (val) \ - YYABORT; \ -} while (0) - #define PE_ABORT(val) \ do { \ if (val == -ENOMEM) \@@ -618,7 +612,9 @@ PE_RAW opt_event_config YYNOMEM; errno = 0; num = strtoull($1 + 1, NULL, 16); - ABORT_ON(errno); + /* Given the lexer will only give [a-fA-F0-9]+ a failure here should be impossible. */ + if (errno) + YYABORT; free($1); err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, /*wildcard=*/false);@@ -978,7 +974,17 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE { struct parse_events_array array;Quoted 9 lines
tools/perf/util/parse-events.y PE_VALUE PE_ARRAY_RANGE PE_VALUE · line 982
Quoted 7 lines
tools/perf/util/parse-events.y +6
-1- ABORT_ON($3 < $1); + if ($3 < $1) { + struct parse_events_state *parse_state = _parse_state; + struct parse_events_error *error = parse_state->error; + char *err_str; + + if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0)Isn't it to be "greater-than or equal" ?
I think the order is right. From the man page:
When successful, these functions return the number of bytes printed, just like sprintf(3). If memory allocation wasn't possible, or some other error occurs, these functions will return -1, and the contents of strp are undefined.
Quoted 6 lines
Quoted 2 lines
So here we need to catch -1 and ensure strp (
&err_str) is NULL before passing it toparse_events_error__handle.Oh, I meant the message not the condition in the if statement. It seems it aborts if $3 < $1, then it expects $3 >= $1 in the normal condition, right?
In the old code with the macro expanded it did:
if ($3 < $1) YYABORT
in the new code it fills in parse_state->error if the same error condition applies. The change is to get rid of the macro and add an error message. The asprintf is just added to make the error message more informative.
Thanks,
Ian
Quoted 2 lines
Thanks,
Namhyung
Re: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
In reply to Ian RogersQuoted 2 lines
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.
Does such a wording really fit to the known requirement “Solve only one problem per patch.”?
Regards,
Markus
Ian Rogers
reviewerRe: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 8 lines · Markus Elfring
Quoted 3 lines
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Does such a wording really fit to the known requirement “Solve only one problem per patch.”?
Sorry your explanation isn't clear. Please can you elaborate.
Thanks,
Ian
Quoted 3 lines
Regards,
Markus
Re: [v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Does such a wording really fit to the known requirement “Solve only one problem per patch.”?
Sorry your explanation isn't clear.
Do you really find the application of the linked development documentation unclear in this case?
Quoted 1 line
Sorry your explanation isn't clear. Please can you elaborate.
Will it become helpful to split the proposed patch into smaller update steps?
Regards,
Markus
Ian Rogers
reviewerRe: [v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 11 lines · Markus Elfring
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
Prefer informative messages rather than none with
ABORT_ON. Document one failure mode and add an error message for another.Does such a wording really fit to the known requirement “Solve only one problem per patch.”?
Sorry your explanation isn't clear.
Quoted 7 lines
Do you really find the application of the linked development documentation unclear in this case?
Quoted 1 line
Sorry your explanation isn't clear. Please can you elaborate.
Will it become helpful to split the proposed patch into smaller update steps?
This is kind of why the series is 13 patches long, I'm not seeing why you think the following stats qualify as "long":
14 insertions(+), 8 deletions(-)
Thanks,
Ian
Quoted 2 lines
Regards,
Markus
Re: [v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 4 lines
Quoted 1 line
Will it become helpful to split the proposed patch into smaller update steps?
This is kind of why the series is 13 patches long, I'm not seeing why you think the following stats qualify as "long":
It seems that we came along different expectations for a desirable change granularity. Intentions influence how known “code problems” can be adjusted (also for this update step).
How should following change ideas be handled then?
1. Deletion of the macro “ABORT_ON”
2. Addition of a comment for a special check
3. Introduction of another error message for one failure mode
Would you like to adjust the change description another bit?
Regards,
Markus
Re: [v2 13/13] perf parse-events: Remove ABORT_ON
Quoted 10 lines · Markus Elfring
Quoted 4 lines
Quoted 1 line
Will it become helpful to split the proposed patch into smaller update steps?
This is kind of why the series is 13 patches long, I'm not seeing why you think the following stats qualify as "long":
It seems that we came along different expectations for a desirable change granularity. Intentions influence how known “code problems” can be adjusted (also for this update step).
How should following change ideas be handled then?
Quoted 8 lines
1. Deletion of the macro “ABORT_ON”
2. Addition of a comment for a special check
3. Introduction of another error message for one failure mode
Would you like to adjust the change description another bit?
Please no, it's fine.