Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / tools / perf / util / parse-events.y
blob5be4a5f216d6d23889e07e225810fec40df67c30
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 %type <num> PE_VALUE
53 %type <num> PE_VALUE_SYM_HW
54 %type <num> PE_VALUE_SYM_SW
55 %type <num> PE_RAW
56 %type <num> PE_TERM
57 %type <str> PE_NAME
58 %type <str> PE_BPF_OBJECT
59 %type <str> PE_BPF_SOURCE
60 %type <str> PE_NAME_CACHE_TYPE
61 %type <str> PE_NAME_CACHE_OP_RESULT
62 %type <str> PE_MODIFIER_EVENT
63 %type <str> PE_MODIFIER_BP
64 %type <str> PE_EVENT_NAME
65 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
66 %type <num> value_sym
67 %type <head> event_config
68 %type <head> opt_event_config
69 %type <term> event_term
70 %type <head> event_pmu
71 %type <head> event_legacy_symbol
72 %type <head> event_legacy_cache
73 %type <head> event_legacy_mem
74 %type <head> event_legacy_tracepoint
75 %type <tracepoint_name> tracepoint_name
76 %type <head> event_legacy_numeric
77 %type <head> event_legacy_raw
78 %type <head> event_bpf_file
79 %type <head> event_def
80 %type <head> event_mod
81 %type <head> event_name
82 %type <head> event
83 %type <head> events
84 %type <head> group_def
85 %type <head> group
86 %type <head> groups
87 %type <array> array
88 %type <array> array_term
89 %type <array> array_terms
91 %union
93 char *str;
94 u64 num;
95 struct list_head *head;
96 struct parse_events_term *term;
97 struct tracepoint_name {
98 char *sys;
99 char *event;
100 } tracepoint_name;
101 struct parse_events_array array;
105 start:
106 PE_START_EVENTS start_events
108 PE_START_TERMS start_terms
110 start_events: groups
112 struct parse_events_evlist *data = _data;
114 parse_events_update_lists($1, &data->list);
117 groups:
118 groups ',' group
120 struct list_head *list = $1;
121 struct list_head *group = $3;
123 parse_events_update_lists(group, list);
124 $$ = list;
127 groups ',' event
129 struct list_head *list = $1;
130 struct list_head *event = $3;
132 parse_events_update_lists(event, list);
133 $$ = list;
136 group
138 event
140 group:
141 group_def ':' PE_MODIFIER_EVENT
143 struct list_head *list = $1;
145 ABORT_ON(parse_events__modifier_group(list, $3));
146 $$ = list;
149 group_def
151 group_def:
152 PE_NAME '{' events '}'
154 struct list_head *list = $3;
156 inc_group_count(list, _data);
157 parse_events__set_leader($1, list);
158 $$ = list;
161 '{' events '}'
163 struct list_head *list = $2;
165 inc_group_count(list, _data);
166 parse_events__set_leader(NULL, list);
167 $$ = list;
170 events:
171 events ',' event
173 struct list_head *event = $3;
174 struct list_head *list = $1;
176 parse_events_update_lists(event, list);
177 $$ = list;
180 event
182 event: event_mod
184 event_mod:
185 event_name PE_MODIFIER_EVENT
187 struct list_head *list = $1;
190 * Apply modifier on all events added by single event definition
191 * (there could be more events added for multiple tracepoint
192 * definitions via '*?'.
194 ABORT_ON(parse_events__modifier_event(list, $2, false));
195 $$ = list;
198 event_name
200 event_name:
201 PE_EVENT_NAME event_def
203 ABORT_ON(parse_events_name($2, $1));
204 free($1);
205 $$ = $2;
208 event_def
210 event_def: event_pmu |
211 event_legacy_symbol |
212 event_legacy_cache sep_dc |
213 event_legacy_mem |
214 event_legacy_tracepoint sep_dc |
215 event_legacy_numeric sep_dc |
216 event_legacy_raw sep_dc |
217 event_bpf_file
219 event_pmu:
220 PE_NAME opt_event_config
222 struct parse_events_evlist *data = _data;
223 struct list_head *list;
225 ALLOC_LIST(list);
226 ABORT_ON(parse_events_add_pmu(data, list, $1, $2));
227 parse_events_terms__delete($2);
228 $$ = list;
231 PE_KERNEL_PMU_EVENT sep_dc
233 struct parse_events_evlist *data = _data;
234 struct list_head *head;
235 struct parse_events_term *term;
236 struct list_head *list;
238 ALLOC_LIST(head);
239 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
240 $1, 1, &@1, NULL));
241 list_add_tail(&term->list, head);
243 ALLOC_LIST(list);
244 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
245 parse_events_terms__delete(head);
246 $$ = list;
249 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
251 struct parse_events_evlist *data = _data;
252 struct list_head *head;
253 struct parse_events_term *term;
254 struct list_head *list;
255 char pmu_name[128];
256 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
258 ALLOC_LIST(head);
259 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
260 &pmu_name, 1, &@1, NULL));
261 list_add_tail(&term->list, head);
263 ALLOC_LIST(list);
264 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
265 parse_events_terms__delete(head);
266 $$ = list;
269 value_sym:
270 PE_VALUE_SYM_HW
272 PE_VALUE_SYM_SW
274 event_legacy_symbol:
275 value_sym '/' event_config '/'
277 struct parse_events_evlist *data = _data;
278 struct list_head *list;
279 int type = $1 >> 16;
280 int config = $1 & 255;
282 ALLOC_LIST(list);
283 ABORT_ON(parse_events_add_numeric(data, list, type, config, $3));
284 parse_events_terms__delete($3);
285 $$ = list;
288 value_sym sep_slash_dc
290 struct parse_events_evlist *data = _data;
291 struct list_head *list;
292 int type = $1 >> 16;
293 int config = $1 & 255;
295 ALLOC_LIST(list);
296 ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL));
297 $$ = list;
300 event_legacy_cache:
301 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
303 struct parse_events_evlist *data = _data;
304 struct parse_events_error *error = data->error;
305 struct list_head *list;
307 ALLOC_LIST(list);
308 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6));
309 parse_events_terms__delete($6);
310 $$ = list;
313 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
315 struct parse_events_evlist *data = _data;
316 struct parse_events_error *error = data->error;
317 struct list_head *list;
319 ALLOC_LIST(list);
320 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4));
321 parse_events_terms__delete($4);
322 $$ = list;
325 PE_NAME_CACHE_TYPE opt_event_config
327 struct parse_events_evlist *data = _data;
328 struct parse_events_error *error = data->error;
329 struct list_head *list;
331 ALLOC_LIST(list);
332 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2));
333 parse_events_terms__delete($2);
334 $$ = list;
337 event_legacy_mem:
338 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
340 struct parse_events_evlist *data = _data;
341 struct list_head *list;
343 ALLOC_LIST(list);
344 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
345 (void *) $2, $6, $4));
346 $$ = list;
349 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
351 struct parse_events_evlist *data = _data;
352 struct list_head *list;
354 ALLOC_LIST(list);
355 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
356 (void *) $2, NULL, $4));
357 $$ = list;
360 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
362 struct parse_events_evlist *data = _data;
363 struct list_head *list;
365 ALLOC_LIST(list);
366 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
367 (void *) $2, $4, 0));
368 $$ = list;
371 PE_PREFIX_MEM PE_VALUE sep_dc
373 struct parse_events_evlist *data = _data;
374 struct list_head *list;
376 ALLOC_LIST(list);
377 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
378 (void *) $2, NULL, 0));
379 $$ = list;
382 event_legacy_tracepoint:
383 tracepoint_name opt_event_config
385 struct parse_events_evlist *data = _data;
386 struct parse_events_error *error = data->error;
387 struct list_head *list;
389 ALLOC_LIST(list);
390 if (error)
391 error->idx = @1.first_column;
393 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
394 error, $2))
395 return -1;
397 $$ = list;
400 tracepoint_name:
401 PE_NAME '-' PE_NAME ':' PE_NAME
403 char sys_name[128];
404 struct tracepoint_name tracepoint;
406 snprintf(&sys_name, 128, "%s-%s", $1, $3);
407 tracepoint.sys = &sys_name;
408 tracepoint.event = $5;
410 $$ = tracepoint;
413 PE_NAME ':' PE_NAME
415 struct tracepoint_name tracepoint = {$1, $3};
417 $$ = tracepoint;
420 event_legacy_numeric:
421 PE_VALUE ':' PE_VALUE opt_event_config
423 struct parse_events_evlist *data = _data;
424 struct list_head *list;
426 ALLOC_LIST(list);
427 ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
428 parse_events_terms__delete($4);
429 $$ = list;
432 event_legacy_raw:
433 PE_RAW opt_event_config
435 struct parse_events_evlist *data = _data;
436 struct list_head *list;
438 ALLOC_LIST(list);
439 ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
440 parse_events_terms__delete($2);
441 $$ = list;
444 event_bpf_file:
445 PE_BPF_OBJECT opt_event_config
447 struct parse_events_evlist *data = _data;
448 struct parse_events_error *error = data->error;
449 struct list_head *list;
451 ALLOC_LIST(list);
452 ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2));
453 parse_events_terms__delete($2);
454 $$ = list;
457 PE_BPF_SOURCE opt_event_config
459 struct parse_events_evlist *data = _data;
460 struct list_head *list;
462 ALLOC_LIST(list);
463 ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2));
464 parse_events_terms__delete($2);
465 $$ = list;
468 opt_event_config:
469 '/' event_config '/'
471 $$ = $2;
474 '/' '/'
476 $$ = NULL;
480 $$ = NULL;
483 start_terms: event_config
485 struct parse_events_terms *data = _data;
486 data->terms = $1;
489 event_config:
490 event_config ',' event_term
492 struct list_head *head = $1;
493 struct parse_events_term *term = $3;
495 ABORT_ON(!head);
496 list_add_tail(&term->list, head);
497 $$ = $1;
500 event_term
502 struct list_head *head = malloc(sizeof(*head));
503 struct parse_events_term *term = $1;
505 ABORT_ON(!head);
506 INIT_LIST_HEAD(head);
507 list_add_tail(&term->list, head);
508 $$ = head;
511 event_term:
512 PE_NAME '=' PE_NAME
514 struct parse_events_term *term;
516 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
517 $1, $3, &@1, &@3));
518 $$ = term;
521 PE_NAME '=' PE_VALUE
523 struct parse_events_term *term;
525 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
526 $1, $3, &@1, &@3));
527 $$ = term;
530 PE_NAME '=' PE_VALUE_SYM_HW
532 struct parse_events_term *term;
533 int config = $3 & 255;
535 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
536 $$ = term;
539 PE_NAME
541 struct parse_events_term *term;
543 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
544 $1, 1, &@1, NULL));
545 $$ = term;
548 PE_VALUE_SYM_HW
550 struct parse_events_term *term;
551 int config = $1 & 255;
553 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
554 $$ = term;
557 PE_TERM '=' PE_NAME
559 struct parse_events_term *term;
561 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
562 $$ = term;
565 PE_TERM '=' PE_VALUE
567 struct parse_events_term *term;
569 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3));
570 $$ = term;
573 PE_TERM
575 struct parse_events_term *term;
577 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
578 $$ = term;
581 PE_NAME array '=' PE_NAME
583 struct parse_events_term *term;
584 int i;
586 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
587 $1, $4, &@1, &@4));
589 term->array = $2;
590 $$ = term;
593 PE_NAME array '=' PE_VALUE
595 struct parse_events_term *term;
597 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
598 $1, $4, &@1, &@4));
599 term->array = $2;
600 $$ = term;
603 array:
604 '[' array_terms ']'
606 $$ = $2;
609 PE_ARRAY_ALL
611 $$.nr_ranges = 0;
612 $$.ranges = NULL;
615 array_terms:
616 array_terms ',' array_term
618 struct parse_events_array new_array;
620 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
621 new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
622 new_array.nr_ranges);
623 ABORT_ON(!new_array.ranges);
624 memcpy(&new_array.ranges[0], $1.ranges,
625 $1.nr_ranges * sizeof(new_array.ranges[0]));
626 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
627 $3.nr_ranges * sizeof(new_array.ranges[0]));
628 free($1.ranges);
629 free($3.ranges);
630 $$ = new_array;
633 array_term
635 array_term:
636 PE_VALUE
638 struct parse_events_array array;
640 array.nr_ranges = 1;
641 array.ranges = malloc(sizeof(array.ranges[0]));
642 ABORT_ON(!array.ranges);
643 array.ranges[0].start = $1;
644 array.ranges[0].length = 1;
645 $$ = array;
648 PE_VALUE PE_ARRAY_RANGE PE_VALUE
650 struct parse_events_array array;
652 ABORT_ON($3 < $1);
653 array.nr_ranges = 1;
654 array.ranges = malloc(sizeof(array.ranges[0]));
655 ABORT_ON(!array.ranges);
656 array.ranges[0].start = $1;
657 array.ranges[0].length = $3 - $1 + 1;
658 $$ = array;
661 sep_dc: ':' |
663 sep_slash_dc: '/' | ':' |
667 void parse_events_error(YYLTYPE *loc, void *data,
668 void *scanner __maybe_unused,
669 char const *msg __maybe_unused)
671 parse_events_evlist_error(data, loc->last_column, "parser error");