tracepoint.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #ifndef _LINUX_TRACEPOINT_H
  2. #define _LINUX_TRACEPOINT_H
  3. /*
  4. * Kernel Tracepoint API.
  5. *
  6. * See Documentation/tracepoint.txt.
  7. *
  8. * (C) Copyright 2008 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
  9. *
  10. * Heavily inspired from the Linux Kernel Markers.
  11. *
  12. * This file is released under the GPLv2.
  13. * See the file COPYING for more details.
  14. */
  15. #include <linux/types.h>
  16. #include <linux/rcupdate.h>
  17. struct module;
  18. struct tracepoint;
  19. struct tracepoint {
  20. const char *name; /* Tracepoint name */
  21. int state; /* State. */
  22. void **funcs;
  23. } __attribute__((aligned(32))); /*
  24. * Aligned on 32 bytes because it is
  25. * globally visible and gcc happily
  26. * align these on the structure size.
  27. * Keep in sync with vmlinux.lds.h.
  28. */
  29. #define TP_PROTO(args...) args
  30. #define TP_ARGS(args...) args
  31. #ifdef CONFIG_TRACEPOINTS
  32. /*
  33. * it_func[0] is never NULL because there is at least one element in the array
  34. * when the array itself is non NULL.
  35. */
  36. #define __DO_TRACE(tp, proto, args) \
  37. do { \
  38. void **it_func; \
  39. \
  40. rcu_read_lock_sched_notrace(); \
  41. it_func = rcu_dereference((tp)->funcs); \
  42. if (it_func) { \
  43. do { \
  44. ((void(*)(proto))(*it_func))(args); \
  45. } while (*(++it_func)); \
  46. } \
  47. rcu_read_unlock_sched_notrace(); \
  48. } while (0)
  49. /*
  50. * Make sure the alignment of the structure in the __tracepoints section will
  51. * not add unwanted padding between the beginning of the section and the
  52. * structure. Force alignment to the same alignment as the section start.
  53. */
  54. #define DECLARE_TRACE(name, proto, args) \
  55. extern struct tracepoint __tracepoint_##name; \
  56. static inline void trace_##name(proto) \
  57. { \
  58. if (unlikely(__tracepoint_##name.state)) \
  59. __DO_TRACE(&__tracepoint_##name, \
  60. TP_PROTO(proto), TP_ARGS(args)); \
  61. } \
  62. static inline int register_trace_##name(void (*probe)(proto)) \
  63. { \
  64. return tracepoint_probe_register(#name, (void *)probe); \
  65. } \
  66. static inline int unregister_trace_##name(void (*probe)(proto)) \
  67. { \
  68. return tracepoint_probe_unregister(#name, (void *)probe);\
  69. }
  70. #define DEFINE_TRACE(name) \
  71. static const char __tpstrtab_##name[] \
  72. __attribute__((section("__tracepoints_strings"))) = #name; \
  73. struct tracepoint __tracepoint_##name \
  74. __attribute__((section("__tracepoints"), aligned(32))) = \
  75. { __tpstrtab_##name, 0, NULL }
  76. #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
  77. EXPORT_SYMBOL_GPL(__tracepoint_##name)
  78. #define EXPORT_TRACEPOINT_SYMBOL(name) \
  79. EXPORT_SYMBOL(__tracepoint_##name)
  80. extern void tracepoint_update_probe_range(struct tracepoint *begin,
  81. struct tracepoint *end);
  82. #else /* !CONFIG_TRACEPOINTS */
  83. #define DECLARE_TRACE(name, proto, args) \
  84. static inline void _do_trace_##name(struct tracepoint *tp, proto) \
  85. { } \
  86. static inline void trace_##name(proto) \
  87. { } \
  88. static inline int register_trace_##name(void (*probe)(proto)) \
  89. { \
  90. return -ENOSYS; \
  91. } \
  92. static inline int unregister_trace_##name(void (*probe)(proto)) \
  93. { \
  94. return -ENOSYS; \
  95. }
  96. #define DEFINE_TRACE(name)
  97. #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
  98. #define EXPORT_TRACEPOINT_SYMBOL(name)
  99. static inline void tracepoint_update_probe_range(struct tracepoint *begin,
  100. struct tracepoint *end)
  101. { }
  102. #endif /* CONFIG_TRACEPOINTS */
  103. /*
  104. * Connect a probe to a tracepoint.
  105. * Internal API, should not be used directly.
  106. */
  107. extern int tracepoint_probe_register(const char *name, void *probe);
  108. /*
  109. * Disconnect a probe from a tracepoint.
  110. * Internal API, should not be used directly.
  111. */
  112. extern int tracepoint_probe_unregister(const char *name, void *probe);
  113. extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
  114. extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
  115. extern void tracepoint_probe_update_all(void);
  116. struct tracepoint_iter {
  117. struct module *module;
  118. struct tracepoint *tracepoint;
  119. };
  120. extern void tracepoint_iter_start(struct tracepoint_iter *iter);
  121. extern void tracepoint_iter_next(struct tracepoint_iter *iter);
  122. extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
  123. extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
  124. extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
  125. struct tracepoint *begin, struct tracepoint *end);
  126. /*
  127. * tracepoint_synchronize_unregister must be called between the last tracepoint
  128. * probe unregistration and the end of module exit to make sure there is no
  129. * caller executing a probe when it is freed.
  130. */
  131. static inline void tracepoint_synchronize_unregister(void)
  132. {
  133. synchronize_sched();
  134. }
  135. #define PARAMS(args...) args
  136. #define TRACE_FORMAT(name, proto, args, fmt) \
  137. DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
  138. #define TRACE_EVENT(name, proto, args, struct, assign, print) \
  139. DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
  140. #endif