blob: afc44c18dfe17b054fe01e10c779dbe747373558 [file] [log] [blame]
Zheng Yanac20de6f2012-06-15 14:31:39 +08001%pure-parser
Jiri Olsa46010ab2012-06-15 14:31:38 +08002%parse-param {void *_data}
Zheng Yanac20de6f2012-06-15 14:31:39 +08003%parse-param {void *scanner}
4%lex-param {void* scanner}
Jiri Olsa89812fc2012-03-15 20:09:15 +01005
6%{
7
8#define YYDEBUG 1
9
10#include <linux/compiler.h>
11#include <linux/list.h>
12#include "types.h"
13#include "util.h"
14#include "parse-events.h"
Zheng Yanac20de6f2012-06-15 14:31:39 +080015#include "parse-events-bison.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010016
Zheng Yanac20de6f2012-06-15 14:31:39 +080017extern int parse_events_lex (YYSTYPE* lvalp, void* scanner);
Jiri Olsa89812fc2012-03-15 20:09:15 +010018
19#define ABORT_ON(val) \
20do { \
21 if (val) \
22 YYABORT; \
23} while (0)
24
Namhyung Kim97f63e42013-01-22 18:09:29 +090025static inc_group_count(struct list_head *list,
26 struct parse_events_evlist *data)
27{
28 /* Count groups only have more than 1 members */
29 if (!list_is_last(list->next, list))
30 data->nr_groups++;
31}
32
Jiri Olsa89812fc2012-03-15 20:09:15 +010033%}
34
Jiri Olsa90e2b222012-06-15 14:31:40 +080035%token PE_START_EVENTS PE_START_TERMS
Jiri Olsacf3506d2012-07-04 00:00:43 +020036%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
Robert Richterac2ba9f2012-08-16 21:10:21 +020037%token PE_EVENT_NAME
Jiri Olsa89812fc2012-03-15 20:09:15 +010038%token PE_NAME
39%token PE_MODIFIER_EVENT PE_MODIFIER_BP
40%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
Jiri Olsa89efb022012-08-08 12:14:14 +020041%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
Jiri Olsa89812fc2012-03-15 20:09:15 +010042%token PE_ERROR
43%type <num> PE_VALUE
Jiri Olsacf3506d2012-07-04 00:00:43 +020044%type <num> PE_VALUE_SYM_HW
45%type <num> PE_VALUE_SYM_SW
Jiri Olsa89812fc2012-03-15 20:09:15 +010046%type <num> PE_RAW
Jiri Olsa8f707d82012-03-15 20:09:16 +010047%type <num> PE_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010048%type <str> PE_NAME
49%type <str> PE_NAME_CACHE_TYPE
50%type <str> PE_NAME_CACHE_OP_RESULT
51%type <str> PE_MODIFIER_EVENT
52%type <str> PE_MODIFIER_BP
Robert Richterac2ba9f2012-08-16 21:10:21 +020053%type <str> PE_EVENT_NAME
Jiri Olsacf3506d2012-07-04 00:00:43 +020054%type <num> value_sym
Jiri Olsa8f707d82012-03-15 20:09:16 +010055%type <head> event_config
56%type <term> event_term
Jiri Olsab847cbd2012-05-21 09:12:51 +020057%type <head> event_pmu
58%type <head> event_legacy_symbol
59%type <head> event_legacy_cache
60%type <head> event_legacy_mem
61%type <head> event_legacy_tracepoint
62%type <head> event_legacy_numeric
63%type <head> event_legacy_raw
64%type <head> event_def
Robert Richterac2ba9f2012-08-16 21:10:21 +020065%type <head> event_mod
66%type <head> event_name
Jiri Olsa89efb022012-08-08 12:14:14 +020067%type <head> event
68%type <head> events
69%type <head> group_def
70%type <head> group
71%type <head> groups
Jiri Olsa89812fc2012-03-15 20:09:15 +010072
73%union
74{
75 char *str;
Robert Richterb527bab2012-08-07 19:43:13 +020076 u64 num;
Jiri Olsa8f707d82012-03-15 20:09:16 +010077 struct list_head *head;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -030078 struct parse_events_term *term;
Jiri Olsa89812fc2012-03-15 20:09:15 +010079}
80%%
81
Jiri Olsa90e2b222012-06-15 14:31:40 +080082start:
Jiri Olsa89efb022012-08-08 12:14:14 +020083PE_START_EVENTS start_events
Jiri Olsa90e2b222012-06-15 14:31:40 +080084|
Jiri Olsa89efb022012-08-08 12:14:14 +020085PE_START_TERMS start_terms
86
87start_events: groups
88{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -030089 struct parse_events_evlist *data = _data;
Jiri Olsa89efb022012-08-08 12:14:14 +020090
91 parse_events_update_lists($1, &data->list);
92}
93
94groups:
95groups ',' group
96{
97 struct list_head *list = $1;
98 struct list_head *group = $3;
99
100 parse_events_update_lists(group, list);
101 $$ = list;
102}
103|
104groups ',' event
105{
106 struct list_head *list = $1;
107 struct list_head *event = $3;
108
109 parse_events_update_lists(event, list);
110 $$ = list;
111}
112|
113group
114|
115event
116
117group:
118group_def ':' PE_MODIFIER_EVENT
119{
120 struct list_head *list = $1;
121
122 ABORT_ON(parse_events__modifier_group(list, $3));
123 $$ = list;
124}
125|
126group_def
127
128group_def:
129PE_NAME '{' events '}'
130{
131 struct list_head *list = $3;
132
Namhyung Kim97f63e42013-01-22 18:09:29 +0900133 inc_group_count(list, _data);
Arnaldo Carvalho de Melo63dab222012-08-14 16:35:48 -0300134 parse_events__set_leader($1, list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200135 $$ = list;
136}
137|
138'{' events '}'
139{
140 struct list_head *list = $2;
141
Namhyung Kim97f63e42013-01-22 18:09:29 +0900142 inc_group_count(list, _data);
Arnaldo Carvalho de Melo63dab222012-08-14 16:35:48 -0300143 parse_events__set_leader(NULL, list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200144 $$ = list;
145}
Jiri Olsa90e2b222012-06-15 14:31:40 +0800146
Jiri Olsa89812fc2012-03-15 20:09:15 +0100147events:
Jiri Olsa89efb022012-08-08 12:14:14 +0200148events ',' event
149{
150 struct list_head *event = $3;
151 struct list_head *list = $1;
152
153 parse_events_update_lists(event, list);
154 $$ = list;
155}
156|
157event
Jiri Olsa89812fc2012-03-15 20:09:15 +0100158
Robert Richterac2ba9f2012-08-16 21:10:21 +0200159event: event_mod
160
161event_mod:
162event_name PE_MODIFIER_EVENT
Jiri Olsa89812fc2012-03-15 20:09:15 +0100163{
Jiri Olsa89efb022012-08-08 12:14:14 +0200164 struct list_head *list = $1;
Jiri Olsa46010ab2012-06-15 14:31:38 +0800165
Jiri Olsa5d7be902012-03-20 19:15:40 +0100166 /*
167 * Apply modifier on all events added by single event definition
168 * (there could be more events added for multiple tracepoint
169 * definitions via '*?'.
170 */
Jiri Olsaf5b11352012-08-08 12:21:54 +0200171 ABORT_ON(parse_events__modifier_event(list, $2, false));
Jiri Olsa89efb022012-08-08 12:14:14 +0200172 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100173}
174|
Robert Richterac2ba9f2012-08-16 21:10:21 +0200175event_name
176
177event_name:
178PE_EVENT_NAME event_def
179{
180 ABORT_ON(parse_events_name($2, $1));
181 free($1);
182 $$ = $2;
183}
184|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100185event_def
186
Jiri Olsa5f537a22012-03-15 20:09:18 +0100187event_def: event_pmu |
188 event_legacy_symbol |
Jiri Olsa89812fc2012-03-15 20:09:15 +0100189 event_legacy_cache sep_dc |
190 event_legacy_mem |
191 event_legacy_tracepoint sep_dc |
192 event_legacy_numeric sep_dc |
193 event_legacy_raw sep_dc
194
Jiri Olsa5f537a22012-03-15 20:09:18 +0100195event_pmu:
196PE_NAME '/' event_config '/'
197{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300198 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200199 struct list_head *list = NULL;
200
Jiri Olsa46010ab2012-06-15 14:31:38 +0800201 ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
Jiri Olsa5f537a22012-03-15 20:09:18 +0100202 parse_events__free_terms($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200203 $$ = list;
Jiri Olsa5f537a22012-03-15 20:09:18 +0100204}
205
Jiri Olsacf3506d2012-07-04 00:00:43 +0200206value_sym:
207PE_VALUE_SYM_HW
208|
209PE_VALUE_SYM_SW
210
Jiri Olsa89812fc2012-03-15 20:09:15 +0100211event_legacy_symbol:
Jiri Olsacf3506d2012-07-04 00:00:43 +0200212value_sym '/' event_config '/'
Jiri Olsa89812fc2012-03-15 20:09:15 +0100213{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300214 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200215 struct list_head *list = NULL;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100216 int type = $1 >> 16;
217 int config = $1 & 255;
218
Jiri Olsa46010ab2012-06-15 14:31:38 +0800219 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
220 type, config, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100221 parse_events__free_terms($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200222 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100223}
224|
Jiri Olsacf3506d2012-07-04 00:00:43 +0200225value_sym sep_slash_dc
Jiri Olsa8f707d82012-03-15 20:09:16 +0100226{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300227 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200228 struct list_head *list = NULL;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100229 int type = $1 >> 16;
230 int config = $1 & 255;
231
Jiri Olsa46010ab2012-06-15 14:31:38 +0800232 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
233 type, config, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200234 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100235}
236
237event_legacy_cache:
238PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
239{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300240 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200241 struct list_head *list = NULL;
242
Jiri Olsa46010ab2012-06-15 14:31:38 +0800243 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200244 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100245}
246|
247PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
248{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300249 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200250 struct list_head *list = NULL;
251
Jiri Olsa46010ab2012-06-15 14:31:38 +0800252 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200253 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100254}
255|
256PE_NAME_CACHE_TYPE
257{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300258 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200259 struct list_head *list = NULL;
260
Jiri Olsa46010ab2012-06-15 14:31:38 +0800261 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200262 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100263}
264
265event_legacy_mem:
266PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
267{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300268 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200269 struct list_head *list = NULL;
270
Jiri Olsa46010ab2012-06-15 14:31:38 +0800271 ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
272 (void *) $2, $4));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200273 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100274}
275|
276PE_PREFIX_MEM PE_VALUE sep_dc
277{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300278 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200279 struct list_head *list = NULL;
280
Jiri Olsa46010ab2012-06-15 14:31:38 +0800281 ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
282 (void *) $2, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200283 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100284}
285
286event_legacy_tracepoint:
287PE_NAME ':' PE_NAME
288{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300289 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200290 struct list_head *list = NULL;
291
Jiri Olsa46010ab2012-06-15 14:31:38 +0800292 ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200293 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100294}
295
296event_legacy_numeric:
297PE_VALUE ':' PE_VALUE
298{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300299 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200300 struct list_head *list = NULL;
301
Robert Richterb527bab2012-08-07 19:43:13 +0200302 ABORT_ON(parse_events_add_numeric(&list, &data->idx, (u32)$1, $3, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200303 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100304}
305
306event_legacy_raw:
307PE_RAW
308{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300309 struct parse_events_evlist *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200310 struct list_head *list = NULL;
311
Jiri Olsa46010ab2012-06-15 14:31:38 +0800312 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
313 PERF_TYPE_RAW, $1, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200314 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100315}
316
Jiri Olsa89efb022012-08-08 12:14:14 +0200317start_terms: event_config
Jiri Olsa90e2b222012-06-15 14:31:40 +0800318{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300319 struct parse_events_terms *data = _data;
Jiri Olsa90e2b222012-06-15 14:31:40 +0800320 data->terms = $1;
321}
322
Jiri Olsa8f707d82012-03-15 20:09:16 +0100323event_config:
324event_config ',' event_term
325{
326 struct list_head *head = $1;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300327 struct parse_events_term *term = $3;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100328
329 ABORT_ON(!head);
330 list_add_tail(&term->list, head);
331 $$ = $1;
332}
333|
334event_term
335{
336 struct list_head *head = malloc(sizeof(*head));
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300337 struct parse_events_term *term = $1;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100338
339 ABORT_ON(!head);
340 INIT_LIST_HEAD(head);
341 list_add_tail(&term->list, head);
342 $$ = head;
343}
344
345event_term:
346PE_NAME '=' PE_NAME
347{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300348 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100349
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300350 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200351 $1, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100352 $$ = term;
353}
354|
355PE_NAME '=' PE_VALUE
356{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300357 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100358
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300359 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200360 $1, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100361 $$ = term;
362}
363|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200364PE_NAME '=' PE_VALUE_SYM_HW
365{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300366 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200367 int config = $3 & 255;
368
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300369 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200370 $$ = term;
371}
372|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100373PE_NAME
374{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300375 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100376
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300377 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200378 $1, 1));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100379 $$ = term;
380}
381|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200382PE_VALUE_SYM_HW
383{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300384 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200385 int config = $1 & 255;
386
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300387 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200388 $$ = term;
389}
390|
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200391PE_TERM '=' PE_NAME
392{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300393 struct parse_events_term *term;
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200394
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300395 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200396 $$ = term;
397}
398|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100399PE_TERM '=' PE_VALUE
400{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300401 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100402
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300403 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100404 $$ = term;
405}
406|
407PE_TERM
408{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300409 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100410
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300411 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100412 $$ = term;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100413}
414
415sep_dc: ':' |
416
Jiri Olsa8f707d82012-03-15 20:09:16 +0100417sep_slash_dc: '/' | ':' |
418
Jiri Olsa89812fc2012-03-15 20:09:15 +0100419%%
420
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300421void parse_events_error(void *data __maybe_unused, void *scanner __maybe_unused,
422 char const *msg __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100423{
424}