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
52 %token PE_DRV_CFG_TERM
54 %type
<num
> PE_VALUE_SYM_HW
55 %type
<num
> PE_VALUE_SYM_SW
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
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
86 %type
<head
> group_def
90 %type
<array
> array_term
91 %type
<array
> array_terms
97 struct list_head
*head
;
98 struct parse_events_term
*term
;
99 struct tracepoint_name
{
103 struct parse_events_array array
;
108 PE_START_EVENTS start_events
110 PE_START_TERMS start_terms
114 struct parse_events_evlist
*data
= _data
;
116 parse_events_update_lists
($1, &data
->list
);
122 struct list_head
*list
= $1;
123 struct list_head
*group
= $3;
125 parse_events_update_lists
(group
, list
);
131 struct list_head
*list
= $1;
132 struct list_head
*event
= $3;
134 parse_events_update_lists
(event
, list
);
143 group_def
':' PE_MODIFIER_EVENT
145 struct list_head
*list
= $1;
147 ABORT_ON
(parse_events__modifier_group
(list
, $3));
154 PE_NAME
'{' events
'}'
156 struct list_head
*list
= $3;
158 inc_group_count
(list
, _data
);
159 parse_events__set_leader
($1, list
);
165 struct list_head
*list
= $2;
167 inc_group_count
(list
, _data
);
168 parse_events__set_leader
(NULL
, list
);
175 struct list_head
*event
= $3;
176 struct list_head
*list
= $1;
178 parse_events_update_lists
(event
, list
);
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
));
203 PE_EVENT_NAME event_def
205 ABORT_ON
(parse_events_name
($2, $1));
212 event_def: event_pmu |
213 event_legacy_symbol |
214 event_legacy_cache sep_dc |
216 event_legacy_tracepoint sep_dc |
217 event_legacy_numeric sep_dc |
218 event_legacy_raw sep_dc |
222 PE_NAME opt_event_config
224 struct parse_events_evlist
*data
= _data
;
225 struct list_head
*list
;
228 ABORT_ON
(parse_events_add_pmu
(data
, list
, $1, $2));
229 parse_events_terms__delete
($2);
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
;
241 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
243 list_add_tail
(&term
->list
, head
);
246 ABORT_ON
(parse_events_add_pmu
(data
, list
, "cpu", head
));
247 parse_events_terms__delete
(head
);
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
;
258 snprintf
(&pmu_name
, 128, "%s-%s", $1, $3);
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
);
266 ABORT_ON
(parse_events_add_pmu
(data
, list
, "cpu", head
));
267 parse_events_terms__delete
(head
);
277 value_sym
'/' event_config
'/'
279 struct parse_events_evlist
*data
= _data
;
280 struct list_head
*list
;
282 int config
= $1 & 255;
285 ABORT_ON
(parse_events_add_numeric
(data
, list
, type
, config
, $3));
286 parse_events_terms__delete
($3);
290 value_sym sep_slash_dc
292 struct parse_events_evlist
*data
= _data
;
293 struct list_head
*list
;
295 int config
= $1 & 255;
298 ABORT_ON
(parse_events_add_numeric
(data
, list
, type
, config
, NULL
));
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
;
310 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, $3, $5, error, $6));
311 parse_events_terms__delete
($6);
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
;
322 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, $3, NULL
, error, $4));
323 parse_events_terms__delete
($4);
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
;
334 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, NULL
, NULL
, error, $2));
335 parse_events_terms__delete
($2);
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
;
346 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
347 (void *) $2, $6, $4));
351 PE_PREFIX_MEM PE_VALUE
'/' PE_VALUE sep_dc
353 struct parse_events_evlist
*data
= _data
;
354 struct list_head
*list
;
357 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
358 (void *) $2, NULL
, $4));
362 PE_PREFIX_MEM PE_VALUE
':' PE_MODIFIER_BP sep_dc
364 struct parse_events_evlist
*data
= _data
;
365 struct list_head
*list
;
368 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
369 (void *) $2, $4, 0));
373 PE_PREFIX_MEM PE_VALUE sep_dc
375 struct parse_events_evlist
*data
= _data
;
376 struct list_head
*list
;
379 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
380 (void *) $2, NULL
, 0));
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
;
393 error->idx
= @
1.first_column
;
395 if
(parse_events_add_tracepoint
(list
, &data
->idx
, $1.sys
, $1.event
,
403 PE_NAME
'-' PE_NAME
':' PE_NAME
406 struct tracepoint_name tracepoint
;
408 snprintf
(&sys_name
, 128, "%s-%s", $1, $3);
409 tracepoint.sys
= &sys_name
;
410 tracepoint.event
= $5;
417 struct tracepoint_name tracepoint
= {$1, $3};
422 event_legacy_numeric:
423 PE_VALUE
':' PE_VALUE opt_event_config
425 struct parse_events_evlist
*data
= _data
;
426 struct list_head
*list
;
429 ABORT_ON
(parse_events_add_numeric
(data
, list
, (u32
)$1, $3, $4));
430 parse_events_terms__delete
($4);
435 PE_RAW opt_event_config
437 struct parse_events_evlist
*data
= _data
;
438 struct list_head
*list
;
441 ABORT_ON
(parse_events_add_numeric
(data
, list
, PERF_TYPE_RAW
, $1, $2));
442 parse_events_terms__delete
($2);
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
;
454 ABORT_ON
(parse_events_load_bpf
(data
, list
, $1, false
, $2));
455 parse_events_terms__delete
($2);
459 PE_BPF_SOURCE opt_event_config
461 struct parse_events_evlist
*data
= _data
;
462 struct list_head
*list
;
465 ABORT_ON
(parse_events_load_bpf
(data
, list
, $1, true
, $2));
466 parse_events_terms__delete
($2);
485 start_terms: event_config
487 struct parse_events_terms
*data
= _data
;
492 event_config
',' event_term
494 struct list_head
*head
= $1;
495 struct parse_events_term
*term
= $3;
498 list_add_tail
(&term
->list
, head
);
504 struct list_head
*head
= malloc
(sizeof
(*head
));
505 struct parse_events_term
*term
= $1;
508 INIT_LIST_HEAD
(head
);
509 list_add_tail
(&term
->list
, head
);
516 struct parse_events_term
*term
;
518 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
525 struct parse_events_term
*term
;
527 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
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
));
543 struct parse_events_term
*term
;
545 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
552 struct parse_events_term
*term
;
553 int config
= $1 & 255;
555 ABORT_ON
(parse_events_term__sym_hw
(&term
, NULL
, config
));
561 struct parse_events_term
*term
;
563 ABORT_ON
(parse_events_term__str
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
569 struct parse_events_term
*term
;
571 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
577 struct parse_events_term
*term
;
579 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, 1, &@
1, NULL
));
583 PE_NAME array
'=' PE_NAME
585 struct parse_events_term
*term
;
588 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
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
,
607 struct parse_events_term
*term
;
609 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_DRV_CFG
,
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]));
649 struct parse_events_array array
;
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;
659 PE_VALUE PE_ARRAY_RANGE PE_VALUE
661 struct parse_events_array array
;
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;
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");