marker.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. struct module;
  15. struct marker;
  16. /**
  17. * marker_probe_func - Type of a marker probe function
  18. * @probe_private: probe private data
  19. * @call_private: call site private data
  20. * @fmt: format string
  21. * @args: variable argument list pointer. Use a pointer to overcome C's
  22. * inability to pass this around as a pointer in a portable manner in
  23. * the callee otherwise.
  24. *
  25. * Type of marker probe functions. They receive the mdata and need to parse the
  26. * format string to recover the variable argument list.
  27. */
  28. typedef void marker_probe_func(void *probe_private, void *call_private,
  29. const char *fmt, va_list *args);
  30. struct marker_probe_closure {
  31. marker_probe_func *func; /* Callback */
  32. void *probe_private; /* Private probe data */
  33. };
  34. struct marker {
  35. const char *name; /* Marker name */
  36. const char *format; /* Marker format string, describing the
  37. * variable argument list.
  38. */
  39. char state; /* Marker state. */
  40. char ptype; /* probe type : 0 : single, 1 : multi */
  41. /* Probe wrapper */
  42. void (*call)(const struct marker *mdata, void *call_private, ...);
  43. struct marker_probe_closure single;
  44. struct marker_probe_closure *multi;
  45. } __attribute__((aligned(8)));
  46. #ifdef CONFIG_MARKERS
  47. /*
  48. * Note : the empty asm volatile with read constraint is used here instead of a
  49. * "used" attribute to fix a gcc 4.1.x bug.
  50. * Make sure the alignment of the structure in the __markers 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. * The "generic" argument controls which marker enabling mechanism must be used.
  55. * If generic is true, a variable read is used.
  56. * If generic is false, immediate values are used.
  57. */
  58. #define __trace_mark(generic, name, call_private, format, args...) \
  59. do { \
  60. static const char __mstrtab_##name[] \
  61. __attribute__((section("__markers_strings"))) \
  62. = #name "\0" format; \
  63. static struct marker __mark_##name \
  64. __attribute__((section("__markers"), aligned(8))) = \
  65. { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
  66. 0, 0, marker_probe_cb, \
  67. { __mark_empty_function, NULL}, NULL }; \
  68. __mark_check_format(format, ## args); \
  69. if (unlikely(__mark_##name.state)) { \
  70. (*__mark_##name.call) \
  71. (&__mark_##name, call_private, ## args);\
  72. } \
  73. } while (0)
  74. extern void marker_update_probe_range(struct marker *begin,
  75. struct marker *end);
  76. #else /* !CONFIG_MARKERS */
  77. #define __trace_mark(generic, name, call_private, format, args...) \
  78. __mark_check_format(format, ## args)
  79. static inline void marker_update_probe_range(struct marker *begin,
  80. struct marker *end)
  81. { }
  82. #endif /* CONFIG_MARKERS */
  83. /**
  84. * trace_mark - Marker using code patching
  85. * @name: marker name, not quoted.
  86. * @format: format string
  87. * @args...: variable argument list
  88. *
  89. * Places a marker using optimized code patching technique (imv_read())
  90. * to be enabled when immediate values are present.
  91. */
  92. #define trace_mark(name, format, args...) \
  93. __trace_mark(0, name, NULL, format, ## args)
  94. /**
  95. * _trace_mark - Marker using variable read
  96. * @name: marker name, not quoted.
  97. * @format: format string
  98. * @args...: variable argument list
  99. *
  100. * Places a marker using a standard memory read (_imv_read()) to be
  101. * enabled. Should be used for markers in code paths where instruction
  102. * modification based enabling is not welcome. (__init and __exit functions,
  103. * lockdep, some traps, printk).
  104. */
  105. #define _trace_mark(name, format, args...) \
  106. __trace_mark(1, name, NULL, format, ## args)
  107. /**
  108. * MARK_NOARGS - Format string for a marker with no argument.
  109. */
  110. #define MARK_NOARGS " "
  111. /* To be used for string format validity checking with gcc */
  112. static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
  113. {
  114. }
  115. #define __mark_check_format(format, args...) \
  116. do { \
  117. if (0) \
  118. ___mark_check_format(format, ## args); \
  119. } while (0)
  120. extern marker_probe_func __mark_empty_function;
  121. extern void marker_probe_cb(const struct marker *mdata,
  122. void *call_private, ...);
  123. extern void marker_probe_cb_noarg(const struct marker *mdata,
  124. void *call_private, ...);
  125. /*
  126. * Connect a probe to a marker.
  127. * private data pointer must be a valid allocated memory address, or NULL.
  128. */
  129. extern int marker_probe_register(const char *name, const char *format,
  130. marker_probe_func *probe, void *probe_private);
  131. /*
  132. * Returns the private data given to marker_probe_register.
  133. */
  134. extern int marker_probe_unregister(const char *name,
  135. marker_probe_func *probe, void *probe_private);
  136. /*
  137. * Unregister a marker by providing the registered private data.
  138. */
  139. extern int marker_probe_unregister_private_data(marker_probe_func *probe,
  140. void *probe_private);
  141. extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
  142. int num);
  143. /*
  144. * marker_synchronize_unregister must be called between the last marker probe
  145. * unregistration and the end of module exit to make sure there is no caller
  146. * executing a probe when it is freed.
  147. */
  148. #define marker_synchronize_unregister() synchronize_sched()
  149. #endif