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 | |
22 | * @mdata: pointer of type struct marker | |
23 | * @private_data: caller site private data | |
24 | * @fmt: format string | |
25 | * @...: variable argument list | |
26 | * | |
27 | * Type of marker probe functions. They receive the mdata and need to parse the | |
28 | * format string to recover the variable argument list. | |
29 | */ | |
30 | typedef void marker_probe_func(const struct marker *mdata, | |
31 | void *private_data, const char *fmt, ...); | |
32 | ||
33 | struct marker { | |
34 | const char *name; /* Marker name */ | |
35 | const char *format; /* Marker format string, describing the | |
36 | * variable argument list. | |
37 | */ | |
38 | char state; /* Marker state. */ | |
39 | marker_probe_func *call;/* Probe handler function pointer */ | |
40 | void *private; /* Private probe data */ | |
41 | } __attribute__((aligned(8))); | |
42 | ||
43 | #ifdef CONFIG_MARKERS | |
44 | ||
45 | /* | |
46 | * Note : the empty asm volatile with read constraint is used here instead of a | |
47 | * "used" attribute to fix a gcc 4.1.x bug. | |
48 | * Make sure the alignment of the structure in the __markers section will | |
49 | * not add unwanted padding between the beginning of the section and the | |
50 | * structure. Force alignment to the same alignment as the section start. | |
51 | */ | |
52 | #define __trace_mark(name, call_data, format, args...) \ | |
53 | do { \ | |
54 | static const char __mstrtab_name_##name[] \ | |
55 | __attribute__((section("__markers_strings"))) \ | |
56 | = #name; \ | |
57 | static const char __mstrtab_format_##name[] \ | |
58 | __attribute__((section("__markers_strings"))) \ | |
59 | = format; \ | |
60 | static struct marker __mark_##name \ | |
61 | __attribute__((section("__markers"), aligned(8))) = \ | |
62 | { __mstrtab_name_##name, __mstrtab_format_##name, \ | |
63 | 0, __mark_empty_function, NULL }; \ | |
8256e47c MD |
64 | __mark_check_format(format, ## args); \ |
65 | if (unlikely(__mark_##name.state)) { \ | |
66 | preempt_disable(); \ | |
67 | (*__mark_##name.call) \ | |
68 | (&__mark_##name, call_data, \ | |
69 | format, ## args); \ | |
70 | preempt_enable(); \ | |
71 | } \ | |
72 | } while (0) | |
73 | ||
74 | extern void marker_update_probe_range(struct marker *begin, | |
75 | struct marker *end, struct module *probe_module, int *refcount); | |
76 | #else /* !CONFIG_MARKERS */ | |
77 | #define __trace_mark(name, call_data, format, args...) \ | |
78 | __mark_check_format(format, ## args) | |
79 | static inline void marker_update_probe_range(struct marker *begin, | |
80 | struct marker *end, struct module *probe_module, int *refcount) | |
81 | { } | |
82 | #endif /* CONFIG_MARKERS */ | |
83 | ||
84 | /** | |
85 | * trace_mark - Marker | |
86 | * @name: marker name, not quoted. | |
87 | * @format: format string | |
88 | * @args...: variable argument list | |
89 | * | |
90 | * Places a marker. | |
91 | */ | |
92 | #define trace_mark(name, format, args...) \ | |
93 | __trace_mark(name, NULL, format, ## args) | |
94 | ||
95 | #define MARK_MAX_FORMAT_LEN 1024 | |
96 | ||
97 | /** | |
98 | * MARK_NOARGS - Format string for a marker with no argument. | |
99 | */ | |
100 | #define MARK_NOARGS " " | |
101 | ||
102 | /* To be used for string format validity checking with gcc */ | |
103 | static inline void __printf(1, 2) __mark_check_format(const char *fmt, ...) | |
104 | { | |
105 | } | |
106 | ||
107 | extern marker_probe_func __mark_empty_function; | |
108 | ||
109 | /* | |
110 | * Connect a probe to a marker. | |
111 | * private data pointer must be a valid allocated memory address, or NULL. | |
112 | */ | |
113 | extern int marker_probe_register(const char *name, const char *format, | |
114 | marker_probe_func *probe, void *private); | |
115 | ||
116 | /* | |
117 | * Returns the private data given to marker_probe_register. | |
118 | */ | |
119 | extern void *marker_probe_unregister(const char *name); | |
120 | /* | |
121 | * Unregister a marker by providing the registered private data. | |
122 | */ | |
123 | extern void *marker_probe_unregister_private_data(void *private); | |
124 | ||
125 | extern int marker_arm(const char *name); | |
126 | extern int marker_disarm(const char *name); | |
127 | extern void *marker_get_private_data(const char *name); | |
128 | ||
129 | #endif |