blob: ffa1a1b63796e25fe2fa291938b236a21469dcb8 [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
Ian Rogersa26e4712019-10-22 17:53:32 -070028static struct list_head* alloc_list()
29{
30 struct list_head *list;
31
32 list = malloc(sizeof(*list));
33 if (!list)
34 return NULL;
35
36 INIT_LIST_HEAD(list);
37 return list;
38}
David Ahernc5cd8ac2013-07-02 13:27:25 -060039
Colin Ian King07ef7572016-03-07 16:44:37 -030040static void inc_group_count(struct list_head *list,
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030041 struct parse_events_state *parse_state)
Namhyung Kim97f63e42013-01-22 18:09:29 +090042{
43 /* Count groups only have more than 1 members */
44 if (!list_is_last(list->next, list))
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030045 parse_state->nr_groups++;
Namhyung Kim97f63e42013-01-22 18:09:29 +090046}
47
Jiri Olsa89812fc2012-03-15 20:09:15 +010048%}
49
Jiri Olsa90e2b222012-06-15 14:31:40 +080050%token PE_START_EVENTS PE_START_TERMS
Jiri Olsacf3506d2012-07-04 00:00:43 +020051%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
Andi Kleenf0fbb112019-03-26 15:18:21 -070052%token PE_VALUE_SYM_TOOL
Robert Richterac2ba9f2012-08-16 21:10:21 +020053%token PE_EVENT_NAME
Jiri Olsa89812fc2012-03-15 20:09:15 +010054%token PE_NAME
Wang Nand509db02015-10-14 12:41:20 +000055%token PE_BPF_OBJECT PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010056%token PE_MODIFIER_EVENT PE_MODIFIER_BP
57%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
Jiri Olsa89efb022012-08-08 12:14:14 +020058%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
Jiri Olsa89812fc2012-03-15 20:09:15 +010059%token PE_ERROR
Kan Liangba32a452014-10-07 11:08:51 -040060%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Wang Nane571e022016-02-22 09:10:35 +000061%token PE_ARRAY_ALL PE_ARRAY_RANGE
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060062%token PE_DRV_CFG_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010063%type <num> PE_VALUE
Jiri Olsacf3506d2012-07-04 00:00:43 +020064%type <num> PE_VALUE_SYM_HW
65%type <num> PE_VALUE_SYM_SW
Andi Kleenf0fbb112019-03-26 15:18:21 -070066%type <num> PE_VALUE_SYM_TOOL
Jiri Olsa89812fc2012-03-15 20:09:15 +010067%type <num> PE_RAW
Jiri Olsa8f707d82012-03-15 20:09:16 +010068%type <num> PE_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010069%type <str> PE_NAME
Wang Nan84c86ca2015-10-14 12:41:14 +000070%type <str> PE_BPF_OBJECT
Wang Nand509db02015-10-14 12:41:20 +000071%type <str> PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010072%type <str> PE_NAME_CACHE_TYPE
73%type <str> PE_NAME_CACHE_OP_RESULT
74%type <str> PE_MODIFIER_EVENT
75%type <str> PE_MODIFIER_BP
Robert Richterac2ba9f2012-08-16 21:10:21 +020076%type <str> PE_EVENT_NAME
Kan Liangba32a452014-10-07 11:08:51 -040077%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060078%type <str> PE_DRV_CFG_TERM
Jiri Olsacf3506d2012-07-04 00:00:43 +020079%type <num> value_sym
Jiri Olsa8f707d82012-03-15 20:09:16 +010080%type <head> event_config
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -030081%type <head> opt_event_config
Jiri Olsaceac7b72018-06-05 14:14:16 +020082%type <head> opt_pmu_config
Jiri Olsa8f707d82012-03-15 20:09:16 +010083%type <term> event_term
Jiri Olsab847cbd2012-05-21 09:12:51 +020084%type <head> event_pmu
85%type <head> event_legacy_symbol
86%type <head> event_legacy_cache
87%type <head> event_legacy_mem
88%type <head> event_legacy_tracepoint
He Kuang865582c2015-09-28 03:52:15 +000089%type <tracepoint_name> tracepoint_name
Jiri Olsab847cbd2012-05-21 09:12:51 +020090%type <head> event_legacy_numeric
91%type <head> event_legacy_raw
Wang Nan84c86ca2015-10-14 12:41:14 +000092%type <head> event_bpf_file
Jiri Olsab847cbd2012-05-21 09:12:51 +020093%type <head> event_def
Robert Richterac2ba9f2012-08-16 21:10:21 +020094%type <head> event_mod
95%type <head> event_name
Jiri Olsa89efb022012-08-08 12:14:14 +020096%type <head> event
97%type <head> events
98%type <head> group_def
99%type <head> group
100%type <head> groups
Wang Nane571e022016-02-22 09:10:35 +0000101%type <array> array
102%type <array> array_term
103%type <array> array_terms
Jiri Olsa89812fc2012-03-15 20:09:15 +0100104
105%union
106{
107 char *str;
Robert Richterb527bab2012-08-07 19:43:13 +0200108 u64 num;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100109 struct list_head *head;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300110 struct parse_events_term *term;
He Kuang865582c2015-09-28 03:52:15 +0000111 struct tracepoint_name {
112 char *sys;
113 char *event;
114 } tracepoint_name;
Wang Nane571e022016-02-22 09:10:35 +0000115 struct parse_events_array array;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100116}
117%%
118
Jiri Olsa90e2b222012-06-15 14:31:40 +0800119start:
Jiri Olsa89efb022012-08-08 12:14:14 +0200120PE_START_EVENTS start_events
Jiri Olsa90e2b222012-06-15 14:31:40 +0800121|
Jiri Olsa89efb022012-08-08 12:14:14 +0200122PE_START_TERMS start_terms
123
124start_events: groups
125{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300126 struct parse_events_state *parse_state = _parse_state;
Jiri Olsa89efb022012-08-08 12:14:14 +0200127
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300128 parse_events_update_lists($1, &parse_state->list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200129}
130
131groups:
132groups ',' group
133{
134 struct list_head *list = $1;
135 struct list_head *group = $3;
136
137 parse_events_update_lists(group, list);
138 $$ = list;
139}
140|
141groups ',' event
142{
143 struct list_head *list = $1;
144 struct list_head *event = $3;
145
146 parse_events_update_lists(event, list);
147 $$ = list;
148}
149|
150group
151|
152event
153
154group:
155group_def ':' PE_MODIFIER_EVENT
156{
157 struct list_head *list = $1;
158
159 ABORT_ON(parse_events__modifier_group(list, $3));
160 $$ = list;
161}
162|
163group_def
164
165group_def:
166PE_NAME '{' events '}'
167{
168 struct list_head *list = $3;
169
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300170 inc_group_count(list, _parse_state);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700171 parse_events__set_leader($1, list, _parse_state);
Jiri Olsa89efb022012-08-08 12:14:14 +0200172 $$ = list;
173}
174|
175'{' events '}'
176{
177 struct list_head *list = $2;
178
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300179 inc_group_count(list, _parse_state);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700180 parse_events__set_leader(NULL, list, _parse_state);
Jiri Olsa89efb022012-08-08 12:14:14 +0200181 $$ = list;
182}
Jiri Olsa90e2b222012-06-15 14:31:40 +0800183
Jiri Olsa89812fc2012-03-15 20:09:15 +0100184events:
Jiri Olsa89efb022012-08-08 12:14:14 +0200185events ',' event
186{
187 struct list_head *event = $3;
188 struct list_head *list = $1;
189
190 parse_events_update_lists(event, list);
191 $$ = list;
192}
193|
194event
Jiri Olsa89812fc2012-03-15 20:09:15 +0100195
Robert Richterac2ba9f2012-08-16 21:10:21 +0200196event: event_mod
197
198event_mod:
199event_name PE_MODIFIER_EVENT
Jiri Olsa89812fc2012-03-15 20:09:15 +0100200{
Jiri Olsa89efb022012-08-08 12:14:14 +0200201 struct list_head *list = $1;
Jiri Olsa46010ab2012-06-15 14:31:38 +0800202
Jiri Olsa5d7be902012-03-20 19:15:40 +0100203 /*
204 * Apply modifier on all events added by single event definition
205 * (there could be more events added for multiple tracepoint
206 * definitions via '*?'.
207 */
Jiri Olsaf5b11352012-08-08 12:21:54 +0200208 ABORT_ON(parse_events__modifier_event(list, $2, false));
Jiri Olsa89efb022012-08-08 12:14:14 +0200209 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100210}
211|
Robert Richterac2ba9f2012-08-16 21:10:21 +0200212event_name
213
214event_name:
215PE_EVENT_NAME event_def
216{
217 ABORT_ON(parse_events_name($2, $1));
218 free($1);
219 $$ = $2;
220}
221|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100222event_def
223
Jiri Olsa5f537a22012-03-15 20:09:18 +0100224event_def: event_pmu |
225 event_legacy_symbol |
Jiri Olsa89812fc2012-03-15 20:09:15 +0100226 event_legacy_cache sep_dc |
227 event_legacy_mem |
228 event_legacy_tracepoint sep_dc |
229 event_legacy_numeric sep_dc |
Wang Nan84c86ca2015-10-14 12:41:14 +0000230 event_legacy_raw sep_dc |
231 event_bpf_file
Jiri Olsa89812fc2012-03-15 20:09:15 +0100232
Jiri Olsa5f537a22012-03-15 20:09:18 +0100233event_pmu:
Jiri Olsaceac7b72018-06-05 14:14:16 +0200234PE_NAME opt_pmu_config
Jiri Olsa5f537a22012-03-15 20:09:18 +0100235{
Jiri Olsaf7fa8272018-06-07 00:15:05 +0200236 struct parse_events_state *parse_state = _parse_state;
237 struct parse_events_error *error = parse_state->error;
Andi Kleen82557182017-03-20 13:17:03 -0700238 struct list_head *list, *orig_terms, *terms;
239
Arnaldo Carvalho de Melo4a35a902018-05-07 15:27:01 -0300240 if (parse_events_copy_term_list($2, &orig_terms))
Andi Kleen82557182017-03-20 13:17:03 -0700241 YYABORT;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200242
Jiri Olsaf7fa8272018-06-07 00:15:05 +0200243 if (error)
244 error->idx = @1.first_column;
245
Ian Rogersa26e4712019-10-22 17:53:32 -0700246 list = alloc_list();
247 ABORT_ON(!list);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700248 if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
Andi Kleen82557182017-03-20 13:17:03 -0700249 struct perf_pmu *pmu = NULL;
250 int ok = 0;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500251 char *pattern;
252
253 if (asprintf(&pattern, "%s*", $1) < 0)
254 YYABORT;
Andi Kleen82557182017-03-20 13:17:03 -0700255
256 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
257 char *name = pmu->name;
258
Andi Kleena820e332017-03-20 13:17:04 -0700259 if (!strncmp(name, "uncore_", 7) &&
260 strncmp($1, "uncore_", 7))
261 name += 7;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500262 if (!fnmatch(pattern, name, 0)) {
263 if (parse_events_copy_term_list(orig_terms, &terms)) {
264 free(pattern);
Andi Kleen82557182017-03-20 13:17:03 -0700265 YYABORT;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500266 }
Kan Liang3cdc5c22018-05-07 14:13:43 -0700267 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
Andi Kleen82557182017-03-20 13:17:03 -0700268 ok++;
269 parse_events_terms__delete(terms);
270 }
271 }
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500272
273 free(pattern);
274
Andi Kleen82557182017-03-20 13:17:03 -0700275 if (!ok)
276 YYABORT;
277 }
Arnaldo Carvalho de Melo4a35a902018-05-07 15:27:01 -0300278 parse_events_terms__delete($2);
Andi Kleen82557182017-03-20 13:17:03 -0700279 parse_events_terms__delete(orig_terms);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200280 $$ = list;
Jiri Olsa5f537a22012-03-15 20:09:18 +0100281}
Adrian Hunterad962272014-08-15 22:08:40 +0300282|
Kan Liangba32a452014-10-07 11:08:51 -0400283PE_KERNEL_PMU_EVENT sep_dc
284{
Kan Liangba32a452014-10-07 11:08:51 -0400285 struct list_head *list;
286
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300287 if (parse_events_multi_pmu_add(_parse_state, $1, &list) < 0)
Andi Kleen231bb2a2017-01-27 18:03:39 -0800288 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400289 $$ = list;
290}
291|
292PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
293{
Kan Liangba32a452014-10-07 11:08:51 -0400294 struct list_head *list;
295 char pmu_name[128];
Andi Kleen82557182017-03-20 13:17:03 -0700296
Kan Liangba32a452014-10-07 11:08:51 -0400297 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300298 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0)
Andi Kleen82557182017-03-20 13:17:03 -0700299 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400300 $$ = list;
301}
Jiri Olsa5f537a22012-03-15 20:09:18 +0100302
Jiri Olsacf3506d2012-07-04 00:00:43 +0200303value_sym:
304PE_VALUE_SYM_HW
305|
306PE_VALUE_SYM_SW
307
Jiri Olsa89812fc2012-03-15 20:09:15 +0100308event_legacy_symbol:
Jiri Olsacf3506d2012-07-04 00:00:43 +0200309value_sym '/' event_config '/'
Jiri Olsa89812fc2012-03-15 20:09:15 +0100310{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600311 struct list_head *list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100312 int type = $1 >> 16;
313 int config = $1 & 255;
314
Ian Rogersa26e4712019-10-22 17:53:32 -0700315 list = alloc_list();
316 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300317 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3));
Arnaldo Carvalho de Melo2146afc2016-02-12 17:09:17 -0300318 parse_events_terms__delete($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200319 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100320}
321|
Jiri Olsa714a92d2019-02-13 13:32:40 +0100322value_sym sep_slash_slash_dc
Jiri Olsa8f707d82012-03-15 20:09:16 +0100323{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600324 struct list_head *list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100325 int type = $1 >> 16;
326 int config = $1 & 255;
327
Ian Rogersa26e4712019-10-22 17:53:32 -0700328 list = alloc_list();
329 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300330 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200331 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100332}
Andi Kleenf0fbb112019-03-26 15:18:21 -0700333|
334PE_VALUE_SYM_TOOL sep_slash_slash_dc
335{
336 struct list_head *list;
337
Ian Rogersa26e4712019-10-22 17:53:32 -0700338 list = alloc_list();
339 ABORT_ON(!list);
Andi Kleenf0fbb112019-03-26 15:18:21 -0700340 ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
341 $$ = list;
342}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100343
344event_legacy_cache:
Wang Nan43d0b972016-02-19 11:44:01 +0000345PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100346{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300347 struct parse_events_state *parse_state = _parse_state;
348 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600349 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200350
Ian Rogersa26e4712019-10-22 17:53:32 -0700351 list = alloc_list();
352 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300353 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6));
Wang Nan43d0b972016-02-19 11:44:01 +0000354 parse_events_terms__delete($6);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200355 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100356}
357|
Wang Nan43d0b972016-02-19 11:44:01 +0000358PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100359{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300360 struct parse_events_state *parse_state = _parse_state;
361 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600362 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200363
Ian Rogersa26e4712019-10-22 17:53:32 -0700364 list = alloc_list();
365 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300366 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4));
Wang Nan43d0b972016-02-19 11:44:01 +0000367 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200368 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100369}
370|
Wang Nan43d0b972016-02-19 11:44:01 +0000371PE_NAME_CACHE_TYPE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100372{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300373 struct parse_events_state *parse_state = _parse_state;
374 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600375 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200376
Ian Rogersa26e4712019-10-22 17:53:32 -0700377 list = alloc_list();
378 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300379 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2));
Wang Nan43d0b972016-02-19 11:44:01 +0000380 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200381 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100382}
383
384event_legacy_mem:
Jacob Shin3741eb92014-05-29 17:26:51 +0200385PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
386{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300387 struct parse_events_state *parse_state = _parse_state;
Jacob Shin3741eb92014-05-29 17:26:51 +0200388 struct list_head *list;
389
Ian Rogersa26e4712019-10-22 17:53:32 -0700390 list = alloc_list();
391 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300392 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200393 (void *) $2, $6, $4));
394 $$ = list;
395}
396|
397PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
398{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300399 struct parse_events_state *parse_state = _parse_state;
Jacob Shin3741eb92014-05-29 17:26:51 +0200400 struct list_head *list;
401
Ian Rogersa26e4712019-10-22 17:53:32 -0700402 list = alloc_list();
403 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300404 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200405 (void *) $2, NULL, $4));
406 $$ = list;
407}
408|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100409PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
410{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300411 struct parse_events_state *parse_state = _parse_state;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600412 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200413
Ian Rogersa26e4712019-10-22 17:53:32 -0700414 list = alloc_list();
415 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300416 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200417 (void *) $2, $4, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200418 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100419}
420|
421PE_PREFIX_MEM PE_VALUE sep_dc
422{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300423 struct parse_events_state *parse_state = _parse_state;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600424 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200425
Ian Rogersa26e4712019-10-22 17:53:32 -0700426 list = alloc_list();
427 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300428 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200429 (void *) $2, NULL, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200430 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100431}
432
433event_legacy_tracepoint:
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300434tracepoint_name opt_event_config
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200435{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300436 struct parse_events_state *parse_state = _parse_state;
437 struct parse_events_error *error = parse_state->error;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200438 struct list_head *list;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200439
Ian Rogersa26e4712019-10-22 17:53:32 -0700440 list = alloc_list();
441 ABORT_ON(!list);
He Kuange637d172015-09-28 03:52:16 +0000442 if (error)
443 error->idx = @1.first_column;
444
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300445 if (parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300446 error, $2))
He Kuange637d172015-09-28 03:52:16 +0000447 return -1;
448
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200449 $$ = list;
450}
He Kuang865582c2015-09-28 03:52:15 +0000451
452tracepoint_name:
453PE_NAME '-' PE_NAME ':' PE_NAME
454{
455 char sys_name[128];
456 struct tracepoint_name tracepoint;
457
458 snprintf(&sys_name, 128, "%s-%s", $1, $3);
459 tracepoint.sys = &sys_name;
460 tracepoint.event = $5;
461
462 $$ = tracepoint;
463}
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200464|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100465PE_NAME ':' PE_NAME
466{
He Kuang865582c2015-09-28 03:52:15 +0000467 struct tracepoint_name tracepoint = {$1, $3};
Jiri Olsab847cbd2012-05-21 09:12:51 +0200468
He Kuang865582c2015-09-28 03:52:15 +0000469 $$ = tracepoint;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100470}
471
472event_legacy_numeric:
Wang Nan10bf3582016-02-19 11:44:00 +0000473PE_VALUE ':' PE_VALUE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100474{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600475 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200476
Ian Rogersa26e4712019-10-22 17:53:32 -0700477 list = alloc_list();
478 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300479 ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4));
Wang Nan10bf3582016-02-19 11:44:00 +0000480 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200481 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100482}
483
484event_legacy_raw:
Wang Nan10bf3582016-02-19 11:44:00 +0000485PE_RAW opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100486{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600487 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200488
Ian Rogersa26e4712019-10-22 17:53:32 -0700489 list = alloc_list();
490 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300491 ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2));
Wang Nan10bf3582016-02-19 11:44:00 +0000492 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200493 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100494}
495
Wang Nan84c86ca2015-10-14 12:41:14 +0000496event_bpf_file:
Wang Nana34f3be2016-02-22 09:10:31 +0000497PE_BPF_OBJECT opt_event_config
Wang Nan84c86ca2015-10-14 12:41:14 +0000498{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300499 struct parse_events_state *parse_state = _parse_state;
Wang Nan84c86ca2015-10-14 12:41:14 +0000500 struct list_head *list;
501
Ian Rogersa26e4712019-10-22 17:53:32 -0700502 list = alloc_list();
503 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300504 ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2));
Wang Nana34f3be2016-02-22 09:10:31 +0000505 parse_events_terms__delete($2);
Wang Nand509db02015-10-14 12:41:20 +0000506 $$ = list;
507}
508|
Wang Nana34f3be2016-02-22 09:10:31 +0000509PE_BPF_SOURCE opt_event_config
Wang Nand509db02015-10-14 12:41:20 +0000510{
Wang Nand509db02015-10-14 12:41:20 +0000511 struct list_head *list;
512
Ian Rogersa26e4712019-10-22 17:53:32 -0700513 list = alloc_list();
514 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300515 ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2));
Wang Nana34f3be2016-02-22 09:10:31 +0000516 parse_events_terms__delete($2);
Wang Nan84c86ca2015-10-14 12:41:14 +0000517 $$ = list;
518}
519
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300520opt_event_config:
521'/' event_config '/'
522{
523 $$ = $2;
524}
525|
526'/' '/'
527{
528 $$ = NULL;
529}
530|
531{
532 $$ = NULL;
533}
534
Jiri Olsaceac7b72018-06-05 14:14:16 +0200535opt_pmu_config:
536'/' event_config '/'
537{
538 $$ = $2;
539}
540|
541'/' '/'
542{
543 $$ = NULL;
544}
545
Jiri Olsa89efb022012-08-08 12:14:14 +0200546start_terms: event_config
Jiri Olsa90e2b222012-06-15 14:31:40 +0800547{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300548 struct parse_events_state *parse_state = _parse_state;
549 parse_state->terms = $1;
Jiri Olsa90e2b222012-06-15 14:31:40 +0800550}
551
Jiri Olsa8f707d82012-03-15 20:09:16 +0100552event_config:
553event_config ',' event_term
554{
555 struct list_head *head = $1;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300556 struct parse_events_term *term = $3;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100557
558 ABORT_ON(!head);
559 list_add_tail(&term->list, head);
560 $$ = $1;
561}
562|
563event_term
564{
565 struct list_head *head = malloc(sizeof(*head));
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300566 struct parse_events_term *term = $1;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100567
568 ABORT_ON(!head);
569 INIT_LIST_HEAD(head);
570 list_add_tail(&term->list, head);
571 $$ = head;
572}
573
574event_term:
575PE_NAME '=' PE_NAME
576{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300577 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100578
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300579 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200580 $1, $3, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100581 $$ = term;
582}
583|
584PE_NAME '=' PE_VALUE
585{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300586 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100587
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300588 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100589 $1, $3, false, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100590 $$ = term;
591}
592|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200593PE_NAME '=' PE_VALUE_SYM_HW
594{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300595 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200596 int config = $3 & 255;
597
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300598 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200599 $$ = term;
600}
601|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100602PE_NAME
603{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300604 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100605
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300606 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100607 $1, 1, true, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100608 $$ = term;
609}
610|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200611PE_VALUE_SYM_HW
612{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300613 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200614 int config = $1 & 255;
615
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300616 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200617 $$ = term;
618}
619|
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200620PE_TERM '=' PE_NAME
621{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300622 struct parse_events_term *term;
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200623
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200624 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200625 $$ = term;
626}
627|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100628PE_TERM '=' PE_VALUE
629{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300630 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100631
Jiri Olsa99e71382017-02-17 15:00:56 +0100632 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100633 $$ = term;
634}
635|
636PE_TERM
637{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300638 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100639
Jiri Olsa99e71382017-02-17 15:00:56 +0100640 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100641 $$ = term;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100642}
Wang Nane571e022016-02-22 09:10:35 +0000643|
644PE_NAME array '=' PE_NAME
645{
646 struct parse_events_term *term;
Wang Nane571e022016-02-22 09:10:35 +0000647
648 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
649 $1, $4, &@1, &@4));
650
651 term->array = $2;
652 $$ = term;
653}
654|
655PE_NAME array '=' PE_VALUE
656{
657 struct parse_events_term *term;
658
659 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100660 $1, $4, false, &@1, &@4));
Wang Nane571e022016-02-22 09:10:35 +0000661 term->array = $2;
662 $$ = term;
663}
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600664|
665PE_DRV_CFG_TERM
666{
667 struct parse_events_term *term;
668
669 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
670 $1, $1, &@1, NULL));
671 $$ = term;
672}
Wang Nane571e022016-02-22 09:10:35 +0000673
674array:
675'[' array_terms ']'
676{
677 $$ = $2;
678}
679|
680PE_ARRAY_ALL
681{
682 $$.nr_ranges = 0;
683 $$.ranges = NULL;
684}
685
686array_terms:
687array_terms ',' array_term
688{
689 struct parse_events_array new_array;
690
691 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
Ian Rogers826100a2019-10-22 17:53:33 -0700692 new_array.ranges = realloc($1.ranges,
693 sizeof(new_array.ranges[0]) *
694 new_array.nr_ranges);
Wang Nane571e022016-02-22 09:10:35 +0000695 ABORT_ON(!new_array.ranges);
Wang Nane571e022016-02-22 09:10:35 +0000696 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
697 $3.nr_ranges * sizeof(new_array.ranges[0]));
Wang Nane571e022016-02-22 09:10:35 +0000698 free($3.ranges);
699 $$ = new_array;
700}
701|
702array_term
703
704array_term:
705PE_VALUE
706{
707 struct parse_events_array array;
708
709 array.nr_ranges = 1;
710 array.ranges = malloc(sizeof(array.ranges[0]));
711 ABORT_ON(!array.ranges);
712 array.ranges[0].start = $1;
713 array.ranges[0].length = 1;
714 $$ = array;
715}
716|
717PE_VALUE PE_ARRAY_RANGE PE_VALUE
718{
719 struct parse_events_array array;
720
721 ABORT_ON($3 < $1);
722 array.nr_ranges = 1;
723 array.ranges = malloc(sizeof(array.ranges[0]));
724 ABORT_ON(!array.ranges);
725 array.ranges[0].start = $1;
726 array.ranges[0].length = $3 - $1 + 1;
727 $$ = array;
728}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100729
730sep_dc: ':' |
731
Jiri Olsa714a92d2019-02-13 13:32:40 +0100732sep_slash_slash_dc: '/' '/' | ':' |
Jiri Olsa8f707d82012-03-15 20:09:16 +0100733
Jiri Olsa89812fc2012-03-15 20:09:15 +0100734%%
735
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300736void parse_events_error(YYLTYPE *loc, void *parse_state,
Jiri Olsa6297d422015-04-22 21:10:17 +0200737 void *scanner __maybe_unused,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300738 char const *msg __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100739{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300740 parse_events_evlist_error(parse_state, loc->last_column, "parser error");
Jiri Olsa89812fc2012-03-15 20:09:15 +0100741}