parse-events.y 7.2 KB

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