blob: f3b5ec901600dc1b88b4e953aa1bd94a80a8f901 [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 Olsa6297d422015-04-22 21:10:17 +02005%locations
Jiri Olsa89812fc2012-03-15 20:09:15 +01006
7%{
8
9#define YYDEBUG 1
10
11#include <linux/compiler.h>
12#include <linux/list.h>
Borislav Petkovd944c4e2014-04-25 21:31:02 +020013#include <linux/types.h>
Jiri Olsa89812fc2012-03-15 20:09:15 +010014#include "util.h"
Andi Kleen231bb2a2017-01-27 18:03:39 -080015#include "pmu.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010016#include "parse-events.h"
Zheng Yanac20de6f2012-06-15 14:31:39 +080017#include "parse-events-bison.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010018
Jiri Olsa89812fc2012-03-15 20:09:15 +010019#define ABORT_ON(val) \
20do { \
21 if (val) \
22 YYABORT; \
23} while (0)
24
David Ahernc5cd8ac2013-07-02 13:27:25 -060025#define ALLOC_LIST(list) \
26do { \
27 list = malloc(sizeof(*list)); \
28 ABORT_ON(!list); \
29 INIT_LIST_HEAD(list); \
30} while (0)
31
Colin Ian King07ef7572016-03-07 16:44:37 -030032static void inc_group_count(struct list_head *list,
Namhyung Kim97f63e42013-01-22 18:09:29 +090033 struct parse_events_evlist *data)
34{
35 /* Count groups only have more than 1 members */
36 if (!list_is_last(list->next, list))
37 data->nr_groups++;
38}
39
Jiri Olsa89812fc2012-03-15 20:09:15 +010040%}
41
Jiri Olsa90e2b222012-06-15 14:31:40 +080042%token PE_START_EVENTS PE_START_TERMS
Jiri Olsacf3506d2012-07-04 00:00:43 +020043%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
Robert Richterac2ba9f2012-08-16 21:10:21 +020044%token PE_EVENT_NAME
Jiri Olsa89812fc2012-03-15 20:09:15 +010045%token PE_NAME
Wang Nand509db02015-10-14 12:41:20 +000046%token PE_BPF_OBJECT PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010047%token PE_MODIFIER_EVENT PE_MODIFIER_BP
48%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
Jiri Olsa89efb022012-08-08 12:14:14 +020049%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
Jiri Olsa89812fc2012-03-15 20:09:15 +010050%token PE_ERROR
Kan Liangba32a452014-10-07 11:08:51 -040051%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Wang Nane571e022016-02-22 09:10:35 +000052%token PE_ARRAY_ALL PE_ARRAY_RANGE
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060053%token PE_DRV_CFG_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010054%type <num> PE_VALUE
Jiri Olsacf3506d2012-07-04 00:00:43 +020055%type <num> PE_VALUE_SYM_HW
56%type <num> PE_VALUE_SYM_SW
Jiri Olsa89812fc2012-03-15 20:09:15 +010057%type <num> PE_RAW
Jiri Olsa8f707d82012-03-15 20:09:16 +010058%type <num> PE_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010059%type <str> PE_NAME
Wang Nan84c86ca2015-10-14 12:41:14 +000060%type <str> PE_BPF_OBJECT
Wang Nand509db02015-10-14 12:41:20 +000061%type <str> PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010062%type <str> PE_NAME_CACHE_TYPE
63%type <str> PE_NAME_CACHE_OP_RESULT
64%type <str> PE_MODIFIER_EVENT
65%type <str> PE_MODIFIER_BP
Robert Richterac2ba9f2012-08-16 21:10:21 +020066%type <str> PE_EVENT_NAME
Kan Liangba32a452014-10-07 11:08:51 -040067%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060068%type <str> PE_DRV_CFG_TERM
Jiri Olsacf3506d2012-07-04 00:00:43 +020069%type <num> value_sym
Jiri Olsa8f707d82012-03-15 20:09:16 +010070%type <head> event_config
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -030071%type <head> opt_event_config
Jiri Olsa8f707d82012-03-15 20:09:16 +010072%type <term> event_term
Jiri Olsab847cbd2012-05-21 09:12:51 +020073%type <head> event_pmu
74%type <head> event_legacy_symbol
75%type <head> event_legacy_cache
76%type <head> event_legacy_mem
77%type <head> event_legacy_tracepoint
He Kuang865582c2015-09-28 03:52:15 +000078%type <tracepoint_name> tracepoint_name
Jiri Olsab847cbd2012-05-21 09:12:51 +020079%type <head> event_legacy_numeric
80%type <head> event_legacy_raw
Wang Nan84c86ca2015-10-14 12:41:14 +000081%type <head> event_bpf_file
Jiri Olsab847cbd2012-05-21 09:12:51 +020082%type <head> event_def
Robert Richterac2ba9f2012-08-16 21:10:21 +020083%type <head> event_mod
84%type <head> event_name
Jiri Olsa89efb022012-08-08 12:14:14 +020085%type <head> event
86%type <head> events
87%type <head> group_def
88%type <head> group
89%type <head> groups
Wang Nane571e022016-02-22 09:10:35 +000090%type <array> array
91%type <array> array_term
92%type <array> array_terms
Jiri Olsa89812fc2012-03-15 20:09:15 +010093
94%union
95{
96 char *str;
Robert Richterb527bab2012-08-07 19:43:13 +020097 u64 num;
Jiri Olsa8f707d82012-03-15 20:09:16 +010098 struct list_head *head;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -030099 struct parse_events_term *term;
He Kuang865582c2015-09-28 03:52:15 +0000100 struct tracepoint_name {
101 char *sys;
102 char *event;
103 } tracepoint_name;
Wang Nane571e022016-02-22 09:10:35 +0000104 struct parse_events_array array;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100105}
106%%
107
Jiri Olsa90e2b222012-06-15 14:31:40 +0800108start:
Jiri Olsa89efb022012-08-08 12:14:14 +0200109PE_START_EVENTS start_events
Jiri Olsa90e2b222012-06-15 14:31:40 +0800110|
Jiri Olsa89efb022012-08-08 12:14:14 +0200111PE_START_TERMS start_terms
112
113start_events: groups
114{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300115 struct parse_events_evlist *data = _data;
Jiri Olsa89efb022012-08-08 12:14:14 +0200116
117 parse_events_update_lists($1, &data->list);
118}
119
120groups:
121groups ',' group
122{
123 struct list_head *list = $1;
124 struct list_head *group = $3;
125
126 parse_events_update_lists(group, list);
127 $$ = list;
128}
129|
130groups ',' event
131{
132 struct list_head *list = $1;
133 struct list_head *event = $3;
134
135 parse_events_update_lists(event, list);
136 $$ = list;
137}
138|
139group
140|
141event
142
143group:
144group_def ':' PE_MODIFIER_EVENT
145{
146 struct list_head *list = $1;
147
148 ABORT_ON(parse_events__modifier_group(list, $3));
149 $$ = list;
150}
151|
152group_def
153
154group_def:
155PE_NAME '{' events '}'
156{
157 struct list_head *list = $3;
158
Namhyung Kim97f63e42013-01-22 18:09:29 +0900159 inc_group_count(list, _data);
Arnaldo Carvalho de Melo63dab222012-08-14 16:35:48 -0300160 parse_events__set_leader($1, list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200161 $$ = list;
162}
163|
164'{' events '}'
165{
166 struct list_head *list = $2;
167
Namhyung Kim97f63e42013-01-22 18:09:29 +0900168 inc_group_count(list, _data);
Arnaldo Carvalho de Melo63dab222012-08-14 16:35:48 -0300169 parse_events__set_leader(NULL, list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200170 $$ = list;
171}
Jiri Olsa90e2b222012-06-15 14:31:40 +0800172
Jiri Olsa89812fc2012-03-15 20:09:15 +0100173events:
Jiri Olsa89efb022012-08-08 12:14:14 +0200174events ',' event
175{
176 struct list_head *event = $3;
177 struct list_head *list = $1;
178
179 parse_events_update_lists(event, list);
180 $$ = list;
181}
182|
183event
Jiri Olsa89812fc2012-03-15 20:09:15 +0100184
Robert Richterac2ba9f2012-08-16 21:10:21 +0200185event: event_mod
186
187event_mod:
188event_name PE_MODIFIER_EVENT
Jiri Olsa89812fc2012-03-15 20:09:15 +0100189{
Jiri Olsa89efb022012-08-08 12:14:14 +0200190 struct list_head *list = $1;
Jiri Olsa46010ab2012-06-15 14:31:38 +0800191
Jiri Olsa5d7be902012-03-20 19:15:40 +0100192 /*
193 * Apply modifier on all events added by single event definition
194 * (there could be more events added for multiple tracepoint
195 * definitions via '*?'.
196 */
Jiri Olsaf5b11352012-08-08 12:21:54 +0200197 ABORT_ON(parse_events__modifier_event(list, $2, false));
Jiri Olsa89efb022012-08-08 12:14:14 +0200198 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100199}
200|
Robert Richterac2ba9f2012-08-16 21:10:21 +0200201event_name
202
203event_name:
204PE_EVENT_NAME event_def
205{
206 ABORT_ON(parse_events_name($2, $1));
207 free($1);
208 $$ = $2;
209}
210|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100211event_def
212
Jiri Olsa5f537a22012-03-15 20:09:18 +0100213event_def: event_pmu |
214 event_legacy_symbol |
Jiri Olsa89812fc2012-03-15 20:09:15 +0100215 event_legacy_cache sep_dc |
216 event_legacy_mem |
217 event_legacy_tracepoint sep_dc |
218 event_legacy_numeric sep_dc |
Wang Nan84c86ca2015-10-14 12:41:14 +0000219 event_legacy_raw sep_dc |
220 event_bpf_file
Jiri Olsa89812fc2012-03-15 20:09:15 +0100221
Jiri Olsa5f537a22012-03-15 20:09:18 +0100222event_pmu:
Arnaldo Carvalho de Melobb109ac2016-02-25 10:56:21 -0300223PE_NAME opt_event_config
Jiri Olsa5f537a22012-03-15 20:09:18 +0100224{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300225 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600226 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200227
David Ahernc5cd8ac2013-07-02 13:27:25 -0600228 ALLOC_LIST(list);
Arnaldo Carvalho de Melobb109ac2016-02-25 10:56:21 -0300229 ABORT_ON(parse_events_add_pmu(data, list, $1, $2));
230 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200231 $$ = list;
Jiri Olsa5f537a22012-03-15 20:09:18 +0100232}
Adrian Hunterad962272014-08-15 22:08:40 +0300233|
Kan Liangba32a452014-10-07 11:08:51 -0400234PE_KERNEL_PMU_EVENT sep_dc
235{
236 struct parse_events_evlist *data = _data;
237 struct list_head *head;
238 struct parse_events_term *term;
239 struct list_head *list;
Andi Kleen231bb2a2017-01-27 18:03:39 -0800240 struct perf_pmu *pmu = NULL;
241 int ok = 0;
Kan Liangba32a452014-10-07 11:08:51 -0400242
Andi Kleen231bb2a2017-01-27 18:03:39 -0800243 /* Add it for all PMUs that support the alias */
Kan Liangba32a452014-10-07 11:08:51 -0400244 ALLOC_LIST(list);
Andi Kleen231bb2a2017-01-27 18:03:39 -0800245 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
246 struct perf_pmu_alias *alias;
247
248 list_for_each_entry(alias, &pmu->aliases, list) {
249 if (!strcasecmp(alias->name, $1)) {
250 ALLOC_LIST(head);
251 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
252 $1, 1, &@1, NULL));
253 list_add_tail(&term->list, head);
254
255 if (!parse_events_add_pmu(data, list,
256 pmu->name, head)) {
257 ok++;
258 }
259
260 parse_events_terms__delete(head);
261 }
262 }
263 }
264 if (!ok)
265 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400266 $$ = list;
267}
268|
269PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
270{
271 struct parse_events_evlist *data = _data;
272 struct list_head *head;
273 struct parse_events_term *term;
274 struct list_head *list;
275 char pmu_name[128];
276 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
277
278 ALLOC_LIST(head);
279 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200280 &pmu_name, 1, &@1, NULL));
Kan Liangba32a452014-10-07 11:08:51 -0400281 list_add_tail(&term->list, head);
282
283 ALLOC_LIST(list);
Jiri Olsa5ad4da42015-09-02 09:56:31 +0200284 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
Arnaldo Carvalho de Melo2146afc2016-02-12 17:09:17 -0300285 parse_events_terms__delete(head);
Kan Liangba32a452014-10-07 11:08:51 -0400286 $$ = list;
287}
Jiri Olsa5f537a22012-03-15 20:09:18 +0100288
Jiri Olsacf3506d2012-07-04 00:00:43 +0200289value_sym:
290PE_VALUE_SYM_HW
291|
292PE_VALUE_SYM_SW
293
Jiri Olsa89812fc2012-03-15 20:09:15 +0100294event_legacy_symbol:
Jiri Olsacf3506d2012-07-04 00:00:43 +0200295value_sym '/' event_config '/'
Jiri Olsa89812fc2012-03-15 20:09:15 +0100296{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300297 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600298 struct list_head *list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100299 int type = $1 >> 16;
300 int config = $1 & 255;
301
David Ahernc5cd8ac2013-07-02 13:27:25 -0600302 ALLOC_LIST(list);
Jiri Olsa87d650b2015-04-22 21:10:24 +0200303 ABORT_ON(parse_events_add_numeric(data, list, type, config, $3));
Arnaldo Carvalho de Melo2146afc2016-02-12 17:09:17 -0300304 parse_events_terms__delete($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200305 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100306}
307|
Jiri Olsacf3506d2012-07-04 00:00:43 +0200308value_sym sep_slash_dc
Jiri Olsa8f707d82012-03-15 20:09:16 +0100309{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300310 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600311 struct list_head *list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100312 int type = $1 >> 16;
313 int config = $1 & 255;
314
David Ahernc5cd8ac2013-07-02 13:27:25 -0600315 ALLOC_LIST(list);
Jiri Olsa87d650b2015-04-22 21:10:24 +0200316 ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200317 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100318}
319
320event_legacy_cache:
Wang Nan43d0b972016-02-19 11:44:01 +0000321PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100322{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300323 struct parse_events_evlist *data = _data;
Wang Nan43d0b972016-02-19 11:44:01 +0000324 struct parse_events_error *error = data->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600325 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200326
David Ahernc5cd8ac2013-07-02 13:27:25 -0600327 ALLOC_LIST(list);
Wang Nan43d0b972016-02-19 11:44:01 +0000328 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6));
329 parse_events_terms__delete($6);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200330 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100331}
332|
Wang Nan43d0b972016-02-19 11:44:01 +0000333PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100334{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300335 struct parse_events_evlist *data = _data;
Wang Nan43d0b972016-02-19 11:44:01 +0000336 struct parse_events_error *error = data->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600337 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200338
David Ahernc5cd8ac2013-07-02 13:27:25 -0600339 ALLOC_LIST(list);
Wang Nan43d0b972016-02-19 11:44:01 +0000340 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4));
341 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200342 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100343}
344|
Wang Nan43d0b972016-02-19 11:44:01 +0000345PE_NAME_CACHE_TYPE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100346{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300347 struct parse_events_evlist *data = _data;
Wang Nan43d0b972016-02-19 11:44:01 +0000348 struct parse_events_error *error = data->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600349 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200350
David Ahernc5cd8ac2013-07-02 13:27:25 -0600351 ALLOC_LIST(list);
Wang Nan43d0b972016-02-19 11:44:01 +0000352 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2));
353 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200354 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100355}
356
357event_legacy_mem:
Jacob Shin3741eb92014-05-29 17:26:51 +0200358PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
359{
360 struct parse_events_evlist *data = _data;
361 struct list_head *list;
362
363 ALLOC_LIST(list);
364 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
365 (void *) $2, $6, $4));
366 $$ = list;
367}
368|
369PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
370{
371 struct parse_events_evlist *data = _data;
372 struct list_head *list;
373
374 ALLOC_LIST(list);
375 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
376 (void *) $2, NULL, $4));
377 $$ = list;
378}
379|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100380PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
381{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300382 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600383 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200384
David Ahernc5cd8ac2013-07-02 13:27:25 -0600385 ALLOC_LIST(list);
386 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200387 (void *) $2, $4, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200388 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100389}
390|
391PE_PREFIX_MEM PE_VALUE sep_dc
392{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300393 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600394 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200395
David Ahernc5cd8ac2013-07-02 13:27:25 -0600396 ALLOC_LIST(list);
397 ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200398 (void *) $2, NULL, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200399 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100400}
401
402event_legacy_tracepoint:
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300403tracepoint_name opt_event_config
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200404{
405 struct parse_events_evlist *data = _data;
Jiri Olsa19658172015-09-07 10:38:07 +0200406 struct parse_events_error *error = data->error;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200407 struct list_head *list;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200408
409 ALLOC_LIST(list);
He Kuange637d172015-09-28 03:52:16 +0000410 if (error)
411 error->idx = @1.first_column;
412
He Kuang865582c2015-09-28 03:52:15 +0000413 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300414 error, $2))
He Kuange637d172015-09-28 03:52:16 +0000415 return -1;
416
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200417 $$ = list;
418}
He Kuang865582c2015-09-28 03:52:15 +0000419
420tracepoint_name:
421PE_NAME '-' PE_NAME ':' PE_NAME
422{
423 char sys_name[128];
424 struct tracepoint_name tracepoint;
425
426 snprintf(&sys_name, 128, "%s-%s", $1, $3);
427 tracepoint.sys = &sys_name;
428 tracepoint.event = $5;
429
430 $$ = tracepoint;
431}
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200432|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100433PE_NAME ':' PE_NAME
434{
He Kuang865582c2015-09-28 03:52:15 +0000435 struct tracepoint_name tracepoint = {$1, $3};
Jiri Olsab847cbd2012-05-21 09:12:51 +0200436
He Kuang865582c2015-09-28 03:52:15 +0000437 $$ = tracepoint;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100438}
439
440event_legacy_numeric:
Wang Nan10bf3582016-02-19 11:44:00 +0000441PE_VALUE ':' PE_VALUE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100442{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300443 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600444 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200445
David Ahernc5cd8ac2013-07-02 13:27:25 -0600446 ALLOC_LIST(list);
Wang Nan10bf3582016-02-19 11:44:00 +0000447 ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
448 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200449 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100450}
451
452event_legacy_raw:
Wang Nan10bf3582016-02-19 11:44:00 +0000453PE_RAW opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100454{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300455 struct parse_events_evlist *data = _data;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600456 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200457
David Ahernc5cd8ac2013-07-02 13:27:25 -0600458 ALLOC_LIST(list);
Wang Nan10bf3582016-02-19 11:44:00 +0000459 ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
460 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200461 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100462}
463
Wang Nan84c86ca2015-10-14 12:41:14 +0000464event_bpf_file:
Wang Nana34f3be2016-02-22 09:10:31 +0000465PE_BPF_OBJECT opt_event_config
Wang Nan84c86ca2015-10-14 12:41:14 +0000466{
467 struct parse_events_evlist *data = _data;
468 struct parse_events_error *error = data->error;
469 struct list_head *list;
470
471 ALLOC_LIST(list);
Wang Nana34f3be2016-02-22 09:10:31 +0000472 ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2));
473 parse_events_terms__delete($2);
Wang Nand509db02015-10-14 12:41:20 +0000474 $$ = list;
475}
476|
Wang Nana34f3be2016-02-22 09:10:31 +0000477PE_BPF_SOURCE opt_event_config
Wang Nand509db02015-10-14 12:41:20 +0000478{
479 struct parse_events_evlist *data = _data;
480 struct list_head *list;
481
482 ALLOC_LIST(list);
Wang Nana34f3be2016-02-22 09:10:31 +0000483 ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2));
484 parse_events_terms__delete($2);
Wang Nan84c86ca2015-10-14 12:41:14 +0000485 $$ = list;
486}
487
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300488opt_event_config:
489'/' event_config '/'
490{
491 $$ = $2;
492}
493|
494'/' '/'
495{
496 $$ = NULL;
497}
498|
499{
500 $$ = NULL;
501}
502
Jiri Olsa89efb022012-08-08 12:14:14 +0200503start_terms: event_config
Jiri Olsa90e2b222012-06-15 14:31:40 +0800504{
Arnaldo Carvalho de Melo23b63392013-01-18 16:56:57 -0300505 struct parse_events_terms *data = _data;
Jiri Olsa90e2b222012-06-15 14:31:40 +0800506 data->terms = $1;
507}
508
Jiri Olsa8f707d82012-03-15 20:09:16 +0100509event_config:
510event_config ',' event_term
511{
512 struct list_head *head = $1;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300513 struct parse_events_term *term = $3;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100514
515 ABORT_ON(!head);
516 list_add_tail(&term->list, head);
517 $$ = $1;
518}
519|
520event_term
521{
522 struct list_head *head = malloc(sizeof(*head));
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300523 struct parse_events_term *term = $1;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100524
525 ABORT_ON(!head);
526 INIT_LIST_HEAD(head);
527 list_add_tail(&term->list, head);
528 $$ = head;
529}
530
531event_term:
532PE_NAME '=' PE_NAME
533{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300534 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100535
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300536 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200537 $1, $3, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100538 $$ = term;
539}
540|
541PE_NAME '=' PE_VALUE
542{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300543 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100544
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300545 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200546 $1, $3, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100547 $$ = term;
548}
549|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200550PE_NAME '=' PE_VALUE_SYM_HW
551{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300552 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200553 int config = $3 & 255;
554
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300555 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200556 $$ = term;
557}
558|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100559PE_NAME
560{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300561 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100562
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300563 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200564 $1, 1, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100565 $$ = term;
566}
567|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200568PE_VALUE_SYM_HW
569{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300570 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200571 int config = $1 & 255;
572
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300573 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200574 $$ = term;
575}
576|
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200577PE_TERM '=' PE_NAME
578{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300579 struct parse_events_term *term;
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200580
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200581 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200582 $$ = term;
583}
584|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100585PE_TERM '=' PE_VALUE
586{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300587 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100588
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200589 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100590 $$ = term;
591}
592|
593PE_TERM
594{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300595 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100596
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200597 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100598 $$ = term;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100599}
Wang Nane571e022016-02-22 09:10:35 +0000600|
601PE_NAME array '=' PE_NAME
602{
603 struct parse_events_term *term;
604 int i;
605
606 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
607 $1, $4, &@1, &@4));
608
609 term->array = $2;
610 $$ = term;
611}
612|
613PE_NAME array '=' PE_VALUE
614{
615 struct parse_events_term *term;
616
617 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
618 $1, $4, &@1, &@4));
619 term->array = $2;
620 $$ = term;
621}
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600622|
623PE_DRV_CFG_TERM
624{
625 struct parse_events_term *term;
626
627 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
628 $1, $1, &@1, NULL));
629 $$ = term;
630}
Wang Nane571e022016-02-22 09:10:35 +0000631
632array:
633'[' array_terms ']'
634{
635 $$ = $2;
636}
637|
638PE_ARRAY_ALL
639{
640 $$.nr_ranges = 0;
641 $$.ranges = NULL;
642}
643
644array_terms:
645array_terms ',' array_term
646{
647 struct parse_events_array new_array;
648
649 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
650 new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
651 new_array.nr_ranges);
652 ABORT_ON(!new_array.ranges);
653 memcpy(&new_array.ranges[0], $1.ranges,
654 $1.nr_ranges * sizeof(new_array.ranges[0]));
655 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
656 $3.nr_ranges * sizeof(new_array.ranges[0]));
657 free($1.ranges);
658 free($3.ranges);
659 $$ = new_array;
660}
661|
662array_term
663
664array_term:
665PE_VALUE
666{
667 struct parse_events_array array;
668
669 array.nr_ranges = 1;
670 array.ranges = malloc(sizeof(array.ranges[0]));
671 ABORT_ON(!array.ranges);
672 array.ranges[0].start = $1;
673 array.ranges[0].length = 1;
674 $$ = array;
675}
676|
677PE_VALUE PE_ARRAY_RANGE PE_VALUE
678{
679 struct parse_events_array array;
680
681 ABORT_ON($3 < $1);
682 array.nr_ranges = 1;
683 array.ranges = malloc(sizeof(array.ranges[0]));
684 ABORT_ON(!array.ranges);
685 array.ranges[0].start = $1;
686 array.ranges[0].length = $3 - $1 + 1;
687 $$ = array;
688}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100689
690sep_dc: ':' |
691
Jiri Olsa8f707d82012-03-15 20:09:16 +0100692sep_slash_dc: '/' | ':' |
693
Jiri Olsa89812fc2012-03-15 20:09:15 +0100694%%
695
Jiri Olsa6297d422015-04-22 21:10:17 +0200696void parse_events_error(YYLTYPE *loc, void *data,
697 void *scanner __maybe_unused,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300698 char const *msg __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100699{
Jiri Olsa6297d422015-04-22 21:10:17 +0200700 parse_events_evlist_error(data, loc->last_column, "parser error");
Jiri Olsa89812fc2012-03-15 20:09:15 +0100701}