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 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
52 %type
<num
> PE_VALUE_SYM_HW
53 %type
<num
> PE_VALUE_SYM_SW
57 %type
<str
> PE_BPF_OBJECT
58 %type
<str
> PE_BPF_SOURCE
59 %type
<str
> PE_NAME_CACHE_TYPE
60 %type
<str
> PE_NAME_CACHE_OP_RESULT
61 %type
<str
> PE_MODIFIER_EVENT
62 %type
<str
> PE_MODIFIER_BP
63 %type
<str
> PE_EVENT_NAME
64 %type
<str
> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
66 %type
<head
> event_config
67 %type
<term
> event_term
68 %type
<head
> event_pmu
69 %type
<head
> event_legacy_symbol
70 %type
<head
> event_legacy_cache
71 %type
<head
> event_legacy_mem
72 %type
<head
> event_legacy_tracepoint
73 %type
<tracepoint_name
> tracepoint_name
74 %type
<head
> event_legacy_numeric
75 %type
<head
> event_legacy_raw
76 %type
<head
> event_bpf_file
77 %type
<head
> event_def
78 %type
<head
> event_mod
79 %type
<head
> event_name
82 %type
<head
> group_def
90 struct list_head
*head
;
91 struct parse_events_term
*term
;
92 struct tracepoint_name
{
100 PE_START_EVENTS start_events
102 PE_START_TERMS start_terms
106 struct parse_events_evlist
*data
= _data
;
108 parse_events_update_lists
($1, &data
->list
);
114 struct list_head
*list
= $1;
115 struct list_head
*group
= $3;
117 parse_events_update_lists
(group
, list
);
123 struct list_head
*list
= $1;
124 struct list_head
*event
= $3;
126 parse_events_update_lists
(event
, list
);
135 group_def
':' PE_MODIFIER_EVENT
137 struct list_head
*list
= $1;
139 ABORT_ON
(parse_events__modifier_group
(list
, $3));
146 PE_NAME
'{' events
'}'
148 struct list_head
*list
= $3;
150 inc_group_count
(list
, _data
);
151 parse_events__set_leader
($1, list
);
157 struct list_head
*list
= $2;
159 inc_group_count
(list
, _data
);
160 parse_events__set_leader
(NULL
, list
);
167 struct list_head
*event
= $3;
168 struct list_head
*list
= $1;
170 parse_events_update_lists
(event
, list
);
179 event_name PE_MODIFIER_EVENT
181 struct list_head
*list
= $1;
184 * Apply modifier on all events added by single event definition
185 * (there could be more events added for multiple tracepoint
186 * definitions via '*?'.
188 ABORT_ON
(parse_events__modifier_event
(list
, $2, false
));
195 PE_EVENT_NAME event_def
197 ABORT_ON
(parse_events_name
($2, $1));
204 event_def: event_pmu |
205 event_legacy_symbol |
206 event_legacy_cache sep_dc |
208 event_legacy_tracepoint sep_dc |
209 event_legacy_numeric sep_dc |
210 event_legacy_raw sep_dc |
214 PE_NAME
'/' event_config
'/'
216 struct parse_events_evlist
*data
= _data
;
217 struct list_head
*list
;
220 ABORT_ON
(parse_events_add_pmu
(data
, list
, $1, $3));
221 parse_events__free_terms
($3);
227 struct parse_events_evlist
*data
= _data
;
228 struct list_head
*list
;
231 ABORT_ON
(parse_events_add_pmu
(data
, list
, $1, NULL
));
235 PE_KERNEL_PMU_EVENT sep_dc
237 struct parse_events_evlist
*data
= _data
;
238 struct list_head
*head
;
239 struct parse_events_term
*term
;
240 struct list_head
*list
;
243 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
245 list_add_tail
(&term
->list
, head
);
248 ABORT_ON
(parse_events_add_pmu
(data
, list
, "cpu", head
));
249 parse_events__free_terms
(head
);
253 PE_PMU_EVENT_PRE
'-' PE_PMU_EVENT_SUF sep_dc
255 struct parse_events_evlist
*data
= _data
;
256 struct list_head
*head
;
257 struct parse_events_term
*term
;
258 struct list_head
*list
;
260 snprintf
(&pmu_name
, 128, "%s-%s", $1, $3);
263 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
264 &pmu_name
, 1, &@
1, NULL
));
265 list_add_tail
(&term
->list
, head
);
268 ABORT_ON
(parse_events_add_pmu
(data
, list
, "cpu", head
));
269 parse_events__free_terms
(head
);
279 value_sym
'/' event_config
'/'
281 struct parse_events_evlist
*data
= _data
;
282 struct list_head
*list
;
284 int config
= $1 & 255;
287 ABORT_ON
(parse_events_add_numeric
(data
, list
, type
, config
, $3));
288 parse_events__free_terms
($3);
292 value_sym sep_slash_dc
294 struct parse_events_evlist
*data
= _data
;
295 struct list_head
*list
;
297 int config
= $1 & 255;
300 ABORT_ON
(parse_events_add_numeric
(data
, list
, type
, config
, NULL
));
305 PE_NAME_CACHE_TYPE
'-' PE_NAME_CACHE_OP_RESULT
'-' PE_NAME_CACHE_OP_RESULT
307 struct parse_events_evlist
*data
= _data
;
308 struct list_head
*list
;
311 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, $3, $5));
315 PE_NAME_CACHE_TYPE
'-' PE_NAME_CACHE_OP_RESULT
317 struct parse_events_evlist
*data
= _data
;
318 struct list_head
*list
;
321 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, $3, NULL
));
327 struct parse_events_evlist
*data
= _data
;
328 struct list_head
*list
;
331 ABORT_ON
(parse_events_add_cache
(list
, &data
->idx
, $1, NULL
, NULL
));
336 PE_PREFIX_MEM PE_VALUE
'/' PE_VALUE
':' PE_MODIFIER_BP sep_dc
338 struct parse_events_evlist
*data
= _data
;
339 struct list_head
*list
;
342 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
343 (void *) $2, $6, $4));
347 PE_PREFIX_MEM PE_VALUE
'/' PE_VALUE sep_dc
349 struct parse_events_evlist
*data
= _data
;
350 struct list_head
*list
;
353 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
354 (void *) $2, NULL
, $4));
358 PE_PREFIX_MEM PE_VALUE
':' PE_MODIFIER_BP sep_dc
360 struct parse_events_evlist
*data
= _data
;
361 struct list_head
*list
;
364 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
365 (void *) $2, $4, 0));
369 PE_PREFIX_MEM PE_VALUE sep_dc
371 struct parse_events_evlist
*data
= _data
;
372 struct list_head
*list
;
375 ABORT_ON
(parse_events_add_breakpoint
(list
, &data
->idx
,
376 (void *) $2, NULL
, 0));
380 event_legacy_tracepoint:
383 struct parse_events_evlist
*data
= _data
;
384 struct parse_events_error
*error = data
->error;
385 struct list_head
*list
;
389 error->idx
= @
1.first_column
;
391 if
(parse_events_add_tracepoint
(list
, &data
->idx
, $1.sys
, $1.event
,
398 tracepoint_name
'/' event_config
'/'
400 struct parse_events_evlist
*data
= _data
;
401 struct parse_events_error
*error = data
->error;
402 struct list_head
*list
;
406 error->idx
= @
1.first_column
;
408 if
(parse_events_add_tracepoint
(list
, &data
->idx
, $1.sys
, $1.event
,
416 PE_NAME
'-' PE_NAME
':' PE_NAME
419 struct tracepoint_name tracepoint
;
421 snprintf
(&sys_name
, 128, "%s-%s", $1, $3);
422 tracepoint.sys
= &sys_name
;
423 tracepoint.event
= $5;
430 struct tracepoint_name tracepoint
= {$1, $3};
435 event_legacy_numeric:
436 PE_VALUE
':' PE_VALUE
438 struct parse_events_evlist
*data
= _data
;
439 struct list_head
*list
;
442 ABORT_ON
(parse_events_add_numeric
(data
, list
, (u32
)$1, $3, NULL
));
449 struct parse_events_evlist
*data
= _data
;
450 struct list_head
*list
;
453 ABORT_ON
(parse_events_add_numeric
(data
, list
, PERF_TYPE_RAW
, $1, NULL
));
460 struct parse_events_evlist
*data
= _data
;
461 struct parse_events_error
*error = data
->error;
462 struct list_head
*list
;
465 ABORT_ON
(parse_events_load_bpf
(data
, list
, $1, false
));
471 struct parse_events_evlist
*data
= _data
;
472 struct list_head
*list
;
475 ABORT_ON
(parse_events_load_bpf
(data
, list
, $1, true
));
479 start_terms: event_config
481 struct parse_events_terms
*data
= _data
;
486 event_config
',' event_term
488 struct list_head
*head
= $1;
489 struct parse_events_term
*term
= $3;
492 list_add_tail
(&term
->list
, head
);
498 struct list_head
*head
= malloc
(sizeof
(*head
));
499 struct parse_events_term
*term
= $1;
502 INIT_LIST_HEAD
(head
);
503 list_add_tail
(&term
->list
, head
);
510 struct parse_events_term
*term
;
512 ABORT_ON
(parse_events_term__str
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
519 struct parse_events_term
*term
;
521 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
526 PE_NAME
'=' PE_VALUE_SYM_HW
528 struct parse_events_term
*term
;
529 int config
= $3 & 255;
531 ABORT_ON
(parse_events_term__sym_hw
(&term
, $1, config
));
537 struct parse_events_term
*term
;
539 ABORT_ON
(parse_events_term__num
(&term
, PARSE_EVENTS__TERM_TYPE_USER
,
546 struct parse_events_term
*term
;
547 int config
= $1 & 255;
549 ABORT_ON
(parse_events_term__sym_hw
(&term
, NULL
, config
));
555 struct parse_events_term
*term
;
557 ABORT_ON
(parse_events_term__str
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
563 struct parse_events_term
*term
;
565 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, $3, &@
1, &@
3));
571 struct parse_events_term
*term
;
573 ABORT_ON
(parse_events_term__num
(&term
, (int)$1, NULL
, 1, &@
1, NULL
));
579 sep_slash_dc: '/' |
':' |
583 void parse_events_error
(YYLTYPE *loc
, void *data
,
584 void *scanner __maybe_unused
,
585 char const *msg __maybe_unused
)
587 parse_events_evlist_error
(data
, loc
->last_column
, "parser error");