marker.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. void (*call)(const struct marker *mdata, /* Probe wrapper */
  42. void *call_private, const char *fmt, ...);
  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. #define __trace_mark(name, call_private, format, args...) \
  55. do { \
  56. static const char __mstrtab_##name[] \
  57. __attribute__((section("__markers_strings"))) \
  58. = #name "\0" format; \
  59. static struct marker __mark_##name \
  60. __attribute__((section("__markers"), aligned(8))) = \
  61. { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
  62. 0, 0, marker_probe_cb, \
  63. { __mark_empty_function, NULL}, NULL }; \
  64. __mark_check_format(format, ## args); \
  65. if (unlikely(__mark_##name.state)) { \
  66. (*__mark_##name.call) \
  67. (&__mark_##name, call_private, \
  68. format, ## args); \
  69. } \
  70. } while (0)
  71. extern void marker_update_probe_range(struct marker *begin,
  72. struct marker *end);
  73. #else /* !CONFIG_MARKERS */
  74. #define __trace_mark(name, call_private, format, args...) \
  75. __mark_check_format(format, ## args)
  76. static inline void marker_update_probe_range(struct marker *begin,
  77. struct marker *end)
  78. { }
  79. #endif /* CONFIG_MARKERS */
  80. /**
  81. * trace_mark - Marker
  82. * @name: marker name, not quoted.
  83. * @format: format string
  84. * @args...: variable argument list
  85. *
  86. * Places a marker.
  87. */
  88. #define trace_mark(name, format, args...) \
  89. __trace_mark(name, NULL, format, ## args)
  90. /**
  91. * MARK_NOARGS - Format string for a marker with no argument.
  92. */
  93. #define MARK_NOARGS " "
  94. /* To be used for string format validity checking with gcc */
  95. static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
  96. {
  97. }
  98. #define __mark_check_format(format, args...) \
  99. do { \
  100. if (0) \
  101. ___mark_check_format(format, ## args); \
  102. } while (0)
  103. extern marker_probe_func __mark_empty_function;
  104. extern void marker_probe_cb(const struct marker *mdata,
  105. void *call_private, const char *fmt, ...);
  106. extern void marker_probe_cb_noarg(const struct marker *mdata,
  107. void *call_private, const char *fmt, ...);
  108. /*
  109. * Connect a probe to a marker.
  110. * private data pointer must be a valid allocated memory address, or NULL.
  111. */
  112. extern int marker_probe_register(const char *name, const char *format,
  113. marker_probe_func *probe, void *probe_private);
  114. /*
  115. * Returns the private data given to marker_probe_register.
  116. */
  117. extern int marker_probe_unregister(const char *name,
  118. marker_probe_func *probe, void *probe_private);
  119. /*
  120. * Unregister a marker by providing the registered private data.
  121. */
  122. extern int marker_probe_unregister_private_data(marker_probe_func *probe,
  123. void *probe_private);
  124. extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
  125. int num);
  126. #endif