blob: 57a307018cebb102f12a7326580e166a151be336 [file] [log] [blame]
Mathieu Desnoyers8256e472007-10-18 23:41:06 -07001#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 Meloe3f8c4b2008-11-14 17:47:36 -050015#include <stdarg.h>
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070016#include <linux/types.h>
17
18struct module;
19struct marker;
20
21/**
22 * marker_probe_func - Type of a marker probe function
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080023 * @probe_private: probe private data
24 * @call_private: call site private data
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070025 * @fmt: format string
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080026 * @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 Desnoyers8256e472007-10-18 23:41:06 -070029 *
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 Desnoyersfb40bd72008-02-13 15:03:37 -080033typedef void marker_probe_func(void *probe_private, void *call_private,
34 const char *fmt, va_list *args);
35
36struct marker_probe_closure {
37 marker_probe_func *func; /* Callback */
38 void *probe_private; /* Private probe data */
39};
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070040
41struct 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 Desnoyersfb40bd72008-02-13 15:03:37 -080047 char ptype; /* probe type : 0 : single, 1 : multi */
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +020048 /* Probe wrapper */
49 void (*call)(const struct marker *mdata, void *call_private, ...);
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080050 struct marker_probe_closure single;
51 struct marker_probe_closure *multi;
Mathieu Desnoyersc1df1bd2008-11-14 17:47:39 -050052 const char *tp_name; /* Optional tracepoint name */
53 void *tp_cb; /* Optional tracepoint callback */
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070054} __attribute__((aligned(8)));
55
56#ifdef CONFIG_MARKERS
57
58/*
59 * Note : the empty asm volatile with read constraint is used here instead of a
60 * "used" attribute to fix a gcc 4.1.x bug.
61 * Make sure the alignment of the structure in the __markers section will
62 * not add unwanted padding between the beginning of the section and the
63 * structure. Force alignment to the same alignment as the section start.
Mathieu Desnoyers0aa977f2008-05-12 21:21:10 +020064 *
65 * The "generic" argument controls which marker enabling mechanism must be used.
66 * If generic is true, a variable read is used.
67 * If generic is false, immediate values are used.
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070068 */
Mathieu Desnoyers0aa977f2008-05-12 21:21:10 +020069#define __trace_mark(generic, name, call_private, format, args...) \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070070 do { \
Mathieu Desnoyersb2e3e652008-02-13 15:03:39 -080071 static const char __mstrtab_##name[] \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070072 __attribute__((section("__markers_strings"))) \
Mathieu Desnoyersb2e3e652008-02-13 15:03:39 -080073 = #name "\0" format; \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070074 static struct marker __mark_##name \
75 __attribute__((section("__markers"), aligned(8))) = \
Mathieu Desnoyersb2e3e652008-02-13 15:03:39 -080076 { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080077 0, 0, marker_probe_cb, \
Mathieu Desnoyersc1df1bd2008-11-14 17:47:39 -050078 { __mark_empty_function, NULL}, NULL, NULL, NULL }; \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070079 __mark_check_format(format, ## args); \
80 if (unlikely(__mark_##name.state)) { \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070081 (*__mark_##name.call) \
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +020082 (&__mark_##name, call_private, ## args);\
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070083 } \
84 } while (0)
85
Mathieu Desnoyersc1df1bd2008-11-14 17:47:39 -050086#define __trace_mark_tp(name, call_private, tp_name, tp_cb, format, args...) \
87 do { \
88 void __check_tp_type(void) \
89 { \
90 register_trace_##tp_name(tp_cb); \
91 } \
92 static const char __mstrtab_##name[] \
93 __attribute__((section("__markers_strings"))) \
94 = #name "\0" format; \
95 static struct marker __mark_##name \
96 __attribute__((section("__markers"), aligned(8))) = \
97 { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
98 0, 0, marker_probe_cb, \
99 { __mark_empty_function, NULL}, NULL, #tp_name, tp_cb };\
100 __mark_check_format(format, ## args); \
101 (*__mark_##name.call)(&__mark_##name, call_private, \
102 ## args); \
103 } while (0)
104
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700105extern void marker_update_probe_range(struct marker *begin,
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800106 struct marker *end);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700107#else /* !CONFIG_MARKERS */
Mathieu Desnoyers0aa977f2008-05-12 21:21:10 +0200108#define __trace_mark(generic, name, call_private, format, args...) \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700109 __mark_check_format(format, ## args)
Mathieu Desnoyersc1df1bd2008-11-14 17:47:39 -0500110#define __trace_mark_tp(name, call_private, tp_name, tp_cb, format, args...) \
111 do { \
112 void __check_tp_type(void) \
113 { \
114 register_trace_##tp_name(tp_cb); \
115 } \
116 __mark_check_format(format, ## args); \
117 } while (0)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700118static inline void marker_update_probe_range(struct marker *begin,
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800119 struct marker *end)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700120{ }
121#endif /* CONFIG_MARKERS */
122
123/**
Mathieu Desnoyers0aa977f2008-05-12 21:21:10 +0200124 * trace_mark - Marker using code patching
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700125 * @name: marker name, not quoted.
126 * @format: format string
127 * @args...: variable argument list
128 *
Mathieu Desnoyers0aa977f2008-05-12 21:21:10 +0200129 * Places a marker using optimized code patching technique (imv_read())
130 * to be enabled when immediate values are present.
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700131 */
132#define trace_mark(name, format, args...) \
Mathieu Desnoyers0aa977f2008-05-12 21:21:10 +0200133 __trace_mark(0, name, NULL, format, ## args)
134
135/**
136 * _trace_mark - Marker using variable read
137 * @name: marker name, not quoted.
138 * @format: format string
139 * @args...: variable argument list
140 *
141 * Places a marker using a standard memory read (_imv_read()) to be
142 * enabled. Should be used for markers in code paths where instruction
143 * modification based enabling is not welcome. (__init and __exit functions,
144 * lockdep, some traps, printk).
145 */
146#define _trace_mark(name, format, args...) \
147 __trace_mark(1, name, NULL, format, ## args)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700148
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700149/**
Mathieu Desnoyersc1df1bd2008-11-14 17:47:39 -0500150 * trace_mark_tp - Marker in a tracepoint callback
151 * @name: marker name, not quoted.
152 * @tp_name: tracepoint name, not quoted.
153 * @tp_cb: tracepoint callback. Should have an associated global symbol so it
154 * is not optimized away by the compiler (should not be static).
155 * @format: format string
156 * @args...: variable argument list
157 *
158 * Places a marker in a tracepoint callback.
159 */
160#define trace_mark_tp(name, tp_name, tp_cb, format, args...) \
161 __trace_mark_tp(name, NULL, tp_name, tp_cb, format, ## args)
162
163/**
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700164 * MARK_NOARGS - Format string for a marker with no argument.
165 */
166#define MARK_NOARGS " "
167
168/* To be used for string format validity checking with gcc */
Mathieu Desnoyersacc49882008-03-04 14:29:00 -0800169static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700170{
171}
172
Mathieu Desnoyersacc49882008-03-04 14:29:00 -0800173#define __mark_check_format(format, args...) \
174 do { \
175 if (0) \
176 ___mark_check_format(format, ## args); \
177 } while (0)
178
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700179extern marker_probe_func __mark_empty_function;
180
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800181extern void marker_probe_cb(const struct marker *mdata,
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +0200182 void *call_private, ...);
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800183
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700184/*
185 * Connect a probe to a marker.
186 * private data pointer must be a valid allocated memory address, or NULL.
187 */
188extern int marker_probe_register(const char *name, const char *format,
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800189 marker_probe_func *probe, void *probe_private);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700190
191/*
192 * Returns the private data given to marker_probe_register.
193 */
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800194extern int marker_probe_unregister(const char *name,
195 marker_probe_func *probe, void *probe_private);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700196/*
197 * Unregister a marker by providing the registered private data.
198 */
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800199extern int marker_probe_unregister_private_data(marker_probe_func *probe,
200 void *probe_private);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700201
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800202extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
203 int num);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700204
Mathieu Desnoyerse98d0ea2008-09-29 11:05:13 -0400205/*
206 * marker_synchronize_unregister must be called between the last marker probe
207 * unregistration and the end of module exit to make sure there is no caller
208 * executing a probe when it is freed.
209 */
Mathieu Desnoyersbfadadf2008-10-10 03:48:25 -0400210#define marker_synchronize_unregister() synchronize_sched()
Mathieu Desnoyerse98d0ea2008-09-29 11:05:13 -0400211
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700212#endif