marker.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <linux/types.h>
  14. #include <linux/rcupdate.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. } __attribute__((aligned(8)));
  47. #ifdef CONFIG_MARKERS
  48. /*
  49. * Note : the empty asm volatile with read constraint is used here instead of a
  50. * "used" attribute to fix a gcc 4.1.x bug.
  51. * Make sure the alignment of the structure in the __markers section will
  52. * not add unwanted padding between the beginning of the section and the
  53. * structure. Force alignment to the same alignment as the section start.
  54. *
  55. * The "generic" argument controls which marker enabling mechanism must be used.
  56. * If generic is true, a variable read is used.
  57. * If generic is false, immediate values are used.
  58. */
  59. #define __trace_mark(generic, name, call_private, format, args...) \
  60. do { \
  61. static const char __mstrtab_##name[] \
  62. __attribute__((section("__markers_strings"))) \
  63. = #name "\0" format; \
  64. static struct marker __mark_##name \
  65. __attribute__((section("__markers"), aligned(8))) = \
  66. { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
  67. 0, 0, marker_probe_cb, \
  68. { __mark_empty_function, NULL}, NULL }; \
  69. __mark_check_format(format, ## args); \
  70. if (unlikely(__mark_##name.state)) { \
  71. (*__mark_##name.call) \
  72. (&__mark_##name, call_private, ## args);\
  73. } \
  74. } while (0)
  75. extern void marker_update_probe_range(struct marker *begin,
  76. struct marker *end);
  77. #else /* !CONFIG_MARKERS */
  78. #define __trace_mark(generic, name, call_private, format, args...) \
  79. __mark_check_format(format, ## args)
  80. static inline void marker_update_probe_range(struct marker *begin,
  81. struct marker *end)
  82. { }
  83. #endif /* CONFIG_MARKERS */
  84. /**
  85. * trace_mark - Marker using code patching
  86. * @name: marker name, not quoted.
  87. * @format: format string
  88. * @args...: variable argument list
  89. *
  90. * Places a marker using optimized code patching technique (imv_read())
  91. * to be enabled when immediate values are present.
  92. */
  93. #define trace_mark(name, format, args...) \
  94. __trace_mark(0, name, NULL, format, ## args)
  95. /**
  96. * _trace_mark - Marker using variable read
  97. * @name: marker name, not quoted.
  98. * @format: format string
  99. * @args...: variable argument list
  100. *
  101. * Places a marker using a standard memory read (_imv_read()) to be
  102. * enabled. Should be used for markers in code paths where instruction
  103. * modification based enabling is not welcome. (__init and __exit functions,
  104. * lockdep, some traps, printk).
  105. */
  106. #define _trace_mark(name, format, args...) \
  107. __trace_mark(1, name, NULL, format, ## args)
  108. /**
  109. * MARK_NOARGS - Format string for a marker with no argument.
  110. */
  111. #define MARK_NOARGS " "
  112. /* To be used for string format validity checking with gcc */
  113. static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
  114. {
  115. }
  116. #define __mark_check_format(format, args...) \
  117. do { \
  118. if (0) \
  119. ___mark_check_format(format, ## args); \
  120. } while (0)
  121. extern marker_probe_func __mark_empty_function;
  122. extern void marker_probe_cb(const struct marker *mdata,
  123. void *call_private, ...);
  124. extern void marker_probe_cb_noarg(const struct marker *mdata,
  125. void *call_private, ...);
  126. /*
  127. * Connect a probe to a marker.
  128. * private data pointer must be a valid allocated memory address, or NULL.
  129. */
  130. extern int marker_probe_register(const char *name, const char *format,
  131. marker_probe_func *probe, void *probe_private);
  132. /*
  133. * Returns the private data given to marker_probe_register.
  134. */
  135. extern int marker_probe_unregister(const char *name,
  136. marker_probe_func *probe, void *probe_private);
  137. /*
  138. * Unregister a marker by providing the registered private data.
  139. */
  140. extern int marker_probe_unregister_private_data(marker_probe_func *probe,
  141. void *probe_private);
  142. extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
  143. int num);
  144. /*
  145. * marker_synchronize_unregister must be called between the last marker probe
  146. * unregistration and the end of module exit to make sure there is no caller
  147. * executing a probe when it is freed.
  148. */
  149. static inline void marker_synchronize_unregister(void)
  150. {
  151. synchronize_sched();
  152. }
  153. #endif