* [PATCH v2 00/13] parse-events clean up
@ 2023-06-27 18:10 Ian Rogers
2023-06-27 18:10 ` [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token Ian Rogers
` (12 more replies)
0 siblings, 13 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
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(-)
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
[not found] ` <8dab7522-31de-2137-7474-991885932308@web.de>
2023-06-27 18:10 ` [PATCH v2 02/13] perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token Ian Rogers
` (11 subsequent siblings)
12 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning
PMUs before parsing").
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 42 ++--------------------------------
1 file changed, 2 insertions(+), 40 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 9f28d4b5502f..64755f9cd600 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 02/13] perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
2023-06-27 18:10 ` [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 03/13] perf parse-events: Remove two unused tokens Ian Rogers
` (10 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning
PMUs before parsing").
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 27 ---------------------------
1 file changed, 27 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 64755f9cd600..4ee6c6865655 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 03/13] perf parse-events: Remove two unused tokens
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
2023-06-27 18:10 ` [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token Ian Rogers
2023-06-27 18:10 ` [PATCH v2 02/13] perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 04/13] perf parse-events: Add more comments to parse_events_state Ian Rogers
` (9 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
The tokens PE_PREFIX_RAW and PE_PREFIX_GROUP are unused so remove them.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 4ee6c6865655..b09a5fa92144 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 04/13] perf parse-events: Add more comments to parse_events_state
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (2 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 03/13] perf parse-events: Remove two unused tokens Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 05/13] perf parse-events: Avoid regrouped warning for wild card events Ian Rogers
` (8 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Improve documentation of struct parse_events_state.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index b0eb95f93e9c..b37e5ee193a8 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -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;
};
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 05/13] perf parse-events: Avoid regrouped warning for wild card events
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (3 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 04/13] perf parse-events: Add more comments to parse_events_state Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 06/13] perf parse-event: Add memory allocation test for name terms Ian Rogers
` (7 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
There 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
```
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5dcfbf316bf6..0aa4308edb6c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -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);
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 06/13] perf parse-event: Add memory allocation test for name terms
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (4 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 05/13] perf parse-events: Avoid regrouped warning for wild card events Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 07/13] perf parse-events: Separate YYABORT and YYNOMEM cases Ian Rogers
` (6 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
If the name memory allocation fails then propagate to the parser.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.c | 5 ++++-
tools/perf/util/parse-events.y | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 0aa4308edb6c..f31f233e395f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -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;
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index b09a5fa92144..3ee351768433 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -263,7 +263,7 @@ PE_EVENT_NAME event_def
free($1);
if (err) {
free_list_evsel($2);
- YYABORT;
+ YYNOMEM;
}
$$ = $2;
}
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 07/13] perf parse-events: Separate YYABORT and YYNOMEM cases
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (5 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 06/13] perf parse-event: Add memory allocation test for name terms Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 08/13] perf parse-events: Move instances of YYABORT to YYNOMEM Ian Rogers
` (5 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Split cases in event_pmu for greater accuracy.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 45 ++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 3ee351768433..d22866b97b76 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 08/13] perf parse-events: Move instances of YYABORT to YYNOMEM
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (6 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 07/13] perf parse-events: Separate YYABORT and YYNOMEM cases Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 09/13] perf parse-events: Separate ENOMEM memory handling Ian Rogers
` (4 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Migration to improve error reporting as YYABORT cases should carry
event parsing errors.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 58 +++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 18 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index d22866b97b76..eaf43bd8fe3f 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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;
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 09/13] perf parse-events: Separate ENOMEM memory handling
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (7 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 08/13] perf parse-events: Move instances of YYABORT to YYNOMEM Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 10/13] perf parse-events: Additional error reporting Ian Rogers
` (3 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Add PE_ABORT that will YYNOMEM or YYABORT accordingly.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 134 ++++++++++++++++++++-------------
1 file changed, 82 insertions(+), 52 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index eaf43bd8fe3f..f090a85c4518 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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;
}
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 10/13] perf parse-events: Additional error reporting
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (8 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 09/13] perf parse-events: Separate ENOMEM memory handling Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 11/13] perf parse-events: Populate error column for BPF/tracepoint events Ian Rogers
` (2 subsequent siblings)
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
When 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.
Fixes: ("70c90e4a6b2f perf parse-events: Avoid scanning PMUs before parsing")
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/parse-events.y | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index f090a85c4518..a636a7db6e6f 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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;
}
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 11/13] perf parse-events: Populate error column for BPF/tracepoint events
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (9 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 10/13] perf parse-events: Additional error reporting Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 12/13] perf parse-events: Improve location for add pmu Ian Rogers
2023-06-27 18:10 ` [PATCH v2 13/13] perf parse-events: Remove ABORT_ON Ian Rogers
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Follow convention from parse_events_terms__num/str and pass the
YYLTYPE for the location.
Signed-off-by: Ian Rogers <irogers@google.com>
---
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(-)
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 8beb46066034..31796f2a80f4 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -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");
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index f31f233e395f..fdd304fbed7c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -499,7 +499,7 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name,
#ifdef HAVE_LIBTRACEEVENT
static void tracepoint_error(struct parse_events_error *e, int err,
- const char *sys, const char *name)
+ const char *sys, const char *name, int column)
{
const char *str;
char help[BUFSIZ];
@@ -526,18 +526,19 @@ static void tracepoint_error(struct parse_events_error *e, int err,
}
tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
- parse_events_error__handle(e, 0, strdup(str), strdup(help));
+ parse_events_error__handle(e, column, strdup(str), strdup(help));
}
static int add_tracepoint(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name,
struct parse_events_error *err,
- struct list_head *head_config)
+ struct list_head *head_config, void *loc_)
{
+ YYLTYPE *loc = loc_;
struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, (*idx)++);
if (IS_ERR(evsel)) {
- tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name);
+ tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name, loc->first_column);
return PTR_ERR(evsel);
}
@@ -556,7 +557,7 @@ static int add_tracepoint(struct list_head *list, int *idx,
static int add_tracepoint_multi_event(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name,
struct parse_events_error *err,
- struct list_head *head_config)
+ struct list_head *head_config, YYLTYPE *loc)
{
char *evt_path;
struct dirent *evt_ent;
@@ -565,13 +566,13 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
evt_path = get_events_file(sys_name);
if (!evt_path) {
- tracepoint_error(err, errno, sys_name, evt_name);
+ tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
return -1;
}
evt_dir = opendir(evt_path);
if (!evt_dir) {
put_events_file(evt_path);
- tracepoint_error(err, errno, sys_name, evt_name);
+ tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
return -1;
}
@@ -588,11 +589,11 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
found++;
ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name,
- err, head_config);
+ err, head_config, loc);
}
if (!found) {
- tracepoint_error(err, ENOENT, sys_name, evt_name);
+ tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column);
ret = -1;
}
@@ -604,19 +605,19 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
static int add_tracepoint_event(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name,
struct parse_events_error *err,
- struct list_head *head_config)
+ struct list_head *head_config, YYLTYPE *loc)
{
return strpbrk(evt_name, "*?") ?
- add_tracepoint_multi_event(list, idx, sys_name, evt_name,
- err, head_config) :
- add_tracepoint(list, idx, sys_name, evt_name,
- err, head_config);
+ add_tracepoint_multi_event(list, idx, sys_name, evt_name,
+ err, head_config, loc) :
+ add_tracepoint(list, idx, sys_name, evt_name,
+ err, head_config, loc);
}
static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name,
struct parse_events_error *err,
- struct list_head *head_config)
+ struct list_head *head_config, YYLTYPE *loc)
{
struct dirent *events_ent;
DIR *events_dir;
@@ -624,7 +625,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
events_dir = tracing_events__opendir();
if (!events_dir) {
- tracepoint_error(err, errno, sys_name, evt_name);
+ tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
return -1;
}
@@ -640,7 +641,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
continue;
ret = add_tracepoint_event(list, idx, events_ent->d_name,
- evt_name, err, head_config);
+ evt_name, err, head_config, loc);
}
closedir(events_dir);
@@ -653,6 +654,7 @@ struct __add_bpf_event_param {
struct parse_events_state *parse_state;
struct list_head *list;
struct list_head *head_config;
+ YYLTYPE *loc;
};
static int add_bpf_event(const char *group, const char *event, int fd, struct bpf_object *obj,
@@ -679,7 +681,7 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bp
err = parse_events_add_tracepoint(&new_evsels, &parse_state->idx, group,
event, parse_state->error,
- param->head_config);
+ param->head_config, param->loc);
if (err) {
struct evsel *evsel, *tmp;
@@ -706,12 +708,14 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bp
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 err;
char errbuf[BUFSIZ];
- struct __add_bpf_event_param param = {parse_state, list, head_config};
+ struct __add_bpf_event_param param = {parse_state, list, head_config, loc};
static bool registered_unprobe_atexit = false;
+ YYLTYPE test_loc = {.first_column = -1};
if (IS_ERR(obj) || !obj) {
snprintf(errbuf, sizeof(errbuf),
@@ -742,6 +746,9 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
goto errout;
}
+ if (!param.loc)
+ param.loc = &test_loc;
+
err = bpf__foreach_event(obj, add_bpf_event, ¶m);
if (err) {
snprintf(errbuf, sizeof(errbuf),
@@ -751,7 +758,7 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
return 0;
errout:
- parse_events_error__handle(parse_state->error, 0,
+ parse_events_error__handle(parse_state->error, param.loc->first_column,
strdup(errbuf), strdup("(add -v to see detail)"));
return err;
}
@@ -839,11 +846,13 @@ 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_)
{
int err;
struct bpf_object *obj;
LIST_HEAD(obj_head_config);
+ YYLTYPE *loc = loc_;
if (head_config)
split_bpf_config_terms(head_config, &obj_head_config);
@@ -863,12 +872,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
-err, errbuf,
sizeof(errbuf));
- parse_events_error__handle(parse_state->error, 0,
+ parse_events_error__handle(parse_state->error, loc->first_column,
strdup(errbuf), strdup("(add -v to see detail)"));
return err;
}
- err = parse_events_load_bpf_obj(parse_state, list, obj, head_config);
+ err = parse_events_load_bpf_obj(parse_state, list, obj, head_config, loc);
if (err)
return err;
err = parse_events_config_bpf(parse_state, obj, &obj_head_config);
@@ -885,9 +894,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
struct list_head *list __maybe_unused,
struct bpf_object *obj __maybe_unused,
- struct list_head *head_config __maybe_unused)
+ struct list_head *head_config __maybe_unused,
+ void *loc_)
{
- parse_events_error__handle(parse_state->error, 0,
+ YYLTYPE *loc = loc_;
+
+ parse_events_error__handle(parse_state->error, loc->first_column,
strdup("BPF support is not compiled"),
strdup("Make sure libbpf-devel is available at build time."));
return -ENOTSUP;
@@ -897,9 +909,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
struct list_head *list __maybe_unused,
char *bpf_file_name __maybe_unused,
bool source __maybe_unused,
- struct list_head *head_config __maybe_unused)
+ struct list_head *head_config __maybe_unused,
+ void *loc_)
{
- parse_events_error__handle(parse_state->error, 0,
+ YYLTYPE *loc = loc_;
+
+ parse_events_error__handle(parse_state->error, loc->first_column,
strdup("BPF support is not compiled"),
strdup("Make sure libbpf-devel is available at build time."));
return -ENOTSUP;
@@ -1433,8 +1448,9 @@ static int get_config_chgs(struct perf_pmu *pmu, struct list_head *head_config,
int parse_events_add_tracepoint(struct list_head *list, int *idx,
const char *sys, const char *event,
struct parse_events_error *err,
- struct list_head *head_config)
+ struct list_head *head_config, void *loc_)
{
+ YYLTYPE *loc = loc_;
#ifdef HAVE_LIBTRACEEVENT
if (head_config) {
struct perf_event_attr attr;
@@ -1446,17 +1462,17 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx,
if (strpbrk(sys, "*?"))
return add_tracepoint_multi_sys(list, idx, sys, event,
- err, head_config);
+ err, head_config, loc);
else
return add_tracepoint_event(list, idx, sys, event,
- err, head_config);
+ err, head_config, loc);
#else
(void)list;
(void)idx;
(void)sys;
(void)event;
(void)head_config;
- parse_events_error__handle(err, 0, strdup("unsupported tracepoint"),
+ parse_events_error__handle(err, loc->first_column, strdup("unsupported tracepoint"),
strdup("libtraceevent is necessary for tracepoint support"));
return -1;
#endif
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index b37e5ee193a8..cabbe70adb82 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -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,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index a636a7db6e6f..50f5b819de37 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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);
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 12/13] perf parse-events: Improve location for add pmu
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (10 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 11/13] perf parse-events: Populate error column for BPF/tracepoint events Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-27 18:10 ` [PATCH v2 13/13] perf parse-events: Remove ABORT_ON Ian Rogers
12 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
Improve the location for add PMU for cases when PMUs aren't found.
Signed-off-by: Ian Rogers <irogers@google.com>
---
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(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index fdd304fbed7c..58fcfff99ec4 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -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++;
}
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index cabbe70adb82..e59b33805886 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -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);
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 50f5b819de37..844646752462 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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;
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
` (11 preceding siblings ...)
2023-06-27 18:10 ` [PATCH v2 12/13] perf parse-events: Improve location for add pmu Ian Rogers
@ 2023-06-27 18:10 ` Ian Rogers
2023-06-29 21:49 ` Namhyung Kim
[not found] ` <ea39aaf0-0314-1780-c1cd-7c3661fa3e7c@web.de>
12 siblings, 2 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-27 18:10 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, Adrian Hunter, Athira Rajeev, Kan Liang,
linux-perf-users, linux-kernel, bpf
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 <irogers@google.com>
---
tools/perf/util/parse-events.y | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 844646752462..454577f7aff6 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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)
--
2.41.0.162.gfafddb0af9-goog
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
2023-06-27 18:10 ` [PATCH v2 13/13] perf parse-events: Remove ABORT_ON Ian Rogers
@ 2023-06-29 21:49 ` Namhyung Kim
2023-06-30 15:14 ` Ian Rogers
[not found] ` <ea39aaf0-0314-1780-c1cd-7c3661fa3e7c@web.de>
1 sibling, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2023-06-29 21:49 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Athira Rajeev, Kan Liang, linux-perf-users, linux-kernel, bpf
On Tue, Jun 27, 2023 at 11:11 AM Ian Rogers <irogers@google.com> wrote:
>
> 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 <irogers@google.com>
> ---
> tools/perf/util/parse-events.y | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> index 844646752462..454577f7aff6 100644
> --- a/tools/perf/util/parse-events.y
> +++ b/tools/perf/util/parse-events.y
> @@ -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)
Isn't it to be "greater-than or equal" ?
Thanks,
Namhyung
> + 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
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
2023-06-29 21:49 ` Namhyung Kim
@ 2023-06-30 15:14 ` Ian Rogers
2023-07-01 18:43 ` Namhyung Kim
0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 15:14 UTC (permalink / raw)
To: Namhyung Kim
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Athira Rajeev, Kan Liang, linux-perf-users, linux-kernel, bpf
On Thu, Jun 29, 2023 at 2:49 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Tue, Jun 27, 2023 at 11:11 AM Ian Rogers <irogers@google.com> wrote:
> >
> > 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 <irogers@google.com>
> > ---
> > tools/perf/util/parse-events.y | 22 ++++++++++++++--------
> > 1 file changed, 14 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> > index 844646752462..454577f7aff6 100644
> > --- a/tools/perf/util/parse-events.y
> > +++ b/tools/perf/util/parse-events.y
> > @@ -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)
>
> 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
> Thanks,
> Namhyung
>
>
> > + 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
> >
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
[not found] ` <8dab7522-31de-2137-7474-991885932308@web.de>
@ 2023-06-30 17:05 ` Ian Rogers
[not found] ` <59e92b31-cd78-5c0c-ef87-f0d824cd20f7@web.de>
2023-07-03 12:46 ` [PATCH v2 " Dan Carpenter
0 siblings, 2 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 17:05 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Fri, Jun 30, 2023 at 9:35 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning
> > PMUs before parsing").
>
> Will the chances ever grow to add another imperative change suggestion?
>
> See also:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94
Sorry, I can't parse this.
Thanks,
Ian
> Regards,
> Markus
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
[not found] ` <ea39aaf0-0314-1780-c1cd-7c3661fa3e7c@web.de>
@ 2023-06-30 17:06 ` Ian Rogers
[not found] ` <a3517306-7804-f5cf-6182-ef63b6054647@web.de>
0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 17:06 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Fri, Jun 30, 2023 at 9:56 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> > 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.”?
>
> See also:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n81
Sorry your explanation isn't clear. Please can you elaborate.
Thanks,
Ian
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
[not found] ` <59e92b31-cd78-5c0c-ef87-f0d824cd20f7@web.de>
@ 2023-06-30 17:16 ` Ian Rogers
[not found] ` <44d77ec3-9a19-cfd5-4bba-4a23d0cd526b@web.de>
0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 17:16 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Fri, Jun 30, 2023 at 10:15 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> >>> Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning
> >>> PMUs before parsing").
> >>
> >> Will the chances ever grow to add another imperative change suggestion?
> >>
> >> See also:
> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94
> >
> >
> > 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
> Regards,
> Markus
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
[not found] ` <44d77ec3-9a19-cfd5-4bba-4a23d0cd526b@web.de>
@ 2023-06-30 17:33 ` Ian Rogers
[not found] ` <dbf08741-0b3d-f61f-bb06-05ca3f445202@web.de>
0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 17:33 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Fri, Jun 30, 2023 at 10:23 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> >>>>> Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning
> >>>>> PMUs before parsing").
> >>>>
> >>>> Will the chances ever grow to add another imperative change suggestion?
> >>>>
> >>>> See also:
> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94
> >>>
> >>>
> >>> 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?
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
> Regards,
> Markus
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
[not found] ` <dbf08741-0b3d-f61f-bb06-05ca3f445202@web.de>
@ 2023-06-30 18:01 ` Ian Rogers
0 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 18:01 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Fri, Jun 30, 2023 at 10:52 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> >> Can the mentioned patch review concern be adjusted with wording alternatives
> >> for improved commit messages?
> >
> > Sorry, checked with a colleague and kernel contributor,
>
> Interesting …
>
>
> > 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
>
>
> > "imperative mood" makes no sense,
>
> How does such an opinion fit to the Linux development documentation?
>
>
> > 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
> Regards,
> Markus
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [v2 13/13] perf parse-events: Remove ABORT_ON
[not found] ` <a3517306-7804-f5cf-6182-ef63b6054647@web.de>
@ 2023-06-30 18:05 ` Ian Rogers
[not found] ` <4672c6f8-ef0d-6a36-49be-145629c2eade@web.de>
0 siblings, 1 reply; 26+ messages in thread
From: Ian Rogers @ 2023-06-30 18:05 UTC (permalink / raw)
To: Markus Elfring
Cc: linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Fri, Jun 30, 2023 at 10:40 AM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> >>> 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.”?
> >>
> >> See also:
> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n81
> >
> > Sorry your explanation isn't clear.
>
> Do you really find the application of the linked development documentation unclear
> in this case?
>
>
> > 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
> Regards,
> Markus
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [v2 13/13] perf parse-events: Remove ABORT_ON
[not found] ` <4672c6f8-ef0d-6a36-49be-145629c2eade@web.de>
@ 2023-07-01 9:32 ` Greg KH
0 siblings, 0 replies; 26+ messages in thread
From: Greg KH @ 2023-07-01 9:32 UTC (permalink / raw)
To: Markus Elfring
Cc: Ian Rogers, linux-perf-users, bpf, kernel-janitors, Adrian Hunter,
Alexander Shishkin, Arnaldo Carvalho de Melo, Athira Rajeev,
Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
LKML
On Sat, Jul 01, 2023 at 11:00:15AM +0200, Markus Elfring wrote:
> >> 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?
Please no, it's fine.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
2023-06-30 15:14 ` Ian Rogers
@ 2023-07-01 18:43 ` Namhyung Kim
2023-07-12 5:01 ` Ian Rogers
0 siblings, 1 reply; 26+ messages in thread
From: Namhyung Kim @ 2023-07-01 18:43 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Athira Rajeev, Kan Liang, linux-perf-users, linux-kernel, bpf
On Fri, Jun 30, 2023 at 8:14 AM Ian Rogers <irogers@google.com> wrote:
>
> On Thu, Jun 29, 2023 at 2:49 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > On Tue, Jun 27, 2023 at 11:11 AM Ian Rogers <irogers@google.com> wrote:
> > >
> > > 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 <irogers@google.com>
> > > ---
> > > tools/perf/util/parse-events.y | 22 ++++++++++++++--------
> > > 1 file changed, 14 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> > > index 844646752462..454577f7aff6 100644
> > > --- a/tools/perf/util/parse-events.y
> > > +++ b/tools/perf/util/parse-events.y
> > > @@ -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)
> >
> > 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.
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
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token
2023-06-30 17:05 ` Ian Rogers
[not found] ` <59e92b31-cd78-5c0c-ef87-f0d824cd20f7@web.de>
@ 2023-07-03 12:46 ` Dan Carpenter
1 sibling, 0 replies; 26+ messages in thread
From: Dan Carpenter @ 2023-07-03 12:46 UTC (permalink / raw)
To: Ian Rogers
Cc: Markus Elfring, linux-perf-users, bpf, kernel-janitors,
Adrian Hunter, Alexander Shishkin, Arnaldo Carvalho de Melo,
Athira Rajeev, Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland,
Namhyung Kim, LKML
On Fri, Jun 30, 2023 at 10:05:22AM -0700, Ian Rogers wrote:
> On Fri, Jun 30, 2023 at 9:35 AM Markus Elfring <Markus.Elfring@web.de> wrote:
> >
> > > Removed by commit 70c90e4a6b2f ("perf parse-events: Avoid scanning
> > > PMUs before parsing").
> >
> > Will the chances ever grow to add another imperative change suggestion?
> >
> > See also:
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94
>
>
> Sorry, I can't parse this.
Markus is banned from vger. Just ignore him.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 13/13] perf parse-events: Remove ABORT_ON
2023-07-01 18:43 ` Namhyung Kim
@ 2023-07-12 5:01 ` Ian Rogers
0 siblings, 0 replies; 26+ messages in thread
From: Ian Rogers @ 2023-07-12 5:01 UTC (permalink / raw)
To: Namhyung Kim
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Athira Rajeev, Kan Liang, linux-perf-users, linux-kernel, bpf
On Sat, Jul 1, 2023 at 11:43 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Fri, Jun 30, 2023 at 8:14 AM Ian Rogers <irogers@google.com> wrote:
> >
> > On Thu, Jun 29, 2023 at 2:49 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > On Tue, Jun 27, 2023 at 11:11 AM Ian Rogers <irogers@google.com> wrote:
> > > >
> > > > 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 <irogers@google.com>
> > > > ---
> > > > tools/perf/util/parse-events.y | 22 ++++++++++++++--------
> > > > 1 file changed, 14 insertions(+), 8 deletions(-)
> > > >
> > > > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> > > > index 844646752462..454577f7aff6 100644
> > > > --- a/tools/perf/util/parse-events.y
> > > > +++ b/tools/perf/util/parse-events.y
> > > > @@ -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)
> > >
> > > 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.
>
> 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
> Thanks,
> Namhyung
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2023-07-12 5:01 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
2023-06-27 18:10 ` [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token Ian Rogers
[not found] ` <8dab7522-31de-2137-7474-991885932308@web.de>
2023-06-30 17:05 ` Ian Rogers
[not found] ` <59e92b31-cd78-5c0c-ef87-f0d824cd20f7@web.de>
2023-06-30 17:16 ` [v2 " Ian Rogers
[not found] ` <44d77ec3-9a19-cfd5-4bba-4a23d0cd526b@web.de>
2023-06-30 17:33 ` Ian Rogers
[not found] ` <dbf08741-0b3d-f61f-bb06-05ca3f445202@web.de>
2023-06-30 18:01 ` Ian Rogers
2023-07-03 12:46 ` [PATCH v2 " Dan Carpenter
2023-06-27 18:10 ` [PATCH v2 02/13] perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token Ian Rogers
2023-06-27 18:10 ` [PATCH v2 03/13] perf parse-events: Remove two unused tokens Ian Rogers
2023-06-27 18:10 ` [PATCH v2 04/13] perf parse-events: Add more comments to parse_events_state Ian Rogers
2023-06-27 18:10 ` [PATCH v2 05/13] perf parse-events: Avoid regrouped warning for wild card events Ian Rogers
2023-06-27 18:10 ` [PATCH v2 06/13] perf parse-event: Add memory allocation test for name terms Ian Rogers
2023-06-27 18:10 ` [PATCH v2 07/13] perf parse-events: Separate YYABORT and YYNOMEM cases Ian Rogers
2023-06-27 18:10 ` [PATCH v2 08/13] perf parse-events: Move instances of YYABORT to YYNOMEM Ian Rogers
2023-06-27 18:10 ` [PATCH v2 09/13] perf parse-events: Separate ENOMEM memory handling Ian Rogers
2023-06-27 18:10 ` [PATCH v2 10/13] perf parse-events: Additional error reporting Ian Rogers
2023-06-27 18:10 ` [PATCH v2 11/13] perf parse-events: Populate error column for BPF/tracepoint events Ian Rogers
2023-06-27 18:10 ` [PATCH v2 12/13] perf parse-events: Improve location for add pmu Ian Rogers
2023-06-27 18:10 ` [PATCH v2 13/13] perf parse-events: Remove ABORT_ON Ian Rogers
2023-06-29 21:49 ` Namhyung Kim
2023-06-30 15:14 ` Ian Rogers
2023-07-01 18:43 ` Namhyung Kim
2023-07-12 5:01 ` Ian Rogers
[not found] ` <ea39aaf0-0314-1780-c1cd-7c3661fa3e7c@web.de>
2023-06-30 17:06 ` Ian Rogers
[not found] ` <a3517306-7804-f5cf-6182-ef63b6054647@web.de>
2023-06-30 18:05 ` [v2 " Ian Rogers
[not found] ` <4672c6f8-ef0d-6a36-49be-145629c2eade@web.de>
2023-07-01 9:32 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).