powerpc/mm/4k: don't allocate larger pmd page table for 4k
[linux/fpc-iii.git] / tools / perf / util / parse-events.y
blob879115f93edcdc52171b42fc6e544662b579da1f
1 %pure-parser
2 %parse-param {void *_data}
3 %parse-param {void *scanner}
4 %lex-param {void* scanner}
5 %locations
7 %{
9 #define YYDEBUG 1
11 #include <linux/compiler.h>
12 #include <linux/list.h>
13 #include <linux/types.h>
14 #include "util.h"
15 #include "parse-events.h"
16 #include "parse-events-bison.h"
18 #define ABORT_ON(val) \
19 do { \
20 if (val) \
21 YYABORT; \
22 } while (0)
24 #define ALLOC_LIST(list) \
25 do { \
26 list = malloc(sizeof(*list)); \
27 ABORT_ON(!list); \
28 INIT_LIST_HEAD(list); \
29 } while (0)
31 static void inc_group_count(struct list_head *list,
32 struct parse_events_evlist *data)
34 /* Count groups only have more than 1 members */
35 if (!list_is_last(list->next, list))
36 data->nr_groups++;
41 %token PE_START_EVENTS PE_START_TERMS
42 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
43 %token PE_EVENT_NAME
44 %token PE_NAME
45 %token PE_BPF_OBJECT PE_BPF_SOURCE
46 %token PE_MODIFIER_EVENT PE_MODIFIER_BP
47 %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
48 %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
49 %token PE_ERROR
50 %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
51 %token PE_ARRAY_ALL PE_ARRAY_RANGE
52 %token PE_DRV_CFG_TERM
53 %type <num> PE_VALUE
54 %type <num> PE_VALUE_SYM_HW
55 %type <num> PE_VALUE_SYM_SW
56 %type <num> PE_RAW
57 %type <num> PE_TERM
58 %type <str> PE_NAME
59 %type <str> PE_BPF_OBJECT
60 %type <str> PE_BPF_SOURCE
61 %type <str> PE_NAME_CACHE_TYPE
62 %type <str> PE_NAME_CACHE_OP_RESULT
63 %type <str> PE_MODIFIER_EVENT
64 %type <str> PE_MODIFIER_BP
65 %type <str> PE_EVENT_NAME
66 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
67 %type <str> PE_DRV_CFG_TERM
68 %type <num> value_sym
69 %type <head> event_config
70 %type <head> opt_event_config
71 %type <term> event_term
72 %type <head> event_pmu
73 %type <head> event_legacy_symbol
74 %type <head> event_legacy_cache
75 %type <head> event_legacy_mem
76 %type <head> event_legacy_tracepoint
77 %type <tracepoint_name> tracepoint_name
78 %type <head> event_legacy_numeric
79 %type <head> event_legacy_raw
80 %type <head> event_bpf_file
81 %type <head> event_def
82 %type <head> event_mod
83 %type <head> event_name
84 %type <head> event
85 %type <head> events
86 %type <head> group_def
87 %type <head> group
88 %type <head> groups
89 %type <array> array
90 %type <array> array_term
91 %type <array> array_terms
93 %union
95 char *str;
96 u64 num;
97 struct list_head *head;
98 struct parse_events_term *term;
99 struct tracepoint_name {
100 char *sys;
101 char *event;
102 } tracepoint_name;
103 struct parse_events_array array;
107 start:
108 PE_START_EVENTS start_events
110 PE_START_TERMS start_terms
112 start_events: groups
114 struct parse_events_evlist *data = _data;
116 parse_events_update_lists($1, &data->list);
119 groups:
120 groups ',' group
122 struct list_head *list = $1;
123 struct list_head *group = $3;
125 parse_events_update_lists(group, list);
126 $$ = list;
129 groups ',' event
131 struct list_head *list = $1;
132 struct list_head *event = $3;
134 parse_events_update_lists(event, list);
135 $$ = list;
138 group
140 event
142 group:
143 group_def ':' PE_MODIFIER_EVENT
145 struct list_head *list = $1;
147 ABORT_ON(parse_events__modifier_group(list, $3));
148 $$ = list;
151 group_def
153 group_def:
154 PE_NAME '{' events '}'
156 struct list_head *list = $3;
158 inc_group_count(list, _data);
159 parse_events__set_leader($1, list);
160 $$ = list;
163 '{' events '}'
165 struct list_head *list = $2;
167 inc_group_count(list, _data);
168 parse_events__set_leader(NULL, list);
169 $$ = list;
172 events:
173 events ',' event
175 struct list_head *event = $3;
176 struct list_head *list = $1;
178 parse_events_update_lists(event, list);
179 $$ = list;
182 event
184 event: event_mod
186 event_mod:
187 event_name PE_MODIFIER_EVENT
189 struct list_head *list = $1;
192 * Apply modifier on all events added by single event definition
193 * (there could be more events added for multiple tracepoint
194 * definitions via '*?'.
196 ABORT_ON(parse_events__modifier_event(list, $2, false));
197 $$ = list;
200 event_name
202 event_name:
203 PE_EVENT_NAME event_def
205 ABORT_ON(parse_events_name($2, $1));
206 free($1);
207 $$ = $2;
210 event_def
212 event_def: event_pmu |
213 event_legacy_symbol |
214 event_legacy_cache sep_dc |
215 event_legacy_mem |
216 event_legacy_tracepoint sep_dc |
217 event_legacy_numeric sep_dc |
218 event_legacy_raw sep_dc |
219 event_bpf_file
221 event_pmu:
222 PE_NAME opt_event_config
224 struct parse_events_evlist *data = _data;
225 struct list_head *list;
227 ALLOC_LIST(list);
228 ABORT_ON(parse_events_add_pmu(data, list, $1, $2));
229 parse_events_terms__delete($2);
230 $$ = list;
233 PE_KERNEL_PMU_EVENT sep_dc
235 struct parse_events_evlist *data = _data;
236 struct list_head *head;
237 struct parse_events_term *term;
238 struct list_head *list;
240 ALLOC_LIST(head);
241 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
242 $1, 1, &@1, NULL));
243 list_add_tail(&term->list, head);
245 ALLOC_LIST(list);
246 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
247 parse_events_terms__delete(head);
248 $$ = list;
251 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
253 struct parse_events_evlist *data = _data;
254 struct list_head *head;
255 struct parse_events_term *term;
256 struct list_head *list;
257 char pmu_name[128];
258 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
260 ALLOC_LIST(head);
261 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
262 &pmu_name, 1, &@1, NULL));
263 list_add_tail(&term->list, head);
265 ALLOC_LIST(list);
266 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
267 parse_events_terms__delete(head);
268 $$ = list;
271 value_sym:
272 PE_VALUE_SYM_HW
274 PE_VALUE_SYM_SW
276 event_legacy_symbol:
277 value_sym '/' event_config '/'
279 struct parse_events_evlist *data = _data;
280 struct list_head *list;
281 int type = $1 >> 16;
282 int config = $1 & 255;
284 ALLOC_LIST(list);
285 ABORT_ON(parse_events_add_numeric(data, list, type, config, $3));
286 parse_events_terms__delete($3);
287 $$ = list;
290 value_sym sep_slash_dc
292 struct parse_events_evlist *data = _data;
293 struct list_head *list;
294 int type = $1 >> 16;
295 int config = $1 & 255;
297 ALLOC_LIST(list);
298 ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL));
299 $$ = list;
302 event_legacy_cache:
303 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
305 struct parse_events_evlist *data = _data;
306 struct parse_events_error *error = data->error;
307 struct list_head *list;
309 ALLOC_LIST(list);
310 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6));
311 parse_events_terms__delete($6);
312 $$ = list;
315 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
317 struct parse_events_evlist *data = _data;
318 struct parse_events_error *error = data->error;
319 struct list_head *list;
321 ALLOC_LIST(list);
322 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4));
323 parse_events_terms__delete($4);
324 $$ = list;
327 PE_NAME_CACHE_TYPE opt_event_config
329 struct parse_events_evlist *data = _data;
330 struct parse_events_error *error = data->error;
331 struct list_head *list;
333 ALLOC_LIST(list);
334 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2));
335 parse_events_terms__delete($2);
336 $$ = list;
339 event_legacy_mem:
340 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
342 struct parse_events_evlist *data = _data;
343 struct list_head *list;
345 ALLOC_LIST(list);
346 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
347 (void *) $2, $6, $4));
348 $$ = list;
351 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
353 struct parse_events_evlist *data = _data;
354 struct list_head *list;
356 ALLOC_LIST(list);
357 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
358 (void *) $2, NULL, $4));
359 $$ = list;
362 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
364 struct parse_events_evlist *data = _data;
365 struct list_head *list;
367 ALLOC_LIST(list);
368 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
369 (void *) $2, $4, 0));
370 $$ = list;
373 PE_PREFIX_MEM PE_VALUE sep_dc
375 struct parse_events_evlist *data = _data;
376 struct list_head *list;
378 ALLOC_LIST(list);
379 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
380 (void *) $2, NULL, 0));
381 $$ = list;
384 event_legacy_tracepoint:
385 tracepoint_name opt_event_config
387 struct parse_events_evlist *data = _data;
388 struct parse_events_error *error = data->error;
389 struct list_head *list;
391 ALLOC_LIST(list);
392 if (error)
393 error->idx = @1.first_column;
395 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
396 error, $2))
397 return -1;
399 $$ = list;
402 tracepoint_name:
403 PE_NAME '-' PE_NAME ':' PE_NAME
405 char sys_name[128];
406 struct tracepoint_name tracepoint;
408 snprintf(&sys_name, 128, "%s-%s", $1, $3);
409 tracepoint.sys = &sys_name;
410 tracepoint.event = $5;
412 $$ = tracepoint;
415 PE_NAME ':' PE_NAME
417 struct tracepoint_name tracepoint = {$1, $3};
419 $$ = tracepoint;
422 event_legacy_numeric:
423 PE_VALUE ':' PE_VALUE opt_event_config
425 struct parse_events_evlist *data = _data;
426 struct list_head *list;
428 ALLOC_LIST(list);
429 ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
430 parse_events_terms__delete($4);
431 $$ = list;
434 event_legacy_raw:
435 PE_RAW opt_event_config
437 struct parse_events_evlist *data = _data;
438 struct list_head *list;
440 ALLOC_LIST(list);
441 ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
442 parse_events_terms__delete($2);
443 $$ = list;
446 event_bpf_file:
447 PE_BPF_OBJECT opt_event_config
449 struct parse_events_evlist *data = _data;
450 struct parse_events_error *error = data->error;
451 struct list_head *list;
453 ALLOC_LIST(list);
454 ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2));
455 parse_events_terms__delete($2);
456 $$ = list;
459 PE_BPF_SOURCE opt_event_config
461 struct parse_events_evlist *data = _data;
462 struct list_head *list;
464 ALLOC_LIST(list);
465 ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2));
466 parse_events_terms__delete($2);
467 $$ = list;
470 opt_event_config:
471 '/' event_config '/'
473 $$ = $2;
476 '/' '/'
478 $$ = NULL;
482 $$ = NULL;
485 start_terms: event_config
487 struct parse_events_terms *data = _data;
488 data->terms = $1;
491 event_config:
492 event_config ',' event_term
494 struct list_head *head = $1;
495 struct parse_events_term *term = $3;
497 ABORT_ON(!head);
498 list_add_tail(&term->list, head);
499 $$ = $1;
502 event_term
504 struct list_head *head = malloc(sizeof(*head));
505 struct parse_events_term *term = $1;
507 ABORT_ON(!head);
508 INIT_LIST_HEAD(head);
509 list_add_tail(&term->list, head);
510 $$ = head;
513 event_term:
514 PE_NAME '=' PE_NAME
516 struct parse_events_term *term;
518 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
519 $1, $3, &@1, &@3));
520 $$ = term;
523 PE_NAME '=' PE_VALUE
525 struct parse_events_term *term;
527 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
528 $1, $3, &@1, &@3));
529 $$ = term;
532 PE_NAME '=' PE_VALUE_SYM_HW
534 struct parse_events_term *term;
535 int config = $3 & 255;
537 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
538 $$ = term;
541 PE_NAME
543 struct parse_events_term *term;
545 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
546 $1, 1, &@1, NULL));
547 $$ = term;
550 PE_VALUE_SYM_HW
552 struct parse_events_term *term;
553 int config = $1 & 255;
555 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
556 $$ = term;
559 PE_TERM '=' PE_NAME
561 struct parse_events_term *term;
563 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
564 $$ = term;
567 PE_TERM '=' PE_VALUE
569 struct parse_events_term *term;
571 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3));
572 $$ = term;
575 PE_TERM
577 struct parse_events_term *term;
579 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
580 $$ = term;
583 PE_NAME array '=' PE_NAME
585 struct parse_events_term *term;
586 int i;
588 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
589 $1, $4, &@1, &@4));
591 term->array = $2;
592 $$ = term;
595 PE_NAME array '=' PE_VALUE
597 struct parse_events_term *term;
599 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
600 $1, $4, &@1, &@4));
601 term->array = $2;
602 $$ = term;
605 PE_DRV_CFG_TERM
607 struct parse_events_term *term;
609 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
610 $1, $1, &@1, NULL));
611 $$ = term;
614 array:
615 '[' array_terms ']'
617 $$ = $2;
620 PE_ARRAY_ALL
622 $$.nr_ranges = 0;
623 $$.ranges = NULL;
626 array_terms:
627 array_terms ',' array_term
629 struct parse_events_array new_array;
631 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
632 new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
633 new_array.nr_ranges);
634 ABORT_ON(!new_array.ranges);
635 memcpy(&new_array.ranges[0], $1.ranges,
636 $1.nr_ranges * sizeof(new_array.ranges[0]));
637 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
638 $3.nr_ranges * sizeof(new_array.ranges[0]));
639 free($1.ranges);
640 free($3.ranges);
641 $$ = new_array;
644 array_term
646 array_term:
647 PE_VALUE
649 struct parse_events_array array;
651 array.nr_ranges = 1;
652 array.ranges = malloc(sizeof(array.ranges[0]));
653 ABORT_ON(!array.ranges);
654 array.ranges[0].start = $1;
655 array.ranges[0].length = 1;
656 $$ = array;
659 PE_VALUE PE_ARRAY_RANGE PE_VALUE
661 struct parse_events_array array;
663 ABORT_ON($3 < $1);
664 array.nr_ranges = 1;
665 array.ranges = malloc(sizeof(array.ranges[0]));
666 ABORT_ON(!array.ranges);
667 array.ranges[0].start = $1;
668 array.ranges[0].length = $3 - $1 + 1;
669 $$ = array;
672 sep_dc: ':' |
674 sep_slash_dc: '/' | ':' |
678 void parse_events_error(YYLTYPE *loc, void *data,
679 void *scanner __maybe_unused,
680 char const *msg __maybe_unused)
682 parse_events_evlist_error(data, loc->last_column, "parser error");