parse-events.y 10.1 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 70 71 72
%type <head> event_pmu
%type <head> event_legacy_symbol
%type <head> event_legacy_cache
%type <head> event_legacy_mem
%type <head> event_legacy_tracepoint
%type <head> event_legacy_numeric
%type <head> event_legacy_raw
%type <head> event_def
73 74
%type <head> event_mod
%type <head> event_name
75 76 77 78 79
%type <head> event
%type <head> events
%type <head> group_def
%type <head> group
%type <head> groups
80 81 82 83

%union
{
	char *str;
84
	u64 num;
85
	struct list_head *head;
86
	struct parse_events_term *term;
87 88 89
}
%%

90
start:
91
PE_START_EVENTS start_events
92
|
93 94 95 96
PE_START_TERMS  start_terms

start_events: groups
{
97
	struct parse_events_evlist *data = _data;
98 99 100 101 102 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

	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;

141
	inc_group_count(list, _data);
142
	parse_events__set_leader($1, list);
143 144 145 146 147 148 149
	$$ = list;
}
|
'{' events '}'
{
	struct list_head *list = $2;

150
	inc_group_count(list, _data);
151
	parse_events__set_leader(NULL, list);
152 153
	$$ = list;
}
154

155
events:
156 157 158 159 160 161 162 163 164 165
events ',' event
{
	struct list_head *event = $3;
	struct list_head *list  = $1;

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

167 168 169 170
event: event_mod

event_mod:
event_name PE_MODIFIER_EVENT
171
{
172
	struct list_head *list = $1;
173

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

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

195 196
event_def: event_pmu |
	   event_legacy_symbol |
197 198 199 200 201 202
	   event_legacy_cache sep_dc |
	   event_legacy_mem |
	   event_legacy_tracepoint sep_dc |
	   event_legacy_numeric sep_dc |
	   event_legacy_raw sep_dc

203 204 205
event_pmu:
PE_NAME '/' event_config '/'
{
206
	struct parse_events_evlist *data = _data;
207
	struct list_head *list;
208

209
	ALLOC_LIST(list);
210
	ABORT_ON(parse_events_add_pmu(data, list, $1, $3));
211
	parse_events__free_terms($3);
212
	$$ = list;
213
}
214 215 216 217 218 219 220
|
PE_NAME '/' '/'
{
	struct parse_events_evlist *data = _data;
	struct list_head *list;

	ALLOC_LIST(list);
221
	ABORT_ON(parse_events_add_pmu(data, list, $1, NULL));
222 223
	$$ = list;
}
224 225 226 227 228 229 230 231 232 233
|
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,
234
					$1, 1, &@1, NULL));
235 236 237
	list_add_tail(&term->list, head);

	ALLOC_LIST(list);
238
	ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
	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,
254
					&pmu_name, 1, &@1, NULL));
255 256 257 258 259 260 261
	list_add_tail(&term->list, head);

	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_pmu(list, &data->idx, "cpu", head));
	parse_events__free_terms(head);
	$$ = list;
}
262

263 264 265 266 267
value_sym:
PE_VALUE_SYM_HW
|
PE_VALUE_SYM_SW

268
event_legacy_symbol:
269
value_sym '/' event_config '/'
270
{
271
	struct parse_events_evlist *data = _data;
272
	struct list_head *list;
273 274 275
	int type = $1 >> 16;
	int config = $1 & 255;

276 277
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_numeric(list, &data->idx,
278
					  type, config, $3));
279
	parse_events__free_terms($3);
280
	$$ = list;
281 282
}
|
283
value_sym sep_slash_dc
284
{
285
	struct parse_events_evlist *data = _data;
286
	struct list_head *list;
287 288 289
	int type = $1 >> 16;
	int config = $1 & 255;

290 291
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_numeric(list, &data->idx,
292
					  type, config, NULL));
293
	$$ = list;
294 295 296 297 298
}

event_legacy_cache:
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
{
299
	struct parse_events_evlist *data = _data;
300
	struct list_head *list;
301

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

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

322 323
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL));
324
	$$ = list;
325 326 327
}

event_legacy_mem:
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
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;
}
|
350 351
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
352
	struct parse_events_evlist *data = _data;
353
	struct list_head *list;
354

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

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

event_legacy_tracepoint:
373 374 375 376 377 378 379 380 381 382 383 384
PE_NAME '-' PE_NAME ':' PE_NAME
{
	struct parse_events_evlist *data = _data;
	struct list_head *list;
	char sys_name[128];
	snprintf(&sys_name, 128, "%s-%s", $1, $3);

	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_tracepoint(list, &data->idx, &sys_name, $5));
	$$ = list;
}
|
385 386
PE_NAME ':' PE_NAME
{
387
	struct parse_events_evlist *data = _data;
388
	struct list_head *list;
389

390
	ALLOC_LIST(list);
391 392 393 394 395 396 397
	if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) {
		struct parse_events_error *error = data->error;

		error->idx = @1.first_column;
		error->str = strdup("unknown tracepoint");
		return -1;
	}
398
	$$ = list;
399 400 401 402 403
}

event_legacy_numeric:
PE_VALUE ':' PE_VALUE
{
404
	struct parse_events_evlist *data = _data;
405
	struct list_head *list;
406

407 408
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_numeric(list, &data->idx, (u32)$1, $3, NULL));
409
	$$ = list;
410 411 412 413 414
}

event_legacy_raw:
PE_RAW
{
415
	struct parse_events_evlist *data = _data;
416
	struct list_head *list;
417

418 419
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_numeric(list, &data->idx,
420
					  PERF_TYPE_RAW, $1, NULL));
421
	$$ = list;
422 423
}

424
start_terms: event_config
425
{
426
	struct parse_events_terms *data = _data;
427 428 429
	data->terms = $1;
}

430 431 432 433
event_config:
event_config ',' event_term
{
	struct list_head *head = $1;
434
	struct parse_events_term *term = $3;
435 436 437 438 439 440 441 442 443

	ABORT_ON(!head);
	list_add_tail(&term->list, head);
	$$ = $1;
}
|
event_term
{
	struct list_head *head = malloc(sizeof(*head));
444
	struct parse_events_term *term = $1;
445 446 447 448 449 450 451 452 453 454

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

event_term:
PE_NAME '=' PE_NAME
{
455
	struct parse_events_term *term;
456

457
	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
458
					$1, $3, &@1, &@3));
459 460 461 462 463
	$$ = term;
}
|
PE_NAME '=' PE_VALUE
{
464
	struct parse_events_term *term;
465

466
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
467
					$1, $3, &@1, &@3));
468 469 470
	$$ = term;
}
|
471 472
PE_NAME '=' PE_VALUE_SYM_HW
{
473
	struct parse_events_term *term;
474 475
	int config = $3 & 255;

476
	ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
477 478 479
	$$ = term;
}
|
480 481
PE_NAME
{
482
	struct parse_events_term *term;
483

484
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
485
					$1, 1, &@1, NULL));
486 487 488
	$$ = term;
}
|
489 490
PE_VALUE_SYM_HW
{
491
	struct parse_events_term *term;
492 493
	int config = $1 & 255;

494
	ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
495 496 497
	$$ = term;
}
|
498 499
PE_TERM '=' PE_NAME
{
500
	struct parse_events_term *term;
501

502
	ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
503 504 505
	$$ = term;
}
|
506 507
PE_TERM '=' PE_VALUE
{
508
	struct parse_events_term *term;
509

510
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3));
511 512 513 514 515
	$$ = term;
}
|
PE_TERM
{
516
	struct parse_events_term *term;
517

518
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
519
	$$ = term;
520 521 522 523
}

sep_dc: ':' |

524 525
sep_slash_dc: '/' | ':' |

526 527
%%

528 529
void parse_events_error(YYLTYPE *loc, void *data,
			void *scanner __maybe_unused,
530
			char const *msg __maybe_unused)
531
{
532
	parse_events_evlist_error(data, loc->last_column, "parser error");
533
}