perf.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 __perf_count
  17. #define __perf_count(c) (__count = (c))
  18. #undef __perf_task
  19. #define __perf_task(t) (__task = (t))
  20. #undef DECLARE_EVENT_CLASS
  21. #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
  22. static notrace void \
  23. perf_trace_##call(void *__data, proto) \
  24. { \
  25. struct trace_event_call *event_call = __data; \
  26. struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
  27. struct trace_event_raw_##call *entry; \
  28. struct pt_regs *__regs; \
  29. u64 __count = 1; \
  30. struct task_struct *__task = NULL; \
  31. struct hlist_head *head; \
  32. int __entry_size; \
  33. int __data_size; \
  34. int rctx; \
  35. \
  36. __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
  37. \
  38. head = this_cpu_ptr(event_call->perf_events); \
  39. if (!bpf_prog_array_valid(event_call) && \
  40. __builtin_constant_p(!__task) && !__task && \
  41. hlist_empty(head)) \
  42. return; \
  43. \
  44. __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
  45. sizeof(u64)); \
  46. __entry_size -= sizeof(u32); \
  47. \
  48. entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \
  49. if (!entry) \
  50. return; \
  51. \
  52. perf_fetch_caller_regs(__regs); \
  53. \
  54. tstruct \
  55. \
  56. { assign; } \
  57. \
  58. perf_trace_run_bpf_submit(entry, __entry_size, rctx, \
  59. event_call, __count, __regs, \
  60. head, __task); \
  61. }
  62. /*
  63. * This part is compiled out, it is only here as a build time check
  64. * to make sure that if the tracepoint handling changes, the
  65. * perf probe will fail to compile unless it too is updated.
  66. */
  67. #undef DEFINE_EVENT
  68. #define DEFINE_EVENT(template, call, proto, args) \
  69. static inline void perf_test_probe_##call(void) \
  70. { \
  71. check_trace_callback_type_##call(perf_trace_##template); \
  72. }
  73. #undef DEFINE_EVENT_PRINT
  74. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  75. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  76. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  77. #endif /* CONFIG_PERF_EVENTS */