2 %parse
-param
{void *_data
}
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>
15 #include "parse-events.h"
16 #include "parse-events-bison.h"
18 #define ABORT_ON(val) \
24 #define ALLOC_LIST(list) \
26 list
= malloc
(sizeof
(*list
)); \
28 INIT_LIST_HEAD
(list
); \
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
))
41 %token PE_START_EVENTS PE_START_TERMS
42 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
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
50 %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
51 %token PE_ARRAY_ALL PE_ARRAY_RANGE
53 %type
<num
> PE_VALUE_SYM_HW
54 %type
<num
> PE_VALUE_SYM_SW
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
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
84 %type
<head
> group_def
88 %type
<array
> array_term
89 %type
<array
> array_terms
95 struct list_head
*head
;
96 struct parse_events_term
*term
;
97 struct tracepoint_name
{
101 struct parse_events_array array
;
106 PE_START_EVENTS start_events
108 PE_START_TERMS start_terms
112 struct parse_events_evlist
*data
= _data
;
114 parse_events_update_lists
($1, &data
->list
);
120 struct list_head
*list
= $1;
121 struct list_head
*group
= $3;
123 parse_events_update_lists
(group
, list
);
129 struct list_head
*list
= $1;
130 struct list_head
*event
= $3;
132 parse_events_update_lists
(event
, list
);
141 group_def
':' PE_MODIFIER_EVENT
143 struct list_head
*list
= $1;
145 ABORT_ON
(parse_events__modifier_group
(list
, $3));
152 PE_NAME
'{' events
'}'
154 struct list_head
*list
= $3;
156 inc_group_count
(list
, _data
);
157 parse_events__set_leader
($1, list
);
163 struct list_head
*list
= $2;
165 inc_group_count
(list
, _data
);
166 parse_events__set_leader
(NULL
, list
);
173 struct list_head
*event
= $3;
174 struct list_head
*list
= $1;
176 parse_events_update_lists
(event
, list
);
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
));
201 PE_EVENT_NAME event_def
203 ABORT_ON
(parse_events_name
($2, $1));
210 event_def: event_pmu |
211 event_legacy_symbol |
212 event_legacy_cache sep_dc |
214 event_legacy_tracepoint sep_dc |
215 event_legacy_numeric sep_dc |
216 event_legacy_raw sep_dc |
220 PE_NAME opt_event_config
222 struct parse_events_evlist
*data
= _data
;
223 struct list_head
*list
;
226 ABORT_ON
(parse_events_add_pmu
(data
, list
, $1, $2));
227 parse_events_terms__delete
($2);
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
;
239 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
241 list_add_tail
(&term
->list
, head
);
244 ABORT_ON
(parse_events_add_pmu
(data
, list
, "cpu", head
));
245 parse_events_terms__delete
(head
);
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
;
256 snprintf
(&pmu_name
, 128, "%s-%s", $1, $3);
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
);
264 ABORT_ON
(parse_events_add_pmu
(data
, list
, "cpu", head
));
265 parse_events_terms__delete
(head
);
275 value_sym
'/' event_config
'/'
277 struct parse_events_evlist
*data
= _data
;
278 struct list_head
*list
;
280 int config
= $1 & 255;
283 ABORT_ON
(parse_events_add_numeric
(data
, list
, type
, config
, $3));
284 parse_events_terms__delete
($3);
288 value_sym sep_slash_dc
290 struct parse_events_evlist
*data
= _data
;
291 struct list_head
*list
;
293 int config
= $1 & 255;
296 ABORT_ON
(parse_events_add_numeric
(data
, list
, type
, config
, NULL
));
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
;
308 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, $3, $5, error, $6));
309 parse_events_terms__delete
($6);
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
;
320 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, $3, NULL
, error, $4));
321 parse_events_terms__delete
($4);
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
;
332 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, NULL
, NULL
, error, $2));
333 parse_events_terms__delete
($2);
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
;
344 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
345 (void *) $2, $6, $4));
349 PE_PREFIX_MEM PE_VALUE
'/' PE_VALUE sep_dc
351 struct parse_events_evlist
*data
= _data
;
352 struct list_head
*list
;
355 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
356 (void *) $2, NULL
, $4));
360 PE_PREFIX_MEM PE_VALUE
':' PE_MODIFIER_BP sep_dc
362 struct parse_events_evlist
*data
= _data
;
363 struct list_head
*list
;
366 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
367 (void *) $2, $4, 0));
371 PE_PREFIX_MEM PE_VALUE sep_dc
373 struct parse_events_evlist
*data
= _data
;
374 struct list_head
*list
;
377 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
378 (void *) $2, NULL
, 0));
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
;
391 error->idx
= @
1.first_column
;
393 if
(parse_events_add_tracepoint
(list
, &data
->idx
, $1.sys
, $1.event
,
401 PE_NAME
'-' PE_NAME
':' PE_NAME
404 struct tracepoint_name tracepoint
;
406 snprintf
(&sys_name
, 128, "%s-%s", $1, $3);
407 tracepoint.sys
= &sys_name
;
408 tracepoint.event
= $5;
415 struct tracepoint_name tracepoint
= {$1, $3};
420 event_legacy_numeric:
421 PE_VALUE
':' PE_VALUE opt_event_config
423 struct parse_events_evlist
*data
= _data
;
424 struct list_head
*list
;
427 ABORT_ON
(parse_events_add_numeric
(data
, list
, (u32
)$1, $3, $4));
428 parse_events_terms__delete
($4);
433 PE_RAW opt_event_config
435 struct parse_events_evlist
*data
= _data
;
436 struct list_head
*list
;
439 ABORT_ON
(parse_events_add_numeric
(data
, list
, PERF_TYPE_RAW
, $1, $2));
440 parse_events_terms__delete
($2);
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
;
452 ABORT_ON
(parse_events_load_bpf
(data
, list
, $1, false
, $2));
453 parse_events_terms__delete
($2);
457 PE_BPF_SOURCE opt_event_config
459 struct parse_events_evlist
*data
= _data
;
460 struct list_head
*list
;
463 ABORT_ON
(parse_events_load_bpf
(data
, list
, $1, true
, $2));
464 parse_events_terms__delete
($2);
483 start_terms: event_config
485 struct parse_events_terms
*data
= _data
;
490 event_config
',' event_term
492 struct list_head
*head
= $1;
493 struct parse_events_term
*term
= $3;
496 list_add_tail
(&term
->list
, head
);
502 struct list_head
*head
= malloc
(sizeof
(*head
));
503 struct parse_events_term
*term
= $1;
506 INIT_LIST_HEAD
(head
);
507 list_add_tail
(&term
->list
, head
);
514 struct parse_events_term
*term
;
516 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
523 struct parse_events_term
*term
;
525 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
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
));
541 struct parse_events_term
*term
;
543 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
550 struct parse_events_term
*term
;
551 int config
= $1 & 255;
553 ABORT_ON
(parse_events_term__sym_hw
(&term
, NULL
, config
));
559 struct parse_events_term
*term
;
561 ABORT_ON
(parse_events_term__str
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
567 struct parse_events_term
*term
;
569 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
575 struct parse_events_term
*term
;
577 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, 1, &@
1, NULL
));
581 PE_NAME array
'=' PE_NAME
583 struct parse_events_term
*term
;
586 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
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
,
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]));
638 struct parse_events_array array
;
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;
648 PE_VALUE PE_ARRAY_RANGE PE_VALUE
650 struct parse_events_array array
;
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;
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");