1 %define api.pure full !! 1 %pure-parser 2 %parse-param {void *_parse_state} !! 2 %parse-param {void *_data} 3 %parse-param {void *scanner} 3 %parse-param {void *scanner} 4 %lex-param {void* scanner} 4 %lex-param {void* scanner} 5 %locations 5 %locations 6 6 7 %{ 7 %{ 8 8 9 #ifndef NDEBUG << 10 #define YYDEBUG 1 9 #define YYDEBUG 1 11 #endif << 12 10 13 #include <errno.h> << 14 #include <linux/compiler.h> 11 #include <linux/compiler.h> >> 12 #include <linux/list.h> 15 #include <linux/types.h> 13 #include <linux/types.h> 16 #include "pmu.h" !! 14 #include "util.h" 17 #include "pmus.h" << 18 #include "evsel.h" << 19 #include "parse-events.h" 15 #include "parse-events.h" 20 #include "parse-events-bison.h" 16 #include "parse-events-bison.h" 21 17 22 int parse_events_lex(YYSTYPE * yylval_param, Y !! 18 #define ABORT_ON(val) \ 23 void parse_events_error(YYLTYPE *loc, void *pa !! 19 do { \ >> 20 if (val) \ >> 21 YYABORT; \ >> 22 } while (0) 24 23 25 #define PE_ABORT(val) \ !! 24 #define ALLOC_LIST(list) \ 26 do { \ 25 do { \ 27 if (val == -ENOMEM) \ !! 26 list = malloc(sizeof(*list)); \ 28 YYNOMEM; \ !! 27 ABORT_ON(!list); \ 29 YYABORT; \ !! 28 INIT_LIST_HEAD(list); \ 30 } while (0) 29 } while (0) 31 30 32 static struct list_head* alloc_list(void) !! 31 static void inc_group_count(struct list_head *list, >> 32 struct parse_events_evlist *data) 33 { 33 { 34 struct list_head *list; !! 34 /* Count groups only have more than 1 members */ 35 !! 35 if (!list_is_last(list->next, list)) 36 list = malloc(sizeof(*list)); !! 36 data->nr_groups++; 37 if (!list) << 38 return NULL; << 39 << 40 INIT_LIST_HEAD(list); << 41 return list; << 42 } << 43 << 44 static void free_list_evsel(struct list_head* << 45 { << 46 struct evsel *evsel, *tmp; << 47 << 48 list_for_each_entry_safe(evsel, tmp, l << 49 list_del_init(&evsel->core.nod << 50 evsel__delete(evsel); << 51 } << 52 free(list_evsel); << 53 } 37 } 54 38 55 %} 39 %} 56 40 57 %token PE_START_EVENTS PE_START_TERMS 41 %token PE_START_EVENTS PE_START_TERMS 58 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_S !! 42 %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM 59 %token PE_VALUE_SYM_TOOL << 60 %token PE_EVENT_NAME 43 %token PE_EVENT_NAME 61 %token PE_RAW PE_NAME !! 44 %token PE_NAME 62 %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_ !! 45 %token PE_BPF_OBJECT PE_BPF_SOURCE 63 %token PE_LEGACY_CACHE !! 46 %token PE_MODIFIER_EVENT PE_MODIFIER_BP 64 %token PE_PREFIX_MEM !! 47 %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT >> 48 %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP 65 %token PE_ERROR 49 %token PE_ERROR >> 50 %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT >> 51 %token PE_ARRAY_ALL PE_ARRAY_RANGE 66 %token PE_DRV_CFG_TERM 52 %token PE_DRV_CFG_TERM 67 %token PE_TERM_HW << 68 %type <num> PE_VALUE 53 %type <num> PE_VALUE 69 %type <num> PE_VALUE_SYM_HW 54 %type <num> PE_VALUE_SYM_HW 70 %type <num> PE_VALUE_SYM_SW 55 %type <num> PE_VALUE_SYM_SW 71 %type <num> PE_VALUE_SYM_TOOL !! 56 %type <num> PE_RAW 72 %type <mod> PE_MODIFIER_EVENT !! 57 %type <num> PE_TERM 73 %type <term_type> PE_TERM << 74 %type <num> value_sym << 75 %type <str> PE_RAW << 76 %type <str> PE_NAME 58 %type <str> PE_NAME 77 %type <str> PE_LEGACY_CACHE !! 59 %type <str> PE_BPF_OBJECT >> 60 %type <str> PE_BPF_SOURCE >> 61 %type <str> PE_NAME_CACHE_TYPE >> 62 %type <str> PE_NAME_CACHE_OP_RESULT >> 63 %type <str> PE_MODIFIER_EVENT 78 %type <str> PE_MODIFIER_BP 64 %type <str> PE_MODIFIER_BP 79 %type <str> PE_EVENT_NAME 65 %type <str> PE_EVENT_NAME >> 66 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT 80 %type <str> PE_DRV_CFG_TERM 67 %type <str> PE_DRV_CFG_TERM 81 %type <str> name_or_raw !! 68 %type <num> value_sym 82 %destructor { free ($$); } <str> !! 69 %type <head> event_config >> 70 %type <head> opt_event_config 83 %type <term> event_term 71 %type <term> event_term 84 %destructor { parse_events_term__delete ($$); !! 72 %type <head> event_pmu 85 %type <list_terms> event_config !! 73 %type <head> event_legacy_symbol 86 %type <list_terms> opt_event_config !! 74 %type <head> event_legacy_cache 87 %type <list_terms> opt_pmu_config !! 75 %type <head> event_legacy_mem 88 %destructor { parse_events_terms__delete ($$); !! 76 %type <head> event_legacy_tracepoint 89 %type <list_evsel> event_pmu << 90 %type <list_evsel> event_legacy_symbol << 91 %type <list_evsel> event_legacy_cache << 92 %type <list_evsel> event_legacy_mem << 93 %type <list_evsel> event_legacy_tracepoint << 94 %type <list_evsel> event_legacy_numeric << 95 %type <list_evsel> event_legacy_raw << 96 %type <list_evsel> event_def << 97 %type <list_evsel> event_mod << 98 %type <list_evsel> event_name << 99 %type <list_evsel> event << 100 %type <list_evsel> events << 101 %type <list_evsel> group_def << 102 %type <list_evsel> group << 103 %type <list_evsel> groups << 104 %destructor { free_list_evsel ($$); } <list_ev << 105 %type <tracepoint_name> tracepoint_name 77 %type <tracepoint_name> tracepoint_name 106 %destructor { free ($$.sys); free ($$.event); !! 78 %type <head> event_legacy_numeric 107 %type <hardware_term> PE_TERM_HW !! 79 %type <head> event_legacy_raw 108 %destructor { free ($$.str); } <hardware_term> !! 80 %type <head> event_bpf_file >> 81 %type <head> event_def >> 82 %type <head> event_mod >> 83 %type <head> event_name >> 84 %type <head> event >> 85 %type <head> events >> 86 %type <head> group_def >> 87 %type <head> group >> 88 %type <head> groups >> 89 %type <array> array >> 90 %type <array> array_term >> 91 %type <array> array_terms 109 92 110 %union 93 %union 111 { 94 { 112 char *str; 95 char *str; 113 u64 num; 96 u64 num; 114 struct parse_events_modifier mod; !! 97 struct list_head *head; 115 enum parse_events__term_type term_type << 116 struct list_head *list_evsel; << 117 struct parse_events_terms *list_terms; << 118 struct parse_events_term *term; 98 struct parse_events_term *term; 119 struct tracepoint_name { 99 struct tracepoint_name { 120 char *sys; 100 char *sys; 121 char *event; 101 char *event; 122 } tracepoint_name; 102 } tracepoint_name; 123 struct hardware_term { !! 103 struct parse_events_array array; 124 char *str; << 125 u64 num; << 126 } hardware_term; << 127 } 104 } 128 %% 105 %% 129 106 130 /* << 131 * Entry points. We are either parsing events << 132 * parsing is used for parsing events in sysf << 133 */ << 134 start: 107 start: 135 PE_START_EVENTS start_events 108 PE_START_EVENTS start_events 136 | 109 | 137 PE_START_TERMS start_terms 110 PE_START_TERMS start_terms 138 111 139 start_events: groups 112 start_events: groups 140 { 113 { 141 /* Take the parsed events, groups.. an !! 114 struct parse_events_evlist *data = _data; 142 struct list_head *groups = $1; << 143 struct parse_events_state *parse_state << 144 115 145 list_splice_tail(groups, &parse_state- !! 116 parse_events_update_lists($1, &data->list); 146 free(groups); << 147 } 117 } 148 118 149 groups: /* A list of groups or events. */ !! 119 groups: 150 groups ',' group 120 groups ',' group 151 { 121 { 152 /* Merge group into the list of events !! 122 struct list_head *list = $1; 153 struct list_head *groups = $1; !! 123 struct list_head *group = $3; 154 struct list_head *group = $3; !! 124 155 !! 125 parse_events_update_lists(group, list); 156 list_splice_tail(group, groups); !! 126 $$ = list; 157 free(group); << 158 $$ = groups; << 159 } 127 } 160 | 128 | 161 groups ',' event 129 groups ',' event 162 { 130 { 163 /* Merge event into the list of events !! 131 struct list_head *list = $1; 164 struct list_head *groups = $1; << 165 struct list_head *event = $3; 132 struct list_head *event = $3; 166 133 167 !! 134 parse_events_update_lists(event, list); 168 list_splice_tail(event, groups); !! 135 $$ = list; 169 free(event); << 170 $$ = groups; << 171 } 136 } 172 | 137 | 173 group 138 group 174 | 139 | 175 event 140 event 176 141 177 group: 142 group: 178 group_def ':' PE_MODIFIER_EVENT 143 group_def ':' PE_MODIFIER_EVENT 179 { 144 { 180 /* Apply the modifier to the events in << 181 struct list_head *list = $1; 145 struct list_head *list = $1; 182 int err; << 183 146 184 err = parse_events__modifier_group(_pa !! 147 ABORT_ON(parse_events__modifier_group(list, $3)); 185 if (err) << 186 YYABORT; << 187 $$ = list; 148 $$ = list; 188 } 149 } 189 | 150 | 190 group_def 151 group_def 191 152 192 group_def: 153 group_def: 193 PE_NAME '{' events '}' 154 PE_NAME '{' events '}' 194 { 155 { 195 struct list_head *list = $3; 156 struct list_head *list = $3; 196 157 197 /* !! 158 inc_group_count(list, _data); 198 * Set the first entry of list to be t << 199 * the leader to $1 taking ownership. << 200 */ << 201 parse_events__set_leader($1, list); 159 parse_events__set_leader($1, list); 202 $$ = list; 160 $$ = list; 203 } 161 } 204 | 162 | 205 '{' events '}' 163 '{' events '}' 206 { 164 { 207 struct list_head *list = $2; 165 struct list_head *list = $2; 208 166 209 /* Set the first entry of list to be t !! 167 inc_group_count(list, _data); 210 parse_events__set_leader(NULL, list); 168 parse_events__set_leader(NULL, list); 211 $$ = list; 169 $$ = list; 212 } 170 } 213 171 214 events: 172 events: 215 events ',' event 173 events ',' event 216 { 174 { 217 struct list_head *events = $1; << 218 struct list_head *event = $3; 175 struct list_head *event = $3; >> 176 struct list_head *list = $1; 219 177 220 list_splice_tail(event, events); !! 178 parse_events_update_lists(event, list); 221 free(event); !! 179 $$ = list; 222 $$ = events; << 223 } 180 } 224 | 181 | 225 event 182 event 226 183 227 event: event_mod 184 event: event_mod 228 185 229 event_mod: 186 event_mod: 230 event_name PE_MODIFIER_EVENT 187 event_name PE_MODIFIER_EVENT 231 { 188 { 232 struct list_head *list = $1; 189 struct list_head *list = $1; 233 int err; << 234 190 235 /* 191 /* 236 * Apply modifier on all events added 192 * Apply modifier on all events added by single event definition 237 * (there could be more events added f 193 * (there could be more events added for multiple tracepoint 238 * definitions via '*?'. 194 * definitions via '*?'. 239 */ 195 */ 240 err = parse_events__modifier_event(_pa !! 196 ABORT_ON(parse_events__modifier_event(list, $2, false)); 241 if (err) << 242 YYABORT; << 243 $$ = list; 197 $$ = list; 244 } 198 } 245 | 199 | 246 event_name 200 event_name 247 201 248 event_name: 202 event_name: 249 PE_EVENT_NAME event_def 203 PE_EVENT_NAME event_def 250 { 204 { 251 /* !! 205 ABORT_ON(parse_events_name($2, $1)); 252 * When an event is parsed the text is !! 206 free($1); 253 * the event is set to the str of PE_E << 254 * no name was on an event via a term, << 255 * taking ownership of the allocation. << 256 */ << 257 int err = parse_events__set_default_na << 258 << 259 if (err) { << 260 free_list_evsel($2); << 261 YYNOMEM; << 262 } << 263 $$ = $2; 207 $$ = $2; 264 } 208 } 265 | 209 | 266 event_def 210 event_def 267 211 268 event_def: event_pmu | 212 event_def: event_pmu | 269 event_legacy_symbol | 213 event_legacy_symbol | 270 event_legacy_cache sep_dc | 214 event_legacy_cache sep_dc | 271 event_legacy_mem sep_dc | !! 215 event_legacy_mem | 272 event_legacy_tracepoint sep_dc | 216 event_legacy_tracepoint sep_dc | 273 event_legacy_numeric sep_dc | 217 event_legacy_numeric sep_dc | 274 event_legacy_raw sep_dc !! 218 event_legacy_raw sep_dc | >> 219 event_bpf_file 275 220 276 event_pmu: 221 event_pmu: 277 PE_NAME opt_pmu_config !! 222 PE_NAME opt_event_config 278 { 223 { 279 /* List of created evsels. */ !! 224 struct parse_events_evlist *data = _data; 280 struct list_head *list = NULL; !! 225 struct list_head *list; 281 int err = parse_events_multi_pmu_add_o << 282 226 >> 227 ALLOC_LIST(list); >> 228 ABORT_ON(parse_events_add_pmu(data, list, $1, $2)); 283 parse_events_terms__delete($2); 229 parse_events_terms__delete($2); 284 free($1); << 285 if (err) << 286 PE_ABORT(err); << 287 $$ = list; 230 $$ = list; 288 } 231 } 289 | 232 | 290 PE_NAME sep_dc !! 233 PE_KERNEL_PMU_EVENT sep_dc 291 { 234 { >> 235 struct parse_events_evlist *data = _data; >> 236 struct list_head *head; >> 237 struct parse_events_term *term; 292 struct list_head *list; 238 struct list_head *list; 293 int err; << 294 239 295 err = parse_events_multi_pmu_add(_pars !! 240 ALLOC_LIST(head); 296 if (err < 0) { !! 241 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 297 struct parse_events_state *par !! 242 $1, 1, &@1, NULL)); 298 struct parse_events_error *err !! 243 list_add_tail(&term->list, head); 299 char *help; << 300 244 301 if (asprintf(&help, "Unable to !! 245 ALLOC_LIST(list); 302 help = NULL; !! 246 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); 303 parse_events_error__handle(err !! 247 parse_events_terms__delete(head); 304 free($1); !! 248 $$ = list; 305 PE_ABORT(err); !! 249 } 306 } !! 250 | 307 free($1); !! 251 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc >> 252 { >> 253 struct parse_events_evlist *data = _data; >> 254 struct list_head *head; >> 255 struct parse_events_term *term; >> 256 struct list_head *list; >> 257 char pmu_name[128]; >> 258 snprintf(&pmu_name, 128, "%s-%s", $1, $3); >> 259 >> 260 ALLOC_LIST(head); >> 261 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 262 &pmu_name, 1, &@1, NULL)); >> 263 list_add_tail(&term->list, head); >> 264 >> 265 ALLOC_LIST(list); >> 266 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); >> 267 parse_events_terms__delete(head); 308 $$ = list; 268 $$ = list; 309 } 269 } 310 270 311 value_sym: 271 value_sym: 312 PE_VALUE_SYM_HW 272 PE_VALUE_SYM_HW 313 | 273 | 314 PE_VALUE_SYM_SW 274 PE_VALUE_SYM_SW 315 275 316 event_legacy_symbol: 276 event_legacy_symbol: 317 value_sym '/' event_config '/' 277 value_sym '/' event_config '/' 318 { 278 { >> 279 struct parse_events_evlist *data = _data; 319 struct list_head *list; 280 struct list_head *list; 320 int type = $1 >> 16; 281 int type = $1 >> 16; 321 int config = $1 & 255; 282 int config = $1 & 255; 322 int err; << 323 bool wildcard = (type == PERF_TYPE_HAR << 324 283 325 list = alloc_list(); !! 284 ALLOC_LIST(list); 326 if (!list) !! 285 ABORT_ON(parse_events_add_numeric(data, list, type, config, $3)); 327 YYNOMEM; << 328 err = parse_events_add_numeric(_parse_ << 329 parse_events_terms__delete($3); 286 parse_events_terms__delete($3); 330 if (err) { << 331 free_list_evsel(list); << 332 PE_ABORT(err); << 333 } << 334 $$ = list; 287 $$ = list; 335 } 288 } 336 | 289 | 337 value_sym sep_slash_slash_dc !! 290 value_sym sep_slash_dc 338 { 291 { >> 292 struct parse_events_evlist *data = _data; 339 struct list_head *list; 293 struct list_head *list; 340 int type = $1 >> 16; 294 int type = $1 >> 16; 341 int config = $1 & 255; 295 int config = $1 & 255; 342 bool wildcard = (type == PERF_TYPE_HAR << 343 int err; << 344 296 345 list = alloc_list(); !! 297 ALLOC_LIST(list); 346 if (!list) !! 298 ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL)); 347 YYNOMEM; << 348 err = parse_events_add_numeric(_parse_ << 349 if (err) << 350 PE_ABORT(err); << 351 $$ = list; 299 $$ = list; 352 } 300 } 353 | !! 301 354 PE_VALUE_SYM_TOOL sep_slash_slash_dc !! 302 event_legacy_cache: >> 303 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config 355 { 304 { >> 305 struct parse_events_evlist *data = _data; >> 306 struct parse_events_error *error = data->error; 356 struct list_head *list; 307 struct list_head *list; 357 int err; << 358 308 359 list = alloc_list(); !! 309 ALLOC_LIST(list); 360 if (!list) !! 310 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6)); 361 YYNOMEM; !! 311 parse_events_terms__delete($6); 362 err = parse_events_add_tool(_parse_sta << 363 if (err) << 364 YYNOMEM; << 365 $$ = list; 312 $$ = list; 366 } 313 } 367 !! 314 | 368 event_legacy_cache: !! 315 PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config 369 PE_LEGACY_CACHE opt_event_config << 370 { 316 { 371 struct parse_events_state *parse_state !! 317 struct parse_events_evlist *data = _data; >> 318 struct parse_events_error *error = data->error; 372 struct list_head *list; 319 struct list_head *list; 373 int err; << 374 320 375 list = alloc_list(); !! 321 ALLOC_LIST(list); 376 if (!list) !! 322 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4)); 377 YYNOMEM; !! 323 parse_events_terms__delete($4); 378 !! 324 $$ = list; 379 err = parse_events_add_cache(list, &pa !! 325 } >> 326 | >> 327 PE_NAME_CACHE_TYPE opt_event_config >> 328 { >> 329 struct parse_events_evlist *data = _data; >> 330 struct parse_events_error *error = data->error; >> 331 struct list_head *list; 380 332 >> 333 ALLOC_LIST(list); >> 334 ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2)); 381 parse_events_terms__delete($2); 335 parse_events_terms__delete($2); 382 free($1); << 383 if (err) { << 384 free_list_evsel(list); << 385 PE_ABORT(err); << 386 } << 387 $$ = list; 336 $$ = list; 388 } 337 } 389 338 390 event_legacy_mem: 339 event_legacy_mem: 391 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE !! 340 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc 392 { 341 { >> 342 struct parse_events_evlist *data = _data; 393 struct list_head *list; 343 struct list_head *list; 394 int err; << 395 << 396 list = alloc_list(); << 397 if (!list) << 398 YYNOMEM; << 399 344 400 err = parse_events_add_breakpoint(_par !! 345 ALLOC_LIST(list); 401 $2, !! 346 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 402 parse_events_terms__delete($7); !! 347 (void *) $2, $6, $4)); 403 free($6); << 404 if (err) { << 405 free(list); << 406 PE_ABORT(err); << 407 } << 408 $$ = list; 348 $$ = list; 409 } 349 } 410 | 350 | 411 PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE op !! 351 PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc 412 { 352 { >> 353 struct parse_events_evlist *data = _data; 413 struct list_head *list; 354 struct list_head *list; 414 int err; << 415 355 416 list = alloc_list(); !! 356 ALLOC_LIST(list); 417 if (!list) !! 357 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 418 YYNOMEM; !! 358 (void *) $2, NULL, $4)); 419 << 420 err = parse_events_add_breakpoint(_par << 421 $2, << 422 parse_events_terms__delete($5); << 423 if (err) { << 424 free(list); << 425 PE_ABORT(err); << 426 } << 427 $$ = list; 359 $$ = list; 428 } 360 } 429 | 361 | 430 PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER !! 362 PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc 431 { 363 { >> 364 struct parse_events_evlist *data = _data; 432 struct list_head *list; 365 struct list_head *list; 433 int err; << 434 << 435 list = alloc_list(); << 436 if (!list) << 437 YYNOMEM; << 438 366 439 err = parse_events_add_breakpoint(_par !! 367 ALLOC_LIST(list); 440 $2, !! 368 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 441 parse_events_terms__delete($5); !! 369 (void *) $2, $4, 0)); 442 free($4); << 443 if (err) { << 444 free(list); << 445 PE_ABORT(err); << 446 } << 447 $$ = list; 370 $$ = list; 448 } 371 } 449 | 372 | 450 PE_PREFIX_MEM PE_VALUE opt_event_config !! 373 PE_PREFIX_MEM PE_VALUE sep_dc 451 { 374 { >> 375 struct parse_events_evlist *data = _data; 452 struct list_head *list; 376 struct list_head *list; 453 int err; << 454 377 455 list = alloc_list(); !! 378 ALLOC_LIST(list); 456 if (!list) !! 379 ABORT_ON(parse_events_add_breakpoint(list, &data->idx, 457 YYNOMEM; !! 380 (void *) $2, NULL, 0)); 458 err = parse_events_add_breakpoint(_par << 459 $2, << 460 parse_events_terms__delete($3); << 461 if (err) { << 462 free(list); << 463 PE_ABORT(err); << 464 } << 465 $$ = list; 381 $$ = list; 466 } 382 } 467 383 468 event_legacy_tracepoint: 384 event_legacy_tracepoint: 469 tracepoint_name opt_event_config 385 tracepoint_name opt_event_config 470 { 386 { 471 struct parse_events_state *parse_state !! 387 struct parse_events_evlist *data = _data; 472 struct parse_events_error *error = par !! 388 struct parse_events_error *error = data->error; 473 struct list_head *list; 389 struct list_head *list; 474 int err; << 475 390 476 list = alloc_list(); !! 391 ALLOC_LIST(list); 477 if (!list) !! 392 if (error) 478 YYNOMEM; !! 393 error->idx = @1.first_column; 479 394 480 err = parse_events_add_tracepoint(pars !! 395 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event, 481 error, !! 396 error, $2)) >> 397 return -1; 482 398 483 parse_events_terms__delete($2); << 484 free($1.sys); << 485 free($1.event); << 486 if (err) { << 487 free(list); << 488 PE_ABORT(err); << 489 } << 490 $$ = list; 399 $$ = list; 491 } 400 } 492 401 493 tracepoint_name: 402 tracepoint_name: >> 403 PE_NAME '-' PE_NAME ':' PE_NAME >> 404 { >> 405 char sys_name[128]; >> 406 struct tracepoint_name tracepoint; >> 407 >> 408 snprintf(&sys_name, 128, "%s-%s", $1, $3); >> 409 tracepoint.sys = &sys_name; >> 410 tracepoint.event = $5; >> 411 >> 412 $$ = tracepoint; >> 413 } >> 414 | 494 PE_NAME ':' PE_NAME 415 PE_NAME ':' PE_NAME 495 { 416 { 496 struct tracepoint_name tracepoint = {$ 417 struct tracepoint_name tracepoint = {$1, $3}; 497 418 498 $$ = tracepoint; 419 $$ = tracepoint; 499 } 420 } 500 421 501 event_legacy_numeric: 422 event_legacy_numeric: 502 PE_VALUE ':' PE_VALUE opt_event_config 423 PE_VALUE ':' PE_VALUE opt_event_config 503 { 424 { >> 425 struct parse_events_evlist *data = _data; 504 struct list_head *list; 426 struct list_head *list; 505 int err; << 506 427 507 list = alloc_list(); !! 428 ALLOC_LIST(list); 508 if (!list) !! 429 ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4)); 509 YYNOMEM; << 510 err = parse_events_add_numeric(_parse_ << 511 /*wildc << 512 parse_events_terms__delete($4); 430 parse_events_terms__delete($4); 513 if (err) { << 514 free(list); << 515 PE_ABORT(err); << 516 } << 517 $$ = list; 431 $$ = list; 518 } 432 } 519 433 520 event_legacy_raw: 434 event_legacy_raw: 521 PE_RAW opt_event_config 435 PE_RAW opt_event_config 522 { 436 { >> 437 struct parse_events_evlist *data = _data; 523 struct list_head *list; 438 struct list_head *list; 524 int err; << 525 u64 num; << 526 439 527 list = alloc_list(); !! 440 ALLOC_LIST(list); 528 if (!list) !! 441 ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2)); 529 YYNOMEM; << 530 errno = 0; << 531 num = strtoull($1 + 1, NULL, 16); << 532 /* Given the lexer will only give [a-f << 533 if (errno) << 534 YYABORT; << 535 free($1); << 536 err = parse_events_add_numeric(_parse_ << 537 /*wildc << 538 parse_events_terms__delete($2); 442 parse_events_terms__delete($2); 539 if (err) { << 540 free(list); << 541 PE_ABORT(err); << 542 } << 543 $$ = list; 443 $$ = list; 544 } 444 } 545 445 546 opt_event_config: !! 446 event_bpf_file: 547 '/' event_config '/' !! 447 PE_BPF_OBJECT opt_event_config 548 { << 549 $$ = $2; << 550 } << 551 | << 552 '/' '/' << 553 { 448 { 554 $$ = NULL; !! 449 struct parse_events_evlist *data = _data; >> 450 struct parse_events_error *error = data->error; >> 451 struct list_head *list; >> 452 >> 453 ALLOC_LIST(list); >> 454 ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2)); >> 455 parse_events_terms__delete($2); >> 456 $$ = list; 555 } 457 } 556 | 458 | >> 459 PE_BPF_SOURCE opt_event_config 557 { 460 { 558 $$ = NULL; !! 461 struct parse_events_evlist *data = _data; >> 462 struct list_head *list; >> 463 >> 464 ALLOC_LIST(list); >> 465 ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2)); >> 466 parse_events_terms__delete($2); >> 467 $$ = list; 559 } 468 } 560 469 561 opt_pmu_config: !! 470 opt_event_config: 562 '/' event_config '/' 471 '/' event_config '/' 563 { 472 { 564 $$ = $2; 473 $$ = $2; 565 } 474 } 566 | 475 | 567 '/' '/' 476 '/' '/' 568 { 477 { 569 $$ = NULL; 478 $$ = NULL; 570 } 479 } >> 480 | >> 481 { >> 482 $$ = NULL; >> 483 } 571 484 572 start_terms: event_config 485 start_terms: event_config 573 { 486 { 574 struct parse_events_state *parse_state !! 487 struct parse_events_terms *data = _data; 575 if (parse_state->terms) { !! 488 data->terms = $1; 576 parse_events_terms__delete ($1 << 577 YYABORT; << 578 } << 579 parse_state->terms = $1; << 580 } 489 } 581 490 582 event_config: 491 event_config: 583 event_config ',' event_term 492 event_config ',' event_term 584 { 493 { 585 struct parse_events_terms *head = $1; !! 494 struct list_head *head = $1; 586 struct parse_events_term *term = $3; 495 struct parse_events_term *term = $3; 587 496 588 if (!head) { !! 497 ABORT_ON(!head); 589 parse_events_term__delete(term !! 498 list_add_tail(&term->list, head); 590 YYABORT; << 591 } << 592 list_add_tail(&term->list, &head->term << 593 $$ = $1; 499 $$ = $1; 594 } 500 } 595 | 501 | 596 event_term 502 event_term 597 { 503 { 598 struct parse_events_terms *head = mall !! 504 struct list_head *head = malloc(sizeof(*head)); 599 struct parse_events_term *term = $1; 505 struct parse_events_term *term = $1; 600 506 601 if (!head) !! 507 ABORT_ON(!head); 602 YYNOMEM; !! 508 INIT_LIST_HEAD(head); 603 parse_events_terms__init(head); !! 509 list_add_tail(&term->list, head); 604 list_add_tail(&term->list, &head->term << 605 $$ = head; 510 $$ = head; 606 } 511 } 607 512 608 name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACH << 609 | << 610 PE_TERM_HW << 611 { << 612 $$ = $1.str; << 613 } << 614 << 615 event_term: 513 event_term: 616 PE_RAW !! 514 PE_NAME '=' PE_NAME 617 { 515 { 618 struct parse_events_term *term; 516 struct parse_events_term *term; 619 int err = parse_events_term__str(&term << 620 strdu << 621 517 622 if (err) { !! 518 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 623 free($1); !! 519 $1, $3, &@1, &@3)); 624 PE_ABORT(err); << 625 } << 626 $$ = term; 520 $$ = term; 627 } 521 } 628 | 522 | 629 name_or_raw '=' name_or_raw !! 523 PE_NAME '=' PE_VALUE 630 { 524 { 631 struct parse_events_term *term; 525 struct parse_events_term *term; 632 int err = parse_events_term__str(&term << 633 526 634 if (err) { !! 527 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 635 free($1); !! 528 $1, $3, &@1, &@3)); 636 free($3); << 637 PE_ABORT(err); << 638 } << 639 $$ = term; 529 $$ = term; 640 } 530 } 641 | 531 | 642 name_or_raw '=' PE_VALUE !! 532 PE_NAME '=' PE_VALUE_SYM_HW 643 { 533 { 644 struct parse_events_term *term; 534 struct parse_events_term *term; 645 int err = parse_events_term__num(&term !! 535 int config = $3 & 255; 646 $1, $ << 647 536 648 if (err) { !! 537 ABORT_ON(parse_events_term__sym_hw(&term, $1, config)); 649 free($1); << 650 PE_ABORT(err); << 651 } << 652 $$ = term; 538 $$ = term; 653 } 539 } 654 | 540 | 655 PE_LEGACY_CACHE !! 541 PE_NAME 656 { 542 { 657 struct parse_events_term *term; 543 struct parse_events_term *term; 658 int err = parse_events_term__num(&term << 659 $1, / << 660 544 661 if (err) { !! 545 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 662 free($1); !! 546 $1, 1, &@1, NULL)); 663 PE_ABORT(err); << 664 } << 665 $$ = term; 547 $$ = term; 666 } 548 } 667 | 549 | 668 PE_NAME !! 550 PE_VALUE_SYM_HW 669 { 551 { 670 struct parse_events_term *term; 552 struct parse_events_term *term; 671 int err = parse_events_term__num(&term !! 553 int config = $1 & 255; 672 $1, / << 673 554 674 if (err) { !! 555 ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); 675 free($1); << 676 PE_ABORT(err); << 677 } << 678 $$ = term; 556 $$ = term; 679 } 557 } 680 | 558 | 681 PE_TERM_HW !! 559 PE_TERM '=' PE_NAME 682 { 560 { 683 struct parse_events_term *term; 561 struct parse_events_term *term; 684 int err = parse_events_term__num(&term << 685 $1.st << 686 &@1, << 687 562 688 if (err) { !! 563 ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); 689 free($1.str); << 690 PE_ABORT(err); << 691 } << 692 $$ = term; 564 $$ = term; 693 } 565 } 694 | 566 | 695 PE_TERM '=' name_or_raw !! 567 PE_TERM '=' PE_VALUE 696 { 568 { 697 struct parse_events_term *term; 569 struct parse_events_term *term; 698 int err = parse_events_term__str(&term << 699 570 700 if (err) { !! 571 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3)); 701 free($3); << 702 PE_ABORT(err); << 703 } << 704 $$ = term; 572 $$ = term; 705 } 573 } 706 | 574 | 707 PE_TERM '=' PE_TERM !! 575 PE_TERM 708 { 576 { 709 struct parse_events_term *term; 577 struct parse_events_term *term; 710 int err = parse_events_term__term(&ter << 711 << 712 if (err) << 713 PE_ABORT(err); << 714 578 >> 579 ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL)); 715 $$ = term; 580 $$ = term; 716 } 581 } 717 | 582 | 718 PE_TERM '=' PE_VALUE !! 583 PE_NAME array '=' PE_NAME 719 { 584 { 720 struct parse_events_term *term; 585 struct parse_events_term *term; 721 int err = parse_events_term__num(&term !! 586 int i; 722 /*con << 723 &@1, << 724 587 725 if (err) !! 588 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 726 PE_ABORT(err); !! 589 $1, $4, &@1, &@4)); 727 590 >> 591 term->array = $2; 728 $$ = term; 592 $$ = term; 729 } 593 } 730 | 594 | 731 PE_TERM !! 595 PE_NAME array '=' PE_VALUE 732 { 596 { 733 struct parse_events_term *term; 597 struct parse_events_term *term; 734 int err = parse_events_term__num(&term << 735 /*con << 736 &@1, << 737 << 738 if (err) << 739 PE_ABORT(err); << 740 598 >> 599 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, >> 600 $1, $4, &@1, &@4)); >> 601 term->array = $2; 741 $$ = term; 602 $$ = term; 742 } 603 } 743 | 604 | 744 PE_DRV_CFG_TERM 605 PE_DRV_CFG_TERM 745 { 606 { 746 struct parse_events_term *term; 607 struct parse_events_term *term; 747 char *config = strdup($1); << 748 int err; << 749 608 750 if (!config) !! 609 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, 751 YYNOMEM; !! 610 $1, $1, &@1, NULL)); 752 err = parse_events_term__str(&term, PA << 753 if (err) { << 754 free($1); << 755 free(config); << 756 PE_ABORT(err); << 757 } << 758 $$ = term; 611 $$ = term; 759 } 612 } 760 613 >> 614 array: >> 615 '[' array_terms ']' >> 616 { >> 617 $$ = $2; >> 618 } >> 619 | >> 620 PE_ARRAY_ALL >> 621 { >> 622 $$.nr_ranges = 0; >> 623 $$.ranges = NULL; >> 624 } >> 625 >> 626 array_terms: >> 627 array_terms ',' array_term >> 628 { >> 629 struct parse_events_array new_array; >> 630 >> 631 new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; >> 632 new_array.ranges = malloc(sizeof(new_array.ranges[0]) * >> 633 new_array.nr_ranges); >> 634 ABORT_ON(!new_array.ranges); >> 635 memcpy(&new_array.ranges[0], $1.ranges, >> 636 $1.nr_ranges * sizeof(new_array.ranges[0])); >> 637 memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, >> 638 $3.nr_ranges * sizeof(new_array.ranges[0])); >> 639 free($1.ranges); >> 640 free($3.ranges); >> 641 $$ = new_array; >> 642 } >> 643 | >> 644 array_term >> 645 >> 646 array_term: >> 647 PE_VALUE >> 648 { >> 649 struct parse_events_array array; >> 650 >> 651 array.nr_ranges = 1; >> 652 array.ranges = malloc(sizeof(array.ranges[0])); >> 653 ABORT_ON(!array.ranges); >> 654 array.ranges[0].start = $1; >> 655 array.ranges[0].length = 1; >> 656 $$ = array; >> 657 } >> 658 | >> 659 PE_VALUE PE_ARRAY_RANGE PE_VALUE >> 660 { >> 661 struct parse_events_array array; >> 662 >> 663 ABORT_ON($3 < $1); >> 664 array.nr_ranges = 1; >> 665 array.ranges = malloc(sizeof(array.ranges[0])); >> 666 ABORT_ON(!array.ranges); >> 667 array.ranges[0].start = $1; >> 668 array.ranges[0].length = $3 - $1 + 1; >> 669 $$ = array; >> 670 } >> 671 761 sep_dc: ':' | 672 sep_dc: ':' | 762 673 763 sep_slash_slash_dc: '/' '/' | ':' | !! 674 sep_slash_dc: '/' | ':' | 764 675 765 %% 676 %% 766 677 767 void parse_events_error(YYLTYPE *loc, void *_p !! 678 void parse_events_error(YYLTYPE *loc, void *data, 768 void *scanner __maybe_ 679 void *scanner __maybe_unused, 769 char const *msg __mayb 680 char const *msg __maybe_unused) 770 { 681 { 771 struct parse_events_state *parse_state !! 682 parse_events_evlist_error(data, loc->last_column, "parser error"); 772 << 773 if (!parse_state->error || !list_empty << 774 return; << 775 << 776 parse_events_error__handle(parse_state << 777 strdup("Unr << 778 } 683 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.