perf.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM_VAR
  3. #ifdef CONFIG_PERF_EVENTS
  4. #include "stages/stage6_event_callback.h"
  5. #undef __perf_count
  6. #define __perf_count(c) (__count = (c))
  7. #undef __perf_task
  8. #define __perf_task(t) (__task = (t))
  9. #undef __DECLARE_EVENT_CLASS
  10. #define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  11. static notrace void \
  12. do_perf_trace_##call(void *__data, proto) \
  13. { \
  14. struct trace_event_call *event_call = __data; \
  15. struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
  16. struct trace_event_raw_##call *entry; \
  17. struct pt_regs *__regs; \
  18. u64 __count = 1; \
  19. struct task_struct *__task = NULL; \
  20. struct hlist_head *head; \
  21. int __entry_size; \
  22. int __data_size; \
  23. int rctx; \
  24. \
  25. __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
  26. \
  27. head = this_cpu_ptr(event_call->perf_events); \
  28. if (!bpf_prog_array_valid(event_call) && \
  29. __builtin_constant_p(!__task) && !__task && \
  30. hlist_empty(head)) \
  31. return; \
  32. \
  33. __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
  34. sizeof(u64)); \
  35. __entry_size -= sizeof(u32); \
  36. \
  37. entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \
  38. if (!entry) \
  39. return; \
  40. \
  41. perf_fetch_caller_regs(__regs); \
  42. \
  43. tstruct \
  44. \
  45. { assign; } \
  46. \
  47. perf_trace_run_bpf_submit(entry, __entry_size, rctx, \
  48. event_call, __count, __regs, \
  49. head, __task); \
  50. }
  51. /*
  52. * Define unused __count and __task variables to use @args to pass
  53. * arguments to do_perf_trace_##call. This is needed because the
  54. * macros __perf_count and __perf_task introduce the side-effect to
  55. * store copies into those local variables.
  56. */
  57. #undef DECLARE_EVENT_CLASS
  58. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  59. __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
  60. PARAMS(assign), PARAMS(print)) \
  61. static notrace void \
  62. perf_trace_##call(void *__data, proto) \
  63. { \
  64. u64 __count __attribute__((unused)); \
  65. struct task_struct *__task __attribute__((unused)); \
  66. \
  67. guard(preempt_notrace)(); \
  68. do_perf_trace_##call(__data, args); \
  69. }
  70. #undef DECLARE_EVENT_SYSCALL_CLASS
  71. #define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, print) \
  72. __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
  73. PARAMS(assign), PARAMS(print)) \
  74. static notrace void \
  75. perf_trace_##call(void *__data, proto) \
  76. { \
  77. u64 __count __attribute__((unused)); \
  78. struct task_struct *__task __attribute__((unused)); \
  79. \
  80. might_fault(); \
  81. guard(preempt_notrace)(); \
  82. do_perf_trace_##call(__data, args); \
  83. }
  84. /*
  85. * This part is compiled out, it is only here as a build time check
  86. * to make sure that if the tracepoint handling changes, the
  87. * perf probe will fail to compile unless it too is updated.
  88. */
  89. #undef DEFINE_EVENT
  90. #define DEFINE_EVENT(template, call, proto, args) \
  91. static inline void perf_test_probe_##call(void) \
  92. { \
  93. check_trace_callback_type_##call(perf_trace_##template); \
  94. }
  95. #undef DEFINE_EVENT_PRINT
  96. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  97. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  98. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  99. #undef __DECLARE_EVENT_CLASS
  100. #endif /* CONFIG_PERF_EVENTS */