1ac20de6fSZheng Yan %pure-parser 289812fc8SJiri Olsa %name-prefix "parse_events_" 346010ab2SJiri Olsa %parse-param {void *_data} 4ac20de6fSZheng Yan %parse-param {void *scanner} 5ac20de6fSZheng Yan %lex-param {void* scanner} 689812fc8SJiri Olsa 789812fc8SJiri Olsa %{ 889812fc8SJiri Olsa 989812fc8SJiri Olsa #define YYDEBUG 1 1089812fc8SJiri Olsa 1189812fc8SJiri Olsa #include <linux/compiler.h> 1289812fc8SJiri Olsa #include <linux/list.h> 1389812fc8SJiri Olsa #include "types.h" 1489812fc8SJiri Olsa #include "util.h" 1589812fc8SJiri Olsa #include "parse-events.h" 16ac20de6fSZheng Yan #include "parse-events-bison.h" 1789812fc8SJiri Olsa 18ac20de6fSZheng Yan extern int parse_events_lex (YYSTYPE* lvalp, void* scanner); 1989812fc8SJiri Olsa 2089812fc8SJiri Olsa #define ABORT_ON(val) \ 2189812fc8SJiri Olsa do { \ 2289812fc8SJiri Olsa if (val) \ 2389812fc8SJiri Olsa YYABORT; \ 2489812fc8SJiri Olsa } while (0) 2589812fc8SJiri Olsa 2689812fc8SJiri Olsa %} 2789812fc8SJiri Olsa 2890e2b22dSJiri Olsa %token PE_START_EVENTS PE_START_TERMS 29cf3506dcSJiri Olsa %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM 30ac2ba9f3SRobert Richter %token PE_EVENT_NAME 3189812fc8SJiri Olsa %token PE_NAME 3289812fc8SJiri Olsa %token PE_MODIFIER_EVENT PE_MODIFIER_BP 3389812fc8SJiri Olsa %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT 3489efb029SJiri Olsa %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP 3589812fc8SJiri Olsa %token PE_ERROR 3689812fc8SJiri Olsa %type <num> PE_VALUE 37cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_HW 38cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_SW 3989812fc8SJiri Olsa %type <num> PE_RAW 408f707d84SJiri Olsa %type <num> PE_TERM 4189812fc8SJiri Olsa %type <str> PE_NAME 4289812fc8SJiri Olsa %type <str> PE_NAME_CACHE_TYPE 4389812fc8SJiri Olsa %type <str> PE_NAME_CACHE_OP_RESULT 4489812fc8SJiri Olsa %type <str> PE_MODIFIER_EVENT 4589812fc8SJiri Olsa %type <str> PE_MODIFIER_BP 46ac2ba9f3SRobert Richter %type <str> PE_EVENT_NAME 47cf3506dcSJiri Olsa %type <num> value_sym 488f707d84SJiri Olsa %type <head> event_config 498f707d84SJiri Olsa %type <term> event_term 50b847cbdcSJiri Olsa %type <head> event_pmu 51b847cbdcSJiri Olsa %type <head> event_legacy_symbol 52b847cbdcSJiri Olsa %type <head> event_legacy_cache 53b847cbdcSJiri Olsa %type <head> event_legacy_mem 54b847cbdcSJiri Olsa %type <head> event_legacy_tracepoint 55b847cbdcSJiri Olsa %type <head> event_legacy_numeric 56b847cbdcSJiri Olsa %type <head> event_legacy_raw 57b847cbdcSJiri Olsa %type <head> event_def 58ac2ba9f3SRobert Richter %type <head> event_mod 59ac2ba9f3SRobert Richter %type <head> event_name 6089efb029SJiri Olsa %type <head> event 6189efb029SJiri Olsa %type <head> events 6289efb029SJiri Olsa %type <head> group_def 6389efb029SJiri Olsa %type <head> group 6489efb029SJiri Olsa %type <head> groups 6589812fc8SJiri Olsa 6689812fc8SJiri Olsa %union 6789812fc8SJiri Olsa { 6889812fc8SJiri Olsa char *str; 69b527bab5SRobert Richter u64 num; 708f707d84SJiri Olsa struct list_head *head; 716cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 7289812fc8SJiri Olsa } 7389812fc8SJiri Olsa %% 7489812fc8SJiri Olsa 7590e2b22dSJiri Olsa start: 7689efb029SJiri Olsa PE_START_EVENTS start_events 7790e2b22dSJiri Olsa | 7889efb029SJiri Olsa PE_START_TERMS start_terms 7989efb029SJiri Olsa 8089efb029SJiri Olsa start_events: groups 8189efb029SJiri Olsa { 82*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 8389efb029SJiri Olsa 8489efb029SJiri Olsa parse_events_update_lists($1, &data->list); 8589efb029SJiri Olsa } 8689efb029SJiri Olsa 8789efb029SJiri Olsa groups: 8889efb029SJiri Olsa groups ',' group 8989efb029SJiri Olsa { 9089efb029SJiri Olsa struct list_head *list = $1; 9189efb029SJiri Olsa struct list_head *group = $3; 9289efb029SJiri Olsa 9389efb029SJiri Olsa parse_events_update_lists(group, list); 9489efb029SJiri Olsa $$ = list; 9589efb029SJiri Olsa } 9689efb029SJiri Olsa | 9789efb029SJiri Olsa groups ',' event 9889efb029SJiri Olsa { 9989efb029SJiri Olsa struct list_head *list = $1; 10089efb029SJiri Olsa struct list_head *event = $3; 10189efb029SJiri Olsa 10289efb029SJiri Olsa parse_events_update_lists(event, list); 10389efb029SJiri Olsa $$ = list; 10489efb029SJiri Olsa } 10589efb029SJiri Olsa | 10689efb029SJiri Olsa group 10789efb029SJiri Olsa | 10889efb029SJiri Olsa event 10989efb029SJiri Olsa 11089efb029SJiri Olsa group: 11189efb029SJiri Olsa group_def ':' PE_MODIFIER_EVENT 11289efb029SJiri Olsa { 11389efb029SJiri Olsa struct list_head *list = $1; 11489efb029SJiri Olsa 11589efb029SJiri Olsa ABORT_ON(parse_events__modifier_group(list, $3)); 11689efb029SJiri Olsa $$ = list; 11789efb029SJiri Olsa } 11889efb029SJiri Olsa | 11989efb029SJiri Olsa group_def 12089efb029SJiri Olsa 12189efb029SJiri Olsa group_def: 12289efb029SJiri Olsa PE_NAME '{' events '}' 12389efb029SJiri Olsa { 12489efb029SJiri Olsa struct list_head *list = $3; 12589efb029SJiri Olsa 12663dab225SArnaldo Carvalho de Melo parse_events__set_leader($1, list); 12789efb029SJiri Olsa $$ = list; 12889efb029SJiri Olsa } 12989efb029SJiri Olsa | 13089efb029SJiri Olsa '{' events '}' 13189efb029SJiri Olsa { 13289efb029SJiri Olsa struct list_head *list = $2; 13389efb029SJiri Olsa 13463dab225SArnaldo Carvalho de Melo parse_events__set_leader(NULL, list); 13589efb029SJiri Olsa $$ = list; 13689efb029SJiri Olsa } 13790e2b22dSJiri Olsa 13889812fc8SJiri Olsa events: 13989efb029SJiri Olsa events ',' event 14089efb029SJiri Olsa { 14189efb029SJiri Olsa struct list_head *event = $3; 14289efb029SJiri Olsa struct list_head *list = $1; 14389efb029SJiri Olsa 14489efb029SJiri Olsa parse_events_update_lists(event, list); 14589efb029SJiri Olsa $$ = list; 14689efb029SJiri Olsa } 14789efb029SJiri Olsa | 14889efb029SJiri Olsa event 14989812fc8SJiri Olsa 150ac2ba9f3SRobert Richter event: event_mod 151ac2ba9f3SRobert Richter 152ac2ba9f3SRobert Richter event_mod: 153ac2ba9f3SRobert Richter event_name PE_MODIFIER_EVENT 15489812fc8SJiri Olsa { 15589efb029SJiri Olsa struct list_head *list = $1; 15646010ab2SJiri Olsa 1575d7be90eSJiri Olsa /* 1585d7be90eSJiri Olsa * Apply modifier on all events added by single event definition 1595d7be90eSJiri Olsa * (there could be more events added for multiple tracepoint 1605d7be90eSJiri Olsa * definitions via '*?'. 1615d7be90eSJiri Olsa */ 162f5b1135bSJiri Olsa ABORT_ON(parse_events__modifier_event(list, $2, false)); 16389efb029SJiri Olsa $$ = list; 16489812fc8SJiri Olsa } 16589812fc8SJiri Olsa | 166ac2ba9f3SRobert Richter event_name 167ac2ba9f3SRobert Richter 168ac2ba9f3SRobert Richter event_name: 169ac2ba9f3SRobert Richter PE_EVENT_NAME event_def 170ac2ba9f3SRobert Richter { 171ac2ba9f3SRobert Richter ABORT_ON(parse_events_name($2, $1)); 172ac2ba9f3SRobert Richter free($1); 173ac2ba9f3SRobert Richter $$ = $2; 174ac2ba9f3SRobert Richter } 175ac2ba9f3SRobert Richter | 17689812fc8SJiri Olsa event_def 17789812fc8SJiri Olsa 1785f537a26SJiri Olsa event_def: event_pmu | 1795f537a26SJiri Olsa event_legacy_symbol | 18089812fc8SJiri Olsa event_legacy_cache sep_dc | 18189812fc8SJiri Olsa event_legacy_mem | 18289812fc8SJiri Olsa event_legacy_tracepoint sep_dc | 18389812fc8SJiri Olsa event_legacy_numeric sep_dc | 18489812fc8SJiri Olsa event_legacy_raw sep_dc 18589812fc8SJiri Olsa 1865f537a26SJiri Olsa event_pmu: 1875f537a26SJiri Olsa PE_NAME '/' event_config '/' 1885f537a26SJiri Olsa { 189*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 190b847cbdcSJiri Olsa struct list_head *list = NULL; 191b847cbdcSJiri Olsa 19246010ab2SJiri Olsa ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3)); 1935f537a26SJiri Olsa parse_events__free_terms($3); 194b847cbdcSJiri Olsa $$ = list; 1955f537a26SJiri Olsa } 1965f537a26SJiri Olsa 197cf3506dcSJiri Olsa value_sym: 198cf3506dcSJiri Olsa PE_VALUE_SYM_HW 199cf3506dcSJiri Olsa | 200cf3506dcSJiri Olsa PE_VALUE_SYM_SW 201cf3506dcSJiri Olsa 20289812fc8SJiri Olsa event_legacy_symbol: 203cf3506dcSJiri Olsa value_sym '/' event_config '/' 20489812fc8SJiri Olsa { 205*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 206b847cbdcSJiri Olsa struct list_head *list = NULL; 20789812fc8SJiri Olsa int type = $1 >> 16; 20889812fc8SJiri Olsa int config = $1 & 255; 20989812fc8SJiri Olsa 21046010ab2SJiri Olsa ABORT_ON(parse_events_add_numeric(&list, &data->idx, 21146010ab2SJiri Olsa type, config, $3)); 2128f707d84SJiri Olsa parse_events__free_terms($3); 213b847cbdcSJiri Olsa $$ = list; 2148f707d84SJiri Olsa } 2158f707d84SJiri Olsa | 216cf3506dcSJiri Olsa value_sym sep_slash_dc 2178f707d84SJiri Olsa { 218*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 219b847cbdcSJiri Olsa struct list_head *list = NULL; 2208f707d84SJiri Olsa int type = $1 >> 16; 2218f707d84SJiri Olsa int config = $1 & 255; 2228f707d84SJiri Olsa 22346010ab2SJiri Olsa ABORT_ON(parse_events_add_numeric(&list, &data->idx, 22446010ab2SJiri Olsa type, config, NULL)); 225b847cbdcSJiri Olsa $$ = list; 22689812fc8SJiri Olsa } 22789812fc8SJiri Olsa 22889812fc8SJiri Olsa event_legacy_cache: 22989812fc8SJiri Olsa PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT 23089812fc8SJiri Olsa { 231*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 232b847cbdcSJiri Olsa struct list_head *list = NULL; 233b847cbdcSJiri Olsa 23446010ab2SJiri Olsa ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5)); 235b847cbdcSJiri Olsa $$ = list; 23689812fc8SJiri Olsa } 23789812fc8SJiri Olsa | 23889812fc8SJiri Olsa PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT 23989812fc8SJiri Olsa { 240*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 241b847cbdcSJiri Olsa struct list_head *list = NULL; 242b847cbdcSJiri Olsa 24346010ab2SJiri Olsa ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL)); 244b847cbdcSJiri Olsa $$ = list; 24589812fc8SJiri Olsa } 24689812fc8SJiri Olsa | 24789812fc8SJiri Olsa PE_NAME_CACHE_TYPE 24889812fc8SJiri Olsa { 249*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 250b847cbdcSJiri Olsa struct list_head *list = NULL; 251b847cbdcSJiri Olsa 25246010ab2SJiri Olsa ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL)); 253b847cbdcSJiri Olsa $$ = list; 25489812fc8SJiri Olsa } 25589812fc8SJiri Olsa 25689812fc8SJiri Olsa event_legacy_mem: 25789812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc 25889812fc8SJiri Olsa { 259*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 260b847cbdcSJiri Olsa struct list_head *list = NULL; 261b847cbdcSJiri Olsa 26246010ab2SJiri Olsa ABORT_ON(parse_events_add_breakpoint(&list, &data->idx, 26346010ab2SJiri Olsa (void *) $2, $4)); 264b847cbdcSJiri Olsa $$ = list; 26589812fc8SJiri Olsa } 26689812fc8SJiri Olsa | 26789812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE sep_dc 26889812fc8SJiri Olsa { 269*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 270b847cbdcSJiri Olsa struct list_head *list = NULL; 271b847cbdcSJiri Olsa 27246010ab2SJiri Olsa ABORT_ON(parse_events_add_breakpoint(&list, &data->idx, 27346010ab2SJiri Olsa (void *) $2, NULL)); 274b847cbdcSJiri Olsa $$ = list; 27589812fc8SJiri Olsa } 27689812fc8SJiri Olsa 27789812fc8SJiri Olsa event_legacy_tracepoint: 27889812fc8SJiri Olsa PE_NAME ':' PE_NAME 27989812fc8SJiri Olsa { 280*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 281b847cbdcSJiri Olsa struct list_head *list = NULL; 282b847cbdcSJiri Olsa 28346010ab2SJiri Olsa ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3)); 284b847cbdcSJiri Olsa $$ = list; 28589812fc8SJiri Olsa } 28689812fc8SJiri Olsa 28789812fc8SJiri Olsa event_legacy_numeric: 28889812fc8SJiri Olsa PE_VALUE ':' PE_VALUE 28989812fc8SJiri Olsa { 290*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 291b847cbdcSJiri Olsa struct list_head *list = NULL; 292b847cbdcSJiri Olsa 293b527bab5SRobert Richter ABORT_ON(parse_events_add_numeric(&list, &data->idx, (u32)$1, $3, NULL)); 294b847cbdcSJiri Olsa $$ = list; 29589812fc8SJiri Olsa } 29689812fc8SJiri Olsa 29789812fc8SJiri Olsa event_legacy_raw: 29889812fc8SJiri Olsa PE_RAW 29989812fc8SJiri Olsa { 300*23b6339bSArnaldo Carvalho de Melo struct parse_events_evlist *data = _data; 301b847cbdcSJiri Olsa struct list_head *list = NULL; 302b847cbdcSJiri Olsa 30346010ab2SJiri Olsa ABORT_ON(parse_events_add_numeric(&list, &data->idx, 30446010ab2SJiri Olsa PERF_TYPE_RAW, $1, NULL)); 305b847cbdcSJiri Olsa $$ = list; 3068f707d84SJiri Olsa } 3078f707d84SJiri Olsa 30889efb029SJiri Olsa start_terms: event_config 30990e2b22dSJiri Olsa { 310*23b6339bSArnaldo Carvalho de Melo struct parse_events_terms *data = _data; 31190e2b22dSJiri Olsa data->terms = $1; 31290e2b22dSJiri Olsa } 31390e2b22dSJiri Olsa 3148f707d84SJiri Olsa event_config: 3158f707d84SJiri Olsa event_config ',' event_term 3168f707d84SJiri Olsa { 3178f707d84SJiri Olsa struct list_head *head = $1; 3186cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term = $3; 3198f707d84SJiri Olsa 3208f707d84SJiri Olsa ABORT_ON(!head); 3218f707d84SJiri Olsa list_add_tail(&term->list, head); 3228f707d84SJiri Olsa $$ = $1; 3238f707d84SJiri Olsa } 3248f707d84SJiri Olsa | 3258f707d84SJiri Olsa event_term 3268f707d84SJiri Olsa { 3278f707d84SJiri Olsa struct list_head *head = malloc(sizeof(*head)); 3286cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term = $1; 3298f707d84SJiri Olsa 3308f707d84SJiri Olsa ABORT_ON(!head); 3318f707d84SJiri Olsa INIT_LIST_HEAD(head); 3328f707d84SJiri Olsa list_add_tail(&term->list, head); 3338f707d84SJiri Olsa $$ = head; 3348f707d84SJiri Olsa } 3358f707d84SJiri Olsa 3368f707d84SJiri Olsa event_term: 3378f707d84SJiri Olsa PE_NAME '=' PE_NAME 3388f707d84SJiri Olsa { 3396cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3408f707d84SJiri Olsa 3416cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 34216fa7e82SJiri Olsa $1, $3)); 3438f707d84SJiri Olsa $$ = term; 3448f707d84SJiri Olsa } 3458f707d84SJiri Olsa | 3468f707d84SJiri Olsa PE_NAME '=' PE_VALUE 3478f707d84SJiri Olsa { 3486cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3498f707d84SJiri Olsa 3506cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 35116fa7e82SJiri Olsa $1, $3)); 3528f707d84SJiri Olsa $$ = term; 3538f707d84SJiri Olsa } 3548f707d84SJiri Olsa | 3551d33d6dcSJiri Olsa PE_NAME '=' PE_VALUE_SYM_HW 3561d33d6dcSJiri Olsa { 3576cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3581d33d6dcSJiri Olsa int config = $3 & 255; 3591d33d6dcSJiri Olsa 3606cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__sym_hw(&term, $1, config)); 3611d33d6dcSJiri Olsa $$ = term; 3621d33d6dcSJiri Olsa } 3631d33d6dcSJiri Olsa | 3648f707d84SJiri Olsa PE_NAME 3658f707d84SJiri Olsa { 3666cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3678f707d84SJiri Olsa 3686cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 36916fa7e82SJiri Olsa $1, 1)); 3708f707d84SJiri Olsa $$ = term; 3718f707d84SJiri Olsa } 3728f707d84SJiri Olsa | 3731d33d6dcSJiri Olsa PE_VALUE_SYM_HW 3741d33d6dcSJiri Olsa { 3756cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3761d33d6dcSJiri Olsa int config = $1 & 255; 3771d33d6dcSJiri Olsa 3786cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); 3791d33d6dcSJiri Olsa $$ = term; 3801d33d6dcSJiri Olsa } 3811d33d6dcSJiri Olsa | 3826b5fc39bSJiri Olsa PE_TERM '=' PE_NAME 3836b5fc39bSJiri Olsa { 3846cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3856b5fc39bSJiri Olsa 3866cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3)); 3876b5fc39bSJiri Olsa $$ = term; 3886b5fc39bSJiri Olsa } 3896b5fc39bSJiri Olsa | 3908f707d84SJiri Olsa PE_TERM '=' PE_VALUE 3918f707d84SJiri Olsa { 3926cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 3938f707d84SJiri Olsa 3946cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3)); 3958f707d84SJiri Olsa $$ = term; 3968f707d84SJiri Olsa } 3978f707d84SJiri Olsa | 3988f707d84SJiri Olsa PE_TERM 3998f707d84SJiri Olsa { 4006cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 4018f707d84SJiri Olsa 4026cee6cd3SArnaldo Carvalho de Melo ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1)); 4038f707d84SJiri Olsa $$ = term; 40489812fc8SJiri Olsa } 40589812fc8SJiri Olsa 40689812fc8SJiri Olsa sep_dc: ':' | 40789812fc8SJiri Olsa 4088f707d84SJiri Olsa sep_slash_dc: '/' | ':' | 4098f707d84SJiri Olsa 41089812fc8SJiri Olsa %% 41189812fc8SJiri Olsa 4121d037ca1SIrina Tirdea void parse_events_error(void *data __maybe_unused, void *scanner __maybe_unused, 4131d037ca1SIrina Tirdea char const *msg __maybe_unused) 41489812fc8SJiri Olsa { 41589812fc8SJiri Olsa } 416