blob: 48126ae4cd13f098ed707a698cdb881485f7b5e0 [file] [log] [blame]
Zheng Yanac20de6f2012-06-15 14:31:39 +08001%pure-parser
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -03002%parse-param {void *_parse_state}
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
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -050011#include <fnmatch.h>
Arnaldo Carvalho de Melobd704622019-09-24 15:45:21 -030012#include <stdio.h>
Jiri Olsa89812fc2012-03-15 20:09:15 +010013#include <linux/compiler.h>
Borislav Petkovd944c4e2014-04-25 21:31:02 +020014#include <linux/types.h>
Andi Kleen231bb2a2017-01-27 18:03:39 -080015#include "pmu.h"
Andi Kleenf0fbb112019-03-26 15:18:21 -070016#include "evsel.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010017#include "parse-events.h"
Zheng Yanac20de6f2012-06-15 14:31:39 +080018#include "parse-events-bison.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010019
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030020void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
Arnaldo Carvalho de Melo34a05482017-02-15 10:09:11 -030021
Jiri Olsa89812fc2012-03-15 20:09:15 +010022#define ABORT_ON(val) \
23do { \
24 if (val) \
25 YYABORT; \
26} while (0)
27
David Ahernc5cd8ac2013-07-02 13:27:25 -060028#define ALLOC_LIST(list) \
29do { \
30 list = malloc(sizeof(*list)); \
31 ABORT_ON(!list); \
32 INIT_LIST_HEAD(list); \
33} while (0)
34
Colin Ian King07ef7572016-03-07 16:44:37 -030035static void inc_group_count(struct list_head *list,
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030036 struct parse_events_state *parse_state)
Namhyung Kim97f63e42013-01-22 18:09:29 +090037{
38 /* Count groups only have more than 1 members */
39 if (!list_is_last(list->next, list))
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030040 parse_state->nr_groups++;
Namhyung Kim97f63e42013-01-22 18:09:29 +090041}
42
Jiri Olsa89812fc2012-03-15 20:09:15 +010043%}
44
Jiri Olsa90e2b222012-06-15 14:31:40 +080045%token PE_START_EVENTS PE_START_TERMS
Jiri Olsacf3506d2012-07-04 00:00:43 +020046%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
Andi Kleenf0fbb112019-03-26 15:18:21 -070047%token PE_VALUE_SYM_TOOL
Robert Richterac2ba9f2012-08-16 21:10:21 +020048%token PE_EVENT_NAME
Jiri Olsa89812fc2012-03-15 20:09:15 +010049%token PE_NAME
Wang Nand509db02015-10-14 12:41:20 +000050%token PE_BPF_OBJECT PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010051%token PE_MODIFIER_EVENT PE_MODIFIER_BP
52%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
Jiri Olsa89efb022012-08-08 12:14:14 +020053%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
Jiri Olsa89812fc2012-03-15 20:09:15 +010054%token PE_ERROR
Kan Liangba32a452014-10-07 11:08:51 -040055%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Wang Nane571e022016-02-22 09:10:35 +000056%token PE_ARRAY_ALL PE_ARRAY_RANGE
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060057%token PE_DRV_CFG_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010058%type <num> PE_VALUE
Jiri Olsacf3506d2012-07-04 00:00:43 +020059%type <num> PE_VALUE_SYM_HW
60%type <num> PE_VALUE_SYM_SW
Andi Kleenf0fbb112019-03-26 15:18:21 -070061%type <num> PE_VALUE_SYM_TOOL
Jiri Olsa89812fc2012-03-15 20:09:15 +010062%type <num> PE_RAW
Jiri Olsa8f707d82012-03-15 20:09:16 +010063%type <num> PE_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010064%type <str> PE_NAME
Wang Nan84c86ca2015-10-14 12:41:14 +000065%type <str> PE_BPF_OBJECT
Wang Nand509db02015-10-14 12:41:20 +000066%type <str> PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010067%type <str> PE_NAME_CACHE_TYPE
68%type <str> PE_NAME_CACHE_OP_RESULT
69%type <str> PE_MODIFIER_EVENT
70%type <str> PE_MODIFIER_BP
Robert Richterac2ba9f2012-08-16 21:10:21 +020071%type <str> PE_EVENT_NAME
Kan Liangba32a452014-10-07 11:08:51 -040072%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060073%type <str> PE_DRV_CFG_TERM
Jiri Olsacf3506d2012-07-04 00:00:43 +020074%type <num> value_sym
Jiri Olsa8f707d82012-03-15 20:09:16 +010075%type <head> event_config
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -030076%type <head> opt_event_config
Jiri Olsaceac7b72018-06-05 14:14:16 +020077%type <head> opt_pmu_config
Jiri Olsa8f707d82012-03-15 20:09:16 +010078%type <term> event_term
Jiri Olsab847cbd2012-05-21 09:12:51 +020079%type <head> event_pmu
80%type <head> event_legacy_symbol
81%type <head> event_legacy_cache
82%type <head> event_legacy_mem
83%type <head> event_legacy_tracepoint
He Kuang865582c2015-09-28 03:52:15 +000084%type <tracepoint_name> tracepoint_name
Jiri Olsab847cbd2012-05-21 09:12:51 +020085%type <head> event_legacy_numeric
86%type <head> event_legacy_raw
Wang Nan84c86ca2015-10-14 12:41:14 +000087%type <head> event_bpf_file
Jiri Olsab847cbd2012-05-21 09:12:51 +020088%type <head> event_def
Robert Richterac2ba9f2012-08-16 21:10:21 +020089%type <head> event_mod
90%type <head> event_name
Jiri Olsa89efb022012-08-08 12:14:14 +020091%type <head> event
92%type <head> events
93%type <head> group_def
94%type <head> group
95%type <head> groups
Wang Nane571e022016-02-22 09:10:35 +000096%type <array> array
97%type <array> array_term
98%type <array> array_terms
Jiri Olsa89812fc2012-03-15 20:09:15 +010099
100%union
101{
102 char *str;
Robert Richterb527bab2012-08-07 19:43:13 +0200103 u64 num;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100104 struct list_head *head;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300105 struct parse_events_term *term;
He Kuang865582c2015-09-28 03:52:15 +0000106 struct tracepoint_name {
107 char *sys;
108 char *event;
109 } tracepoint_name;
Wang Nane571e022016-02-22 09:10:35 +0000110 struct parse_events_array array;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100111}
112%%
113
Jiri Olsa90e2b222012-06-15 14:31:40 +0800114start:
Jiri Olsa89efb022012-08-08 12:14:14 +0200115PE_START_EVENTS start_events
Jiri Olsa90e2b222012-06-15 14:31:40 +0800116|
Jiri Olsa89efb022012-08-08 12:14:14 +0200117PE_START_TERMS start_terms
118
119start_events: groups
120{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300121 struct parse_events_state *parse_state = _parse_state;
Jiri Olsa89efb022012-08-08 12:14:14 +0200122
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300123 parse_events_update_lists($1, &parse_state->list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200124}
125
126groups:
127groups ',' group
128{
129 struct list_head *list = $1;
130 struct list_head *group = $3;
131
132 parse_events_update_lists(group, list);
133 $$ = list;
134}
135|
136groups ',' event
137{
138 struct list_head *list = $1;
139 struct list_head *event = $3;
140
141 parse_events_update_lists(event, list);
142 $$ = list;
143}
144|
145group
146|
147event
148
149group:
150group_def ':' PE_MODIFIER_EVENT
151{
152 struct list_head *list = $1;
153
154 ABORT_ON(parse_events__modifier_group(list, $3));
155 $$ = list;
156}
157|
158group_def
159
160group_def:
161PE_NAME '{' events '}'
162{
163 struct list_head *list = $3;
164
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300165 inc_group_count(list, _parse_state);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700166 parse_events__set_leader($1, list, _parse_state);
Jiri Olsa89efb022012-08-08 12:14:14 +0200167 $$ = list;
168}
169|
170'{' events '}'
171{
172 struct list_head *list = $2;
173
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300174 inc_group_count(list, _parse_state);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700175 parse_events__set_leader(NULL, list, _parse_state);
Jiri Olsa89efb022012-08-08 12:14:14 +0200176 $$ = list;
177}
Jiri Olsa90e2b222012-06-15 14:31:40 +0800178
Jiri Olsa89812fc2012-03-15 20:09:15 +0100179events:
Jiri Olsa89efb022012-08-08 12:14:14 +0200180events ',' event
181{
182 struct list_head *event = $3;
183 struct list_head *list = $1;
184
185 parse_events_update_lists(event, list);
186 $$ = list;
187}
188|
189event
Jiri Olsa89812fc2012-03-15 20:09:15 +0100190
Robert Richterac2ba9f2012-08-16 21:10:21 +0200191event: event_mod
192
193event_mod:
194event_name PE_MODIFIER_EVENT
Jiri Olsa89812fc2012-03-15 20:09:15 +0100195{
Jiri Olsa89efb022012-08-08 12:14:14 +0200196 struct list_head *list = $1;
Jiri Olsa46010ab2012-06-15 14:31:38 +0800197
Jiri Olsa5d7be902012-03-20 19:15:40 +0100198 /*
199 * Apply modifier on all events added by single event definition
200 * (there could be more events added for multiple tracepoint
201 * definitions via '*?'.
202 */
Jiri Olsaf5b11352012-08-08 12:21:54 +0200203 ABORT_ON(parse_events__modifier_event(list, $2, false));
Jiri Olsa89efb022012-08-08 12:14:14 +0200204 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100205}
206|
Robert Richterac2ba9f2012-08-16 21:10:21 +0200207event_name
208
209event_name:
210PE_EVENT_NAME event_def
211{
212 ABORT_ON(parse_events_name($2, $1));
213 free($1);
214 $$ = $2;
215}
216|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100217event_def
218
Jiri Olsa5f537a22012-03-15 20:09:18 +0100219event_def: event_pmu |
220 event_legacy_symbol |
Jiri Olsa89812fc2012-03-15 20:09:15 +0100221 event_legacy_cache sep_dc |
222 event_legacy_mem |
223 event_legacy_tracepoint sep_dc |
224 event_legacy_numeric sep_dc |
Wang Nan84c86ca2015-10-14 12:41:14 +0000225 event_legacy_raw sep_dc |
226 event_bpf_file
Jiri Olsa89812fc2012-03-15 20:09:15 +0100227
Jiri Olsa5f537a22012-03-15 20:09:18 +0100228event_pmu:
Jiri Olsaceac7b72018-06-05 14:14:16 +0200229PE_NAME opt_pmu_config
Jiri Olsa5f537a22012-03-15 20:09:18 +0100230{
Jiri Olsaf7fa8272018-06-07 00:15:05 +0200231 struct parse_events_state *parse_state = _parse_state;
232 struct parse_events_error *error = parse_state->error;
Andi Kleen82557182017-03-20 13:17:03 -0700233 struct list_head *list, *orig_terms, *terms;
234
Arnaldo Carvalho de Melo4a35a902018-05-07 15:27:01 -0300235 if (parse_events_copy_term_list($2, &orig_terms))
Andi Kleen82557182017-03-20 13:17:03 -0700236 YYABORT;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200237
Jiri Olsaf7fa8272018-06-07 00:15:05 +0200238 if (error)
239 error->idx = @1.first_column;
240
David Ahernc5cd8ac2013-07-02 13:27:25 -0600241 ALLOC_LIST(list);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700242 if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
Andi Kleen82557182017-03-20 13:17:03 -0700243 struct perf_pmu *pmu = NULL;
244 int ok = 0;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500245 char *pattern;
246
247 if (asprintf(&pattern, "%s*", $1) < 0)
248 YYABORT;
Andi Kleen82557182017-03-20 13:17:03 -0700249
250 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
251 char *name = pmu->name;
252
Andi Kleena820e332017-03-20 13:17:04 -0700253 if (!strncmp(name, "uncore_", 7) &&
254 strncmp($1, "uncore_", 7))
255 name += 7;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500256 if (!fnmatch(pattern, name, 0)) {
257 if (parse_events_copy_term_list(orig_terms, &terms)) {
258 free(pattern);
Andi Kleen82557182017-03-20 13:17:03 -0700259 YYABORT;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500260 }
Kan Liang3cdc5c22018-05-07 14:13:43 -0700261 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
Andi Kleen82557182017-03-20 13:17:03 -0700262 ok++;
263 parse_events_terms__delete(terms);
264 }
265 }
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500266
267 free(pattern);
268
Andi Kleen82557182017-03-20 13:17:03 -0700269 if (!ok)
270 YYABORT;
271 }
Arnaldo Carvalho de Melo4a35a902018-05-07 15:27:01 -0300272 parse_events_terms__delete($2);
Andi Kleen82557182017-03-20 13:17:03 -0700273 parse_events_terms__delete(orig_terms);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200274 $$ = list;
Jiri Olsa5f537a22012-03-15 20:09:18 +0100275}
Adrian Hunterad962272014-08-15 22:08:40 +0300276|
Kan Liangba32a452014-10-07 11:08:51 -0400277PE_KERNEL_PMU_EVENT sep_dc
278{
Kan Liangba32a452014-10-07 11:08:51 -0400279 struct list_head *list;
280
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300281 if (parse_events_multi_pmu_add(_parse_state, $1, &list) < 0)
Andi Kleen231bb2a2017-01-27 18:03:39 -0800282 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400283 $$ = list;
284}
285|
286PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
287{
Kan Liangba32a452014-10-07 11:08:51 -0400288 struct list_head *list;
289 char pmu_name[128];
Andi Kleen82557182017-03-20 13:17:03 -0700290
Kan Liangba32a452014-10-07 11:08:51 -0400291 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300292 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0)
Andi Kleen82557182017-03-20 13:17:03 -0700293 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400294 $$ = list;
295}
Jiri Olsa5f537a22012-03-15 20:09:18 +0100296
Jiri Olsacf3506d2012-07-04 00:00:43 +0200297value_sym:
298PE_VALUE_SYM_HW
299|
300PE_VALUE_SYM_SW
301
Jiri Olsa89812fc2012-03-15 20:09:15 +0100302event_legacy_symbol:
Jiri Olsacf3506d2012-07-04 00:00:43 +0200303value_sym '/' event_config '/'
Jiri Olsa89812fc2012-03-15 20:09:15 +0100304{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600305 struct list_head *list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100306 int type = $1 >> 16;
307 int config = $1 & 255;
308
David Ahernc5cd8ac2013-07-02 13:27:25 -0600309 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300310 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3));
Arnaldo Carvalho de Melo2146afc2016-02-12 17:09:17 -0300311 parse_events_terms__delete($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200312 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100313}
314|
Jiri Olsa714a92d2019-02-13 13:32:40 +0100315value_sym sep_slash_slash_dc
Jiri Olsa8f707d82012-03-15 20:09:16 +0100316{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600317 struct list_head *list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100318 int type = $1 >> 16;
319 int config = $1 & 255;
320
David Ahernc5cd8ac2013-07-02 13:27:25 -0600321 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300322 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200323 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100324}
Andi Kleenf0fbb112019-03-26 15:18:21 -0700325|
326PE_VALUE_SYM_TOOL sep_slash_slash_dc
327{
328 struct list_head *list;
329
330 ALLOC_LIST(list);
331 ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
332 $$ = list;
333}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100334
335event_legacy_cache:
Wang Nan43d0b972016-02-19 11:44:01 +0000336PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100337{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300338 struct parse_events_state *parse_state = _parse_state;
339 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600340 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200341
David Ahernc5cd8ac2013-07-02 13:27:25 -0600342 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300343 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6));
Wang Nan43d0b972016-02-19 11:44:01 +0000344 parse_events_terms__delete($6);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200345 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100346}
347|
Wang Nan43d0b972016-02-19 11:44:01 +0000348PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100349{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300350 struct parse_events_state *parse_state = _parse_state;
351 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600352 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200353
David Ahernc5cd8ac2013-07-02 13:27:25 -0600354 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300355 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4));
Wang Nan43d0b972016-02-19 11:44:01 +0000356 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200357 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100358}
359|
Wang Nan43d0b972016-02-19 11:44:01 +0000360PE_NAME_CACHE_TYPE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100361{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300362 struct parse_events_state *parse_state = _parse_state;
363 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600364 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200365
David Ahernc5cd8ac2013-07-02 13:27:25 -0600366 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300367 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2));
Wang Nan43d0b972016-02-19 11:44:01 +0000368 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200369 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100370}
371
372event_legacy_mem:
Jacob Shin3741eb92014-05-29 17:26:51 +0200373PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
374{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300375 struct parse_events_state *parse_state = _parse_state;
Jacob Shin3741eb92014-05-29 17:26:51 +0200376 struct list_head *list;
377
378 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300379 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200380 (void *) $2, $6, $4));
381 $$ = list;
382}
383|
384PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
385{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300386 struct parse_events_state *parse_state = _parse_state;
Jacob Shin3741eb92014-05-29 17:26:51 +0200387 struct list_head *list;
388
389 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300390 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200391 (void *) $2, NULL, $4));
392 $$ = list;
393}
394|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100395PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
396{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300397 struct parse_events_state *parse_state = _parse_state;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600398 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200399
David Ahernc5cd8ac2013-07-02 13:27:25 -0600400 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300401 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200402 (void *) $2, $4, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200403 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100404}
405|
406PE_PREFIX_MEM PE_VALUE sep_dc
407{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300408 struct parse_events_state *parse_state = _parse_state;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600409 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200410
David Ahernc5cd8ac2013-07-02 13:27:25 -0600411 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300412 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200413 (void *) $2, NULL, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200414 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100415}
416
417event_legacy_tracepoint:
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300418tracepoint_name opt_event_config
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200419{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300420 struct parse_events_state *parse_state = _parse_state;
421 struct parse_events_error *error = parse_state->error;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200422 struct list_head *list;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200423
424 ALLOC_LIST(list);
He Kuange637d172015-09-28 03:52:16 +0000425 if (error)
426 error->idx = @1.first_column;
427
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300428 if (parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300429 error, $2))
He Kuange637d172015-09-28 03:52:16 +0000430 return -1;
431
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200432 $$ = list;
433}
He Kuang865582c2015-09-28 03:52:15 +0000434
435tracepoint_name:
436PE_NAME '-' PE_NAME ':' PE_NAME
437{
438 char sys_name[128];
439 struct tracepoint_name tracepoint;
440
441 snprintf(&sys_name, 128, "%s-%s", $1, $3);
442 tracepoint.sys = &sys_name;
443 tracepoint.event = $5;
444
445 $$ = tracepoint;
446}
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200447|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100448PE_NAME ':' PE_NAME
449{
He Kuang865582c2015-09-28 03:52:15 +0000450 struct tracepoint_name tracepoint = {$1, $3};
Jiri Olsab847cbd2012-05-21 09:12:51 +0200451
He Kuang865582c2015-09-28 03:52:15 +0000452 $$ = tracepoint;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100453}
454
455event_legacy_numeric:
Wang Nan10bf3582016-02-19 11:44:00 +0000456PE_VALUE ':' PE_VALUE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100457{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600458 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200459
David Ahernc5cd8ac2013-07-02 13:27:25 -0600460 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300461 ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4));
Wang Nan10bf3582016-02-19 11:44:00 +0000462 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200463 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100464}
465
466event_legacy_raw:
Wang Nan10bf3582016-02-19 11:44:00 +0000467PE_RAW opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100468{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600469 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200470
David Ahernc5cd8ac2013-07-02 13:27:25 -0600471 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300472 ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2));
Wang Nan10bf3582016-02-19 11:44:00 +0000473 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200474 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100475}
476
Wang Nan84c86ca2015-10-14 12:41:14 +0000477event_bpf_file:
Wang Nana34f3be2016-02-22 09:10:31 +0000478PE_BPF_OBJECT opt_event_config
Wang Nan84c86ca2015-10-14 12:41:14 +0000479{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300480 struct parse_events_state *parse_state = _parse_state;
Wang Nan84c86ca2015-10-14 12:41:14 +0000481 struct list_head *list;
482
483 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300484 ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2));
Wang Nana34f3be2016-02-22 09:10:31 +0000485 parse_events_terms__delete($2);
Wang Nand509db02015-10-14 12:41:20 +0000486 $$ = list;
487}
488|
Wang Nana34f3be2016-02-22 09:10:31 +0000489PE_BPF_SOURCE opt_event_config
Wang Nand509db02015-10-14 12:41:20 +0000490{
Wang Nand509db02015-10-14 12:41:20 +0000491 struct list_head *list;
492
493 ALLOC_LIST(list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300494 ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2));
Wang Nana34f3be2016-02-22 09:10:31 +0000495 parse_events_terms__delete($2);
Wang Nan84c86ca2015-10-14 12:41:14 +0000496 $$ = list;
497}
498
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300499opt_event_config:
500'/' event_config '/'
501{
502 $$ = $2;
503}
504|
505'/' '/'
506{
507 $$ = NULL;
508}
509|
510{
511 $$ = NULL;
512}
513
Jiri Olsaceac7b72018-06-05 14:14:16 +0200514opt_pmu_config:
515'/' event_config '/'
516{
517 $$ = $2;
518}
519|
520'/' '/'
521{
522 $$ = NULL;
523}
524
Jiri Olsa89efb022012-08-08 12:14:14 +0200525start_terms: event_config
Jiri Olsa90e2b222012-06-15 14:31:40 +0800526{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300527 struct parse_events_state *parse_state = _parse_state;
528 parse_state->terms = $1;
Jiri Olsa90e2b222012-06-15 14:31:40 +0800529}
530
Jiri Olsa8f707d82012-03-15 20:09:16 +0100531event_config:
532event_config ',' event_term
533{
534 struct list_head *head = $1;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300535 struct parse_events_term *term = $3;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100536
537 ABORT_ON(!head);
538 list_add_tail(&term->list, head);
539 $$ = $1;
540}
541|
542event_term
543{
544 struct list_head *head = malloc(sizeof(*head));
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300545 struct parse_events_term *term = $1;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100546
547 ABORT_ON(!head);
548 INIT_LIST_HEAD(head);
549 list_add_tail(&term->list, head);
550 $$ = head;
551}
552
553event_term:
554PE_NAME '=' PE_NAME
555{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300556 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100557
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300558 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200559 $1, $3, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100560 $$ = term;
561}
562|
563PE_NAME '=' PE_VALUE
564{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300565 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100566
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300567 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100568 $1, $3, false, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100569 $$ = term;
570}
571|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200572PE_NAME '=' PE_VALUE_SYM_HW
573{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300574 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200575 int config = $3 & 255;
576
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300577 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200578 $$ = term;
579}
580|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100581PE_NAME
582{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300583 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100584
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300585 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100586 $1, 1, true, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100587 $$ = term;
588}
589|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200590PE_VALUE_SYM_HW
591{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300592 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200593 int config = $1 & 255;
594
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300595 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200596 $$ = term;
597}
598|
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200599PE_TERM '=' PE_NAME
600{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300601 struct parse_events_term *term;
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200602
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200603 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200604 $$ = term;
605}
606|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100607PE_TERM '=' PE_VALUE
608{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300609 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100610
Jiri Olsa99e71382017-02-17 15:00:56 +0100611 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100612 $$ = term;
613}
614|
615PE_TERM
616{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300617 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100618
Jiri Olsa99e71382017-02-17 15:00:56 +0100619 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100620 $$ = term;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100621}
Wang Nane571e022016-02-22 09:10:35 +0000622|
623PE_NAME array '=' PE_NAME
624{
625 struct parse_events_term *term;
Wang Nane571e022016-02-22 09:10:35 +0000626
627 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
628 $1, $4, &@1, &@4));
629
630 term->array = $2;
631 $$ = term;
632}
633|
634PE_NAME array '=' PE_VALUE
635{
636 struct parse_events_term *term;
637
638 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100639 $1, $4, false, &@1, &@4));
Wang Nane571e022016-02-22 09:10:35 +0000640 term->array = $2;
641 $$ = term;
642}
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600643|
644PE_DRV_CFG_TERM
645{
646 struct parse_events_term *term;
647
648 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
649 $1, $1, &@1, NULL));
650 $$ = term;
651}
Wang Nane571e022016-02-22 09:10:35 +0000652
653array:
654'[' array_terms ']'
655{
656 $$ = $2;
657}
658|
659PE_ARRAY_ALL
660{
661 $$.nr_ranges = 0;
662 $$.ranges = NULL;
663}
664
665array_terms:
666array_terms ',' array_term
667{
668 struct parse_events_array new_array;
669
670 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
671 new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
672 new_array.nr_ranges);
673 ABORT_ON(!new_array.ranges);
674 memcpy(&new_array.ranges[0], $1.ranges,
675 $1.nr_ranges * sizeof(new_array.ranges[0]));
676 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
677 $3.nr_ranges * sizeof(new_array.ranges[0]));
678 free($1.ranges);
679 free($3.ranges);
680 $$ = new_array;
681}
682|
683array_term
684
685array_term:
686PE_VALUE
687{
688 struct parse_events_array array;
689
690 array.nr_ranges = 1;
691 array.ranges = malloc(sizeof(array.ranges[0]));
692 ABORT_ON(!array.ranges);
693 array.ranges[0].start = $1;
694 array.ranges[0].length = 1;
695 $$ = array;
696}
697|
698PE_VALUE PE_ARRAY_RANGE PE_VALUE
699{
700 struct parse_events_array array;
701
702 ABORT_ON($3 < $1);
703 array.nr_ranges = 1;
704 array.ranges = malloc(sizeof(array.ranges[0]));
705 ABORT_ON(!array.ranges);
706 array.ranges[0].start = $1;
707 array.ranges[0].length = $3 - $1 + 1;
708 $$ = array;
709}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100710
711sep_dc: ':' |
712
Jiri Olsa714a92d2019-02-13 13:32:40 +0100713sep_slash_slash_dc: '/' '/' | ':' |
Jiri Olsa8f707d82012-03-15 20:09:16 +0100714
Jiri Olsa89812fc2012-03-15 20:09:15 +0100715%%
716
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300717void parse_events_error(YYLTYPE *loc, void *parse_state,
Jiri Olsa6297d422015-04-22 21:10:17 +0200718 void *scanner __maybe_unused,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300719 char const *msg __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100720{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300721 parse_events_evlist_error(parse_state, loc->last_column, "parser error");
Jiri Olsa89812fc2012-03-15 20:09:15 +0100722}