parse-events.y 10.5 KB
Newer Older
1
%pure-parser
2
%parse-param {void *_data}
3 4
%parse-param {void *scanner}
%lex-param {void* scanner}
5
%locations
6 7 8 9 10 11 12

%{

#define YYDEBUG 1

#include <linux/compiler.h>
#include <linux/list.h>
B
Borislav Petkov 已提交
13
#include <linux/types.h>
14 15
#include "util.h"
#include "parse-events.h"
16
#include "parse-events-bison.h"
17 18 19 20 21 22 23

#define ABORT_ON(val) \
do { \
	if (val) \
		YYABORT; \
} while (0)

24 25 26 27 28 29 30
#define ALLOC_LIST(list) \
do { \
	list = malloc(sizeof(*list)); \
	ABORT_ON(!list);              \
	INIT_LIST_HEAD(list);         \
} while (0)

31 32 33 34 35 36 37 38
static inc_group_count(struct list_head *list,
		       struct parse_events_evlist *data)
{
	/* Count groups only have more than 1 members */
	if (!list_is_last(list->next, list))
		data->nr_groups++;
}

39 40
%}

41
%token PE_START_EVENTS PE_START_TERMS
42
%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
43
%token PE_EVENT_NAME
44 45 46
%token PE_NAME
%token PE_MODIFIER_EVENT PE_MODIFIER_BP
%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
47
%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
48
%token PE_ERROR
49
%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
50
%type <num> PE_VALUE
51 52
%type <num> PE_VALUE_SYM_HW
%type <num> PE_VALUE_SYM_SW
53
%type <num> PE_RAW
54
%type <num> PE_TERM
55 56 57 58 59
%type <str> PE_NAME
%type <str> PE_NAME_CACHE_TYPE
%type <str> PE_NAME_CACHE_OP_RESULT
%type <str> PE_MODIFIER_EVENT
%type <str> PE_MODIFIER_BP
60
%type <str> PE_EVENT_NAME
61
%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
62
%type <num> value_sym
63 64
%type <head> event_config
%type <term> event_term
65 66 67 68 69
%type <head> event_pmu
%type <head> event_legacy_symbol
%type <head> event_legacy_cache
%type <head> event_legacy_mem
%type <head> event_legacy_tracepoint
70
%type <tracepoint_name> tracepoint_name
71 72 73
%type <head> event_legacy_numeric
%type <head> event_legacy_raw
%type <head> event_def
74 75
%type <head> event_mod
%type <head> event_name
76 77 78 79 80
%type <head> event
%type <head> events
%type <head> group_def
%type <head> group
%type <head> groups
81 82 83 84

%union
{
	char *str;
85
	u64 num;
86
	struct list_head *head;
87
	struct parse_events_term *term;
88 89 90 91
	struct tracepoint_name {
		char *sys;
		char *event;
	} tracepoint_name;
92 93 94
}
%%

95
start:
96
PE_START_EVENTS start_events
97
|
98 99 100 101
PE_START_TERMS  start_terms

start_events: groups
{
102
	struct parse_events_evlist *data = _data;
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

	parse_events_update_lists($1, &data->list);
}

groups:
groups ',' group
{
	struct list_head *list  = $1;
	struct list_head *group = $3;

	parse_events_update_lists(group, list);
	$$ = list;
}
|
groups ',' event
{
	struct list_head *list  = $1;
	struct list_head *event = $3;

	parse_events_update_lists(event, list);
	$$ = list;
}
|
group
|
event

group:
group_def ':' PE_MODIFIER_EVENT
{
	struct list_head *list = $1;

	ABORT_ON(parse_events__modifier_group(list, $3));
	$$ = list;
}
|
group_def

group_def:
PE_NAME '{' events '}'
{
	struct list_head *list = $3;

146
	inc_group_count(list, _data);
147
	parse_events__set_leader($1, list);
148 149 150 151 152 153 154
	$$ = list;
}
|
'{' events '}'
{
	struct list_head *list = $2;

155
	inc_group_count(list, _data);
156
	parse_events__set_leader(NULL, list);
157 158
	$$ = list;
}
159

160
events:
161 162 163 164 165 166 167 168 169 170
events ',' event
{
	struct list_head *event = $3;
	struct list_head *list  = $1;

	parse_events_update_lists(event, list);
	$$ = list;
}
|
event
171

172 173 174 175
event: event_mod

event_mod:
event_name PE_MODIFIER_EVENT
176
{
177
	struct list_head *list = $1;
178

179 180 181 182 183
	/*
	 * Apply modifier on all events added by single event definition
	 * (there could be more events added for multiple tracepoint
	 * definitions via '*?'.
	 */
184
	ABORT_ON(parse_events__modifier_event(list, $2, false));
185
	$$ = list;
186 187
}
|
188 189 190 191 192 193 194 195 196 197
event_name

event_name:
PE_EVENT_NAME event_def
{
	ABORT_ON(parse_events_name($2, $1));
	free($1);
	$$ = $2;
}
|
198 199
event_def

200 201
event_def: event_pmu |
	   event_legacy_symbol |
202 203 204 205 206 207
	   event_legacy_cache sep_dc |
	   event_legacy_mem |
	   event_legacy_tracepoint sep_dc |
	   event_legacy_numeric sep_dc |
	   event_legacy_raw sep_dc

208 209 210
event_pmu:
PE_NAME '/' event_config '/'
{
211
	struct parse_events_evlist *data = _data;
212
	struct list_head *list;
213

214
	ALLOC_LIST(list);
215
	ABORT_ON(parse_events_add_pmu(data, list, $1, $3));
216
	parse_events__free_terms($3);
217
	$$ = list;
218
}
219 220 221 222 223 224 225
|
PE_NAME '/' '/'
{
	struct parse_events_evlist *data = _data;
	struct list_head *list;

	ALLOC_LIST(list);
226
	ABORT_ON(parse_events_add_pmu(data, list, $1, NULL));
227 228
	$$ = list;
}
229 230 231 232 233 234 235 236 237 238
|
PE_KERNEL_PMU_EVENT sep_dc
{
	struct parse_events_evlist *data = _data;
	struct list_head *head;
	struct parse_events_term *term;
	struct list_head *list;

	ALLOC_LIST(head);
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
239
					$1, 1, &@1, NULL));
240 241 242
	list_add_tail(&term->list, head);

	ALLOC_LIST(list);
243
	ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
	parse_events__free_terms(head);
	$$ = list;
}
|
PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
{
	struct parse_events_evlist *data = _data;
	struct list_head *head;
	struct parse_events_term *term;
	struct list_head *list;
	char pmu_name[128];
	snprintf(&pmu_name, 128, "%s-%s", $1, $3);

	ALLOC_LIST(head);
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
259
					&pmu_name, 1, &@1, NULL));
260 261 262
	list_add_tail(&term->list, head);

	ALLOC_LIST(list);
263
	ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
264 265 266
	parse_events__free_terms(head);
	$$ = list;
}
267

268 269 270 271 272
value_sym:
PE_VALUE_SYM_HW
|
PE_VALUE_SYM_SW

273
event_legacy_symbol:
274
value_sym '/' event_config '/'
275
{
276
	struct parse_events_evlist *data = _data;
277
	struct list_head *list;
278 279 280
	int type = $1 >> 16;
	int config = $1 & 255;

281
	ALLOC_LIST(list);
282
	ABORT_ON(parse_events_add_numeric(data, list, type, config, $3));
283
	parse_events__free_terms($3);
284
	$$ = list;
285 286
}
|
287
value_sym sep_slash_dc
288
{
289
	struct parse_events_evlist *data = _data;
290
	struct list_head *list;
291 292 293
	int type = $1 >> 16;
	int config = $1 & 255;

294
	ALLOC_LIST(list);
295
	ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL));
296
	$$ = list;
297 298 299 300 301
}

event_legacy_cache:
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
{
302
	struct parse_events_evlist *data = _data;
303
	struct list_head *list;
304

305 306
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5));
307
	$$ = list;
308 309 310 311
}
|
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
{
312
	struct parse_events_evlist *data = _data;
313
	struct list_head *list;
314

315 316
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL));
317
	$$ = list;
318 319 320 321
}
|
PE_NAME_CACHE_TYPE
{
322
	struct parse_events_evlist *data = _data;
323
	struct list_head *list;
324

325 326
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL));
327
	$$ = list;
328 329 330
}

event_legacy_mem:
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
	struct parse_events_evlist *data = _data;
	struct list_head *list;

	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
					     (void *) $2, $6, $4));
	$$ = list;
}
|
PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
{
	struct parse_events_evlist *data = _data;
	struct list_head *list;

	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
					     (void *) $2, NULL, $4));
	$$ = list;
}
|
353 354
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
355
	struct parse_events_evlist *data = _data;
356
	struct list_head *list;
357

358 359
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
360
					     (void *) $2, $4, 0));
361
	$$ = list;
362 363 364 365
}
|
PE_PREFIX_MEM PE_VALUE sep_dc
{
366
	struct parse_events_evlist *data = _data;
367
	struct list_head *list;
368

369 370
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
371
					     (void *) $2, NULL, 0));
372
	$$ = list;
373 374 375
}

event_legacy_tracepoint:
376
tracepoint_name
377 378
{
	struct parse_events_evlist *data = _data;
379
	struct parse_events_error *error = data->error;
380 381 382
	struct list_head *list;

	ALLOC_LIST(list);
383 384 385
	if (error)
		error->idx = @1.first_column;

386
	if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
387
					error, NULL))
388
		return -1;
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406

	$$ = list;
}
|
tracepoint_name '/' event_config '/'
{
	struct parse_events_evlist *data = _data;
	struct parse_events_error *error = data->error;
	struct list_head *list;

	ALLOC_LIST(list);
	if (error)
		error->idx = @1.first_column;

	if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
					error, $3))
		return -1;

407 408
	$$ = list;
}
409 410 411 412 413 414 415 416 417 418 419 420 421

tracepoint_name:
PE_NAME '-' PE_NAME ':' PE_NAME
{
	char sys_name[128];
	struct tracepoint_name tracepoint;

	snprintf(&sys_name, 128, "%s-%s", $1, $3);
	tracepoint.sys = &sys_name;
	tracepoint.event = $5;

	$$ = tracepoint;
}
422
|
423 424
PE_NAME ':' PE_NAME
{
425
	struct tracepoint_name tracepoint = {$1, $3};
426

427
	$$ = tracepoint;
428 429 430 431 432
}

event_legacy_numeric:
PE_VALUE ':' PE_VALUE
{
433
	struct parse_events_evlist *data = _data;
434
	struct list_head *list;
435

436
	ALLOC_LIST(list);
437
	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, NULL));
438
	$$ = list;
439 440 441 442 443
}

event_legacy_raw:
PE_RAW
{
444
	struct parse_events_evlist *data = _data;
445
	struct list_head *list;
446

447
	ALLOC_LIST(list);
448
	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, NULL));
449
	$$ = list;
450 451
}

452
start_terms: event_config
453
{
454
	struct parse_events_terms *data = _data;
455 456 457
	data->terms = $1;
}

458 459 460 461
event_config:
event_config ',' event_term
{
	struct list_head *head = $1;
462
	struct parse_events_term *term = $3;
463 464 465 466 467 468 469 470 471

	ABORT_ON(!head);
	list_add_tail(&term->list, head);
	$$ = $1;
}
|
event_term
{
	struct list_head *head = malloc(sizeof(*head));
472
	struct parse_events_term *term = $1;
473 474 475 476 477 478 479 480 481 482

	ABORT_ON(!head);
	INIT_LIST_HEAD(head);
	list_add_tail(&term->list, head);
	$$ = head;
}

event_term:
PE_NAME '=' PE_NAME
{
483
	struct parse_events_term *term;
484

485
	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
486
					$1, $3, &@1, &@3));
487 488 489 490 491
	$$ = term;
}
|
PE_NAME '=' PE_VALUE
{
492
	struct parse_events_term *term;
493

494
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
495
					$1, $3, &@1, &@3));
496 497 498
	$$ = term;
}
|
499 500
PE_NAME '=' PE_VALUE_SYM_HW
{
501
	struct parse_events_term *term;
502 503
	int config = $3 & 255;

504
	ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
505 506 507
	$$ = term;
}
|
508 509
PE_NAME
{
510
	struct parse_events_term *term;
511

512
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
513
					$1, 1, &@1, NULL));
514 515 516
	$$ = term;
}
|
517 518
PE_VALUE_SYM_HW
{
519
	struct parse_events_term *term;
520 521
	int config = $1 & 255;

522
	ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
523 524 525
	$$ = term;
}
|
526 527
PE_TERM '=' PE_NAME
{
528
	struct parse_events_term *term;
529

530
	ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
531 532 533
	$$ = term;
}
|
534 535
PE_TERM '=' PE_VALUE
{
536
	struct parse_events_term *term;
537

538
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3));
539 540 541 542 543
	$$ = term;
}
|
PE_TERM
{
544
	struct parse_events_term *term;
545

546
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
547
	$$ = term;
548 549 550 551
}

sep_dc: ':' |

552 553
sep_slash_dc: '/' | ':' |

554 555
%%

556 557
void parse_events_error(YYLTYPE *loc, void *data,
			void *scanner __maybe_unused,
558
			char const *msg __maybe_unused)
559
{
560
	parse_events_evlist_error(data, loc->last_column, "parser error");
561
}