parse-events.y 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. %parse-param {struct list_head *list_all}
  2. %parse-param {struct list_head *list_event}
  3. %parse-param {int *idx}
  4. %{
  5. #define YYDEBUG 1
  6. #include <linux/compiler.h>
  7. #include <linux/list.h>
  8. #include "types.h"
  9. #include "util.h"
  10. #include "parse-events.h"
  11. extern int parse_events_lex (void);
  12. #define ABORT_ON(val) \
  13. do { \
  14. if (val) \
  15. YYABORT; \
  16. } while (0)
  17. %}
  18. %token PE_VALUE PE_VALUE_SYM PE_RAW PE_SH_RAW PE_FAB_RAW PE_TERM
  19. %token PE_NAME
  20. %token PE_MODIFIER_EVENT PE_MODIFIER_BP
  21. %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
  22. %token PE_PREFIX_MEM PE_PREFIX_RAW
  23. %token PE_ERROR
  24. %type <num> PE_VALUE
  25. %type <num> PE_VALUE_SYM
  26. %type <num> PE_RAW
  27. %type <num> PE_SH_RAW
  28. %type <num> PE_FAB_RAW
  29. %type <num> PE_TERM
  30. %type <str> PE_NAME
  31. %type <str> PE_NAME_CACHE_TYPE
  32. %type <str> PE_NAME_CACHE_OP_RESULT
  33. %type <str> PE_MODIFIER_EVENT
  34. %type <str> PE_MODIFIER_BP
  35. %type <head> event_config
  36. %type <term> event_term
  37. %union
  38. {
  39. char *str;
  40. unsigned long num;
  41. struct list_head *head;
  42. struct parse_events__term *term;
  43. }
  44. %%
  45. events:
  46. events ',' event | event
  47. event:
  48. event_def PE_MODIFIER_EVENT
  49. {
  50. /*
  51. * Apply modifier on all events added by single event definition
  52. * (there could be more events added for multiple tracepoint
  53. * definitions via '*?'.
  54. */
  55. ABORT_ON(parse_events_modifier(list_event, $2));
  56. parse_events_update_lists(list_event, list_all);
  57. }
  58. |
  59. event_def
  60. {
  61. parse_events_update_lists(list_event, list_all);
  62. }
  63. event_def: event_pmu |
  64. event_legacy_symbol |
  65. event_legacy_cache sep_dc |
  66. event_legacy_mem |
  67. event_legacy_tracepoint sep_dc |
  68. event_legacy_numeric sep_dc |
  69. event_legacy_raw sep_dc |
  70. event_legacy_shared_raw sep_dc |
  71. event_legacy_fabric_raw sep_dc
  72. event_pmu:
  73. PE_NAME '/' event_config '/'
  74. {
  75. ABORT_ON(parse_events_add_pmu(list_event, idx, $1, $3));
  76. parse_events__free_terms($3);
  77. }
  78. event_legacy_symbol:
  79. PE_VALUE_SYM '/' event_config '/'
  80. {
  81. int type = $1 >> 16;
  82. int config = $1 & 255;
  83. ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, $3));
  84. parse_events__free_terms($3);
  85. }
  86. |
  87. PE_VALUE_SYM sep_slash_dc
  88. {
  89. int type = $1 >> 16;
  90. int config = $1 & 255;
  91. ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, NULL));
  92. }
  93. event_legacy_cache:
  94. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
  95. {
  96. ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, $5));
  97. }
  98. |
  99. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
  100. {
  101. ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, NULL));
  102. }
  103. |
  104. PE_NAME_CACHE_TYPE
  105. {
  106. ABORT_ON(parse_events_add_cache(list_event, idx, $1, NULL, NULL));
  107. }
  108. event_legacy_mem:
  109. PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
  110. {
  111. ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, $4));
  112. }
  113. |
  114. PE_PREFIX_MEM PE_VALUE sep_dc
  115. {
  116. ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, NULL));
  117. }
  118. event_legacy_tracepoint:
  119. PE_NAME ':' PE_NAME
  120. {
  121. ABORT_ON(parse_events_add_tracepoint(list_event, idx, $1, $3));
  122. }
  123. event_legacy_numeric:
  124. PE_VALUE ':' PE_VALUE
  125. {
  126. ABORT_ON(parse_events_add_numeric(list_event, idx, $1, $3, NULL));
  127. }
  128. event_legacy_raw:
  129. PE_RAW
  130. {
  131. ABORT_ON(parse_events_add_numeric(list_event, idx, PERF_TYPE_RAW, $1, NULL));
  132. }
  133. event_legacy_shared_raw:
  134. PE_SH_RAW
  135. {
  136. ABORT_ON(parse_events_add_numeric_legacy(list_event, idx, "msm-l2", $1, NULL));
  137. }
  138. event_legacy_fabric_raw:
  139. PE_FAB_RAW
  140. {
  141. ABORT_ON(parse_events_add_numeric_legacy(list_event, idx, "msm-busmon", $1, NULL));
  142. }
  143. event_config:
  144. event_config ',' event_term
  145. {
  146. struct list_head *head = $1;
  147. struct parse_events__term *term = $3;
  148. ABORT_ON(!head);
  149. list_add_tail(&term->list, head);
  150. $$ = $1;
  151. }
  152. |
  153. event_term
  154. {
  155. struct list_head *head = malloc(sizeof(*head));
  156. struct parse_events__term *term = $1;
  157. ABORT_ON(!head);
  158. INIT_LIST_HEAD(head);
  159. list_add_tail(&term->list, head);
  160. $$ = head;
  161. }
  162. event_term:
  163. PE_NAME '=' PE_NAME
  164. {
  165. struct parse_events__term *term;
  166. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_STR,
  167. $1, $3, 0));
  168. $$ = term;
  169. }
  170. |
  171. PE_NAME '=' PE_VALUE
  172. {
  173. struct parse_events__term *term;
  174. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_NUM,
  175. $1, NULL, $3));
  176. $$ = term;
  177. }
  178. |
  179. PE_NAME
  180. {
  181. struct parse_events__term *term;
  182. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_NUM,
  183. $1, NULL, 1));
  184. $$ = term;
  185. }
  186. |
  187. PE_TERM '=' PE_VALUE
  188. {
  189. struct parse_events__term *term;
  190. ABORT_ON(parse_events__new_term(&term, $1, NULL, NULL, $3));
  191. $$ = term;
  192. }
  193. |
  194. PE_TERM
  195. {
  196. struct parse_events__term *term;
  197. ABORT_ON(parse_events__new_term(&term, $1, NULL, NULL, 1));
  198. $$ = term;
  199. }
  200. sep_dc: ':' |
  201. sep_slash_dc: '/' | ':' |
  202. %%
  203. void parse_events_error(struct list_head *list_all __used,
  204. struct list_head *list_event __used,
  205. int *idx __used,
  206. char const *msg __used)
  207. {
  208. }