2 %parse-param {void *_parse_state}
3 %parse-param {void *scanner}
4 %lex-param {void* scanner}
14 #include <linux/compiler.h>
15 #include <linux/types.h>
16 #include <linux/zalloc.h>
20 #include "parse-events.h"
21 #include "parse-events-bison.h"
23 void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
25 #define ABORT_ON(val) \
31 static struct list_head* alloc_list(void)
33 struct list_head *list;
35 list = malloc(sizeof(*list));
43 static void free_list_evsel(struct list_head* list_evsel)
45 struct evsel *evsel, *tmp;
47 list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
48 list_del_init(&evsel->core.node);
56 %token PE_START_EVENTS PE_START_TERMS
57 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM
58 %token PE_VALUE_SYM_TOOL
61 %token PE_BPF_OBJECT PE_BPF_SOURCE
62 %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH
63 %token PE_LEGACY_CACHE
64 %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
66 %token PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
67 %token PE_ARRAY_ALL PE_ARRAY_RANGE
68 %token PE_DRV_CFG_TERM
71 %type <num> PE_VALUE_SYM_HW
72 %type <num> PE_VALUE_SYM_SW
73 %type <num> PE_VALUE_SYM_TOOL
78 %type <str> PE_BPF_OBJECT
79 %type <str> PE_BPF_SOURCE
80 %type <str> PE_LEGACY_CACHE
81 %type <str> PE_MODIFIER_EVENT
82 %type <str> PE_MODIFIER_BP
83 %type <str> PE_EVENT_NAME
84 %type <str> PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
85 %type <str> PE_DRV_CFG_TERM
86 %type <str> name_or_raw name_or_legacy
87 %destructor { free ($$); } <str>
88 %type <term> event_term
89 %destructor { parse_events_term__delete ($$); } <term>
90 %type <list_terms> event_config
91 %type <list_terms> opt_event_config
92 %type <list_terms> opt_pmu_config
93 %destructor { parse_events_terms__delete ($$); } <list_terms>
94 %type <list_evsel> event_pmu
95 %type <list_evsel> event_legacy_symbol
96 %type <list_evsel> event_legacy_cache
97 %type <list_evsel> event_legacy_mem
98 %type <list_evsel> event_legacy_tracepoint
99 %type <list_evsel> event_legacy_numeric
100 %type <list_evsel> event_legacy_raw
101 %type <list_evsel> event_bpf_file
102 %type <list_evsel> event_def
103 %type <list_evsel> event_mod
104 %type <list_evsel> event_name
105 %type <list_evsel> event
106 %type <list_evsel> events
107 %type <list_evsel> group_def
108 %type <list_evsel> group
109 %type <list_evsel> groups
110 %destructor { free_list_evsel ($$); } <list_evsel>
111 %type <tracepoint_name> tracepoint_name
112 %destructor { free ($$.sys); free ($$.event); } <tracepoint_name>
114 %type <array> array_term
115 %type <array> array_terms
116 %destructor { free ($$.ranges); } <array>
117 %type <hardware_term> PE_TERM_HW
118 %destructor { free ($$.str); } <hardware_term>
124 struct list_head *list_evsel;
125 struct list_head *list_terms;
126 struct parse_events_term *term;
127 struct tracepoint_name {
131 struct parse_events_array array;
132 struct hardware_term {
140 PE_START_EVENTS start_events
142 PE_START_TERMS start_terms
146 struct parse_events_state *parse_state = _parse_state;
149 parse_events_update_lists($1, &parse_state->list);
155 struct list_head *list = $1;
156 struct list_head *group = $3;
159 parse_events_update_lists(group, list);
165 struct list_head *list = $1;
166 struct list_head *event = $3;
169 parse_events_update_lists(event, list);
178 group_def ':' PE_MODIFIER_EVENT
180 struct list_head *list = $1;
183 err = parse_events__modifier_group(list, $3);
186 struct parse_events_state *parse_state = _parse_state;
187 struct parse_events_error *error = parse_state->error;
189 parse_events_error__handle(error, @3.first_column,
190 strdup("Bad modifier"), NULL);
191 free_list_evsel(list);
200 PE_NAME '{' events '}'
202 struct list_head *list = $3;
204 /* Takes ownership of $1. */
205 parse_events__set_leader($1, list);
211 struct list_head *list = $2;
213 parse_events__set_leader(NULL, list);
220 struct list_head *event = $3;
221 struct list_head *list = $1;
224 parse_events_update_lists(event, list);
233 event_name PE_MODIFIER_EVENT
235 struct list_head *list = $1;
239 * Apply modifier on all events added by single event definition
240 * (there could be more events added for multiple tracepoint
241 * definitions via '*?'.
243 err = parse_events__modifier_event(list, $2, false);
246 struct parse_events_state *parse_state = _parse_state;
247 struct parse_events_error *error = parse_state->error;
249 parse_events_error__handle(error, @2.first_column,
250 strdup("Bad modifier"), NULL);
251 free_list_evsel(list);
260 PE_EVENT_NAME event_def
264 err = parse_events_name($2, $1);
275 event_def: event_pmu |
276 event_legacy_symbol |
277 event_legacy_cache sep_dc |
278 event_legacy_mem sep_dc |
279 event_legacy_tracepoint sep_dc |
280 event_legacy_numeric sep_dc |
281 event_legacy_raw sep_dc |
285 PE_NAME opt_pmu_config
287 struct parse_events_state *parse_state = _parse_state;
288 struct parse_events_error *error = parse_state->error;
289 struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL;
290 char *pattern = NULL;
292 #define CLEANUP_YYABORT \
294 parse_events_terms__delete($2); \
295 parse_events_terms__delete(orig_terms); \
302 if (parse_events_copy_term_list($2, &orig_terms))
306 error->idx = @1.first_column;
311 /* Attempt to add to list assuming $1 is a PMU name. */
312 if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false)) {
313 struct perf_pmu *pmu = NULL;
316 /* Failure to add, try wildcard expansion of $1 as a PMU name. */
317 if (asprintf(&pattern, "%s*", $1) < 0)
320 while ((pmu = perf_pmus__scan(pmu)) != NULL) {
321 char *name = pmu->name;
323 if (parse_events__filter_pmu(parse_state, pmu))
326 if (!strncmp(name, "uncore_", 7) &&
327 strncmp($1, "uncore_", 7))
329 if (!perf_pmu__match(pattern, name, $1) ||
330 !perf_pmu__match(pattern, pmu->alias_name, $1)) {
331 bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu);
333 if (parse_events_copy_term_list(orig_terms, &terms))
335 if (!parse_events_add_pmu(parse_state, list, pmu->name, terms,
338 parse_state->wild_card_pmus = true;
340 parse_events_terms__delete(terms);
345 /* Failure to add, assume $1 is an event name. */
347 ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list);
353 parse_events_terms__delete($2);
354 parse_events_terms__delete(orig_terms);
358 #undef CLEANUP_YYABORT
361 PE_KERNEL_PMU_EVENT sep_dc
363 struct list_head *list;
366 err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
375 struct list_head *list;
378 err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
385 PE_KERNEL_PMU_EVENT opt_pmu_config
387 struct list_head *list;
391 err = parse_events_multi_pmu_add(_parse_state, $1, $2, &list);
398 PE_PMU_EVENT_FAKE sep_dc
400 struct list_head *list;
407 err = parse_events_add_pmu(_parse_state, list, $1, /*head_config=*/NULL,
408 /*auto_merge_stats=*/false);
417 PE_PMU_EVENT_FAKE opt_pmu_config
419 struct list_head *list;
426 err = parse_events_add_pmu(_parse_state, list, $1, $2, /*auto_merge_stats=*/false);
428 parse_events_terms__delete($2);
442 value_sym '/' event_config '/'
444 struct list_head *list;
446 int config = $1 & 255;
448 bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE);
452 err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard);
453 parse_events_terms__delete($3);
455 free_list_evsel(list);
461 value_sym sep_slash_slash_dc
463 struct list_head *list;
465 int config = $1 & 255;
466 bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE);
470 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config,
471 /*head_config=*/NULL, wildcard));
475 PE_VALUE_SYM_TOOL sep_slash_slash_dc
477 struct list_head *list;
481 ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
486 PE_LEGACY_CACHE opt_event_config
488 struct parse_events_state *parse_state = _parse_state;
489 struct list_head *list;
494 err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2);
496 parse_events_terms__delete($2);
499 free_list_evsel(list);
506 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config
508 struct list_head *list;
513 err = parse_events_add_breakpoint(_parse_state, list,
515 parse_events_terms__delete($7);
524 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config
526 struct list_head *list;
531 err = parse_events_add_breakpoint(_parse_state, list,
533 parse_events_terms__delete($5);
541 PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config
543 struct list_head *list;
548 err = parse_events_add_breakpoint(_parse_state, list,
550 parse_events_terms__delete($5);
559 PE_PREFIX_MEM PE_VALUE opt_event_config
561 struct list_head *list;
566 err = parse_events_add_breakpoint(_parse_state, list,
568 parse_events_terms__delete($3);
576 event_legacy_tracepoint:
577 tracepoint_name opt_event_config
579 struct parse_events_state *parse_state = _parse_state;
580 struct parse_events_error *error = parse_state->error;
581 struct list_head *list;
587 error->idx = @1.first_column;
589 err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
592 parse_events_terms__delete($2);
605 struct tracepoint_name tracepoint = {$1, $3};
610 event_legacy_numeric:
611 PE_VALUE ':' PE_VALUE opt_event_config
613 struct list_head *list;
618 err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4,
620 parse_events_terms__delete($4);
629 PE_RAW opt_event_config
631 struct list_head *list;
638 num = strtoull($1 + 1, NULL, 16);
641 err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2,
643 parse_events_terms__delete($2);
652 PE_BPF_OBJECT opt_event_config
654 struct parse_events_state *parse_state = _parse_state;
655 struct list_head *list;
660 err = parse_events_load_bpf(parse_state, list, $1, false, $2);
661 parse_events_terms__delete($2);
670 PE_BPF_SOURCE opt_event_config
672 struct list_head *list;
677 err = parse_events_load_bpf(_parse_state, list, $1, true, $2);
678 parse_events_terms__delete($2);
712 start_terms: event_config
714 struct parse_events_state *parse_state = _parse_state;
715 if (parse_state->terms) {
716 parse_events_terms__delete ($1);
719 parse_state->terms = $1;
723 event_config ',' event_term
725 struct list_head *head = $1;
726 struct parse_events_term *term = $3;
729 parse_events_term__delete(term);
732 list_add_tail(&term->list, head);
738 struct list_head *head = malloc(sizeof(*head));
739 struct parse_events_term *term = $1;
742 INIT_LIST_HEAD(head);
743 list_add_tail(&term->list, head);
747 name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE
749 name_or_legacy: PE_NAME | PE_LEGACY_CACHE
754 struct parse_events_term *term;
756 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW,
757 strdup("raw"), $1, &@1, &@1)) {
764 name_or_raw '=' name_or_legacy
766 struct parse_events_term *term;
768 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
777 name_or_raw '=' PE_VALUE
779 struct parse_events_term *term;
781 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
782 $1, $3, false, &@1, &@3)) {
789 name_or_raw '=' PE_TERM_HW
791 struct parse_events_term *term;
793 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
794 $1, $3.str, &@1, &@3)) {
804 struct parse_events_term *term;
806 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE,
807 $1, 1, true, &@1, NULL)) {
816 struct parse_events_term *term;
818 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
819 $1, 1, true, &@1, NULL)) {
828 struct parse_events_term *term;
830 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE,
831 $1.str, $1.num & 255, false, &@1, NULL)) {
838 PE_TERM '=' name_or_legacy
840 struct parse_events_term *term;
842 if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) {
849 PE_TERM '=' PE_TERM_HW
851 struct parse_events_term *term;
853 if (parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3)) {
862 struct parse_events_term *term;
864 ABORT_ON(parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3));
870 struct parse_events_term *term;
872 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
878 struct parse_events_term *term;
880 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
884 name_or_raw array '=' name_or_legacy
886 struct parse_events_term *term;
888 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
899 name_or_raw array '=' PE_VALUE
901 struct parse_events_term *term;
903 if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
904 $1, $4, false, &@1, &@4)) {
915 struct parse_events_term *term;
916 char *config = strdup($1);
919 if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
920 config, $1, &@1, NULL)) {
941 array_terms ',' array_term
943 struct parse_events_array new_array;
945 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
946 new_array.ranges = realloc($1.ranges,
947 sizeof(new_array.ranges[0]) *
948 new_array.nr_ranges);
949 ABORT_ON(!new_array.ranges);
950 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
951 $3.nr_ranges * sizeof(new_array.ranges[0]));
961 struct parse_events_array array;
964 array.ranges = malloc(sizeof(array.ranges[0]));
965 ABORT_ON(!array.ranges);
966 array.ranges[0].start = $1;
967 array.ranges[0].length = 1;
971 PE_VALUE PE_ARRAY_RANGE PE_VALUE
973 struct parse_events_array array;
977 array.ranges = malloc(sizeof(array.ranges[0]));
978 ABORT_ON(!array.ranges);
979 array.ranges[0].start = $1;
980 array.ranges[0].length = $3 - $1 + 1;
986 sep_slash_slash_dc: '/' '/' | ':' |
990 void parse_events_error(YYLTYPE *loc, void *parse_state,
991 void *scanner __maybe_unused,
992 char const *msg __maybe_unused)
994 parse_events_evlist_error(parse_state, loc->last_column, "parser error");