marker.h 4.3 KB

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