2 * Copyright 2006-2008 John Birrell <jb@FreeBSD.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
27 * Statically Defined Tracing (SDT) definitions.
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)
43 /* The promise of things to come. Worlds to explore. People to meet. Things to do. */
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)
56 #define SDT_PROBE_DEFINE1(prov, mod, func, name, arg0)
57 #define SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1)
58 #define SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2)
59 #define SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3)
60 #define SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4)
65 * This type definition must match that of dtrace_probe. It is defined this
66 * way to avoid having to rely on CDDL code.
68 typedef void (*sdt_probe_func_t)(u_int32_t, uintptr_t arg0, uintptr_t arg1,
69 uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
72 * The hook for the probe function. See kern_sdt.c which defaults this to
73 * it's own stub. The 'sdt' provider will set it to dtrace_probe when it
76 extern sdt_probe_func_t sdt_probe_func;
87 int ndx; /* Argument index. */
88 const char *type; /* Argument type string. */
89 TAILQ_ENTRY(sdt_argtype)
90 argtype_entry; /* Argument type list entry. */
92 *probe; /* Ptr to the probe structure. */
96 int version; /* Set to sizeof(struct sdt_ref). */
99 *prov; /* Ptr to the provider structure. */
100 TAILQ_ENTRY(sdt_probe)
101 probe_entry; /* SDT probe list entry. */
102 TAILQ_HEAD(argtype_list_head, sdt_argtype) argtype_list;
106 id_t id; /* DTrace probe ID. */
107 int n_args; /* Number of arguments. */
110 struct sdt_provider {
111 const char *name; /* Provider name. */
112 TAILQ_ENTRY(sdt_provider)
113 prov_entry; /* SDT provider list entry. */
114 TAILQ_HEAD(probe_list_head, sdt_probe) probe_list;
115 uintptr_t id; /* DTrace provider ID. */
118 #define SDT_PROVIDER_DEFINE(prov) \
119 struct sdt_provider sdt_provider_##prov[1] = { \
120 { #prov, { NULL, NULL }, { NULL, NULL } } \
122 SYSINIT(sdt_provider_##prov##_init, SI_SUB_KDTRACE, \
123 SI_ORDER_SECOND, sdt_provider_register, \
124 sdt_provider_##prov ); \
125 SYSUNINIT(sdt_provider_##prov##_uninit, SI_SUB_KDTRACE, \
126 SI_ORDER_SECOND, sdt_provider_deregister, \
127 sdt_provider_##prov )
129 #define SDT_PROVIDER_DECLARE(prov) \
130 extern struct sdt_provider sdt_provider_##prov[1]
132 #define SDT_PROBE_DEFINE(prov, mod, func, name) \
133 struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1] = { \
134 { sizeof(struct sdt_probe), 0, sdt_provider_##prov, \
135 { NULL, NULL }, { NULL, NULL }, #mod, #func, #name, 0, 0 } \
137 SYSINIT(sdt_##prov##_##mod##_##func##_##name##_init, SI_SUB_KDTRACE, \
138 SI_ORDER_SECOND + 1, sdt_probe_register, \
139 sdt_##prov##_##mod##_##func##_##name ); \
140 SYSUNINIT(sdt_##prov##_##mod##_##func##_##name##_uninit, \
141 SI_SUB_KDTRACE, SI_ORDER_SECOND + 1, sdt_probe_deregister, \
142 sdt_##prov##_##mod##_##func##_##name )
144 #define SDT_PROBE_DECLARE(prov, mod, func, name) \
145 extern struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1]
147 #define SDT_PROBE(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \
148 if (sdt_##prov##_##mod##_##func##_##name->id) \
149 (*sdt_probe_func)(sdt_##prov##_##mod##_##func##_##name->id, \
150 (uintptr_t) arg0, (uintptr_t) arg1, (uintptr_t) arg2, \
151 (uintptr_t) arg3, (uintptr_t) arg4)
153 #define SDT_PROBE_ARGTYPE(prov, mod, func, name, num, type) \
154 struct sdt_argtype sdt_##prov##_##mod##_##func##_##name##num[1] \
155 = { { num, type, { NULL, NULL }, \
156 sdt_##prov##_##mod##_##func##_##name } \
158 SYSINIT(sdt_##prov##_##mod##_##func##_##name##num##_init, \
159 SI_SUB_KDTRACE, SI_ORDER_SECOND + 2, sdt_argtype_register, \
160 sdt_##prov##_##mod##_##func##_##name##num ); \
161 SYSUNINIT(sdt_##prov##_##mod##_##func##_##name##num##_uninit, \
162 SI_SUB_KDTRACE, SI_ORDER_SECOND + 2, sdt_argtype_deregister, \
163 sdt_##prov##_##mod##_##func##_##name##num )
165 #define SDT_PROBE_DEFINE1(prov, mod, func, name, arg0) \
166 SDT_PROBE_DEFINE(prov, mod, func, name); \
167 SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0)
169 #define SDT_PROBE_DEFINE2(prov, mod, func, name, arg0, arg1) \
170 SDT_PROBE_DEFINE(prov, mod, func, name); \
171 SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
172 SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1)
174 #define SDT_PROBE_DEFINE3(prov, mod, func, name, arg0, arg1, arg2) \
175 SDT_PROBE_DEFINE(prov, mod, func, name); \
176 SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
177 SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
178 SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2)
180 #define SDT_PROBE_DEFINE4(prov, mod, func, name, arg0, arg1, arg2, arg3) \
181 SDT_PROBE_DEFINE(prov, mod, func, name); \
182 SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
183 SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
184 SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2); \
185 SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3)
187 #define SDT_PROBE_DEFINE5(prov, mod, func, name, arg0, arg1, arg2, arg3, arg4) \
188 SDT_PROBE_DEFINE(prov, mod, func, name); \
189 SDT_PROBE_ARGTYPE(prov, mod, func, name, 0, arg0); \
190 SDT_PROBE_ARGTYPE(prov, mod, func, name, 1, arg1); \
191 SDT_PROBE_ARGTYPE(prov, mod, func, name, 2, arg2); \
192 SDT_PROBE_ARGTYPE(prov, mod, func, name, 3, arg3); \
193 SDT_PROBE_ARGTYPE(prov, mod, func, name, 4, arg4)
195 typedef int (*sdt_argtype_listall_func_t)(struct sdt_argtype *, void *);
196 typedef int (*sdt_probe_listall_func_t)(struct sdt_probe *, void *);
197 typedef int (*sdt_provider_listall_func_t)(struct sdt_provider *, void *);
199 void sdt_argtype_deregister(void *);
200 void sdt_argtype_register(void *);
201 void sdt_probe_deregister(void *);
202 void sdt_probe_register(void *);
203 void sdt_provider_deregister(void *);
204 void sdt_provider_register(void *);
205 void sdt_probe_stub(u_int32_t, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2,
206 uintptr_t arg3, uintptr_t arg4);
207 int sdt_argtype_listall(struct sdt_probe *, sdt_argtype_listall_func_t, void *);
208 int sdt_probe_listall(struct sdt_provider *, sdt_probe_listall_func_t, void *);
209 int sdt_provider_listall(sdt_provider_listall_func_t,void *);
211 #endif /* KDTRACE_HOOKS */
215 #endif /* _SYS_SDT_H */