marker.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * @mdata: pointer of type struct marker
  19. * @private_data: caller site private data
  20. * @fmt: format string
  21. * @...: variable argument list
  22. *
  23. * Type of marker probe functions. They receive the mdata and need to parse the
  24. * format string to recover the variable argument list.
  25. */
  26. typedef void marker_probe_func(const struct marker *mdata,
  27. void *private_data, const char *fmt, ...);
  28. struct marker {
  29. const char *name; /* Marker name */
  30. const char *format; /* Marker format string, describing the
  31. * variable argument list.
  32. */
  33. char state; /* Marker state. */
  34. marker_probe_func *call;/* Probe handler function pointer */
  35. void *private; /* Private probe data */
  36. } __attribute__((aligned(8)));
  37. #ifdef CONFIG_MARKERS
  38. /*
  39. * Note : the empty asm volatile with read constraint is used here instead of a
  40. * "used" attribute to fix a gcc 4.1.x bug.
  41. * Make sure the alignment of the structure in the __markers section will
  42. * not add unwanted padding between the beginning of the section and the
  43. * structure. Force alignment to the same alignment as the section start.
  44. */
  45. #define __trace_mark(name, call_data, format, args...) \
  46. do { \
  47. static const char __mstrtab_name_##name[] \
  48. __attribute__((section("__markers_strings"))) \
  49. = #name; \
  50. static const char __mstrtab_format_##name[] \
  51. __attribute__((section("__markers_strings"))) \
  52. = format; \
  53. static struct marker __mark_##name \
  54. __attribute__((section("__markers"), aligned(8))) = \
  55. { __mstrtab_name_##name, __mstrtab_format_##name, \
  56. 0, __mark_empty_function, NULL }; \
  57. asm volatile("" : : "i" (&__mark_##name)); \
  58. __mark_check_format(format, ## args); \
  59. if (unlikely(__mark_##name.state)) { \
  60. preempt_disable(); \
  61. (*__mark_##name.call) \
  62. (&__mark_##name, call_data, \
  63. format, ## args); \
  64. preempt_enable(); \
  65. } \
  66. } while (0)
  67. extern void marker_update_probe_range(struct marker *begin,
  68. struct marker *end, struct module *probe_module, int *refcount);
  69. #else /* !CONFIG_MARKERS */
  70. #define __trace_mark(name, call_data, format, args...) \
  71. __mark_check_format(format, ## args)
  72. static inline void marker_update_probe_range(struct marker *begin,
  73. struct marker *end, struct module *probe_module, int *refcount)
  74. { }
  75. #endif /* CONFIG_MARKERS */
  76. /**
  77. * trace_mark - Marker
  78. * @name: marker name, not quoted.
  79. * @format: format string
  80. * @args...: variable argument list
  81. *
  82. * Places a marker.
  83. */
  84. #define trace_mark(name, format, args...) \
  85. __trace_mark(name, NULL, format, ## args)
  86. #define MARK_MAX_FORMAT_LEN 1024
  87. /**
  88. * MARK_NOARGS - Format string for a marker with no argument.
  89. */
  90. #define MARK_NOARGS " "
  91. /* To be used for string format validity checking with gcc */
  92. static inline void __printf(1, 2) __mark_check_format(const char *fmt, ...)
  93. {
  94. }
  95. extern marker_probe_func __mark_empty_function;
  96. /*
  97. * Connect a probe to a marker.
  98. * private data pointer must be a valid allocated memory address, or NULL.
  99. */
  100. extern int marker_probe_register(const char *name, const char *format,
  101. marker_probe_func *probe, void *private);
  102. /*
  103. * Returns the private data given to marker_probe_register.
  104. */
  105. extern void *marker_probe_unregister(const char *name);
  106. /*
  107. * Unregister a marker by providing the registered private data.
  108. */
  109. extern void *marker_probe_unregister_private_data(void *private);
  110. extern int marker_arm(const char *name);
  111. extern int marker_disarm(const char *name);
  112. extern void *marker_get_private_data(const char *name);
  113. #endif