parse-events.y 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. %pure-parser
  2. %parse-param {void *_data}
  3. %parse-param {void *scanner}
  4. %lex-param {void* scanner}
  5. %{
  6. #define YYDEBUG 1
  7. #include <linux/compiler.h>
  8. #include <linux/list.h>
  9. #include "types.h"
  10. #include "util.h"
  11. #include "parse-events.h"
  12. #include "parse-events-bison.h"
  13. extern int parse_events_lex (YYSTYPE* lvalp, void* scanner);
  14. #define ABORT_ON(val) \
  15. do { \
  16. if (val) \
  17. YYABORT; \
  18. } while (0)
  19. static inc_group_count(struct list_head *list,
  20. struct parse_events_evlist *data)
  21. {
  22. /* Count groups only have more than 1 members */
  23. if (!list_is_last(list->next, list))
  24. data->nr_groups++;
  25. }
  26. %}
  27. %token PE_START_EVENTS PE_START_TERMS
  28. %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
  29. %token PE_EVENT_NAME
  30. %token PE_NAME
  31. %token PE_MODIFIER_EVENT PE_MODIFIER_BP
  32. %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
  33. %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
  34. %token PE_ERROR
  35. %type <num> PE_VALUE
  36. %type <num> PE_VALUE_SYM_HW
  37. %type <num> PE_VALUE_SYM_SW
  38. %type <num> PE_RAW
  39. %type <num> PE_TERM
  40. %type <str> PE_NAME
  41. %type <str> PE_NAME_CACHE_TYPE
  42. %type <str> PE_NAME_CACHE_OP_RESULT
  43. %type <str> PE_MODIFIER_EVENT
  44. %type <str> PE_MODIFIER_BP
  45. %type <str> PE_EVENT_NAME
  46. %type <num> value_sym
  47. %type <head> event_config
  48. %type <term> event_term
  49. %type <head> event_pmu
  50. %type <head> event_legacy_symbol
  51. %type <head> event_legacy_cache
  52. %type <head> event_legacy_mem
  53. %type <head> event_legacy_tracepoint
  54. %type <head> event_legacy_numeric
  55. %type <head> event_legacy_raw
  56. %type <head> event_def
  57. %type <head> event_mod
  58. %type <head> event_name
  59. %type <head> event
  60. %type <head> events
  61. %type <head> group_def
  62. %type <head> group
  63. %type <head> groups
  64. %union
  65. {
  66. char *str;
  67. u64 num;
  68. struct list_head *head;
  69. struct parse_events_term *term;
  70. }
  71. %%
  72. start:
  73. PE_START_EVENTS start_events
  74. |
  75. PE_START_TERMS start_terms
  76. start_events: groups
  77. {
  78. struct parse_events_evlist *data = _data;
  79. parse_events_update_lists($1, &data->list);
  80. }
  81. groups:
  82. groups ',' group
  83. {
  84. struct list_head *list = $1;
  85. struct list_head *group = $3;
  86. parse_events_update_lists(group, list);
  87. $$ = list;
  88. }
  89. |
  90. groups ',' event
  91. {
  92. struct list_head *list = $1;
  93. struct list_head *event = $3;
  94. parse_events_update_lists(event, list);
  95. $$ = list;
  96. }
  97. |
  98. group
  99. |
  100. event
  101. group:
  102. group_def ':' PE_MODIFIER_EVENT
  103. {
  104. struct list_head *list = $1;
  105. ABORT_ON(parse_events__modifier_group(list, $3));
  106. $$ = list;
  107. }
  108. |
  109. group_def
  110. group_def:
  111. PE_NAME '{' events '}'
  112. {
  113. struct list_head *list = $3;
  114. inc_group_count(list, _data);
  115. parse_events__set_leader($1, list);
  116. $$ = list;
  117. }
  118. |
  119. '{' events '}'
  120. {
  121. struct list_head *list = $2;
  122. inc_group_count(list, _data);
  123. parse_events__set_leader(NULL, list);
  124. $$ = list;
  125. }
  126. events:
  127. events ',' event
  128. {
  129. struct list_head *event = $3;
  130. struct list_head *list = $1;
  131. parse_events_update_lists(event, list);
  132. $$ = list;
  133. }
  134. |
  135. event
  136. event: event_mod
  137. event_mod:
  138. event_name PE_MODIFIER_EVENT
  139. {
  140. struct list_head *list = $1;
  141. /*
  142. * Apply modifier on all events added by single event definition
  143. * (there could be more events added for multiple tracepoint
  144. * definitions via '*?'.
  145. */
  146. ABORT_ON(parse_events__modifier_event(list, $2, false));
  147. $$ = list;
  148. }
  149. |
  150. event_name
  151. event_name:
  152. PE_EVENT_NAME event_def
  153. {
  154. ABORT_ON(parse_events_name($2, $1));
  155. free($1);
  156. $$ = $2;
  157. }
  158. |
  159. event_def
  160. event_def: event_pmu |
  161. event_legacy_symbol |
  162. event_legacy_cache sep_dc |
  163. event_legacy_mem |
  164. event_legacy_tracepoint sep_dc |
  165. event_legacy_numeric sep_dc |
  166. event_legacy_raw sep_dc
  167. event_pmu:
  168. PE_NAME '/' event_config '/'
  169. {
  170. struct parse_events_evlist *data = _data;
  171. struct list_head *list = NULL;
  172. ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
  173. parse_events__free_terms($3);
  174. $$ = list;
  175. }
  176. value_sym:
  177. PE_VALUE_SYM_HW
  178. |
  179. PE_VALUE_SYM_SW
  180. event_legacy_symbol:
  181. value_sym '/' event_config '/'
  182. {
  183. struct parse_events_evlist *data = _data;
  184. struct list_head *list = NULL;
  185. int type = $1 >> 16;
  186. int config = $1 & 255;
  187. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  188. type, config, $3));
  189. parse_events__free_terms($3);
  190. $$ = list;
  191. }
  192. |
  193. value_sym sep_slash_dc
  194. {
  195. struct parse_events_evlist *data = _data;
  196. struct list_head *list = NULL;
  197. int type = $1 >> 16;
  198. int config = $1 & 255;
  199. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  200. type, config, NULL));
  201. $$ = list;
  202. }
  203. event_legacy_cache:
  204. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
  205. {
  206. struct parse_events_evlist *data = _data;
  207. struct list_head *list = NULL;
  208. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
  209. $$ = list;
  210. }
  211. |
  212. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
  213. {
  214. struct parse_events_evlist *data = _data;
  215. struct list_head *list = NULL;
  216. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
  217. $$ = list;
  218. }
  219. |
  220. PE_NAME_CACHE_TYPE
  221. {
  222. struct parse_events_evlist *data = _data;
  223. struct list_head *list = NULL;
  224. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
  225. $$ = list;
  226. }
  227. event_legacy_mem:
  228. PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
  229. {
  230. struct parse_events_evlist *data = _data;
  231. struct list_head *list = NULL;
  232. ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
  233. (void *) $2, $4));
  234. $$ = list;
  235. }
  236. |
  237. PE_PREFIX_MEM PE_VALUE sep_dc
  238. {
  239. struct parse_events_evlist *data = _data;
  240. struct list_head *list = NULL;
  241. ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
  242. (void *) $2, NULL));
  243. $$ = list;
  244. }
  245. event_legacy_tracepoint:
  246. PE_NAME ':' PE_NAME
  247. {
  248. struct parse_events_evlist *data = _data;
  249. struct list_head *list = NULL;
  250. ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
  251. $$ = list;
  252. }
  253. event_legacy_numeric:
  254. PE_VALUE ':' PE_VALUE
  255. {
  256. struct parse_events_evlist *data = _data;
  257. struct list_head *list = NULL;
  258. ABORT_ON(parse_events_add_numeric(&list, &data->idx, (u32)$1, $3, NULL));
  259. $$ = list;
  260. }
  261. event_legacy_raw:
  262. PE_RAW
  263. {
  264. struct parse_events_evlist *data = _data;
  265. struct list_head *list = NULL;
  266. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  267. PERF_TYPE_RAW, $1, NULL));
  268. $$ = list;
  269. }
  270. start_terms: event_config
  271. {
  272. struct parse_events_terms *data = _data;
  273. data->terms = $1;
  274. }
  275. event_config:
  276. event_config ',' event_term
  277. {
  278. struct list_head *head = $1;
  279. struct parse_events_term *term = $3;
  280. ABORT_ON(!head);
  281. list_add_tail(&term->list, head);
  282. $$ = $1;
  283. }
  284. |
  285. event_term
  286. {
  287. struct list_head *head = malloc(sizeof(*head));
  288. struct parse_events_term *term = $1;
  289. ABORT_ON(!head);
  290. INIT_LIST_HEAD(head);
  291. list_add_tail(&term->list, head);
  292. $$ = head;
  293. }
  294. event_term:
  295. PE_NAME '=' PE_NAME
  296. {
  297. struct parse_events_term *term;
  298. ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
  299. $1, $3));
  300. $$ = term;
  301. }
  302. |
  303. PE_NAME '=' PE_VALUE
  304. {
  305. struct parse_events_term *term;
  306. ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
  307. $1, $3));
  308. $$ = term;
  309. }
  310. |
  311. PE_NAME '=' PE_VALUE_SYM_HW
  312. {
  313. struct parse_events_term *term;
  314. int config = $3 & 255;
  315. ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
  316. $$ = term;
  317. }
  318. |
  319. PE_NAME
  320. {
  321. struct parse_events_term *term;
  322. ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
  323. $1, 1));
  324. $$ = term;
  325. }
  326. |
  327. PE_VALUE_SYM_HW
  328. {
  329. struct parse_events_term *term;
  330. int config = $1 & 255;
  331. ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
  332. $$ = term;
  333. }
  334. |
  335. PE_TERM '=' PE_NAME
  336. {
  337. struct parse_events_term *term;
  338. ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3));
  339. $$ = term;
  340. }
  341. |
  342. PE_TERM '=' PE_VALUE
  343. {
  344. struct parse_events_term *term;
  345. ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3));
  346. $$ = term;
  347. }
  348. |
  349. PE_TERM
  350. {
  351. struct parse_events_term *term;
  352. ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1));
  353. $$ = term;
  354. }
  355. sep_dc: ':' |
  356. sep_slash_dc: '/' | ':' |
  357. %%
  358. void parse_events_error(void *data __maybe_unused, void *scanner __maybe_unused,
  359. char const *msg __maybe_unused)
  360. {
  361. }