]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - sys/sys/sdt.h
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.git] / 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 #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)
61
62 #else
63
64 /*
65  * This type definition must match that of dtrace_probe. It is defined this
66  * way to avoid having to rely on CDDL code.
67  */
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);
70
71 /*
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
74  * loads.
75  */
76 extern sdt_probe_func_t sdt_probe_func;
77
78 typedef enum {
79         SDT_UNINIT = 1,
80         SDT_INIT,
81 } sdt_state_t;
82
83 struct sdt_probe;
84 struct sdt_provider;
85
86 struct sdt_argtype {
87         int     ndx;                    /* Argument index. */
88         const char *type;               /* Argument type string. */
89         TAILQ_ENTRY(sdt_argtype)
90                         argtype_entry;  /* Argument type list entry. */
91         struct sdt_probe
92                         *probe;         /* Ptr to the probe structure. */
93 };
94
95 struct sdt_probe {
96         int             version;        /* Set to sizeof(struct sdt_ref). */
97         sdt_state_t     state;
98         struct sdt_provider
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;
103         const char      *mod;
104         const char      *func;
105         const char      *name;
106         id_t            id;             /* DTrace probe ID. */
107         int             n_args;         /* Number of arguments. */
108 };
109
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. */
116 };
117
118 #define SDT_PROVIDER_DEFINE(prov)                                               \
119         struct sdt_provider sdt_provider_##prov[1] = {                          \
120                 { #prov, { NULL, NULL }, { NULL, NULL } }                       \
121         };                                                                      \
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 )
128
129 #define SDT_PROVIDER_DECLARE(prov)                                              \
130         extern struct sdt_provider sdt_provider_##prov[1]
131
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 }  \
136         };                                                                      \
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 )
143
144 #define SDT_PROBE_DECLARE(prov, mod, func, name)                                \
145         extern struct sdt_probe sdt_##prov##_##mod##_##func##_##name[1]
146
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)
152
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 }                              \
157         };                                                                      \
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 )
164
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)
168
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)
173
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)
179
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)
186
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)
194
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 *);
198
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 *);
210
211 #endif /* KDTRACE_HOOKS */
212
213 #endif /* _KERNEL */
214
215 #endif /* _SYS_SDT_H */