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 #define PE_ABORT(val) \
38 static struct list_head* alloc_list(void)
40 struct list_head *list;
42 list = malloc(sizeof(*list));
50 static void free_list_evsel(struct list_head* list_evsel)
52 struct evsel *evsel, *tmp;
54 list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
55 list_del_init(&evsel->core.node);
63 %token PE_START_EVENTS PE_START_TERMS
64 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM
65 %token PE_VALUE_SYM_TOOL
68 %token PE_BPF_OBJECT PE_BPF_SOURCE
69 %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH
70 %token PE_LEGACY_CACHE
73 %token PE_ARRAY_ALL PE_ARRAY_RANGE
74 %token PE_DRV_CFG_TERM
77 %type <num> PE_VALUE_SYM_HW
78 %type <num> PE_VALUE_SYM_SW
79 %type <num> PE_VALUE_SYM_TOOL
84 %type <str> PE_BPF_OBJECT
85 %type <str> PE_BPF_SOURCE
86 %type <str> PE_LEGACY_CACHE
87 %type <str> PE_MODIFIER_EVENT
88 %type <str> PE_MODIFIER_BP
89 %type <str> PE_EVENT_NAME
90 %type <str> PE_DRV_CFG_TERM
91 %type <str> name_or_raw name_or_legacy
92 %destructor { free ($$); } <str>
93 %type <term> event_term
94 %destructor { parse_events_term__delete ($$); } <term>
95 %type <list_terms> event_config
96 %type <list_terms> opt_event_config
97 %type <list_terms> opt_pmu_config
98 %destructor { parse_events_terms__delete ($$); } <list_terms>
99 %type <list_evsel> event_pmu
100 %type <list_evsel> event_legacy_symbol
101 %type <list_evsel> event_legacy_cache
102 %type <list_evsel> event_legacy_mem
103 %type <list_evsel> event_legacy_tracepoint
104 %type <list_evsel> event_legacy_numeric
105 %type <list_evsel> event_legacy_raw
106 %type <list_evsel> event_bpf_file
107 %type <list_evsel> event_def
108 %type <list_evsel> event_mod
109 %type <list_evsel> event_name
110 %type <list_evsel> event
111 %type <list_evsel> events
112 %type <list_evsel> group_def
113 %type <list_evsel> group
114 %type <list_evsel> groups
115 %destructor { free_list_evsel ($$); } <list_evsel>
116 %type <tracepoint_name> tracepoint_name
117 %destructor { free ($$.sys); free ($$.event); } <tracepoint_name>
119 %type <array> array_term
120 %type <array> array_terms
121 %destructor { free ($$.ranges); } <array>
122 %type <hardware_term> PE_TERM_HW
123 %destructor { free ($$.str); } <hardware_term>
129 struct list_head *list_evsel;
130 struct list_head *list_terms;
131 struct parse_events_term *term;
132 struct tracepoint_name {
136 struct parse_events_array array;
137 struct hardware_term {
145 PE_START_EVENTS start_events
147 PE_START_TERMS start_terms
151 struct parse_events_state *parse_state = _parse_state;
154 parse_events_update_lists($1, &parse_state->list);
160 struct list_head *list = $1;
161 struct list_head *group = $3;
164 parse_events_update_lists(group, list);
170 struct list_head *list = $1;
171 struct list_head *event = $3;
174 parse_events_update_lists(event, list);
183 group_def ':' PE_MODIFIER_EVENT
185 struct list_head *list = $1;
188 err = parse_events__modifier_group(list, $3);
191 struct parse_events_state *parse_state = _parse_state;
192 struct parse_events_error *error = parse_state->error;
194 parse_events_error__handle(error, @3.first_column,
195 strdup("Bad modifier"), NULL);
196 free_list_evsel(list);
205 PE_NAME '{' events '}'
207 struct list_head *list = $3;
209 /* Takes ownership of $1. */
210 parse_events__set_leader($1, list);
216 struct list_head *list = $2;
218 parse_events__set_leader(NULL, list);
225 struct list_head *event = $3;
226 struct list_head *list = $1;
229 parse_events_update_lists(event, list);
238 event_name PE_MODIFIER_EVENT
240 struct list_head *list = $1;
244 * Apply modifier on all events added by single event definition
245 * (there could be more events added for multiple tracepoint
246 * definitions via '*?'.
248 err = parse_events__modifier_event(list, $2, false);
251 struct parse_events_state *parse_state = _parse_state;
252 struct parse_events_error *error = parse_state->error;
254 parse_events_error__handle(error, @2.first_column,
255 strdup("Bad modifier"), NULL);
256 free_list_evsel(list);
265 PE_EVENT_NAME event_def
269 err = parse_events_name($2, $1);
280 event_def: event_pmu |
281 event_legacy_symbol |
282 event_legacy_cache sep_dc |
283 event_legacy_mem sep_dc |
284 event_legacy_tracepoint sep_dc |
285 event_legacy_numeric sep_dc |
286 event_legacy_raw sep_dc |
290 PE_NAME opt_pmu_config
292 struct parse_events_state *parse_state = _parse_state;
293 struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL;
294 char *pattern = NULL;
298 parse_events_terms__delete($2); \
299 parse_events_terms__delete(orig_terms); \
305 if (parse_events_copy_term_list($2, &orig_terms)) {
315 /* Attempt to add to list assuming $1 is a PMU name. */
316 if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false)) {
317 struct perf_pmu *pmu = NULL;
320 /* Failure to add, try wildcard expansion of $1 as a PMU name. */
321 if (asprintf(&pattern, "%s*", $1) < 0) {
326 while ((pmu = perf_pmus__scan(pmu)) != NULL) {
327 char *name = pmu->name;
329 if (parse_events__filter_pmu(parse_state, pmu))
332 if (!strncmp(name, "uncore_", 7) &&
333 strncmp($1, "uncore_", 7))
335 if (!perf_pmu__match(pattern, name, $1) ||
336 !perf_pmu__match(pattern, pmu->alias_name, $1)) {
337 bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu);
339 if (parse_events_copy_term_list(orig_terms, &terms)) {
343 if (!parse_events_add_pmu(parse_state, list, pmu->name, terms,
346 parse_state->wild_card_pmus = true;
348 parse_events_terms__delete(terms);
353 /* Failure to add, assume $1 is an event name. */
355 ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list);
359 struct parse_events_error *error = parse_state->error;
362 if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0)
364 parse_events_error__handle(error, @1.first_column,
365 strdup("Bad event or PMU"),
379 struct list_head *list;
382 err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
384 struct parse_events_state *parse_state = _parse_state;
385 struct parse_events_error *error = parse_state->error;
388 if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0)
390 parse_events_error__handle(error, @1.first_column, strdup("Bad event name"), help);
404 value_sym '/' event_config '/'
406 struct list_head *list;
408 int config = $1 & 255;
410 bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE);
415 err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard);
416 parse_events_terms__delete($3);
418 free_list_evsel(list);
424 value_sym sep_slash_slash_dc
426 struct list_head *list;
428 int config = $1 & 255;
429 bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE);
435 err = parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard);
441 PE_VALUE_SYM_TOOL sep_slash_slash_dc
443 struct list_head *list;
449 err = parse_events_add_tool(_parse_state, list, $1);
456 PE_LEGACY_CACHE opt_event_config
458 struct parse_events_state *parse_state = _parse_state;
459 struct list_head *list;
466 err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2);
468 parse_events_terms__delete($2);
471 free_list_evsel(list);
478 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config
480 struct list_head *list;
487 err = parse_events_add_breakpoint(_parse_state, list,
489 parse_events_terms__delete($7);
498 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config
500 struct list_head *list;
507 err = parse_events_add_breakpoint(_parse_state, list,
509 parse_events_terms__delete($5);
517 PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config
519 struct list_head *list;
526 err = parse_events_add_breakpoint(_parse_state, list,
528 parse_events_terms__delete($5);
537 PE_PREFIX_MEM PE_VALUE opt_event_config
539 struct list_head *list;
545 err = parse_events_add_breakpoint(_parse_state, list,
547 parse_events_terms__delete($3);
555 event_legacy_tracepoint:
556 tracepoint_name opt_event_config
558 struct parse_events_state *parse_state = _parse_state;
559 struct parse_events_error *error = parse_state->error;
560 struct list_head *list;
567 error->idx = @1.first_column;
569 err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
572 parse_events_terms__delete($2);
585 struct tracepoint_name tracepoint = {$1, $3};
590 event_legacy_numeric:
591 PE_VALUE ':' PE_VALUE opt_event_config
593 struct list_head *list;
599 err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4,
601 parse_events_terms__delete($4);
610 PE_RAW opt_event_config
612 struct list_head *list;
620 num = strtoull($1 + 1, NULL, 16);
623 err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2,
625 parse_events_terms__delete($2);
634 PE_BPF_OBJECT opt_event_config
636 struct parse_events_state *parse_state = _parse_state;
637 struct list_head *list;
643 err = parse_events_load_bpf(parse_state, list, $1, false, $2);
644 parse_events_terms__delete($2);
653 PE_BPF_SOURCE opt_event_config
655 struct list_head *list;
661 err = parse_events_load_bpf(_parse_state, list, $1, true, $2);
662 parse_events_terms__delete($2);
696 start_terms: event_config
698 struct parse_events_state *parse_state = _parse_state;
699 if (parse_state->terms) {
700 parse_events_terms__delete ($1);
703 parse_state->terms = $1;
707 event_config ',' event_term
709 struct list_head *head = $1;
710 struct parse_events_term *term = $3;
713 parse_events_term__delete(term);
716 list_add_tail(&term->list, head);
722 struct list_head *head = malloc(sizeof(*head));
723 struct parse_events_term *term = $1;
727 INIT_LIST_HEAD(head);
728 list_add_tail(&term->list, head);
732 name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE
734 name_or_legacy: PE_NAME | PE_LEGACY_CACHE
739 struct parse_events_term *term;
740 int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW,
741 strdup("raw"), $1, &@1, &@1);
750 name_or_raw '=' name_or_legacy
752 struct parse_events_term *term;
753 int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $3, &@1, &@3);
763 name_or_raw '=' PE_VALUE
765 struct parse_events_term *term;
766 int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
767 $1, $3, false, &@1, &@3);
776 name_or_raw '=' PE_TERM_HW
778 struct parse_events_term *term;
779 int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
780 $1, $3.str, &@1, &@3);
792 struct parse_events_term *term;
793 int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE,
794 $1, 1, true, &@1, NULL);
805 struct parse_events_term *term;
806 int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
807 $1, 1, true, &@1, NULL);
818 struct parse_events_term *term;
819 int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE,
820 $1.str, $1.num & 255, false, &@1, NULL);
829 PE_TERM '=' name_or_legacy
831 struct parse_events_term *term;
832 int err = parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3);
841 PE_TERM '=' PE_TERM_HW
843 struct parse_events_term *term;
844 int err = parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3);
855 struct parse_events_term *term;
856 int err = parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3);
866 struct parse_events_term *term;
867 int err = parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3);
877 struct parse_events_term *term;
878 int err = parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL);
886 name_or_raw array '=' name_or_legacy
888 struct parse_events_term *term;
889 int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, &@1, &@4);
901 name_or_raw array '=' PE_VALUE
903 struct parse_events_term *term;
904 int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, false, &@1, &@4);
917 struct parse_events_term *term;
918 char *config = strdup($1);
923 err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, config, $1, &@1, NULL);
945 array_terms ',' array_term
947 struct parse_events_array new_array;
949 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
950 new_array.ranges = realloc($1.ranges,
951 sizeof(new_array.ranges[0]) *
952 new_array.nr_ranges);
953 if (!new_array.ranges)
955 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
956 $3.nr_ranges * sizeof(new_array.ranges[0]));
966 struct parse_events_array array;
969 array.ranges = malloc(sizeof(array.ranges[0]));
972 array.ranges[0].start = $1;
973 array.ranges[0].length = 1;
977 PE_VALUE PE_ARRAY_RANGE PE_VALUE
979 struct parse_events_array array;
983 array.ranges = malloc(sizeof(array.ranges[0]));
986 array.ranges[0].start = $1;
987 array.ranges[0].length = $3 - $1 + 1;
993 sep_slash_slash_dc: '/' '/' | ':' |
997 void parse_events_error(YYLTYPE *loc, void *parse_state,
998 void *scanner __maybe_unused,
999 char const *msg __maybe_unused)
1001 parse_events_evlist_error(parse_state, loc->last_column, "parser error");