perf.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM_VAR
  3. #ifdef CONFIG_PERF_EVENTS
  4. #undef __entry
  5. #define __entry entry
  6. #undef __get_dynamic_array
  7. #define __get_dynamic_array(field) \
  8. ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
  9. #undef __get_dynamic_array_len
  10. #define __get_dynamic_array_len(field) \
  11. ((__entry->__data_loc_##field >> 16) & 0xffff)
  12. #undef __get_str
  13. #define __get_str(field) ((char *)__get_dynamic_array(field))
  14. #undef __get_bitmask
  15. #define __get_bitmask(field) (char *)__get_dynamic_array(field)
  16. #undef __get_sockaddr
  17. #define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
  18. #undef __get_rel_dynamic_array
  19. #define __get_rel_dynamic_array(field) \
  20. ((void *)__entry + \
  21. offsetof(typeof(*__entry), __rel_loc_##field) + \
  22. sizeof(__entry->__rel_loc_##field) + \
  23. (__entry->__rel_loc_##field & 0xffff))
  24. #undef __get_rel_dynamic_array_len
  25. #define __get_rel_dynamic_array_len(field) \
  26. ((__entry->__rel_loc_##field >> 16) & 0xffff)
  27. #undef __get_rel_str
  28. #define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
  29. #undef __get_rel_bitmask
  30. #define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
  31. #undef __get_rel_sockaddr
  32. #define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
  33. #undef __perf_count
  34. #define __perf_count(c) (__count = (c))
  35. #undef __perf_task
  36. #define __perf_task(t) (__task = (t))
  37. #undef DECLARE_EVENT_CLASS
  38. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  39. static notrace void \
  40. perf_trace_##call(void *__data, proto) \
  41. { \
  42. struct trace_event_call *event_call = __data; \
  43. struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
  44. struct trace_event_raw_##call *entry; \
  45. struct pt_regs *__regs; \
  46. u64 __count = 1; \
  47. struct task_struct *__task = NULL; \
  48. struct hlist_head *head; \
  49. int __entry_size; \
  50. int __data_size; \
  51. int rctx; \
  52. \
  53. __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
  54. \
  55. head = this_cpu_ptr(event_call->perf_events); \
  56. if (!bpf_prog_array_valid(event_call) && \
  57. __builtin_constant_p(!__task) && !__task && \
  58. hlist_empty(head)) \
  59. return; \
  60. \
  61. __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
  62. sizeof(u64)); \
  63. __entry_size -= sizeof(u32); \
  64. \
  65. entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \
  66. if (!entry) \
  67. return; \
  68. \
  69. perf_fetch_caller_regs(__regs); \
  70. \
  71. tstruct \
  72. \
  73. { assign; } \
  74. \
  75. perf_trace_run_bpf_submit(entry, __entry_size, rctx, \
  76. event_call, __count, __regs, \
  77. head, __task); \
  78. }
  79. /*
  80. * This part is compiled out, it is only here as a build time check
  81. * to make sure that if the tracepoint handling changes, the
  82. * perf probe will fail to compile unless it too is updated.
  83. */
  84. #undef DEFINE_EVENT
  85. #define DEFINE_EVENT(template, call, proto, args) \
  86. static inline void perf_test_probe_##call(void) \
  87. { \
  88. check_trace_callback_type_##call(perf_trace_##template); \
  89. }
  90. #undef DEFINE_EVENT_PRINT
  91. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  92. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  93. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  94. #endif /* CONFIG_PERF_EVENTS */