tracepoint.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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(8)));
  24. #define TPPROTO(args...) args
  25. #define TPARGS(args...) args
  26. #ifdef CONFIG_TRACEPOINTS
  27. /*
  28. * it_func[0] is never NULL because there is at least one element in the array
  29. * when the array itself is non NULL.
  30. */
  31. #define __DO_TRACE(tp, proto, args) \
  32. do { \
  33. void **it_func; \
  34. \
  35. rcu_read_lock_sched(); \
  36. it_func = rcu_dereference((tp)->funcs); \
  37. if (it_func) { \
  38. do { \
  39. ((void(*)(proto))(*it_func))(args); \
  40. } while (*(++it_func)); \
  41. } \
  42. rcu_read_unlock_sched(); \
  43. } while (0)
  44. /*
  45. * Make sure the alignment of the structure in the __tracepoints section will
  46. * not add unwanted padding between the beginning of the section and the
  47. * structure. Force alignment to the same alignment as the section start.
  48. */
  49. #define DEFINE_TRACE(name, proto, args) \
  50. static inline void trace_##name(proto) \
  51. { \
  52. static const char __tpstrtab_##name[] \
  53. __attribute__((section("__tracepoints_strings"))) \
  54. = #name ":" #proto; \
  55. static struct tracepoint __tracepoint_##name \
  56. __attribute__((section("__tracepoints"), aligned(8))) = \
  57. { __tpstrtab_##name, 0, NULL }; \
  58. if (unlikely(__tracepoint_##name.state)) \
  59. __DO_TRACE(&__tracepoint_##name, \
  60. TPPROTO(proto), TPARGS(args)); \
  61. } \
  62. static inline int register_trace_##name(void (*probe)(proto)) \
  63. { \
  64. return tracepoint_probe_register(#name ":" #proto, \
  65. (void *)probe); \
  66. } \
  67. static inline void unregister_trace_##name(void (*probe)(proto))\
  68. { \
  69. tracepoint_probe_unregister(#name ":" #proto, \
  70. (void *)probe); \
  71. }
  72. extern void tracepoint_update_probe_range(struct tracepoint *begin,
  73. struct tracepoint *end);
  74. #else /* !CONFIG_TRACEPOINTS */
  75. #define DEFINE_TRACE(name, proto, args) \
  76. static inline void _do_trace_##name(struct tracepoint *tp, proto) \
  77. { } \
  78. static inline void trace_##name(proto) \
  79. { } \
  80. static inline int register_trace_##name(void (*probe)(proto)) \
  81. { \
  82. return -ENOSYS; \
  83. } \
  84. static inline void unregister_trace_##name(void (*probe)(proto))\
  85. { }
  86. static inline void tracepoint_update_probe_range(struct tracepoint *begin,
  87. struct tracepoint *end)
  88. { }
  89. #endif /* CONFIG_TRACEPOINTS */
  90. /*
  91. * Connect a probe to a tracepoint.
  92. * Internal API, should not be used directly.
  93. */
  94. extern int tracepoint_probe_register(const char *name, void *probe);
  95. /*
  96. * Disconnect a probe from a tracepoint.
  97. * Internal API, should not be used directly.
  98. */
  99. extern int tracepoint_probe_unregister(const char *name, void *probe);
  100. struct tracepoint_iter {
  101. struct module *module;
  102. struct tracepoint *tracepoint;
  103. };
  104. extern void tracepoint_iter_start(struct tracepoint_iter *iter);
  105. extern void tracepoint_iter_next(struct tracepoint_iter *iter);
  106. extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
  107. extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
  108. extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
  109. struct tracepoint *begin, struct tracepoint *end);
  110. /*
  111. * tracepoint_synchronize_unregister must be called between the last tracepoint
  112. * probe unregistration and the end of module exit to make sure there is no
  113. * caller executing a probe when it is freed.
  114. */
  115. static inline void tracepoint_synchronize_unregister(void)
  116. {
  117. synchronize_sched();
  118. }
  119. #endif