tracepoint-defs.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef TRACEPOINT_DEFS_H
  3. #define TRACEPOINT_DEFS_H 1
  4. /*
  5. * File can be included directly by headers who only want to access
  6. * tracepoint->key to guard out of line trace calls, or the definition of
  7. * trace_print_flags{_u64}. Otherwise linux/tracepoint.h should be used.
  8. */
  9. #include <linux/atomic.h>
  10. #include <linux/static_key.h>
  11. struct static_call_key;
  12. struct trace_print_flags {
  13. unsigned long mask;
  14. const char *name;
  15. };
  16. struct trace_print_flags_u64 {
  17. unsigned long long mask;
  18. const char *name;
  19. };
  20. struct tracepoint_func {
  21. void *func;
  22. void *data;
  23. int prio;
  24. };
  25. struct tracepoint {
  26. const char *name; /* Tracepoint name */
  27. struct static_key key;
  28. struct static_call_key *static_call_key;
  29. void *static_call_tramp;
  30. void *iterator;
  31. int (*regfunc)(void);
  32. void (*unregfunc)(void);
  33. struct tracepoint_func __rcu *funcs;
  34. };
  35. #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
  36. typedef const int tracepoint_ptr_t;
  37. #else
  38. typedef struct tracepoint * const tracepoint_ptr_t;
  39. #endif
  40. struct bpf_raw_event_map {
  41. struct tracepoint *tp;
  42. void *bpf_func;
  43. u32 num_args;
  44. u32 writable_size;
  45. } __aligned(32);
  46. /*
  47. * If a tracepoint needs to be called from a header file, it is not
  48. * recommended to call it directly, as tracepoints in header files
  49. * may cause side-effects and bloat the kernel. Instead, use
  50. * tracepoint_enabled() to test if the tracepoint is enabled, then if
  51. * it is, call a wrapper function defined in a C file that will then
  52. * call the tracepoint.
  53. *
  54. * For "trace_foo_bar()", you would need to create a wrapper function
  55. * in a C file to call trace_foo_bar():
  56. * void do_trace_foo_bar(args) { trace_foo_bar(args); }
  57. * Then in the header file, declare the tracepoint:
  58. * DECLARE_TRACEPOINT(foo_bar);
  59. * And call your wrapper:
  60. * static inline void some_inlined_function() {
  61. * [..]
  62. * if (tracepoint_enabled(foo_bar))
  63. * do_trace_foo_bar(args);
  64. * [..]
  65. * }
  66. *
  67. * Note: tracepoint_enabled(foo_bar) is equivalent to trace_foo_bar_enabled()
  68. * but is safe to have in headers, where trace_foo_bar_enabled() is not.
  69. */
  70. #define DECLARE_TRACEPOINT(tp) \
  71. extern struct tracepoint __tracepoint_##tp
  72. #ifdef CONFIG_TRACEPOINTS
  73. # define tracepoint_enabled(tp) \
  74. static_key_false(&(__tracepoint_##tp).key)
  75. #else
  76. # define tracepoint_enabled(tracepoint) false
  77. #endif
  78. #endif