1 #ifndef _LINUX_MARKER_H
2 #define _LINUX_MARKER_H
5 * Code markup for dynamic and static tracing.
7 * See Documentation/marker.txt.
9 * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
11 * This file is released under the GPLv2.
12 * See the file COPYING for more details.
15 #include <linux/types.h>
16 #include <linux/rcupdate.h>
22 * marker_probe_func - Type of a marker probe function
23 * @probe_private: probe private data
24 * @call_private: call site private data
26 * @args: variable argument list pointer. Use a pointer to overcome C's
27 * inability to pass this around as a pointer in a portable manner in
28 * the callee otherwise.
30 * Type of marker probe functions. They receive the mdata and need to parse the
31 * format string to recover the variable argument list.
33 typedef void marker_probe_func(void *probe_private, void *call_private,
34 const char *fmt, va_list *args);
36 struct marker_probe_closure {
37 marker_probe_func *func; /* Callback */
38 void *probe_private; /* Private probe data */
42 const char *name; /* Marker name */
43 const char *format; /* Marker format string, describing the
44 * variable argument list.
46 char state; /* Marker state. */
47 char ptype; /* probe type : 0 : single, 1 : multi */
49 void (*call)(const struct marker *mdata, void *call_private, ...);
50 struct marker_probe_closure single;
51 struct marker_probe_closure *multi;
52 } __attribute__((aligned(8)));
57 * Note : the empty asm volatile with read constraint is used here instead of a
58 * "used" attribute to fix a gcc 4.1.x bug.
59 * Make sure the alignment of the structure in the __markers section will
60 * not add unwanted padding between the beginning of the section and the
61 * structure. Force alignment to the same alignment as the section start.
63 * The "generic" argument controls which marker enabling mechanism must be used.
64 * If generic is true, a variable read is used.
65 * If generic is false, immediate values are used.
67 #define __trace_mark(generic, name, call_private, format, args...) \
69 static const char __mstrtab_##name[] \
70 __attribute__((section("__markers_strings"))) \
71 = #name "\0" format; \
72 static struct marker __mark_##name \
73 __attribute__((section("__markers"), aligned(8))) = \
74 { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
75 0, 0, marker_probe_cb, \
76 { __mark_empty_function, NULL}, NULL }; \
77 __mark_check_format(format, ## args); \
78 if (unlikely(__mark_##name.state)) { \
79 (*__mark_##name.call) \
80 (&__mark_##name, call_private, ## args);\
84 extern void marker_update_probe_range(struct marker *begin,
86 #else /* !CONFIG_MARKERS */
87 #define __trace_mark(generic, name, call_private, format, args...) \
88 __mark_check_format(format, ## args)
89 static inline void marker_update_probe_range(struct marker *begin,
92 #endif /* CONFIG_MARKERS */
95 * trace_mark - Marker using code patching
96 * @name: marker name, not quoted.
97 * @format: format string
98 * @args...: variable argument list
100 * Places a marker using optimized code patching technique (imv_read())
101 * to be enabled when immediate values are present.
103 #define trace_mark(name, format, args...) \
104 __trace_mark(0, name, NULL, format, ## args)
107 * _trace_mark - Marker using variable read
108 * @name: marker name, not quoted.
109 * @format: format string
110 * @args...: variable argument list
112 * Places a marker using a standard memory read (_imv_read()) to be
113 * enabled. Should be used for markers in code paths where instruction
114 * modification based enabling is not welcome. (__init and __exit functions,
115 * lockdep, some traps, printk).
117 #define _trace_mark(name, format, args...) \
118 __trace_mark(1, name, NULL, format, ## args)
121 * MARK_NOARGS - Format string for a marker with no argument.
123 #define MARK_NOARGS " "
125 /* To be used for string format validity checking with gcc */
126 static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
130 #define __mark_check_format(format, args...) \
133 ___mark_check_format(format, ## args); \
136 extern marker_probe_func __mark_empty_function;
138 extern void marker_probe_cb(const struct marker *mdata,
139 void *call_private, ...);
140 extern void marker_probe_cb_noarg(const struct marker *mdata,
141 void *call_private, ...);
144 * Connect a probe to a marker.
145 * private data pointer must be a valid allocated memory address, or NULL.
147 extern int marker_probe_register(const char *name, const char *format,
148 marker_probe_func *probe, void *probe_private);
151 * Returns the private data given to marker_probe_register.
153 extern int marker_probe_unregister(const char *name,
154 marker_probe_func *probe, void *probe_private);
156 * Unregister a marker by providing the registered private data.
158 extern int marker_probe_unregister_private_data(marker_probe_func *probe,
159 void *probe_private);
161 extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
165 * marker_synchronize_unregister must be called between the last marker probe
166 * unregistration and the end of module exit to make sure there is no caller
167 * executing a probe when it is freed.
169 static inline void marker_synchronize_unregister(void)