2 %parse
-param
{void *_parse_state
}
3 %parse
-param
{void *scanner
}
4 %lex
-param
{void* scanner
}
11 #include <linux/compiler.h>
12 #include <linux/list.h>
13 #include <linux/types.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) \
28 #define ALLOC_LIST(list) \
30 list
= malloc
(sizeof
(*list
)); \
32 INIT_LIST_HEAD
(list
); \
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
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
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
58 %type
<num
> PE_VALUE_SYM_HW
59 %type
<num
> PE_VALUE_SYM_SW
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
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
90 %type
<head
> group_def
94 %type
<array
> array_term
95 %type
<array
> array_terms
101 struct list_head
*head
;
102 struct parse_events_term
*term
;
103 struct tracepoint_name
{
107 struct parse_events_array array
;
112 PE_START_EVENTS start_events
114 PE_START_TERMS start_terms
118 struct parse_events_state
*parse_state
= _parse_state
;
120 parse_events_update_lists
($1, &parse_state
->list
);
126 struct list_head
*list
= $1;
127 struct list_head
*group
= $3;
129 parse_events_update_lists
(group
, list
);
135 struct list_head
*list
= $1;
136 struct list_head
*event
= $3;
138 parse_events_update_lists
(event
, list
);
147 group_def
':' PE_MODIFIER_EVENT
149 struct list_head
*list
= $1;
151 ABORT_ON
(parse_events__modifier_group
(list
, $3));
158 PE_NAME
'{' events
'}'
160 struct list_head
*list
= $3;
162 inc_group_count
(list
, _parse_state
);
163 parse_events__set_leader
($1, list
);
169 struct list_head
*list
= $2;
171 inc_group_count
(list
, _parse_state
);
172 parse_events__set_leader
(NULL
, list
);
179 struct list_head
*event
= $3;
180 struct list_head
*list
= $1;
182 parse_events_update_lists
(event
, list
);
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
));
207 PE_EVENT_NAME event_def
209 ABORT_ON
(parse_events_name
($2, $1));
216 event_def: event_pmu |
217 event_legacy_symbol |
218 event_legacy_cache sep_dc |
220 event_legacy_tracepoint sep_dc |
221 event_legacy_numeric sep_dc |
222 event_legacy_raw sep_dc |
226 PE_NAME opt_event_config
228 struct list_head
*list
, *orig_terms
, *terms
;
230 if
(parse_events_copy_term_list
($2, &orig_terms
))
234 if
(parse_events_add_pmu
(_parse_state
, list
, $1, $2)) {
235 struct perf_pmu
*pmu
= NULL
;
238 while
((pmu
= perf_pmu__scan
(pmu
)) != NULL
) {
239 char *name
= pmu
->name
;
241 if
(!strncmp
(name
, "uncore_", 7) &&
242 strncmp
($1, "uncore_", 7))
244 if
(!strncmp
($1, name
, strlen
($1))) {
245 if
(parse_events_copy_term_list
(orig_terms
, &terms
))
247 if
(!parse_events_add_pmu
(_parse_state
, list
, pmu
->name
, terms
))
249 parse_events_terms__delete
(terms
);
255 parse_events_terms__delete
($2);
256 parse_events_terms__delete
(orig_terms
);
260 PE_KERNEL_PMU_EVENT sep_dc
262 struct list_head
*list
;
264 if
(parse_events_multi_pmu_add
(_parse_state
, $1, &list
) < 0)
269 PE_PMU_EVENT_PRE
'-' PE_PMU_EVENT_SUF sep_dc
271 struct list_head
*list
;
274 snprintf
(&pmu_name
, 128, "%s-%s", $1, $3);
275 if
(parse_events_multi_pmu_add
(_parse_state
, pmu_name
, &list
) < 0)
286 value_sym
'/' event_config
'/'
288 struct list_head
*list
;
290 int config
= $1 & 255;
293 ABORT_ON
(parse_events_add_numeric
(_parse_state
, list
, type
, config
, $3));
294 parse_events_terms__delete
($3);
298 value_sym sep_slash_dc
300 struct list_head
*list
;
302 int config
= $1 & 255;
305 ABORT_ON
(parse_events_add_numeric
(_parse_state
, list
, type
, config
, NULL
));
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
;
317 ABORT_ON
(parse_events_add_cache
(list
, &parse_state
->idx
, $1, $3, $5, error, $6));
318 parse_events_terms__delete
($6);
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
;
329 ABORT_ON
(parse_events_add_cache
(list
, &parse_state
->idx
, $1, $3, NULL
, error, $4));
330 parse_events_terms__delete
($4);
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
;
341 ABORT_ON
(parse_events_add_cache
(list
, &parse_state
->idx
, $1, NULL
, NULL
, error, $2));
342 parse_events_terms__delete
($2);
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
;
353 ABORT_ON
(parse_events_add_breakpoint
(list
, &parse_state
->idx
,
354 (void *) $2, $6, $4));
358 PE_PREFIX_MEM PE_VALUE
'/' PE_VALUE sep_dc
360 struct parse_events_state
*parse_state
= _parse_state
;
361 struct list_head
*list
;
364 ABORT_ON
(parse_events_add_breakpoint
(list
, &parse_state
->idx
,
365 (void *) $2, NULL
, $4));
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
;
375 ABORT_ON
(parse_events_add_breakpoint
(list
, &parse_state
->idx
,
376 (void *) $2, $4, 0));
380 PE_PREFIX_MEM PE_VALUE sep_dc
382 struct parse_events_state
*parse_state
= _parse_state
;
383 struct list_head
*list
;
386 ABORT_ON
(parse_events_add_breakpoint
(list
, &parse_state
->idx
,
387 (void *) $2, NULL
, 0));
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
;
400 error->idx
= @
1.first_column
;
402 if
(parse_events_add_tracepoint
(list
, &parse_state
->idx
, $1.sys
, $1.event
,
410 PE_NAME
'-' PE_NAME
':' PE_NAME
413 struct tracepoint_name tracepoint
;
415 snprintf
(&sys_name
, 128, "%s-%s", $1, $3);
416 tracepoint.sys
= &sys_name
;
417 tracepoint.event
= $5;
424 struct tracepoint_name tracepoint
= {$1, $3};
429 event_legacy_numeric:
430 PE_VALUE
':' PE_VALUE opt_event_config
432 struct list_head
*list
;
435 ABORT_ON
(parse_events_add_numeric
(_parse_state
, list
, (u32
)$1, $3, $4));
436 parse_events_terms__delete
($4);
441 PE_RAW opt_event_config
443 struct list_head
*list
;
446 ABORT_ON
(parse_events_add_numeric
(_parse_state
, list
, PERF_TYPE_RAW
, $1, $2));
447 parse_events_terms__delete
($2);
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
;
459 ABORT_ON
(parse_events_load_bpf
(parse_state
, list
, $1, false
, $2));
460 parse_events_terms__delete
($2);
464 PE_BPF_SOURCE opt_event_config
466 struct list_head
*list
;
469 ABORT_ON
(parse_events_load_bpf
(_parse_state
, list
, $1, true
, $2));
470 parse_events_terms__delete
($2);
489 start_terms: event_config
491 struct parse_events_state
*parse_state
= _parse_state
;
492 parse_state
->terms
= $1;
496 event_config
',' event_term
498 struct list_head
*head
= $1;
499 struct parse_events_term
*term
= $3;
502 list_add_tail
(&term
->list
, head
);
508 struct list_head
*head
= malloc
(sizeof
(*head
));
509 struct parse_events_term
*term
= $1;
512 INIT_LIST_HEAD
(head
);
513 list_add_tail
(&term
->list
, head
);
520 struct parse_events_term
*term
;
522 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
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));
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
));
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
));
556 struct parse_events_term
*term
;
557 int config
= $1 & 255;
559 ABORT_ON
(parse_events_term__sym_hw
(&term
, NULL
, config
));
565 struct parse_events_term
*term
;
567 ABORT_ON
(parse_events_term__str
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
573 struct parse_events_term
*term
;
575 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, $3, false
, &@
1, &@
3));
581 struct parse_events_term
*term
;
583 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, 1, true
, &@
1, NULL
));
587 PE_NAME array
'=' PE_NAME
589 struct parse_events_term
*term
;
592 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
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));
611 struct parse_events_term
*term
;
613 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_DRV_CFG
,
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]));
653 struct parse_events_array array
;
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;
663 PE_VALUE PE_ARRAY_RANGE PE_VALUE
665 struct parse_events_array array
;
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;
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");