Commit | Line | Data |
---|---|---|
8256e47c MD |
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 | |
fb40bd78 MD |
22 | * @probe_private: probe private data |
23 | * @call_private: call site private data | |
8256e47c | 24 | * @fmt: format string |
fb40bd78 MD |
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. | |
8256e47c MD |
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 | */ | |
fb40bd78 MD |
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 | }; | |
8256e47c MD |
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. */ | |
fb40bd78 MD |
46 | char ptype; /* probe type : 0 : single, 1 : multi */ |
47 | void (*call)(const struct marker *mdata, /* Probe wrapper */ | |
48 | void *call_private, const char *fmt, ...); | |
49 | struct marker_probe_closure single; | |
50 | struct marker_probe_closure *multi; | |
8256e47c MD |
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. | |
61 | */ | |
fb40bd78 | 62 | #define __trace_mark(name, call_private, format, args...) \ |
8256e47c | 63 | do { \ |
b2e3e658 | 64 | static const char __mstrtab_##name[] \ |
8256e47c | 65 | __attribute__((section("__markers_strings"))) \ |
b2e3e658 | 66 | = #name "\0" format; \ |
8256e47c MD |
67 | static struct marker __mark_##name \ |
68 | __attribute__((section("__markers"), aligned(8))) = \ | |
b2e3e658 | 69 | { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \ |
fb40bd78 MD |
70 | 0, 0, marker_probe_cb, \ |
71 | { __mark_empty_function, NULL}, NULL }; \ | |
8256e47c MD |
72 | __mark_check_format(format, ## args); \ |
73 | if (unlikely(__mark_##name.state)) { \ | |
8256e47c | 74 | (*__mark_##name.call) \ |
fb40bd78 | 75 | (&__mark_##name, call_private, \ |
8256e47c | 76 | format, ## args); \ |
8256e47c MD |
77 | } \ |
78 | } while (0) | |
79 | ||
80 | extern void marker_update_probe_range(struct marker *begin, | |
fb40bd78 | 81 | struct marker *end); |
8256e47c | 82 | #else /* !CONFIG_MARKERS */ |
fb40bd78 | 83 | #define __trace_mark(name, call_private, format, args...) \ |
8256e47c MD |
84 | __mark_check_format(format, ## args) |
85 | static inline void marker_update_probe_range(struct marker *begin, | |
fb40bd78 | 86 | struct marker *end) |
8256e47c MD |
87 | { } |
88 | #endif /* CONFIG_MARKERS */ | |
89 | ||
90 | /** | |
91 | * trace_mark - Marker | |
92 | * @name: marker name, not quoted. | |
93 | * @format: format string | |
94 | * @args...: variable argument list | |
95 | * | |
96 | * Places a marker. | |
97 | */ | |
98 | #define trace_mark(name, format, args...) \ | |
99 | __trace_mark(name, NULL, format, ## args) | |
100 | ||
8256e47c MD |
101 | /** |
102 | * MARK_NOARGS - Format string for a marker with no argument. | |
103 | */ | |
104 | #define MARK_NOARGS " " | |
105 | ||
106 | /* To be used for string format validity checking with gcc */ | |
acc4988b | 107 | static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...) |
8256e47c MD |
108 | { |
109 | } | |
110 | ||
acc4988b MD |
111 | #define __mark_check_format(format, args...) \ |
112 | do { \ | |
113 | if (0) \ | |
114 | ___mark_check_format(format, ## args); \ | |
115 | } while (0) | |
116 | ||
8256e47c MD |
117 | extern marker_probe_func __mark_empty_function; |
118 | ||
fb40bd78 MD |
119 | extern void marker_probe_cb(const struct marker *mdata, |
120 | void *call_private, const char *fmt, ...); | |
121 | extern void marker_probe_cb_noarg(const struct marker *mdata, | |
122 | void *call_private, const char *fmt, ...); | |
123 | ||
8256e47c MD |
124 | /* |
125 | * Connect a probe to a marker. | |
126 | * private data pointer must be a valid allocated memory address, or NULL. | |
127 | */ | |
128 | extern int marker_probe_register(const char *name, const char *format, | |
fb40bd78 | 129 | marker_probe_func *probe, void *probe_private); |
8256e47c MD |
130 | |
131 | /* | |
132 | * Returns the private data given to marker_probe_register. | |
133 | */ | |
fb40bd78 MD |
134 | extern int marker_probe_unregister(const char *name, |
135 | marker_probe_func *probe, void *probe_private); | |
8256e47c MD |
136 | /* |
137 | * Unregister a marker by providing the registered private data. | |
138 | */ | |
fb40bd78 MD |
139 | extern int marker_probe_unregister_private_data(marker_probe_func *probe, |
140 | void *probe_private); | |
8256e47c | 141 | |
fb40bd78 MD |
142 | extern void *marker_get_private_data(const char *name, marker_probe_func *probe, |
143 | int num); | |
8256e47c MD |
144 | |
145 | #endif |