net: Convert dccp_v4_ops
[linux/fpc-iii.git] / tools / perf / util / parse-events.y
blobe81a20ea8d7df1d2c7d8313279daa834eda88415
1 %pure-parser
2 %parse-param {void *_parse_state}
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 "pmu.h"
16 #include "debug.h"
17 #include "parse-events.h"
18 #include "parse-events-bison.h"
20 void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
22 #define ABORT_ON(val) \
23 do { \
24 if (val) \
25 YYABORT; \
26 } while (0)
28 #define ALLOC_LIST(list) \
29 do { \
30 list = malloc(sizeof(*list)); \
31 ABORT_ON(!list); \
32 INIT_LIST_HEAD(list); \
33 } while (0)
35 static void inc_group_count(struct list_head *list,
36 struct parse_events_state *parse_state)
38 /* Count groups only have more than 1 members */
39 if (!list_is_last(list->next, list))
40 parse_state->nr_groups++;
45 %token PE_START_EVENTS PE_START_TERMS
46 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
47 %token PE_EVENT_NAME
48 %token PE_NAME
49 %token PE_BPF_OBJECT PE_BPF_SOURCE
50 %token PE_MODIFIER_EVENT PE_MODIFIER_BP
51 %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
52 %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
53 %token PE_ERROR
54 %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
55 %token PE_ARRAY_ALL PE_ARRAY_RANGE
56 %token PE_DRV_CFG_TERM
57 %type <num> PE_VALUE
58 %type <num> PE_VALUE_SYM_HW
59 %type <num> PE_VALUE_SYM_SW
60 %type <num> PE_RAW
61 %type <num> PE_TERM
62 %type <str> PE_NAME
63 %type <str> PE_BPF_OBJECT
64 %type <str> PE_BPF_SOURCE
65 %type <str> PE_NAME_CACHE_TYPE
66 %type <str> PE_NAME_CACHE_OP_RESULT
67 %type <str> PE_MODIFIER_EVENT
68 %type <str> PE_MODIFIER_BP
69 %type <str> PE_EVENT_NAME
70 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
71 %type <str> PE_DRV_CFG_TERM
72 %type <num> value_sym
73 %type <head> event_config
74 %type <head> opt_event_config
75 %type <term> event_term
76 %type <head> event_pmu
77 %type <head> event_legacy_symbol
78 %type <head> event_legacy_cache
79 %type <head> event_legacy_mem
80 %type <head> event_legacy_tracepoint
81 %type <tracepoint_name> tracepoint_name
82 %type <head> event_legacy_numeric
83 %type <head> event_legacy_raw
84 %type <head> event_bpf_file
85 %type <head> event_def
86 %type <head> event_mod
87 %type <head> event_name
88 %type <head> event
89 %type <head> events
90 %type <head> group_def
91 %type <head> group
92 %type <head> groups
93 %type <array> array
94 %type <array> array_term
95 %type <array> array_terms
97 %union
99 char *str;
100 u64 num;
101 struct list_head *head;
102 struct parse_events_term *term;
103 struct tracepoint_name {
104 char *sys;
105 char *event;
106 } tracepoint_name;
107 struct parse_events_array array;
111 start:
112 PE_START_EVENTS start_events
114 PE_START_TERMS start_terms
116 start_events: groups
118 struct parse_events_state *parse_state = _parse_state;
120 parse_events_update_lists($1, &parse_state->list);
123 groups:
124 groups ',' group
126 struct list_head *list = $1;
127 struct list_head *group = $3;
129 parse_events_update_lists(group, list);
130 $$ = list;
133 groups ',' event
135 struct list_head *list = $1;
136 struct list_head *event = $3;
138 parse_events_update_lists(event, list);
139 $$ = list;
142 group
144 event
146 group:
147 group_def ':' PE_MODIFIER_EVENT
149 struct list_head *list = $1;
151 ABORT_ON(parse_events__modifier_group(list, $3));
152 $$ = list;
155 group_def
157 group_def:
158 PE_NAME '{' events '}'
160 struct list_head *list = $3;
162 inc_group_count(list, _parse_state);
163 parse_events__set_leader($1, list);
164 $$ = list;
167 '{' events '}'
169 struct list_head *list = $2;
171 inc_group_count(list, _parse_state);
172 parse_events__set_leader(NULL, list);
173 $$ = list;
176 events:
177 events ',' event
179 struct list_head *event = $3;
180 struct list_head *list = $1;
182 parse_events_update_lists(event, list);
183 $$ = list;
186 event
188 event: event_mod
190 event_mod:
191 event_name PE_MODIFIER_EVENT
193 struct list_head *list = $1;
196 * Apply modifier on all events added by single event definition
197 * (there could be more events added for multiple tracepoint
198 * definitions via '*?'.
200 ABORT_ON(parse_events__modifier_event(list, $2, false));
201 $$ = list;
204 event_name
206 event_name:
207 PE_EVENT_NAME event_def
209 ABORT_ON(parse_events_name($2, $1));
210 free($1);
211 $$ = $2;
214 event_def
216 event_def: event_pmu |
217 event_legacy_symbol |
218 event_legacy_cache sep_dc |
219 event_legacy_mem |
220 event_legacy_tracepoint sep_dc |
221 event_legacy_numeric sep_dc |
222 event_legacy_raw sep_dc |
223 event_bpf_file
225 event_pmu:
226 PE_NAME opt_event_config
228 struct list_head *list, *orig_terms, *terms;
230 if (parse_events_copy_term_list($2, &orig_terms))
231 YYABORT;
233 ALLOC_LIST(list);
234 if (parse_events_add_pmu(_parse_state, list, $1, $2)) {
235 struct perf_pmu *pmu = NULL;
236 int ok = 0;
238 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
239 char *name = pmu->name;
241 if (!strncmp(name, "uncore_", 7) &&
242 strncmp($1, "uncore_", 7))
243 name += 7;
244 if (!strncmp($1, name, strlen($1))) {
245 if (parse_events_copy_term_list(orig_terms, &terms))
246 YYABORT;
247 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms))
248 ok++;
249 parse_events_terms__delete(terms);
252 if (!ok)
253 YYABORT;
255 parse_events_terms__delete($2);
256 parse_events_terms__delete(orig_terms);
257 $$ = list;
260 PE_KERNEL_PMU_EVENT sep_dc
262 struct list_head *list;
264 if (parse_events_multi_pmu_add(_parse_state, $1, &list) < 0)
265 YYABORT;
266 $$ = list;
269 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
271 struct list_head *list;
272 char pmu_name[128];
274 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
275 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0)
276 YYABORT;
277 $$ = list;
280 value_sym:
281 PE_VALUE_SYM_HW
283 PE_VALUE_SYM_SW
285 event_legacy_symbol:
286 value_sym '/' event_config '/'
288 struct list_head *list;
289 int type = $1 >> 16;
290 int config = $1 & 255;
292 ALLOC_LIST(list);
293 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3));
294 parse_events_terms__delete($3);
295 $$ = list;
298 value_sym sep_slash_dc
300 struct list_head *list;
301 int type = $1 >> 16;
302 int config = $1 & 255;
304 ALLOC_LIST(list);
305 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
306 $$ = list;
309 event_legacy_cache:
310 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
312 struct parse_events_state *parse_state = _parse_state;
313 struct parse_events_error *error = parse_state->error;
314 struct list_head *list;
316 ALLOC_LIST(list);
317 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6));
318 parse_events_terms__delete($6);
319 $$ = list;
322 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
324 struct parse_events_state *parse_state = _parse_state;
325 struct parse_events_error *error = parse_state->error;
326 struct list_head *list;
328 ALLOC_LIST(list);
329 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4));
330 parse_events_terms__delete($4);
331 $$ = list;
334 PE_NAME_CACHE_TYPE opt_event_config
336 struct parse_events_state *parse_state = _parse_state;
337 struct parse_events_error *error = parse_state->error;
338 struct list_head *list;
340 ALLOC_LIST(list);
341 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2));
342 parse_events_terms__delete($2);
343 $$ = list;
346 event_legacy_mem:
347 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
349 struct parse_events_state *parse_state = _parse_state;
350 struct list_head *list;
352 ALLOC_LIST(list);
353 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
354 (void *) $2, $6, $4));
355 $$ = list;
358 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
360 struct parse_events_state *parse_state = _parse_state;
361 struct list_head *list;
363 ALLOC_LIST(list);
364 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
365 (void *) $2, NULL, $4));
366 $$ = list;
369 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
371 struct parse_events_state *parse_state = _parse_state;
372 struct list_head *list;
374 ALLOC_LIST(list);
375 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
376 (void *) $2, $4, 0));
377 $$ = list;
380 PE_PREFIX_MEM PE_VALUE sep_dc
382 struct parse_events_state *parse_state = _parse_state;
383 struct list_head *list;
385 ALLOC_LIST(list);
386 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
387 (void *) $2, NULL, 0));
388 $$ = list;
391 event_legacy_tracepoint:
392 tracepoint_name opt_event_config
394 struct parse_events_state *parse_state = _parse_state;
395 struct parse_events_error *error = parse_state->error;
396 struct list_head *list;
398 ALLOC_LIST(list);
399 if (error)
400 error->idx = @1.first_column;
402 if (parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
403 error, $2))
404 return -1;
406 $$ = list;
409 tracepoint_name:
410 PE_NAME '-' PE_NAME ':' PE_NAME
412 char sys_name[128];
413 struct tracepoint_name tracepoint;
415 snprintf(&sys_name, 128, "%s-%s", $1, $3);
416 tracepoint.sys = &sys_name;
417 tracepoint.event = $5;
419 $$ = tracepoint;
422 PE_NAME ':' PE_NAME
424 struct tracepoint_name tracepoint = {$1, $3};
426 $$ = tracepoint;
429 event_legacy_numeric:
430 PE_VALUE ':' PE_VALUE opt_event_config
432 struct list_head *list;
434 ALLOC_LIST(list);
435 ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4));
436 parse_events_terms__delete($4);
437 $$ = list;
440 event_legacy_raw:
441 PE_RAW opt_event_config
443 struct list_head *list;
445 ALLOC_LIST(list);
446 ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2));
447 parse_events_terms__delete($2);
448 $$ = list;
451 event_bpf_file:
452 PE_BPF_OBJECT opt_event_config
454 struct parse_events_state *parse_state = _parse_state;
455 struct parse_events_error *error = parse_state->error;
456 struct list_head *list;
458 ALLOC_LIST(list);
459 ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2));
460 parse_events_terms__delete($2);
461 $$ = list;
464 PE_BPF_SOURCE opt_event_config
466 struct list_head *list;
468 ALLOC_LIST(list);
469 ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2));
470 parse_events_terms__delete($2);
471 $$ = list;
474 opt_event_config:
475 '/' event_config '/'
477 $$ = $2;
480 '/' '/'
482 $$ = NULL;
486 $$ = NULL;
489 start_terms: event_config
491 struct parse_events_state *parse_state = _parse_state;
492 parse_state->terms = $1;
495 event_config:
496 event_config ',' event_term
498 struct list_head *head = $1;
499 struct parse_events_term *term = $3;
501 ABORT_ON(!head);
502 list_add_tail(&term->list, head);
503 $$ = $1;
506 event_term
508 struct list_head *head = malloc(sizeof(*head));
509 struct parse_events_term *term = $1;
511 ABORT_ON(!head);
512 INIT_LIST_HEAD(head);
513 list_add_tail(&term->list, head);
514 $$ = head;
517 event_term:
518 PE_NAME '=' PE_NAME
520 struct parse_events_term *term;
522 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
523 $1, $3, &@1, &@3));
524 $$ = term;
527 PE_NAME '=' PE_VALUE
529 struct parse_events_term *term;
531 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
532 $1, $3, false, &@1, &@3));
533 $$ = term;
536 PE_NAME '=' PE_VALUE_SYM_HW
538 struct parse_events_term *term;
539 int config = $3 & 255;
541 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
542 $$ = term;
545 PE_NAME
547 struct parse_events_term *term;
549 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
550 $1, 1, true, &@1, NULL));
551 $$ = term;
554 PE_VALUE_SYM_HW
556 struct parse_events_term *term;
557 int config = $1 & 255;
559 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
560 $$ = term;
563 PE_TERM '=' PE_NAME
565 struct parse_events_term *term;
567 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
568 $$ = term;
571 PE_TERM '=' PE_VALUE
573 struct parse_events_term *term;
575 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
576 $$ = term;
579 PE_TERM
581 struct parse_events_term *term;
583 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
584 $$ = term;
587 PE_NAME array '=' PE_NAME
589 struct parse_events_term *term;
590 int i;
592 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
593 $1, $4, &@1, &@4));
595 term->array = $2;
596 $$ = term;
599 PE_NAME array '=' PE_VALUE
601 struct parse_events_term *term;
603 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
604 $1, $4, false, &@1, &@4));
605 term->array = $2;
606 $$ = term;
609 PE_DRV_CFG_TERM
611 struct parse_events_term *term;
613 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
614 $1, $1, &@1, NULL));
615 $$ = term;
618 array:
619 '[' array_terms ']'
621 $$ = $2;
624 PE_ARRAY_ALL
626 $$.nr_ranges = 0;
627 $$.ranges = NULL;
630 array_terms:
631 array_terms ',' array_term
633 struct parse_events_array new_array;
635 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
636 new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
637 new_array.nr_ranges);
638 ABORT_ON(!new_array.ranges);
639 memcpy(&new_array.ranges[0], $1.ranges,
640 $1.nr_ranges * sizeof(new_array.ranges[0]));
641 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
642 $3.nr_ranges * sizeof(new_array.ranges[0]));
643 free($1.ranges);
644 free($3.ranges);
645 $$ = new_array;
648 array_term
650 array_term:
651 PE_VALUE
653 struct parse_events_array array;
655 array.nr_ranges = 1;
656 array.ranges = malloc(sizeof(array.ranges[0]));
657 ABORT_ON(!array.ranges);
658 array.ranges[0].start = $1;
659 array.ranges[0].length = 1;
660 $$ = array;
663 PE_VALUE PE_ARRAY_RANGE PE_VALUE
665 struct parse_events_array array;
667 ABORT_ON($3 < $1);
668 array.nr_ranges = 1;
669 array.ranges = malloc(sizeof(array.ranges[0]));
670 ABORT_ON(!array.ranges);
671 array.ranges[0].start = $1;
672 array.ranges[0].length = $3 - $1 + 1;
673 $$ = array;
676 sep_dc: ':' |
678 sep_slash_dc: '/' | ':' |
682 void parse_events_error(YYLTYPE *loc, void *parse_state,
683 void *scanner __maybe_unused,
684 char const *msg __maybe_unused)
686 parse_events_evlist_error(parse_state, loc->last_column, "parser error");