blob: 338533abb47ba9f03b1c1e4e2f21f550dc19770f [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
15#include <linux/types.h>
16
17struct module;
18struct marker;
19
20/**
21 * marker_probe_func - Type of a marker probe function
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080022 * @probe_private: probe private data
23 * @call_private: call site private data
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070024 * @fmt: format string
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080025 * @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 Desnoyers8256e472007-10-18 23:41:06 -070028 *
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 Desnoyersfb40bd72008-02-13 15:03:37 -080032typedef void marker_probe_func(void *probe_private, void *call_private,
33 const char *fmt, va_list *args);
34
35struct marker_probe_closure {
36 marker_probe_func *func; /* Callback */
37 void *probe_private; /* Private probe data */
38};
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070039
40struct 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 Desnoyersfb40bd72008-02-13 15:03:37 -080046 char ptype; /* probe type : 0 : single, 1 : multi */
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +020047 /* Probe wrapper */
48 void (*call)(const struct marker *mdata, void *call_private, ...);
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080049 struct marker_probe_closure single;
50 struct marker_probe_closure *multi;
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070051} __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 */
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080062#define __trace_mark(name, call_private, format, args...) \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070063 do { \
Mathieu Desnoyersb2e3e652008-02-13 15:03:39 -080064 static const char __mstrtab_##name[] \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070065 __attribute__((section("__markers_strings"))) \
Mathieu Desnoyersb2e3e652008-02-13 15:03:39 -080066 = #name "\0" format; \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070067 static struct marker __mark_##name \
68 __attribute__((section("__markers"), aligned(8))) = \
Mathieu Desnoyersb2e3e652008-02-13 15:03:39 -080069 { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080070 0, 0, marker_probe_cb, \
71 { __mark_empty_function, NULL}, NULL }; \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070072 __mark_check_format(format, ## args); \
73 if (unlikely(__mark_##name.state)) { \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070074 (*__mark_##name.call) \
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +020075 (&__mark_##name, call_private, ## args);\
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070076 } \
77 } while (0)
78
79extern void marker_update_probe_range(struct marker *begin,
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080080 struct marker *end);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070081#else /* !CONFIG_MARKERS */
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080082#define __trace_mark(name, call_private, format, args...) \
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070083 __mark_check_format(format, ## args)
84static inline void marker_update_probe_range(struct marker *begin,
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -080085 struct marker *end)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -070086{ }
87#endif /* CONFIG_MARKERS */
88
89/**
90 * trace_mark - Marker
91 * @name: marker name, not quoted.
92 * @format: format string
93 * @args...: variable argument list
94 *
95 * Places a marker.
96 */
97#define trace_mark(name, format, args...) \
98 __trace_mark(name, NULL, format, ## args)
99
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700100/**
101 * MARK_NOARGS - Format string for a marker with no argument.
102 */
103#define MARK_NOARGS " "
104
105/* To be used for string format validity checking with gcc */
Mathieu Desnoyersacc49882008-03-04 14:29:00 -0800106static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700107{
108}
109
Mathieu Desnoyersacc49882008-03-04 14:29:00 -0800110#define __mark_check_format(format, args...) \
111 do { \
112 if (0) \
113 ___mark_check_format(format, ## args); \
114 } while (0)
115
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700116extern marker_probe_func __mark_empty_function;
117
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800118extern void marker_probe_cb(const struct marker *mdata,
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +0200119 void *call_private, ...);
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800120extern void marker_probe_cb_noarg(const struct marker *mdata,
Mathieu Desnoyersdc102a82008-05-12 21:21:09 +0200121 void *call_private, ...);
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800122
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700123/*
124 * Connect a probe to a marker.
125 * private data pointer must be a valid allocated memory address, or NULL.
126 */
127extern int marker_probe_register(const char *name, const char *format,
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800128 marker_probe_func *probe, void *probe_private);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700129
130/*
131 * Returns the private data given to marker_probe_register.
132 */
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800133extern int marker_probe_unregister(const char *name,
134 marker_probe_func *probe, void *probe_private);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700135/*
136 * Unregister a marker by providing the registered private data.
137 */
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800138extern int marker_probe_unregister_private_data(marker_probe_func *probe,
139 void *probe_private);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700140
Mathieu Desnoyersfb40bd72008-02-13 15:03:37 -0800141extern void *marker_get_private_data(const char *name, marker_probe_func *probe,
142 int num);
Mathieu Desnoyers8256e472007-10-18 23:41:06 -0700143
144#endif