marker.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #ifndef _LINUX_MARKER_H
  2. #define _LINUX_MARKER_H
  3. /*
  4. * Code markup for dynamic and static tracing.
  5. *
  6. * See Documentation/marker.txt.
  7. *
  8. * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
  9. *
  10. * This file is released under the GPLv2.
  11. * See the file COPYING for more details.
  12. */
  13. #include <stdarg.h>
  14. #include <linux/types.h>
  15. struct module;
  16. struct marker;
  17. /**
  18. * marker_probe_func - Type of a marker probe function
  19. * @probe_private: probe private data
  20. * @call_private: call site private data
  21. * @fmt: format string
  22. * @args: variable argument list pointer. Use a pointer to overcome C's
  23. * inability to pass this around as a pointer in a portable manner in
  24. * the callee otherwise.
  25. *
  26. * Type of marker probe functions. They receive the mdata and need to parse the
  27. * format string to recover the variable argument list.
  28. */
  29. typedef void marker_probe_func(void *probe_private, void *call_private,
  30. const char *fmt, va_list *args);
  31. struct marker_probe_closure {
  32. marker_probe_func *func; /* Callback */
  33. void *probe_private; /* Private probe data */
  34. };
  35. struct marker {
  36. const char *name; /* Marker name */
  37. const char *format; /* Marker format string, describing the
  38. * variable argument list.
  39. */
  40. char state; /* Marker state. */
  41. char ptype; /* probe type : 0 : single, 1 : multi */
  42. /* Probe wrapper */
  43. void (*call)(const struct marker *mdata, void *call_private, ...);
  44. struct marker_probe_closure single;
  45. struct marker_probe_closure *multi;
  46. const char *tp_name; /* Optional tracepoint name */
  47. void *tp_cb; /* Optional tracepoint callback */
  48. } __attribute__((aligned(8)));
  49. #ifdef CONFIG_MARKERS
  50. #define _DEFINE_MARKER(name, tp_name_str, tp_cb, format) \
  51. static const char __mstrtab_##name[] \
  52. __attribute__((section("__markers_strings"))) \
  53. = #name "\0" format; \
  54. static struct marker __mark_##name \
  55. __attribute__((section("__markers"), aligned(8))) = \
  56. { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
  57. 0, 0, marker_probe_cb, { __mark_empty_function, NULL},\
  58. NULL, tp_name_str, tp_cb }
  59. #define DEFINE_MARKER(name, format) \
  60. _DEFINE_MARKER(name, NULL, NULL, format)
  61. #define DEFINE_MARKER_TP(name, tp_name, tp_cb, format) \
  62. _DEFINE_MARKER(name, #tp_name, tp_cb, format)
  63. /*
  64. * Note : the empty asm volatile with read constraint is used here instead of a
  65. * "used" attribute to fix a gcc 4.1.x bug.
  66. * Make sure the alignment of the structure in the __markers section will
  67. * not add unwanted padding between the beginning of the section and the
  68. * structure. Force alignment to the same alignment as the section start.
  69. *
  70. * The "generic" argument controls which marker enabling mechanism must be used.
  71. * If generic is true, a variable read is used.
  72. * If generic is false, immediate values are used.
  73. */
  74. #define __trace_mark(generic, name, call_private, format, args...) \
  75. do { \
  76. DEFINE_MARKER(name, format); \
  77. __mark_check_format(format, ## args); \
  78. if (unlikely(__mark_##name.state)) { \
  79. (*__mark_##name.call) \
  80. (&__mark_##name, call_private, ## args);\
  81. } \
  82. } while (0)
  83. #define __trace_mark_tp(name, call_private, tp_name, tp_cb, format, args...) \
  84. do { \
  85. void __check_tp_type(void) \
  86. { \
  87. register_trace_##tp_name(tp_cb); \
  88. } \
  89. DEFINE_MARKER_TP(name, tp_name, tp_cb, format); \
  90. __mark_check_format(format, ## args); \
  91. (*__mark_##name.call)(&__mark_##name, call_private, \
  92. ## args); \
  93. } while (0)
  94. extern void marker_update_probe_range(struct marker *begin,
  95. struct marker *end);
  96. #define GET_MARKER(name) (__mark_##name)
  97. #else /* !CONFIG_MARKERS */
  98. #define DEFINE_MARKER(name, tp_name, tp_cb, format)
  99. #define __trace_mark(generic, name, call_private, format, args...) \
  100. __mark_check_format(format, ## args)
  101. #define __trace_mark_tp(name, call_private, tp_name, tp_cb, format, args...) \
  102. do { \
  103. void __check_tp_type(void) \
  104. { \
  105. register_trace_##tp_name(tp_cb); \
  106. } \
  107. __mark_check_format(format, ## args); \
  108. } while (0)
  109. static inline void marker_update_probe_range(struct marker *begin,
  110. struct marker *end)
  111. { }
  112. #define GET_MARKER(name)
  113. #endif /* CONFIG_MARKERS */
  114. /**
  115. * trace_mark - Marker using code patching
  116. * @name: marker name, not quoted.
  117. * @format: format string
  118. * @args...: variable argument list
  119. *
  120. * Places a marker using optimized code patching technique (imv_read())
  121. * to be enabled when immediate values are present.
  122. */
  123. #define trace_mark(name, format, args...) \
  124. __trace_mark(0, name, NULL, format, ## args)
  125. /**
  126. * _trace_mark - Marker using variable read
  127. * @name: marker name, not quoted.
  128. * @format: format string
  129. * @args...: variable argument list
  130. *
  131. * Places a marker using a standard memory read (_imv_read()) to be
  132. * enabled. Should be used for markers in code paths where instruction
  133. * modification based enabling is not welcome. (__init and __exit functions,
  134. * lockdep, some traps, printk).
  135. */
  136. #define _trace_mark(name, format, args...) \
  137. __trace_mark(1, name, NULL, format, ## args)
  138. /**
  139. * trace_mark_tp - Marker in a tracepoint callback
  140. * @name: marker name, not quoted.
  141. * @tp_name: tracepoint name, not quoted.
  142. * @tp_cb: tracepoint callback. Should have an associated global symbol so it
  143. * is not optimized away by the compiler (should not be static).
  144. * @format: format string
  145. * @args...: variable argument list
  146. *
  147. * Places a marker in a tracepoint callback.
  148. */
  149. #define trace_mark_tp(name, tp_name, tp_cb, format, args...) \
  150. __trace_mark_tp(name, NULL, tp_name, tp_cb, format, ## args)
  151. /**
  152. * MARK_NOARGS - Format string for a marker with no argument.
  153. */
  154. #define MARK_NOARGS " "
  155. /* To be used for string format validity checking with gcc */
  156. static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
  157. {
  158. }
  159. #define __mark_check_format(format, args...) \
  160. do { \
  161. if (0) \
  162. ___mark_check_format(format, ## args); \
  163. } while (0)
  164. extern marker_probe_func __mark_empty_function;
  165. extern void marker_probe_cb(const struct marker *mdata,
  166. void *call_private, ...);
  167. /*
  168. * Connect a probe to a marker.
  169. * private data pointer must be a valid allocated memory address, or NULL.
  170. */
  171. extern int marker_probe_register(const char *name, const char *format,
  172. marker_probe_func *probe, void *probe_private);
  173. /*
  174. * Returns the private data given to marker_probe_register.
  175. */
  176. extern int marker_probe_unregister(const char *name,
  177. marker_probe_func *probe, void *probe_private);
  178. /*
  179. * Unregister a marker by providing the registered private data.
  180. */
  181. extern int marker_probe_unregister_private_data(marker_probe_func *probe,
  182. void *probe_private);
  183. extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
  184. int num);
  185. /*
  186. * marker_synchronize_unregister must be called between the last marker probe
  187. * unregistration and the first one of
  188. * - the end of module exit function
  189. * - the free of any resource used by the probes
  190. * to ensure the code and data are valid for any possibly running probes.
  191. */
  192. #define marker_synchronize_unregister() synchronize_sched()
  193. #endif