Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_MARKER_H |
| 2 | #define _LINUX_MARKER_H |
| 3 | |
| 4 | /* |
| 5 | * Code markup for dynamic and static tracing. |
| 6 | * |
| 7 | * See Documentation/marker.txt. |
| 8 | * |
| 9 | * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
| 10 | * |
| 11 | * This file is released under the GPLv2. |
| 12 | * See the file COPYING for more details. |
| 13 | */ |
| 14 | |
Arnaldo Carvalho de Melo | e3f8c4b | 2008-11-14 17:47:36 -0500 | [diff] [blame] | 15 | #include <stdarg.h> |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 16 | #include <linux/types.h> |
| 17 | |
| 18 | struct module; |
| 19 | struct marker; |
| 20 | |
| 21 | /** |
| 22 | * marker_probe_func - Type of a marker probe function |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 23 | * @probe_private: probe private data |
| 24 | * @call_private: call site private data |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 25 | * @fmt: format string |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 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. |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 29 | * |
| 30 | * Type of marker probe functions. They receive the mdata and need to parse the |
| 31 | * format string to recover the variable argument list. |
| 32 | */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 33 | typedef void marker_probe_func(void *probe_private, void *call_private, |
| 34 | const char *fmt, va_list *args); |
| 35 | |
| 36 | struct marker_probe_closure { |
| 37 | marker_probe_func *func; /* Callback */ |
| 38 | void *probe_private; /* Private probe data */ |
| 39 | }; |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 40 | |
| 41 | struct marker { |
| 42 | const char *name; /* Marker name */ |
| 43 | const char *format; /* Marker format string, describing the |
| 44 | * variable argument list. |
| 45 | */ |
| 46 | char state; /* Marker state. */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 47 | char ptype; /* probe type : 0 : single, 1 : multi */ |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 48 | /* Probe wrapper */ |
| 49 | void (*call)(const struct marker *mdata, void *call_private, ...); |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 50 | struct marker_probe_closure single; |
| 51 | struct marker_probe_closure *multi; |
Mathieu Desnoyers | c1df1bd | 2008-11-14 17:47:39 -0500 | [diff] [blame] | 52 | const char *tp_name; /* Optional tracepoint name */ |
| 53 | void *tp_cb; /* Optional tracepoint callback */ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 54 | } __attribute__((aligned(8))); |
| 55 | |
| 56 | #ifdef CONFIG_MARKERS |
| 57 | |
Mathieu Desnoyers | a0bca6a | 2008-11-14 17:47:40 -0500 | [diff] [blame] | 58 | #define _DEFINE_MARKER(name, tp_name_str, tp_cb, format) \ |
| 59 | static const char __mstrtab_##name[] \ |
| 60 | __attribute__((section("__markers_strings"))) \ |
| 61 | = #name "\0" format; \ |
| 62 | static struct marker __mark_##name \ |
| 63 | __attribute__((section("__markers"), aligned(8))) = \ |
| 64 | { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \ |
| 65 | 0, 0, marker_probe_cb, { __mark_empty_function, NULL},\ |
| 66 | NULL, tp_name_str, tp_cb } |
| 67 | |
| 68 | #define DEFINE_MARKER(name, format) \ |
| 69 | _DEFINE_MARKER(name, NULL, NULL, format) |
| 70 | |
| 71 | #define DEFINE_MARKER_TP(name, tp_name, tp_cb, format) \ |
| 72 | _DEFINE_MARKER(name, #tp_name, tp_cb, format) |
| 73 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 74 | /* |
| 75 | * Note : the empty asm volatile with read constraint is used here instead of a |
| 76 | * "used" attribute to fix a gcc 4.1.x bug. |
| 77 | * Make sure the alignment of the structure in the __markers section will |
| 78 | * not add unwanted padding between the beginning of the section and the |
| 79 | * structure. Force alignment to the same alignment as the section start. |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 80 | * |
| 81 | * The "generic" argument controls which marker enabling mechanism must be used. |
| 82 | * If generic is true, a variable read is used. |
| 83 | * If generic is false, immediate values are used. |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 84 | */ |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 85 | #define __trace_mark(generic, name, call_private, format, args...) \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 86 | do { \ |
Mathieu Desnoyers | a0bca6a | 2008-11-14 17:47:40 -0500 | [diff] [blame] | 87 | DEFINE_MARKER(name, format); \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 88 | __mark_check_format(format, ## args); \ |
| 89 | if (unlikely(__mark_##name.state)) { \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 90 | (*__mark_##name.call) \ |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 91 | (&__mark_##name, call_private, ## args);\ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 92 | } \ |
| 93 | } while (0) |
| 94 | |
Mathieu Desnoyers | c1df1bd | 2008-11-14 17:47:39 -0500 | [diff] [blame] | 95 | #define __trace_mark_tp(name, call_private, tp_name, tp_cb, format, args...) \ |
| 96 | do { \ |
| 97 | void __check_tp_type(void) \ |
| 98 | { \ |
| 99 | register_trace_##tp_name(tp_cb); \ |
| 100 | } \ |
Mathieu Desnoyers | a0bca6a | 2008-11-14 17:47:40 -0500 | [diff] [blame] | 101 | DEFINE_MARKER_TP(name, tp_name, tp_cb, format); \ |
Mathieu Desnoyers | c1df1bd | 2008-11-14 17:47:39 -0500 | [diff] [blame] | 102 | __mark_check_format(format, ## args); \ |
| 103 | (*__mark_##name.call)(&__mark_##name, call_private, \ |
| 104 | ## args); \ |
| 105 | } while (0) |
| 106 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 107 | extern void marker_update_probe_range(struct marker *begin, |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 108 | struct marker *end); |
Mathieu Desnoyers | a0bca6a | 2008-11-14 17:47:40 -0500 | [diff] [blame] | 109 | |
| 110 | #define GET_MARKER(name) (__mark_##name) |
| 111 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 112 | #else /* !CONFIG_MARKERS */ |
Mathieu Desnoyers | a0bca6a | 2008-11-14 17:47:40 -0500 | [diff] [blame] | 113 | #define DEFINE_MARKER(name, tp_name, tp_cb, format) |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 114 | #define __trace_mark(generic, name, call_private, format, args...) \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 115 | __mark_check_format(format, ## args) |
Mathieu Desnoyers | c1df1bd | 2008-11-14 17:47:39 -0500 | [diff] [blame] | 116 | #define __trace_mark_tp(name, call_private, tp_name, tp_cb, format, args...) \ |
| 117 | do { \ |
| 118 | void __check_tp_type(void) \ |
| 119 | { \ |
| 120 | register_trace_##tp_name(tp_cb); \ |
| 121 | } \ |
| 122 | __mark_check_format(format, ## args); \ |
| 123 | } while (0) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 124 | static inline void marker_update_probe_range(struct marker *begin, |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 125 | struct marker *end) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 126 | { } |
Mathieu Desnoyers | a0bca6a | 2008-11-14 17:47:40 -0500 | [diff] [blame] | 127 | #define GET_MARKER(name) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 128 | #endif /* CONFIG_MARKERS */ |
| 129 | |
| 130 | /** |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 131 | * trace_mark - Marker using code patching |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 132 | * @name: marker name, not quoted. |
| 133 | * @format: format string |
| 134 | * @args...: variable argument list |
| 135 | * |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 136 | * Places a marker using optimized code patching technique (imv_read()) |
| 137 | * to be enabled when immediate values are present. |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 138 | */ |
| 139 | #define trace_mark(name, format, args...) \ |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 140 | __trace_mark(0, name, NULL, format, ## args) |
| 141 | |
| 142 | /** |
| 143 | * _trace_mark - Marker using variable read |
| 144 | * @name: marker name, not quoted. |
| 145 | * @format: format string |
| 146 | * @args...: variable argument list |
| 147 | * |
| 148 | * Places a marker using a standard memory read (_imv_read()) to be |
| 149 | * enabled. Should be used for markers in code paths where instruction |
| 150 | * modification based enabling is not welcome. (__init and __exit functions, |
| 151 | * lockdep, some traps, printk). |
| 152 | */ |
| 153 | #define _trace_mark(name, format, args...) \ |
| 154 | __trace_mark(1, name, NULL, format, ## args) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 155 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 156 | /** |
Mathieu Desnoyers | c1df1bd | 2008-11-14 17:47:39 -0500 | [diff] [blame] | 157 | * trace_mark_tp - Marker in a tracepoint callback |
| 158 | * @name: marker name, not quoted. |
| 159 | * @tp_name: tracepoint name, not quoted. |
| 160 | * @tp_cb: tracepoint callback. Should have an associated global symbol so it |
| 161 | * is not optimized away by the compiler (should not be static). |
| 162 | * @format: format string |
| 163 | * @args...: variable argument list |
| 164 | * |
| 165 | * Places a marker in a tracepoint callback. |
| 166 | */ |
| 167 | #define trace_mark_tp(name, tp_name, tp_cb, format, args...) \ |
| 168 | __trace_mark_tp(name, NULL, tp_name, tp_cb, format, ## args) |
| 169 | |
| 170 | /** |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 171 | * MARK_NOARGS - Format string for a marker with no argument. |
| 172 | */ |
| 173 | #define MARK_NOARGS " " |
| 174 | |
| 175 | /* To be used for string format validity checking with gcc */ |
Mathieu Desnoyers | acc4988 | 2008-03-04 14:29:00 -0800 | [diff] [blame] | 176 | static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 177 | { |
| 178 | } |
| 179 | |
Mathieu Desnoyers | acc4988 | 2008-03-04 14:29:00 -0800 | [diff] [blame] | 180 | #define __mark_check_format(format, args...) \ |
| 181 | do { \ |
| 182 | if (0) \ |
| 183 | ___mark_check_format(format, ## args); \ |
| 184 | } while (0) |
| 185 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 186 | extern marker_probe_func __mark_empty_function; |
| 187 | |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 188 | extern void marker_probe_cb(const struct marker *mdata, |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 189 | void *call_private, ...); |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 190 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 191 | /* |
| 192 | * Connect a probe to a marker. |
| 193 | * private data pointer must be a valid allocated memory address, or NULL. |
| 194 | */ |
| 195 | extern int marker_probe_register(const char *name, const char *format, |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 196 | marker_probe_func *probe, void *probe_private); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * Returns the private data given to marker_probe_register. |
| 200 | */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 201 | extern int marker_probe_unregister(const char *name, |
| 202 | marker_probe_func *probe, void *probe_private); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 203 | /* |
| 204 | * Unregister a marker by providing the registered private data. |
| 205 | */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 206 | extern int marker_probe_unregister_private_data(marker_probe_func *probe, |
| 207 | void *probe_private); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 208 | |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 209 | extern void *marker_get_private_data(const char *name, marker_probe_func *probe, |
| 210 | int num); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 211 | |
Mathieu Desnoyers | e98d0ea | 2008-09-29 11:05:13 -0400 | [diff] [blame] | 212 | /* |
| 213 | * marker_synchronize_unregister must be called between the last marker probe |
Wu Fengguang | a838c2e | 2008-11-27 16:14:44 +0800 | [diff] [blame] | 214 | * unregistration and the first one of |
| 215 | * - the end of module exit function |
| 216 | * - the free of any resource used by the probes |
| 217 | * to ensure the code and data are valid for any possibly running probes. |
Mathieu Desnoyers | e98d0ea | 2008-09-29 11:05:13 -0400 | [diff] [blame] | 218 | */ |
Mathieu Desnoyers | bfadadf | 2008-10-10 03:48:25 -0400 | [diff] [blame] | 219 | #define marker_synchronize_unregister() synchronize_sched() |
Mathieu Desnoyers | e98d0ea | 2008-09-29 11:05:13 -0400 | [diff] [blame] | 220 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 221 | #endif |