perf.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 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. * This part is compiled out, it is only here as a build time check
  53. * to make sure that if the tracepoint handling changes, the
  54. * perf probe will fail to compile unless it too is updated.
  55. */
  56. #undef DEFINE_EVENT
  57. #define DEFINE_EVENT(template, call, proto, args) \
  58. static inline void perf_test_probe_##call(void) \
  59. { \
  60. check_trace_callback_type_##call(perf_trace_##template); \
  61. }
  62. #undef DEFINE_EVENT_PRINT
  63. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  64. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  65. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  66. #endif /* CONFIG_PERF_EVENTS */