2 %parse-param {void *_parse_state}
3 %parse-param {void *scanner}
4 %lex-param {void* scanner}
12 #include <linux/compiler.h>
13 #include <linux/list.h>
14 #include <linux/types.h>
19 #include "parse-events.h"
20 #include "parse-events-bison.h"
22 void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
24 #define ABORT_ON(val) \
30 #define ALLOC_LIST(list) \
32 list = malloc(sizeof(*list)); \
34 INIT_LIST_HEAD(list); \
37 static void inc_group_count(struct list_head *list,
38 struct parse_events_state *parse_state)
40 /* Count groups only have more than 1 members */
41 if (!list_is_last(list->next, list))
42 parse_state->nr_groups++;
47 %token PE_START_EVENTS PE_START_TERMS
48 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
49 %token PE_VALUE_SYM_TOOL
52 %token PE_BPF_OBJECT PE_BPF_SOURCE
53 %token PE_MODIFIER_EVENT PE_MODIFIER_BP
54 %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
55 %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
57 %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
58 %token PE_ARRAY_ALL PE_ARRAY_RANGE
59 %token PE_DRV_CFG_TERM
61 %type <num> PE_VALUE_SYM_HW
62 %type <num> PE_VALUE_SYM_SW
63 %type <num> PE_VALUE_SYM_TOOL
67 %type <str> PE_BPF_OBJECT
68 %type <str> PE_BPF_SOURCE
69 %type <str> PE_NAME_CACHE_TYPE
70 %type <str> PE_NAME_CACHE_OP_RESULT
71 %type <str> PE_MODIFIER_EVENT
72 %type <str> PE_MODIFIER_BP
73 %type <str> PE_EVENT_NAME
74 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
75 %type <str> PE_DRV_CFG_TERM
77 %type <head> event_config
78 %type <head> opt_event_config
79 %type <head> opt_pmu_config
80 %type <term> event_term
81 %type <head> event_pmu
82 %type <head> event_legacy_symbol
83 %type <head> event_legacy_cache
84 %type <head> event_legacy_mem
85 %type <head> event_legacy_tracepoint
86 %type <tracepoint_name> tracepoint_name
87 %type <head> event_legacy_numeric
88 %type <head> event_legacy_raw
89 %type <head> event_bpf_file
90 %type <head> event_def
91 %type <head> event_mod
92 %type <head> event_name
95 %type <head> group_def
99 %type <array> array_term
100 %type <array> array_terms
106 struct list_head *head;
107 struct parse_events_term *term;
108 struct tracepoint_name {
112 struct parse_events_array array;
117 PE_START_EVENTS start_events
119 PE_START_TERMS start_terms
123 struct parse_events_state *parse_state = _parse_state;
125 parse_events_update_lists($1, &parse_state->list);
131 struct list_head *list = $1;
132 struct list_head *group = $3;
134 parse_events_update_lists(group, list);
140 struct list_head *list = $1;
141 struct list_head *event = $3;
143 parse_events_update_lists(event, list);
152 group_def ':' PE_MODIFIER_EVENT
154 struct list_head *list = $1;
156 ABORT_ON(parse_events__modifier_group(list, $3));
163 PE_NAME '{' events '}'
165 struct list_head *list = $3;
167 inc_group_count(list, _parse_state);
168 parse_events__set_leader($1, list, _parse_state);
174 struct list_head *list = $2;
176 inc_group_count(list, _parse_state);
177 parse_events__set_leader(NULL, list, _parse_state);
184 struct list_head *event = $3;
185 struct list_head *list = $1;
187 parse_events_update_lists(event, list);
196 event_name PE_MODIFIER_EVENT
198 struct list_head *list = $1;
201 * Apply modifier on all events added by single event definition
202 * (there could be more events added for multiple tracepoint
203 * definitions via '*?'.
205 ABORT_ON(parse_events__modifier_event(list, $2, false));
212 PE_EVENT_NAME event_def
214 ABORT_ON(parse_events_name($2, $1));
221 event_def: event_pmu |
222 event_legacy_symbol |
223 event_legacy_cache sep_dc |
225 event_legacy_tracepoint sep_dc |
226 event_legacy_numeric sep_dc |
227 event_legacy_raw sep_dc |
231 PE_NAME opt_pmu_config
233 struct parse_events_state *parse_state = _parse_state;
234 struct parse_events_error *error = parse_state->error;
235 struct list_head *list, *orig_terms, *terms;
237 if (parse_events_copy_term_list($2, &orig_terms))
241 error->idx = @1.first_column;
244 if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
245 struct perf_pmu *pmu = NULL;
249 if (asprintf(&pattern, "%s*", $1) < 0)
252 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
253 char *name = pmu->name;
255 if (!strncmp(name, "uncore_", 7) &&
256 strncmp($1, "uncore_", 7))
258 if (!fnmatch(pattern, name, 0)) {
259 if (parse_events_copy_term_list(orig_terms, &terms)) {
263 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
265 parse_events_terms__delete(terms);
274 parse_events_terms__delete($2);
275 parse_events_terms__delete(orig_terms);
279 PE_KERNEL_PMU_EVENT sep_dc
281 struct list_head *list;
283 if (parse_events_multi_pmu_add(_parse_state, $1, &list) < 0)
288 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
290 struct list_head *list;
293 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
294 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0)
305 value_sym '/' event_config '/'
307 struct list_head *list;
309 int config = $1 & 255;
312 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3));
313 parse_events_terms__delete($3);
317 value_sym sep_slash_slash_dc
319 struct list_head *list;
321 int config = $1 & 255;
324 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
328 PE_VALUE_SYM_TOOL sep_slash_slash_dc
330 struct list_head *list;
333 ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
338 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
340 struct parse_events_state *parse_state = _parse_state;
341 struct parse_events_error *error = parse_state->error;
342 struct list_head *list;
345 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6));
346 parse_events_terms__delete($6);
350 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
352 struct parse_events_state *parse_state = _parse_state;
353 struct parse_events_error *error = parse_state->error;
354 struct list_head *list;
357 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4));
358 parse_events_terms__delete($4);
362 PE_NAME_CACHE_TYPE opt_event_config
364 struct parse_events_state *parse_state = _parse_state;
365 struct parse_events_error *error = parse_state->error;
366 struct list_head *list;
369 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2));
370 parse_events_terms__delete($2);
375 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
377 struct parse_events_state *parse_state = _parse_state;
378 struct list_head *list;
381 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
382 (void *) $2, $6, $4));
386 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
388 struct parse_events_state *parse_state = _parse_state;
389 struct list_head *list;
392 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
393 (void *) $2, NULL, $4));
397 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
399 struct parse_events_state *parse_state = _parse_state;
400 struct list_head *list;
403 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
404 (void *) $2, $4, 0));
408 PE_PREFIX_MEM PE_VALUE sep_dc
410 struct parse_events_state *parse_state = _parse_state;
411 struct list_head *list;
414 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
415 (void *) $2, NULL, 0));
419 event_legacy_tracepoint:
420 tracepoint_name opt_event_config
422 struct parse_events_state *parse_state = _parse_state;
423 struct parse_events_error *error = parse_state->error;
424 struct list_head *list;
428 error->idx = @1.first_column;
430 if (parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
438 PE_NAME '-' PE_NAME ':' PE_NAME
441 struct tracepoint_name tracepoint;
443 snprintf(&sys_name, 128, "%s-%s", $1, $3);
444 tracepoint.sys = &sys_name;
445 tracepoint.event = $5;
452 struct tracepoint_name tracepoint = {$1, $3};
457 event_legacy_numeric:
458 PE_VALUE ':' PE_VALUE opt_event_config
460 struct list_head *list;
463 ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4));
464 parse_events_terms__delete($4);
469 PE_RAW opt_event_config
471 struct list_head *list;
474 ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2));
475 parse_events_terms__delete($2);
480 PE_BPF_OBJECT opt_event_config
482 struct parse_events_state *parse_state = _parse_state;
483 struct list_head *list;
486 ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2));
487 parse_events_terms__delete($2);
491 PE_BPF_SOURCE opt_event_config
493 struct list_head *list;
496 ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2));
497 parse_events_terms__delete($2);
527 start_terms: event_config
529 struct parse_events_state *parse_state = _parse_state;
530 parse_state->terms = $1;
534 event_config ',' event_term
536 struct list_head *head = $1;
537 struct parse_events_term *term = $3;
540 list_add_tail(&term->list, head);
546 struct list_head *head = malloc(sizeof(*head));
547 struct parse_events_term *term = $1;
550 INIT_LIST_HEAD(head);
551 list_add_tail(&term->list, head);
558 struct parse_events_term *term;
560 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
567 struct parse_events_term *term;
569 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
570 $1, $3, false, &@1, &@3));
574 PE_NAME '=' PE_VALUE_SYM_HW
576 struct parse_events_term *term;
577 int config = $3 & 255;
579 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
585 struct parse_events_term *term;
587 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
588 $1, 1, true, &@1, NULL));
594 struct parse_events_term *term;
595 int config = $1 & 255;
597 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
603 struct parse_events_term *term;
605 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
611 struct parse_events_term *term;
613 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
619 struct parse_events_term *term;
621 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
625 PE_NAME array '=' PE_NAME
627 struct parse_events_term *term;
629 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
636 PE_NAME array '=' PE_VALUE
638 struct parse_events_term *term;
640 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
641 $1, $4, false, &@1, &@4));
648 struct parse_events_term *term;
650 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
668 array_terms ',' array_term
670 struct parse_events_array new_array;
672 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
673 new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
674 new_array.nr_ranges);
675 ABORT_ON(!new_array.ranges);
676 memcpy(&new_array.ranges[0], $1.ranges,
677 $1.nr_ranges * sizeof(new_array.ranges[0]));
678 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
679 $3.nr_ranges * sizeof(new_array.ranges[0]));
690 struct parse_events_array array;
693 array.ranges = malloc(sizeof(array.ranges[0]));
694 ABORT_ON(!array.ranges);
695 array.ranges[0].start = $1;
696 array.ranges[0].length = 1;
700 PE_VALUE PE_ARRAY_RANGE PE_VALUE
702 struct parse_events_array array;
706 array.ranges = malloc(sizeof(array.ranges[0]));
707 ABORT_ON(!array.ranges);
708 array.ranges[0].start = $1;
709 array.ranges[0].length = $3 - $1 + 1;
715 sep_slash_slash_dc: '/' '/' | ':' |
719 void parse_events_error(YYLTYPE *loc, void *parse_state,
720 void *scanner __maybe_unused,
721 char const *msg __maybe_unused)
723 parse_events_evlist_error(parse_state, loc->last_column, "parser error");