blob: 035edfa8d42e9d15cb57a0480b832a9894e11731 [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>
Ian Rogersf2a8ecd2019-10-30 15:34:44 -070015#include <linux/zalloc.h>
Andi Kleen231bb2a2017-01-27 18:03:39 -080016#include "pmu.h"
Andi Kleenf0fbb112019-03-26 15:18:21 -070017#include "evsel.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010018#include "parse-events.h"
Zheng Yanac20de6f2012-06-15 14:31:39 +080019#include "parse-events-bison.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010020
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030021void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
Arnaldo Carvalho de Melo34a05482017-02-15 10:09:11 -030022
Jiri Olsa89812fc2012-03-15 20:09:15 +010023#define ABORT_ON(val) \
24do { \
25 if (val) \
26 YYABORT; \
27} while (0)
28
Ian Rogersa26e4712019-10-22 17:53:32 -070029static struct list_head* alloc_list()
30{
31 struct list_head *list;
32
33 list = malloc(sizeof(*list));
34 if (!list)
35 return NULL;
36
37 INIT_LIST_HEAD(list);
38 return list;
39}
David Ahernc5cd8ac2013-07-02 13:27:25 -060040
Ian Rogersf2a8ecd2019-10-30 15:34:44 -070041static void free_list_evsel(struct list_head* list_evsel)
42{
43 struct evsel *evsel, *tmp;
44
45 list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
46 list_del_init(&evsel->core.node);
47 perf_evsel__delete(evsel);
48 }
49 free(list_evsel);
50}
51
52static void free_term(struct parse_events_term *term)
53{
54 if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
55 free(term->val.str);
56 zfree(&term->array.ranges);
57 free(term);
58}
59
Colin Ian King07ef7572016-03-07 16:44:37 -030060static void inc_group_count(struct list_head *list,
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030061 struct parse_events_state *parse_state)
Namhyung Kim97f63e42013-01-22 18:09:29 +090062{
63 /* Count groups only have more than 1 members */
64 if (!list_is_last(list->next, list))
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -030065 parse_state->nr_groups++;
Namhyung Kim97f63e42013-01-22 18:09:29 +090066}
67
Jiri Olsa89812fc2012-03-15 20:09:15 +010068%}
69
Jiri Olsa90e2b222012-06-15 14:31:40 +080070%token PE_START_EVENTS PE_START_TERMS
Jiri Olsacf3506d2012-07-04 00:00:43 +020071%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
Andi Kleenf0fbb112019-03-26 15:18:21 -070072%token PE_VALUE_SYM_TOOL
Robert Richterac2ba9f2012-08-16 21:10:21 +020073%token PE_EVENT_NAME
Jiri Olsa89812fc2012-03-15 20:09:15 +010074%token PE_NAME
Wang Nand509db02015-10-14 12:41:20 +000075%token PE_BPF_OBJECT PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010076%token PE_MODIFIER_EVENT PE_MODIFIER_BP
77%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
Jiri Olsa89efb022012-08-08 12:14:14 +020078%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
Jiri Olsa89812fc2012-03-15 20:09:15 +010079%token PE_ERROR
Kan Liangba32a452014-10-07 11:08:51 -040080%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Wang Nane571e022016-02-22 09:10:35 +000081%token PE_ARRAY_ALL PE_ARRAY_RANGE
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060082%token PE_DRV_CFG_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010083%type <num> PE_VALUE
Jiri Olsacf3506d2012-07-04 00:00:43 +020084%type <num> PE_VALUE_SYM_HW
85%type <num> PE_VALUE_SYM_SW
Andi Kleenf0fbb112019-03-26 15:18:21 -070086%type <num> PE_VALUE_SYM_TOOL
Jiri Olsa89812fc2012-03-15 20:09:15 +010087%type <num> PE_RAW
Jiri Olsa8f707d82012-03-15 20:09:16 +010088%type <num> PE_TERM
Ian Rogersf2a8ecd2019-10-30 15:34:44 -070089%type <num> value_sym
Jiri Olsa89812fc2012-03-15 20:09:15 +010090%type <str> PE_NAME
Wang Nan84c86ca2015-10-14 12:41:14 +000091%type <str> PE_BPF_OBJECT
Wang Nand509db02015-10-14 12:41:20 +000092%type <str> PE_BPF_SOURCE
Jiri Olsa89812fc2012-03-15 20:09:15 +010093%type <str> PE_NAME_CACHE_TYPE
94%type <str> PE_NAME_CACHE_OP_RESULT
95%type <str> PE_MODIFIER_EVENT
96%type <str> PE_MODIFIER_BP
Robert Richterac2ba9f2012-08-16 21:10:21 +020097%type <str> PE_EVENT_NAME
Kan Liangba32a452014-10-07 11:08:51 -040098%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
Mathieu Poirierdd60fba2016-09-06 10:37:15 -060099%type <str> PE_DRV_CFG_TERM
Ian Rogersf2a8ecd2019-10-30 15:34:44 -0700100%destructor { free ($$); } <str>
Jiri Olsa8f707d82012-03-15 20:09:16 +0100101%type <term> event_term
Ian Rogersf2a8ecd2019-10-30 15:34:44 -0700102%destructor { free_term ($$); } <term>
103%type <list_terms> event_config
104%type <list_terms> opt_event_config
105%type <list_terms> opt_pmu_config
106%destructor { parse_events_terms__delete ($$); } <list_terms>
107%type <list_evsel> event_pmu
108%type <list_evsel> event_legacy_symbol
109%type <list_evsel> event_legacy_cache
110%type <list_evsel> event_legacy_mem
111%type <list_evsel> event_legacy_tracepoint
112%type <list_evsel> event_legacy_numeric
113%type <list_evsel> event_legacy_raw
114%type <list_evsel> event_bpf_file
115%type <list_evsel> event_def
116%type <list_evsel> event_mod
117%type <list_evsel> event_name
118%type <list_evsel> event
119%type <list_evsel> events
120%type <list_evsel> group_def
121%type <list_evsel> group
122%type <list_evsel> groups
123%destructor { free_list_evsel ($$); } <list_evsel>
He Kuang865582c2015-09-28 03:52:15 +0000124%type <tracepoint_name> tracepoint_name
Ian Rogersf2a8ecd2019-10-30 15:34:44 -0700125%destructor { free ($$.sys); free ($$.event); } <tracepoint_name>
Wang Nane571e022016-02-22 09:10:35 +0000126%type <array> array
127%type <array> array_term
128%type <array> array_terms
Ian Rogersf2a8ecd2019-10-30 15:34:44 -0700129%destructor { free ($$.ranges); } <array>
Jiri Olsa89812fc2012-03-15 20:09:15 +0100130
131%union
132{
133 char *str;
Robert Richterb527bab2012-08-07 19:43:13 +0200134 u64 num;
Ian Rogersf2a8ecd2019-10-30 15:34:44 -0700135 struct list_head *list_evsel;
136 struct list_head *list_terms;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300137 struct parse_events_term *term;
He Kuang865582c2015-09-28 03:52:15 +0000138 struct tracepoint_name {
139 char *sys;
140 char *event;
141 } tracepoint_name;
Wang Nane571e022016-02-22 09:10:35 +0000142 struct parse_events_array array;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100143}
144%%
145
Jiri Olsa90e2b222012-06-15 14:31:40 +0800146start:
Jiri Olsa89efb022012-08-08 12:14:14 +0200147PE_START_EVENTS start_events
Jiri Olsa90e2b222012-06-15 14:31:40 +0800148|
Jiri Olsa89efb022012-08-08 12:14:14 +0200149PE_START_TERMS start_terms
150
151start_events: groups
152{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300153 struct parse_events_state *parse_state = _parse_state;
Jiri Olsa89efb022012-08-08 12:14:14 +0200154
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300155 parse_events_update_lists($1, &parse_state->list);
Jiri Olsa89efb022012-08-08 12:14:14 +0200156}
157
158groups:
159groups ',' group
160{
161 struct list_head *list = $1;
162 struct list_head *group = $3;
163
164 parse_events_update_lists(group, list);
165 $$ = list;
166}
167|
168groups ',' event
169{
170 struct list_head *list = $1;
171 struct list_head *event = $3;
172
173 parse_events_update_lists(event, list);
174 $$ = list;
175}
176|
177group
178|
179event
180
181group:
182group_def ':' PE_MODIFIER_EVENT
183{
184 struct list_head *list = $1;
185
186 ABORT_ON(parse_events__modifier_group(list, $3));
187 $$ = list;
188}
189|
190group_def
191
192group_def:
193PE_NAME '{' events '}'
194{
195 struct list_head *list = $3;
196
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300197 inc_group_count(list, _parse_state);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700198 parse_events__set_leader($1, list, _parse_state);
Jiri Olsa89efb022012-08-08 12:14:14 +0200199 $$ = list;
200}
201|
202'{' events '}'
203{
204 struct list_head *list = $2;
205
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300206 inc_group_count(list, _parse_state);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700207 parse_events__set_leader(NULL, list, _parse_state);
Jiri Olsa89efb022012-08-08 12:14:14 +0200208 $$ = list;
209}
Jiri Olsa90e2b222012-06-15 14:31:40 +0800210
Jiri Olsa89812fc2012-03-15 20:09:15 +0100211events:
Jiri Olsa89efb022012-08-08 12:14:14 +0200212events ',' event
213{
214 struct list_head *event = $3;
215 struct list_head *list = $1;
216
217 parse_events_update_lists(event, list);
218 $$ = list;
219}
220|
221event
Jiri Olsa89812fc2012-03-15 20:09:15 +0100222
Robert Richterac2ba9f2012-08-16 21:10:21 +0200223event: event_mod
224
225event_mod:
226event_name PE_MODIFIER_EVENT
Jiri Olsa89812fc2012-03-15 20:09:15 +0100227{
Jiri Olsa89efb022012-08-08 12:14:14 +0200228 struct list_head *list = $1;
Jiri Olsa46010ab2012-06-15 14:31:38 +0800229
Jiri Olsa5d7be902012-03-20 19:15:40 +0100230 /*
231 * Apply modifier on all events added by single event definition
232 * (there could be more events added for multiple tracepoint
233 * definitions via '*?'.
234 */
Jiri Olsaf5b11352012-08-08 12:21:54 +0200235 ABORT_ON(parse_events__modifier_event(list, $2, false));
Jiri Olsa89efb022012-08-08 12:14:14 +0200236 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100237}
238|
Robert Richterac2ba9f2012-08-16 21:10:21 +0200239event_name
240
241event_name:
242PE_EVENT_NAME event_def
243{
244 ABORT_ON(parse_events_name($2, $1));
245 free($1);
246 $$ = $2;
247}
248|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100249event_def
250
Jiri Olsa5f537a22012-03-15 20:09:18 +0100251event_def: event_pmu |
252 event_legacy_symbol |
Jiri Olsa89812fc2012-03-15 20:09:15 +0100253 event_legacy_cache sep_dc |
254 event_legacy_mem |
255 event_legacy_tracepoint sep_dc |
256 event_legacy_numeric sep_dc |
Wang Nan84c86ca2015-10-14 12:41:14 +0000257 event_legacy_raw sep_dc |
258 event_bpf_file
Jiri Olsa89812fc2012-03-15 20:09:15 +0100259
Jiri Olsa5f537a22012-03-15 20:09:18 +0100260event_pmu:
Jiri Olsaceac7b72018-06-05 14:14:16 +0200261PE_NAME opt_pmu_config
Jiri Olsa5f537a22012-03-15 20:09:18 +0100262{
Jiri Olsaf7fa8272018-06-07 00:15:05 +0200263 struct parse_events_state *parse_state = _parse_state;
264 struct parse_events_error *error = parse_state->error;
Andi Kleen82557182017-03-20 13:17:03 -0700265 struct list_head *list, *orig_terms, *terms;
266
Arnaldo Carvalho de Melo4a35a902018-05-07 15:27:01 -0300267 if (parse_events_copy_term_list($2, &orig_terms))
Andi Kleen82557182017-03-20 13:17:03 -0700268 YYABORT;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200269
Jiri Olsaf7fa8272018-06-07 00:15:05 +0200270 if (error)
271 error->idx = @1.first_column;
272
Ian Rogersa26e4712019-10-22 17:53:32 -0700273 list = alloc_list();
274 ABORT_ON(!list);
Kan Liang3cdc5c22018-05-07 14:13:43 -0700275 if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
Andi Kleen82557182017-03-20 13:17:03 -0700276 struct perf_pmu *pmu = NULL;
277 int ok = 0;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500278 char *pattern;
279
280 if (asprintf(&pattern, "%s*", $1) < 0)
281 YYABORT;
Andi Kleen82557182017-03-20 13:17:03 -0700282
283 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
284 char *name = pmu->name;
285
Andi Kleena820e332017-03-20 13:17:04 -0700286 if (!strncmp(name, "uncore_", 7) &&
287 strncmp($1, "uncore_", 7))
288 name += 7;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500289 if (!fnmatch(pattern, name, 0)) {
290 if (parse_events_copy_term_list(orig_terms, &terms)) {
291 free(pattern);
Andi Kleen82557182017-03-20 13:17:03 -0700292 YYABORT;
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500293 }
Kan Liang3cdc5c22018-05-07 14:13:43 -0700294 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
Andi Kleen82557182017-03-20 13:17:03 -0700295 ok++;
296 parse_events_terms__delete(terms);
297 }
298 }
Agustin Vega-Friasb2b9d3a2018-03-06 09:04:42 -0500299
300 free(pattern);
301
Andi Kleen82557182017-03-20 13:17:03 -0700302 if (!ok)
303 YYABORT;
304 }
Arnaldo Carvalho de Melo4a35a902018-05-07 15:27:01 -0300305 parse_events_terms__delete($2);
Andi Kleen82557182017-03-20 13:17:03 -0700306 parse_events_terms__delete(orig_terms);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200307 $$ = list;
Jiri Olsa5f537a22012-03-15 20:09:18 +0100308}
Adrian Hunterad962272014-08-15 22:08:40 +0300309|
Kan Liangba32a452014-10-07 11:08:51 -0400310PE_KERNEL_PMU_EVENT sep_dc
311{
Kan Liangba32a452014-10-07 11:08:51 -0400312 struct list_head *list;
313
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300314 if (parse_events_multi_pmu_add(_parse_state, $1, &list) < 0)
Andi Kleen231bb2a2017-01-27 18:03:39 -0800315 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400316 $$ = list;
317}
318|
319PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
320{
Kan Liangba32a452014-10-07 11:08:51 -0400321 struct list_head *list;
322 char pmu_name[128];
Andi Kleen82557182017-03-20 13:17:03 -0700323
Kan Liangba32a452014-10-07 11:08:51 -0400324 snprintf(&pmu_name, 128, "%s-%s", $1, $3);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300325 if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0)
Andi Kleen82557182017-03-20 13:17:03 -0700326 YYABORT;
Kan Liangba32a452014-10-07 11:08:51 -0400327 $$ = list;
328}
Jiri Olsa5f537a22012-03-15 20:09:18 +0100329
Jiri Olsacf3506d2012-07-04 00:00:43 +0200330value_sym:
331PE_VALUE_SYM_HW
332|
333PE_VALUE_SYM_SW
334
Jiri Olsa89812fc2012-03-15 20:09:15 +0100335event_legacy_symbol:
Jiri Olsacf3506d2012-07-04 00:00:43 +0200336value_sym '/' event_config '/'
Jiri Olsa89812fc2012-03-15 20:09:15 +0100337{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600338 struct list_head *list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100339 int type = $1 >> 16;
340 int config = $1 & 255;
341
Ian Rogersa26e4712019-10-22 17:53:32 -0700342 list = alloc_list();
343 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300344 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3));
Arnaldo Carvalho de Melo2146afc2016-02-12 17:09:17 -0300345 parse_events_terms__delete($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200346 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100347}
348|
Jiri Olsa714a92d2019-02-13 13:32:40 +0100349value_sym sep_slash_slash_dc
Jiri Olsa8f707d82012-03-15 20:09:16 +0100350{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600351 struct list_head *list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100352 int type = $1 >> 16;
353 int config = $1 & 255;
354
Ian Rogersa26e4712019-10-22 17:53:32 -0700355 list = alloc_list();
356 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300357 ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200358 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100359}
Andi Kleenf0fbb112019-03-26 15:18:21 -0700360|
361PE_VALUE_SYM_TOOL sep_slash_slash_dc
362{
363 struct list_head *list;
364
Ian Rogersa26e4712019-10-22 17:53:32 -0700365 list = alloc_list();
366 ABORT_ON(!list);
Andi Kleenf0fbb112019-03-26 15:18:21 -0700367 ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
368 $$ = list;
369}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100370
371event_legacy_cache:
Wang Nan43d0b972016-02-19 11:44:01 +0000372PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100373{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300374 struct parse_events_state *parse_state = _parse_state;
375 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600376 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200377
Ian Rogersa26e4712019-10-22 17:53:32 -0700378 list = alloc_list();
379 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300380 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6));
Wang Nan43d0b972016-02-19 11:44:01 +0000381 parse_events_terms__delete($6);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200382 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100383}
384|
Wang Nan43d0b972016-02-19 11:44:01 +0000385PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100386{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300387 struct parse_events_state *parse_state = _parse_state;
388 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600389 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200390
Ian Rogersa26e4712019-10-22 17:53:32 -0700391 list = alloc_list();
392 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300393 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4));
Wang Nan43d0b972016-02-19 11:44:01 +0000394 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200395 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100396}
397|
Wang Nan43d0b972016-02-19 11:44:01 +0000398PE_NAME_CACHE_TYPE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100399{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300400 struct parse_events_state *parse_state = _parse_state;
401 struct parse_events_error *error = parse_state->error;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600402 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200403
Ian Rogersa26e4712019-10-22 17:53:32 -0700404 list = alloc_list();
405 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300406 ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2));
Wang Nan43d0b972016-02-19 11:44:01 +0000407 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200408 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100409}
410
411event_legacy_mem:
Jacob Shin3741eb92014-05-29 17:26:51 +0200412PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
413{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300414 struct parse_events_state *parse_state = _parse_state;
Jacob Shin3741eb92014-05-29 17:26:51 +0200415 struct list_head *list;
416
Ian Rogersa26e4712019-10-22 17:53:32 -0700417 list = alloc_list();
418 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300419 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200420 (void *) $2, $6, $4));
421 $$ = list;
422}
423|
424PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
425{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300426 struct parse_events_state *parse_state = _parse_state;
Jacob Shin3741eb92014-05-29 17:26:51 +0200427 struct list_head *list;
428
Ian Rogersa26e4712019-10-22 17:53:32 -0700429 list = alloc_list();
430 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300431 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200432 (void *) $2, NULL, $4));
433 $$ = list;
434}
435|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100436PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
437{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300438 struct parse_events_state *parse_state = _parse_state;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600439 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200440
Ian Rogersa26e4712019-10-22 17:53:32 -0700441 list = alloc_list();
442 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300443 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200444 (void *) $2, $4, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200445 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100446}
447|
448PE_PREFIX_MEM PE_VALUE sep_dc
449{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300450 struct parse_events_state *parse_state = _parse_state;
David Ahernc5cd8ac2013-07-02 13:27:25 -0600451 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200452
Ian Rogersa26e4712019-10-22 17:53:32 -0700453 list = alloc_list();
454 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300455 ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
Jacob Shin3741eb92014-05-29 17:26:51 +0200456 (void *) $2, NULL, 0));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200457 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100458}
459
460event_legacy_tracepoint:
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300461tracepoint_name opt_event_config
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200462{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300463 struct parse_events_state *parse_state = _parse_state;
464 struct parse_events_error *error = parse_state->error;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200465 struct list_head *list;
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200466
Ian Rogersa26e4712019-10-22 17:53:32 -0700467 list = alloc_list();
468 ABORT_ON(!list);
He Kuange637d172015-09-28 03:52:16 +0000469 if (error)
470 error->idx = @1.first_column;
471
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300472 if (parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300473 error, $2))
He Kuange637d172015-09-28 03:52:16 +0000474 return -1;
475
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200476 $$ = list;
477}
He Kuang865582c2015-09-28 03:52:15 +0000478
479tracepoint_name:
480PE_NAME '-' PE_NAME ':' PE_NAME
481{
482 char sys_name[128];
483 struct tracepoint_name tracepoint;
484
485 snprintf(&sys_name, 128, "%s-%s", $1, $3);
486 tracepoint.sys = &sys_name;
487 tracepoint.event = $5;
488
489 $$ = tracepoint;
490}
Alexander Yarygin2b9032e2014-04-25 17:34:05 +0200491|
Jiri Olsa89812fc2012-03-15 20:09:15 +0100492PE_NAME ':' PE_NAME
493{
He Kuang865582c2015-09-28 03:52:15 +0000494 struct tracepoint_name tracepoint = {$1, $3};
Jiri Olsab847cbd2012-05-21 09:12:51 +0200495
He Kuang865582c2015-09-28 03:52:15 +0000496 $$ = tracepoint;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100497}
498
499event_legacy_numeric:
Wang Nan10bf3582016-02-19 11:44:00 +0000500PE_VALUE ':' PE_VALUE opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100501{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600502 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200503
Ian Rogersa26e4712019-10-22 17:53:32 -0700504 list = alloc_list();
505 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300506 ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4));
Wang Nan10bf3582016-02-19 11:44:00 +0000507 parse_events_terms__delete($4);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200508 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100509}
510
511event_legacy_raw:
Wang Nan10bf3582016-02-19 11:44:00 +0000512PE_RAW opt_event_config
Jiri Olsa89812fc2012-03-15 20:09:15 +0100513{
David Ahernc5cd8ac2013-07-02 13:27:25 -0600514 struct list_head *list;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200515
Ian Rogersa26e4712019-10-22 17:53:32 -0700516 list = alloc_list();
517 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300518 ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2));
Wang Nan10bf3582016-02-19 11:44:00 +0000519 parse_events_terms__delete($2);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200520 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100521}
522
Wang Nan84c86ca2015-10-14 12:41:14 +0000523event_bpf_file:
Wang Nana34f3be2016-02-22 09:10:31 +0000524PE_BPF_OBJECT opt_event_config
Wang Nan84c86ca2015-10-14 12:41:14 +0000525{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300526 struct parse_events_state *parse_state = _parse_state;
Wang Nan84c86ca2015-10-14 12:41:14 +0000527 struct list_head *list;
528
Ian Rogersa26e4712019-10-22 17:53:32 -0700529 list = alloc_list();
530 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300531 ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2));
Wang Nana34f3be2016-02-22 09:10:31 +0000532 parse_events_terms__delete($2);
Wang Nand509db02015-10-14 12:41:20 +0000533 $$ = list;
534}
535|
Wang Nana34f3be2016-02-22 09:10:31 +0000536PE_BPF_SOURCE opt_event_config
Wang Nand509db02015-10-14 12:41:20 +0000537{
Wang Nand509db02015-10-14 12:41:20 +0000538 struct list_head *list;
539
Ian Rogersa26e4712019-10-22 17:53:32 -0700540 list = alloc_list();
541 ABORT_ON(!list);
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300542 ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2));
Wang Nana34f3be2016-02-22 09:10:31 +0000543 parse_events_terms__delete($2);
Wang Nan84c86ca2015-10-14 12:41:14 +0000544 $$ = list;
545}
546
Arnaldo Carvalho de Melo1d55e8e2016-02-19 18:45:12 -0300547opt_event_config:
548'/' event_config '/'
549{
550 $$ = $2;
551}
552|
553'/' '/'
554{
555 $$ = NULL;
556}
557|
558{
559 $$ = NULL;
560}
561
Jiri Olsaceac7b72018-06-05 14:14:16 +0200562opt_pmu_config:
563'/' event_config '/'
564{
565 $$ = $2;
566}
567|
568'/' '/'
569{
570 $$ = NULL;
571}
572
Jiri Olsa89efb022012-08-08 12:14:14 +0200573start_terms: event_config
Jiri Olsa90e2b222012-06-15 14:31:40 +0800574{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300575 struct parse_events_state *parse_state = _parse_state;
576 parse_state->terms = $1;
Jiri Olsa90e2b222012-06-15 14:31:40 +0800577}
578
Jiri Olsa8f707d82012-03-15 20:09:16 +0100579event_config:
580event_config ',' event_term
581{
582 struct list_head *head = $1;
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300583 struct parse_events_term *term = $3;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100584
585 ABORT_ON(!head);
586 list_add_tail(&term->list, head);
587 $$ = $1;
588}
589|
590event_term
591{
592 struct list_head *head = malloc(sizeof(*head));
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300593 struct parse_events_term *term = $1;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100594
595 ABORT_ON(!head);
596 INIT_LIST_HEAD(head);
597 list_add_tail(&term->list, head);
598 $$ = head;
599}
600
601event_term:
602PE_NAME '=' PE_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__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200607 $1, $3, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100608 $$ = term;
609}
610|
611PE_NAME '=' PE_VALUE
612{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300613 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100614
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300615 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100616 $1, $3, false, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100617 $$ = term;
618}
619|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200620PE_NAME '=' PE_VALUE_SYM_HW
621{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300622 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200623 int config = $3 & 255;
624
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300625 ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200626 $$ = term;
627}
628|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100629PE_NAME
630{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300631 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100632
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300633 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100634 $1, 1, true, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100635 $$ = term;
636}
637|
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200638PE_VALUE_SYM_HW
639{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300640 struct parse_events_term *term;
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200641 int config = $1 & 255;
642
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300643 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
Jiri Olsa1d33d6d2012-10-10 14:53:17 +0200644 $$ = term;
645}
646|
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200647PE_TERM '=' PE_NAME
648{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300649 struct parse_events_term *term;
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200650
Jiri Olsacecf3a2e2015-04-22 21:10:20 +0200651 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200652 $$ = term;
653}
654|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100655PE_TERM '=' PE_VALUE
656{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300657 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100658
Jiri Olsa99e71382017-02-17 15:00:56 +0100659 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100660 $$ = term;
661}
662|
663PE_TERM
664{
Arnaldo Carvalho de Melo6cee6cd2013-01-18 16:29:49 -0300665 struct parse_events_term *term;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100666
Jiri Olsa99e71382017-02-17 15:00:56 +0100667 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100668 $$ = term;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100669}
Wang Nane571e022016-02-22 09:10:35 +0000670|
671PE_NAME array '=' PE_NAME
672{
673 struct parse_events_term *term;
Wang Nane571e022016-02-22 09:10:35 +0000674
675 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
676 $1, $4, &@1, &@4));
677
678 term->array = $2;
679 $$ = term;
680}
681|
682PE_NAME array '=' PE_VALUE
683{
684 struct parse_events_term *term;
685
686 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
Jiri Olsa99e71382017-02-17 15:00:56 +0100687 $1, $4, false, &@1, &@4));
Wang Nane571e022016-02-22 09:10:35 +0000688 term->array = $2;
689 $$ = term;
690}
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600691|
692PE_DRV_CFG_TERM
693{
694 struct parse_events_term *term;
Ian Rogersb6645a72019-10-30 15:34:43 -0700695 char *config = strdup($1);
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600696
Ian Rogersb6645a72019-10-30 15:34:43 -0700697 ABORT_ON(!config);
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600698 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
Ian Rogersb6645a72019-10-30 15:34:43 -0700699 config, $1, &@1, NULL));
Mathieu Poirierdd60fba2016-09-06 10:37:15 -0600700 $$ = term;
701}
Wang Nane571e022016-02-22 09:10:35 +0000702
703array:
704'[' array_terms ']'
705{
706 $$ = $2;
707}
708|
709PE_ARRAY_ALL
710{
711 $$.nr_ranges = 0;
712 $$.ranges = NULL;
713}
714
715array_terms:
716array_terms ',' array_term
717{
718 struct parse_events_array new_array;
719
720 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
Ian Rogers826100a2019-10-22 17:53:33 -0700721 new_array.ranges = realloc($1.ranges,
722 sizeof(new_array.ranges[0]) *
723 new_array.nr_ranges);
Wang Nane571e022016-02-22 09:10:35 +0000724 ABORT_ON(!new_array.ranges);
Wang Nane571e022016-02-22 09:10:35 +0000725 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
726 $3.nr_ranges * sizeof(new_array.ranges[0]));
Wang Nane571e022016-02-22 09:10:35 +0000727 free($3.ranges);
728 $$ = new_array;
729}
730|
731array_term
732
733array_term:
734PE_VALUE
735{
736 struct parse_events_array array;
737
738 array.nr_ranges = 1;
739 array.ranges = malloc(sizeof(array.ranges[0]));
740 ABORT_ON(!array.ranges);
741 array.ranges[0].start = $1;
742 array.ranges[0].length = 1;
743 $$ = array;
744}
745|
746PE_VALUE PE_ARRAY_RANGE PE_VALUE
747{
748 struct parse_events_array array;
749
750 ABORT_ON($3 < $1);
751 array.nr_ranges = 1;
752 array.ranges = malloc(sizeof(array.ranges[0]));
753 ABORT_ON(!array.ranges);
754 array.ranges[0].start = $1;
755 array.ranges[0].length = $3 - $1 + 1;
756 $$ = array;
757}
Jiri Olsa89812fc2012-03-15 20:09:15 +0100758
759sep_dc: ':' |
760
Jiri Olsa714a92d2019-02-13 13:32:40 +0100761sep_slash_slash_dc: '/' '/' | ':' |
Jiri Olsa8f707d82012-03-15 20:09:16 +0100762
Jiri Olsa89812fc2012-03-15 20:09:15 +0100763%%
764
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300765void parse_events_error(YYLTYPE *loc, void *parse_state,
Jiri Olsa6297d422015-04-22 21:10:17 +0200766 void *scanner __maybe_unused,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300767 char const *msg __maybe_unused)
Jiri Olsa89812fc2012-03-15 20:09:15 +0100768{
Arnaldo Carvalho de Melo5d9cdc12017-08-17 16:13:34 -0300769 parse_events_evlist_error(parse_state, loc->last_column, "parser error");
Jiri Olsa89812fc2012-03-15 20:09:15 +0100770}