FreeBSD/Linux Kernel Cross Reference
sys/sys/sdt.h
1 /*-
2 * Copyright 2006-2008 John Birrell <jb@FreeBSD.org>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 * $FreeBSD$
26 *
27 * Statically Defined Tracing (SDT) definitions.
28 *
29 */
30
31 #ifndef _SYS_SDT_H
32 #define _SYS_SDT_H
33
34 /* Stub these for the time being. */
35 #define DTRACE_PROBE(name)
36 #define DTRACE_PROBE1(name, type1, arg1)
37 #define DTRACE_PROBE2(name, type1, arg1, type2, arg2)
38 #define DTRACE_PROBE3(name, type1, arg1, type2, arg2, type3, arg3)
39 #define DTRACE_PROBE4(name, type1, arg1, type2, arg2, type3, arg3, type4, arg4)
40
41 #ifndef _KERNEL
42
43 /* The promise of things to come. Worlds to explore. People to meet. Things to do. */
44
45 #else
46
47 #ifndef KDTRACE_HOOKS
48
49 #define SDT_PROVIDER_DEFINE(prov)
50 #define SDT_PROVIDER_DECLARE(prov)
51 #define SDT_PROBE_DEFINE(prov, mod, func, name)
52 #define SDT_PROBE_DECLARE(prov, mod, func, name)
53 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
54 #define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type)
55
56 #else
57
58 /*
59 * This type definition must match that of dtrace_probe. It is defined this
60 * way to avoid having to rely on CDDL code.
61 */
62 typedef void (*sdt_probe_func_t)(u_int32_t, uintptr_t arg0, uintptr_t arg1,
63 uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
64
65 /*
66 * The hook for the probe function. See kern_sdt.c which defaults this to
67 * it's own stub. The 'sdt' provider will set it to dtrace_probe when it
68 * loads.
69 */
70 extern sdt_probe_func_t sdt_probe_func;
71
72 typedef enum {
73 SDT_UNINIT = 1,
74 SDT_INIT,
75 } sdt_state_t;
76
77 struct sdt_probe;
78 struct sdt_provider;
79
80 struct sdt_argtype {
81 int ndx; /* Argument index. */
82 const char *type; /* Argument type string. */
83 TAILQ_ENTRY(sdt_argtype)
84 argtype_entry; /* Argument type list entry. */
85 struct sdt_probe
86 *probe; /* Ptr to the probe structure. */
87 };
88
89 struct sdt_probe {
90 int version; /* Set to sizeof(struct sdt_ref). */
91 sdt_state_t state;
92 struct sdt_provider
93 *prov; /* Ptr to the provider structure. */
94 TAILQ_ENTRY(sdt_probe)
95 probe_entry; /* SDT probe list entry. */
96 TAILQ_HEAD(argtype_list_head, sdt_argtype) argtype_list;
97 const char *mod;
98 const char *func;
99 const char *name;
100 id_t id; /* DTrace probe ID. */
101 int n_args; /* Number of arguments. */
102 };
103
104 struct sdt_provider {
105 const char *name; /* Provider name. */
106 TAILQ_ENTRY(sdt_provider)
107 prov_entry; /* SDT provider list entry. */
108 TAILQ_HEAD(probe_list_head, sdt_probe) probe_list;
109 uintptr_t id; /* DTrace provider ID. */
110 };
111
112 #define SDT_PROVIDER_DEFINE(prov) \
113 struct sdt_provider sdt_provider_##prov[1] = { \
114 { #prov, { NULL, NULL }, { NULL, NULL } } \
115 }; \
116 SYSINIT(sdt_provider_##prov##_init, SI_SUB_KDTRACE, \
117 SI_ORDER_SECOND, sdt_provider_register, \
118 sdt_provider_##prov ); \
119 SYSUNINIT(sdt_provider_##prov##_uninit, SI_SUB_KDTRACE, \
120 SI_ORDER_SECOND, sdt_provider_deregister, \
121 sdt_provider_##prov )
122
123 #define SDT_PROVIDER_DECLARE(prov) \
124 extern struct sdt_provider sdt_provider_##prov[1]
125
126 #define SDT_PROBE_DEFINE(prov, mod, func, name) \
127 struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1] = { \
128 { sizeof(struct sdt_probe), 0, sdt_provider_##prov, \
129 { NULL, NULL }, { NULL, NULL }, #mod, #func, #name, 0, 0 } \
130 }; \
131 SYSINIT(sdt_##prov##_##mod##_##func##_##name##_init, SI_SUB_KDTRACE, \
132 SI_ORDER_SECOND + 1, sdt_probe_register, \
133 sdt_##prov##_##mod##_##func##_##name ); \
134 SYSUNINIT(sdt_##prov##_##mod##_##func##_##name##_uninit, \
135 SI_SUB_KDTRACE, SI_ORDER_SECOND + 1, sdt_probe_deregister, \
136 sdt_##prov##_##mod##_##func##_##name )
137
138 #define SDT_PROBE_DECLARE(prov, mod, func, name) \
139 extern struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1]
140
141 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \
142 if (sdt_##prov##_##mod##_##func##_##name->id) \
143 (*sdt_probe_func)(sdt_##prov##_##mod##_##func##_##name->id, \
144 (uintptr_t) arg0, (uintptr_t) arg1, (uintptr_t) arg2, \
145 (uintptr_t) arg3, (uintptr_t) arg4)
146
147 #define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type) \
148 struct sdt_argtype sdt_##prov##_##mod##_##func##_##name##num[1] \
149 = { { num, type, { NULL, NULL }, \
150 sdt_##prov##_##mod##_##func##_##name } \
151 }; \
152 SYSINIT(sdt_##prov##_##mod##_##func##_##name##num##_init, \
153 SI_SUB_KDTRACE, SI_ORDER_SECOND + 2, sdt_argtype_register, \
154 sdt_##prov##_##mod##_##func##_##name##num ); \
155 SYSUNINIT(sdt_##prov##_##mod##_##func##_##name##num##_uninit, \
156 SI_SUB_KDTRACE, SI_ORDER_SECOND + 2, sdt_argtype_deregister, \
157 sdt_##prov##_##mod##_##func##_##name##num )
158
159 typedef int (*sdt_argtype_listall_func_t)(struct sdt_argtype *, void *);
160 typedef int (*sdt_probe_listall_func_t)(struct sdt_probe *, void *);
161 typedef int (*sdt_provider_listall_func_t)(struct sdt_provider *, void *);
162
163 void sdt_argtype_deregister(void *);
164 void sdt_argtype_register(void *);
165 void sdt_probe_deregister(void *);
166 void sdt_probe_register(void *);
167 void sdt_provider_deregister(void *);
168 void sdt_provider_register(void *);
169 void sdt_probe_stub(u_int32_t, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2,
170 uintptr_t arg3, uintptr_t arg4);
171 int sdt_argtype_listall(struct sdt_probe *, sdt_argtype_listall_func_t, void *);
172 int sdt_probe_listall(struct sdt_provider *, sdt_probe_listall_func_t, void *);
173 int sdt_provider_listall(sdt_provider_listall_func_t,void *);
174
175 #endif /* KDTRACE_HOOKS */
176
177 #endif /* _KERNEL */
178
179 #endif /* _SYS_SDT_H */
Cache object: 3df193cbe1cbf8f6a3b21a7d3e10b1db
|