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 | |
| 15 | #include <linux/types.h> |
| 16 | |
| 17 | struct module; |
| 18 | struct marker; |
| 19 | |
| 20 | /** |
| 21 | * marker_probe_func - Type of a marker probe function |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 22 | * @probe_private: probe private data |
| 23 | * @call_private: call site private data |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 24 | * @fmt: format string |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 25 | * @args: variable argument list pointer. Use a pointer to overcome C's |
| 26 | * inability to pass this around as a pointer in a portable manner in |
| 27 | * the callee otherwise. |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 28 | * |
| 29 | * Type of marker probe functions. They receive the mdata and need to parse the |
| 30 | * format string to recover the variable argument list. |
| 31 | */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 32 | typedef void marker_probe_func(void *probe_private, void *call_private, |
| 33 | const char *fmt, va_list *args); |
| 34 | |
| 35 | struct marker_probe_closure { |
| 36 | marker_probe_func *func; /* Callback */ |
| 37 | void *probe_private; /* Private probe data */ |
| 38 | }; |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 39 | |
| 40 | struct marker { |
| 41 | const char *name; /* Marker name */ |
| 42 | const char *format; /* Marker format string, describing the |
| 43 | * variable argument list. |
| 44 | */ |
| 45 | char state; /* Marker state. */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 46 | char ptype; /* probe type : 0 : single, 1 : multi */ |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 47 | /* Probe wrapper */ |
| 48 | void (*call)(const struct marker *mdata, void *call_private, ...); |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 49 | struct marker_probe_closure single; |
| 50 | struct marker_probe_closure *multi; |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 51 | } __attribute__((aligned(8))); |
| 52 | |
| 53 | #ifdef CONFIG_MARKERS |
| 54 | |
| 55 | /* |
| 56 | * Note : the empty asm volatile with read constraint is used here instead of a |
| 57 | * "used" attribute to fix a gcc 4.1.x bug. |
| 58 | * Make sure the alignment of the structure in the __markers section will |
| 59 | * not add unwanted padding between the beginning of the section and the |
| 60 | * structure. Force alignment to the same alignment as the section start. |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 61 | * |
| 62 | * The "generic" argument controls which marker enabling mechanism must be used. |
| 63 | * If generic is true, a variable read is used. |
| 64 | * If generic is false, immediate values are used. |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 65 | */ |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 66 | #define __trace_mark(generic, name, call_private, format, args...) \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 67 | do { \ |
Mathieu Desnoyers | b2e3e65 | 2008-02-13 15:03:39 -0800 | [diff] [blame] | 68 | static const char __mstrtab_##name[] \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 69 | __attribute__((section("__markers_strings"))) \ |
Mathieu Desnoyers | b2e3e65 | 2008-02-13 15:03:39 -0800 | [diff] [blame] | 70 | = #name "\0" format; \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 71 | static struct marker __mark_##name \ |
| 72 | __attribute__((section("__markers"), aligned(8))) = \ |
Mathieu Desnoyers | b2e3e65 | 2008-02-13 15:03:39 -0800 | [diff] [blame] | 73 | { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 74 | 0, 0, marker_probe_cb, \ |
| 75 | { __mark_empty_function, NULL}, NULL }; \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 76 | __mark_check_format(format, ## args); \ |
| 77 | if (unlikely(__mark_##name.state)) { \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 78 | (*__mark_##name.call) \ |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 79 | (&__mark_##name, call_private, ## args);\ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 80 | } \ |
| 81 | } while (0) |
| 82 | |
| 83 | extern void marker_update_probe_range(struct marker *begin, |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 84 | struct marker *end); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 85 | #else /* !CONFIG_MARKERS */ |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 86 | #define __trace_mark(generic, name, call_private, format, args...) \ |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 87 | __mark_check_format(format, ## args) |
| 88 | static inline void marker_update_probe_range(struct marker *begin, |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 89 | struct marker *end) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 90 | { } |
| 91 | #endif /* CONFIG_MARKERS */ |
| 92 | |
| 93 | /** |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 94 | * trace_mark - Marker using code patching |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 95 | * @name: marker name, not quoted. |
| 96 | * @format: format string |
| 97 | * @args...: variable argument list |
| 98 | * |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 99 | * Places a marker using optimized code patching technique (imv_read()) |
| 100 | * to be enabled when immediate values are present. |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 101 | */ |
| 102 | #define trace_mark(name, format, args...) \ |
Mathieu Desnoyers | 0aa977f | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 103 | __trace_mark(0, name, NULL, format, ## args) |
| 104 | |
| 105 | /** |
| 106 | * _trace_mark - Marker using variable read |
| 107 | * @name: marker name, not quoted. |
| 108 | * @format: format string |
| 109 | * @args...: variable argument list |
| 110 | * |
| 111 | * Places a marker using a standard memory read (_imv_read()) to be |
| 112 | * enabled. Should be used for markers in code paths where instruction |
| 113 | * modification based enabling is not welcome. (__init and __exit functions, |
| 114 | * lockdep, some traps, printk). |
| 115 | */ |
| 116 | #define _trace_mark(name, format, args...) \ |
| 117 | __trace_mark(1, name, NULL, format, ## args) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 118 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 119 | /** |
| 120 | * MARK_NOARGS - Format string for a marker with no argument. |
| 121 | */ |
| 122 | #define MARK_NOARGS " " |
| 123 | |
| 124 | /* To be used for string format validity checking with gcc */ |
Mathieu Desnoyers | acc4988 | 2008-03-04 14:29:00 -0800 | [diff] [blame] | 125 | static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...) |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 126 | { |
| 127 | } |
| 128 | |
Mathieu Desnoyers | acc4988 | 2008-03-04 14:29:00 -0800 | [diff] [blame] | 129 | #define __mark_check_format(format, args...) \ |
| 130 | do { \ |
| 131 | if (0) \ |
| 132 | ___mark_check_format(format, ## args); \ |
| 133 | } while (0) |
| 134 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 135 | extern marker_probe_func __mark_empty_function; |
| 136 | |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 137 | extern void marker_probe_cb(const struct marker *mdata, |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 138 | void *call_private, ...); |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 139 | extern void marker_probe_cb_noarg(const struct marker *mdata, |
Mathieu Desnoyers | dc102a8 | 2008-05-12 21:21:09 +0200 | [diff] [blame] | 140 | void *call_private, ...); |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 141 | |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 142 | /* |
| 143 | * Connect a probe to a marker. |
| 144 | * private data pointer must be a valid allocated memory address, or NULL. |
| 145 | */ |
| 146 | extern int marker_probe_register(const char *name, const char *format, |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 147 | marker_probe_func *probe, void *probe_private); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 148 | |
| 149 | /* |
| 150 | * Returns the private data given to marker_probe_register. |
| 151 | */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 152 | extern int marker_probe_unregister(const char *name, |
| 153 | marker_probe_func *probe, void *probe_private); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 154 | /* |
| 155 | * Unregister a marker by providing the registered private data. |
| 156 | */ |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 157 | extern int marker_probe_unregister_private_data(marker_probe_func *probe, |
| 158 | void *probe_private); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 159 | |
Mathieu Desnoyers | fb40bd7 | 2008-02-13 15:03:37 -0800 | [diff] [blame] | 160 | extern void *marker_get_private_data(const char *name, marker_probe_func *probe, |
| 161 | int num); |
Mathieu Desnoyers | 8256e47 | 2007-10-18 23:41:06 -0700 | [diff] [blame] | 162 | |
| 163 | #endif |