parse-events.y 9.9 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 210
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, $3));
211
	parse_events__free_terms($3);
212
	$$ = list;
213
}
214 215 216 217 218 219 220 221 222 223
|
PE_NAME '/' '/'
{
	struct parse_events_evlist *data = _data;
	struct list_head *list;

	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_pmu(list, &data->idx, $1, NULL));
	$$ = list;
}
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
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,
					$1, 1));
	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;
}
|
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,
					&pmu_name, 1));
	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 391
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_tracepoint(list, &data->idx, $1, $3));
392
	$$ = list;
393 394 395 396 397
}

event_legacy_numeric:
PE_VALUE ':' PE_VALUE
{
398
	struct parse_events_evlist *data = _data;
399
	struct list_head *list;
400

401 402
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_numeric(list, &data->idx, (u32)$1, $3, NULL));
403
	$$ = list;
404 405 406 407 408
}

event_legacy_raw:
PE_RAW
{
409
	struct parse_events_evlist *data = _data;
410
	struct list_head *list;
411

412 413
	ALLOC_LIST(list);
	ABORT_ON(parse_events_add_numeric(list, &data->idx,
414
					  PERF_TYPE_RAW, $1, NULL));
415
	$$ = list;
416 417
}

418
start_terms: event_config
419
{
420
	struct parse_events_terms *data = _data;
421 422 423
	data->terms = $1;
}

424 425 426 427
event_config:
event_config ',' event_term
{
	struct list_head *head = $1;
428
	struct parse_events_term *term = $3;
429 430 431 432 433 434 435 436 437

	ABORT_ON(!head);
	list_add_tail(&term->list, head);
	$$ = $1;
}
|
event_term
{
	struct list_head *head = malloc(sizeof(*head));
438
	struct parse_events_term *term = $1;
439 440 441 442 443 444 445 446 447 448

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

event_term:
PE_NAME '=' PE_NAME
{
449
	struct parse_events_term *term;
450

451
	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
452
					$1, $3));
453 454 455 456 457
	$$ = term;
}
|
PE_NAME '=' PE_VALUE
{
458
	struct parse_events_term *term;
459

460
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
461
					$1, $3));
462 463 464
	$$ = term;
}
|
465 466
PE_NAME '=' PE_VALUE_SYM_HW
{
467
	struct parse_events_term *term;
468 469
	int config = $3 & 255;

470
	ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
471 472 473
	$$ = term;
}
|
474 475
PE_NAME
{
476
	struct parse_events_term *term;
477

478
	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
479
					$1, 1));
480 481 482
	$$ = term;
}
|
483 484
PE_VALUE_SYM_HW
{
485
	struct parse_events_term *term;
486 487
	int config = $1 & 255;

488
	ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
489 490 491
	$$ = term;
}
|
492 493
PE_TERM '=' PE_NAME
{
494
	struct parse_events_term *term;
495

496
	ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3));
497 498 499
	$$ = term;
}
|
500 501
PE_TERM '=' PE_VALUE
{
502
	struct parse_events_term *term;
503

504
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3));
505 506 507 508 509
	$$ = term;
}
|
PE_TERM
{
510
	struct parse_events_term *term;
511

512
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1));
513
	$$ = term;
514 515 516 517
}

sep_dc: ':' |

518 519
sep_slash_dc: '/' | ':' |

520 521
%%

522 523
void parse_events_error(YYLTYPE *loc, void *data,
			void *scanner __maybe_unused,
524
			char const *msg __maybe_unused)
525
{
526
	parse_events_evlist_error(data, loc->last_column, "parser error");
527
}