]>
Commit | Line | Data |
---|---|---|
2d21ac55 A |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
6d2010ae | 22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
2d21ac55 A |
23 | * Use is subject to license terms. |
24 | */ | |
25 | ||
2d21ac55 A |
26 | #include <sys/param.h> |
27 | #include <sys/systm.h> | |
28 | #include <sys/errno.h> | |
29 | #include <sys/stat.h> | |
30 | #include <sys/ioctl.h> | |
31 | #include <sys/conf.h> | |
32 | #include <sys/fcntl.h> | |
33 | #include <miscfs/devfs/devfs.h> | |
34 | ||
35 | #include <sys/dtrace.h> | |
36 | #include <sys/dtrace_impl.h> | |
37 | ||
38 | #include <sys/dtrace_glue.h> | |
39 | ||
40 | #include <sys/lockstat.h> | |
41 | ||
0a7de745 A |
42 | #include <kern/lock_stat.h> |
43 | ||
2d21ac55 A |
44 | #include <kern/processor.h> |
45 | ||
46 | #define membar_producer dtrace_membar_producer | |
47 | ||
5ba3f43e A |
48 | #define PROBE_ARGS0(a, b, c, d, e) "\000" |
49 | #define PROBE_ARGS1(a, b, c, d, e) a "\000" | |
50 | #define PROBE_ARGS2(a, b, c, d, e) a "\000" b "\000" | |
51 | #define PROBE_ARGS3(a, b, c, d, e) a "\000" b "\000" c "\000" | |
52 | #define PROBE_ARGS4(a, b, c, d, e) a "\000" b "\000" c "\000" d "\000" | |
53 | #define PROBE_ARGS5(a, b, c, d, e) a "\000" b "\000" c "\000" d "\000" e "\000" | |
54 | #define PROBE_ARGS_(a, b, c, d, e, n, ...) PROBE_ARGS##n(a, b, c, d, e) | |
55 | #define PROBE_ARGS(...) PROBE_ARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0) | |
56 | ||
57 | #define LOCKSTAT_PROBE(func, name, probe, ...) \ | |
58 | {func, name, probe, DTRACE_IDNONE, PROBE_ARGS(__VA_ARGS__)} | |
59 | ||
2d21ac55 A |
60 | /* |
61 | * Hot patch values, x86 | |
62 | */ | |
39236c6e | 63 | #if defined(__x86_64__) |
0a7de745 A |
64 | #define NOP 0x90 |
65 | #define RET 0xc3 | |
2d21ac55 | 66 | #define LOCKSTAT_AFRAMES 1 |
0a7de745 A |
67 | #elif defined(__arm__) |
68 | #define NOP 0xE1A00000 | |
69 | #define BXLR 0xE12FFF1E | |
5ba3f43e A |
70 | #define LOCKSTAT_AFRAMES 2 |
71 | #elif defined(__arm64__) | |
0a7de745 A |
72 | #define NOP 0xD503201F |
73 | #define RET 0xD65f03c0 | |
5ba3f43e | 74 | #define LOCKSTAT_AFRAMES 2 |
2d21ac55 A |
75 | #else |
76 | #error "not ported to this architecture" | |
77 | #endif | |
78 | ||
2d21ac55 | 79 | typedef struct lockstat_probe { |
0a7de745 A |
80 | const char *lsp_func; |
81 | const char *lsp_name; | |
82 | int lsp_probe; | |
83 | dtrace_id_t lsp_id; | |
84 | const char *lsp_args; | |
2d21ac55 A |
85 | } lockstat_probe_t; |
86 | ||
87 | lockstat_probe_t lockstat_probes[] = | |
88 | { | |
39236c6e | 89 | #if defined(__x86_64__) |
316670eb | 90 | /* Only provide implemented probes for each architecture */ |
5ba3f43e A |
91 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_ACQUIRE, LS_LCK_MTX_LOCK_ACQUIRE, "lck_mtx_t"), |
92 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_SPIN, LS_LCK_MTX_LOCK_SPIN, "lck_mtx_t", "uint64_t"), | |
93 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_BLOCK, LS_LCK_MTX_LOCK_BLOCK, "lck_mtx_t", "uint64_t"), | |
94 | LOCKSTAT_PROBE(LS_LCK_MTX_TRY_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_LOCK_ACQUIRE, "lck_mtx_t"), | |
95 | LOCKSTAT_PROBE(LS_LCK_MTX_TRY_SPIN_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE, "lck_mtx_t"), | |
96 | LOCKSTAT_PROBE(LS_LCK_MTX_UNLOCK, LSA_RELEASE, LS_LCK_MTX_UNLOCK_RELEASE, "lck_mtx_t"), | |
97 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_ACQUIRE, LS_LCK_MTX_EXT_LOCK_ACQUIRE, "lck_mtx_t"), | |
98 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_SPIN, LS_LCK_MTX_EXT_LOCK_SPIN, "lck_mtx_t", "uint64_t"), | |
99 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_BLOCK, LS_LCK_MTX_EXT_LOCK_BLOCK, "lck_mtx_t", "uint64_t"), | |
100 | // LOCKSTAT_PROBE(LS_LCK_MTX_EXT_TRY_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE) | |
101 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_UNLOCK, LSA_RELEASE, LS_LCK_MTX_EXT_UNLOCK_RELEASE, "lck_mtx_t"), | |
102 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK_SPIN_LOCK, LSA_ACQUIRE, LS_LCK_MTX_LOCK_SPIN_ACQUIRE, "lck_mtx_t"), | |
103 | // TODO: This should not be a uint64_t ! | |
104 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_ACQUIRE, LS_LCK_RW_LOCK_SHARED_ACQUIRE, "lck_rw_t", "uint64_t"), | |
105 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_BLOCK, LS_LCK_RW_LOCK_SHARED_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
106 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_SPIN, LS_LCK_RW_LOCK_SHARED_SPIN, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
107 | // TODO: This should NOT be a uint64_t | |
108 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_ACQUIRE, LS_LCK_RW_LOCK_EXCL_ACQUIRE, "lck_rw_t", "uint64_t"), | |
109 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_BLOCK, LS_LCK_RW_LOCK_EXCL_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
110 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_SPIN, LS_LCK_RW_LOCK_EXCL_SPIN, "lck_rw_t", "uint64_t", "int"), | |
111 | LOCKSTAT_PROBE(LS_LCK_RW_DONE, LSR_RELEASE, LS_LCK_RW_DONE_RELEASE, "lck_rw_t", "_Bool"), | |
112 | // TODO : This should NOT be a uint64_t | |
113 | LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_SHARED, LSR_ACQUIRE, LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE, "lck_rw_t", "uint64_t"), | |
114 | // See above | |
115 | LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_EXCL, LSR_ACQUIRE, LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE, "lck_rw_t", "uint64_t"), | |
116 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_UPGRADE, LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE, "lck_rw_t", "_Bool"), | |
117 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_SPIN, LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN, "lck_rw_t", "uint64_t"), | |
118 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_BLOCK, LS_LCK_RW_LOCK_SHARED_TO_EXCL_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
119 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL_TO_SHARED, LSR_DOWNGRADE, LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE, "lck_rw_t"), | |
120 | //TODO : Separate the probes for the hw_bit from the probe for the normal hw locks | |
121 | LOCKSTAT_PROBE(LS_LCK_SPIN_LOCK, LSS_ACQUIRE, LS_LCK_SPIN_LOCK_ACQUIRE, "hw_lock_t"), | |
122 | LOCKSTAT_PROBE(LS_LCK_SPIN_LOCK, LSS_SPIN, LS_LCK_SPIN_LOCK_SPIN, "hw_lock_t", "uint64_t", "uint64_t"), | |
123 | LOCKSTAT_PROBE(LS_LCK_SPIN_UNLOCK, LSS_RELEASE, LS_LCK_SPIN_UNLOCK_RELEASE, "hw_lock_t"), | |
124 | #elif defined(__arm__) || defined(__arm64__) | |
125 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_ACQUIRE, LS_LCK_MTX_LOCK_ACQUIRE, "lck_mtx_t"), | |
126 | // LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_SPIN, LS_LCK_MTX_LOCK_SPIN, "lck_mtx_t", "uint64_t"), | |
127 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_BLOCK, LS_LCK_MTX_LOCK_BLOCK, "lck_mtx_t", "uint64_t"), | |
128 | LOCKSTAT_PROBE(LS_LCK_MTX_TRY_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_LOCK_ACQUIRE, "lck_mtx_t"), | |
129 | // LOCKSTAT_PROBE(LS_LCK_MTX_TRY_SPIN_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE, "lck_mtx_t"), | |
130 | LOCKSTAT_PROBE(LS_LCK_MTX_UNLOCK, LSA_RELEASE, LS_LCK_MTX_UNLOCK_RELEASE, "lck_mtx_t"), | |
131 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_ACQUIRE, LS_LCK_MTX_EXT_LOCK_ACQUIRE, "lck_mtx_t"), | |
132 | // LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_SPIN, LS_LCK_MTX_EXT_LOCK_SPIN, "lck_mtx_t", "uint64_t"), | |
133 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_BLOCK, LS_LCK_MTX_EXT_LOCK_BLOCK, "lck_mtx_t", "uint64_t"), | |
134 | // LOCKSTAT_PROBE(LS_LCK_MTX_EXT_TRY_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE) | |
135 | // LOCKSTAT_PROBE(LS_LCK_MTX_EXT_UNLOCK, LSA_RELEASE, LS_LCK_MTX_EXT_UNLOCK_RELEASE, "lck_mtx_t"), | |
136 | // LOCKSTAT_PROBE(LS_LCK_MTX_LOCK_SPIN_LOCK, LSA_ACQUIRE, LS_LCK_MTX_LOCK_SPIN_ACQUIRE, "lck_mtx_t"), | |
137 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_ACQUIRE, LS_LCK_RW_LOCK_SHARED_ACQUIRE, "lck_rw_t", "uint64_t"), | |
138 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_BLOCK, LS_LCK_RW_LOCK_SHARED_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
139 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_SPIN, LS_LCK_RW_LOCK_SHARED_SPIN, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
140 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_ACQUIRE, LS_LCK_RW_LOCK_EXCL_ACQUIRE, "lck_rw_t", "uint64_t"), | |
141 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_BLOCK, LS_LCK_RW_LOCK_EXCL_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
142 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_SPIN, LS_LCK_RW_LOCK_EXCL_SPIN, "lck_rw_t", "uint64_t", "int"), | |
143 | LOCKSTAT_PROBE(LS_LCK_RW_DONE, LSR_RELEASE, LS_LCK_RW_DONE_RELEASE, "lck_rw_t", "_Bool"), | |
144 | // TODO : This should NOT be a uint64_t | |
145 | LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_SHARED, LSR_ACQUIRE, LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE, "lck_rw_t", "uint64_t"), | |
146 | // See above | |
147 | LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_EXCL, LSR_ACQUIRE, LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE, "lck_rw_t", "uint64_t"), | |
148 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_UPGRADE, LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE, "lck_rw_t", "_Bool"), | |
149 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_SPIN, LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN, "lck_rw_t", "uint64_t"), | |
150 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_BLOCK, LS_LCK_RW_LOCK_SHARED_TO_EXCL_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"), | |
151 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL_TO_SHARED, LSR_DOWNGRADE, LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE, "lck_rw_t"), | |
152 | //TODO : Separate the probes for the hw_bit from the probe for the normal hw locks | |
153 | LOCKSTAT_PROBE(LS_LCK_SPIN_LOCK, LSS_ACQUIRE, LS_LCK_SPIN_LOCK_ACQUIRE, "hw_lock_t"), | |
154 | LOCKSTAT_PROBE(LS_LCK_SPIN_LOCK, LSS_SPIN, LS_LCK_SPIN_LOCK_SPIN, "hw_lock_t", "uint64_t", "uint64_t"), | |
155 | LOCKSTAT_PROBE(LS_LCK_SPIN_UNLOCK, LSS_RELEASE, LS_LCK_SPIN_UNLOCK_RELEASE, "hw_lock_t"), | |
316670eb | 156 | #endif |
5ba3f43e A |
157 | /* Interlock measurements would be nice, but later */ |
158 | ||
0a7de745 | 159 | #ifdef LATER |
5ba3f43e A |
160 | LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL_TO_SHARED, LSA_ILK_SPIN, LS_LCK_RW_LOCK_EXCL_TO_SHARED_ILK_SPIN), |
161 | LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_ILK_SPIN, LS_LCK_MTX_LOCK_ILK_SPIN), | |
162 | LOCKSTAT_PROBE(LS_LCK_MTX_EXT_LOCK, LSA_ILK_SPIN, LS_LCK_MTX_EXT_LOCK_ILK_SPIN), | |
163 | LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_EXCL, LSA_ILK_SPIN, LS_LCK_RW_TRY_LOCK_EXCL_ILK_SPIN), | |
164 | LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_SHARED, LSA_SPIN, LS_LCK_RW_TRY_LOCK_SHARED_SPIN) | |
2d21ac55 A |
165 | #endif |
166 | ||
0a7de745 A |
167 | { |
168 | NULL, NULL, 0, 0, NULL | |
169 | } | |
2d21ac55 A |
170 | }; |
171 | ||
172 | dtrace_id_t lockstat_probemap[LS_NPROBES]; | |
2d21ac55 | 173 | void (*lockstat_probe)(dtrace_id_t, uint64_t, uint64_t, |
0a7de745 | 174 | uint64_t, uint64_t, uint64_t); |
316670eb | 175 | |
2d21ac55 A |
176 | static dtrace_provider_id_t lockstat_id; |
177 | ||
178 | /*ARGSUSED*/ | |
6d2010ae | 179 | static int |
2d21ac55 A |
180 | lockstat_enable(void *arg, dtrace_id_t id, void *parg) |
181 | { | |
b0d623f7 | 182 | #pragma unused(arg) /* __APPLE__ */ |
0a7de745 | 183 | |
2d21ac55 A |
184 | lockstat_probe_t *probe = parg; |
185 | ||
186 | ASSERT(!lockstat_probemap[probe->lsp_probe]); | |
187 | ||
188 | lockstat_probemap[probe->lsp_probe] = id; | |
189 | membar_producer(); | |
190 | ||
2d21ac55 | 191 | membar_producer(); |
0a7de745 | 192 | return 0; |
2d21ac55 A |
193 | } |
194 | ||
195 | /*ARGSUSED*/ | |
196 | static void | |
197 | lockstat_disable(void *arg, dtrace_id_t id, void *parg) | |
198 | { | |
b0d623f7 A |
199 | #pragma unused(arg, id) /* __APPLE__ */ |
200 | ||
2d21ac55 A |
201 | lockstat_probe_t *probe = parg; |
202 | int i; | |
203 | ||
204 | ASSERT(lockstat_probemap[probe->lsp_probe]); | |
205 | ||
206 | lockstat_probemap[probe->lsp_probe] = 0; | |
2d21ac55 A |
207 | membar_producer(); |
208 | ||
209 | /* | |
210 | * See if we have any probes left enabled. | |
211 | */ | |
212 | for (i = 0; i < LS_NPROBES; i++) { | |
213 | if (lockstat_probemap[i]) { | |
214 | /* | |
215 | * This probe is still enabled. We don't need to deal | |
216 | * with waiting for all threads to be out of the | |
217 | * lockstat critical sections; just return. | |
218 | */ | |
219 | return; | |
220 | } | |
221 | } | |
2d21ac55 A |
222 | } |
223 | ||
224 | /*ARGSUSED*/ | |
225 | static void | |
226 | lockstat_provide(void *arg, const dtrace_probedesc_t *desc) | |
227 | { | |
b0d623f7 | 228 | #pragma unused(arg, desc) /* __APPLE__ */ |
0a7de745 | 229 | |
2d21ac55 A |
230 | int i = 0; |
231 | ||
232 | for (i = 0; lockstat_probes[i].lsp_func != NULL; i++) { | |
233 | lockstat_probe_t *probe = &lockstat_probes[i]; | |
234 | ||
235 | if (dtrace_probe_lookup(lockstat_id, "mach_kernel", | |
0a7de745 | 236 | probe->lsp_func, probe->lsp_name) != 0) { |
2d21ac55 | 237 | continue; |
0a7de745 | 238 | } |
2d21ac55 A |
239 | |
240 | ASSERT(!probe->lsp_id); | |
241 | probe->lsp_id = dtrace_probe_create(lockstat_id, | |
242 | "mach_kernel", probe->lsp_func, probe->lsp_name, | |
243 | LOCKSTAT_AFRAMES, probe); | |
244 | } | |
245 | } | |
246 | ||
247 | ||
248 | /*ARGSUSED*/ | |
249 | static void | |
250 | lockstat_destroy(void *arg, dtrace_id_t id, void *parg) | |
251 | { | |
b0d623f7 | 252 | #pragma unused(arg, id) /* __APPLE__ */ |
0a7de745 | 253 | |
2d21ac55 A |
254 | lockstat_probe_t *probe = parg; |
255 | ||
256 | ASSERT(!lockstat_probemap[probe->lsp_probe]); | |
257 | probe->lsp_id = 0; | |
258 | } | |
259 | ||
5ba3f43e A |
260 | static void |
261 | lockstat_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc) | |
262 | { | |
263 | #pragma unused(arg, id) | |
264 | lockstat_probe_t *probe = parg; | |
265 | const char* argdesc = probe->lsp_args; | |
266 | int narg = 0; | |
267 | ||
268 | desc->dtargd_native[0] = '\0'; | |
269 | desc->dtargd_xlate[0] = '\0'; | |
270 | ||
0a7de745 | 271 | while (argdesc[0] != '\0') { |
5ba3f43e A |
272 | if (narg == desc->dtargd_ndx) { |
273 | strlcpy(desc->dtargd_native, argdesc, DTRACE_ARGTYPELEN); | |
274 | return; | |
275 | } | |
276 | argdesc += strlen(argdesc) + 1; | |
277 | narg++; | |
278 | } | |
279 | ||
280 | desc->dtargd_ndx = DTRACE_ARGNONE; | |
281 | } | |
282 | ||
2d21ac55 | 283 | static dtrace_pattr_t lockstat_attr = { |
0a7de745 A |
284 | { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, |
285 | { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, | |
286 | { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN }, | |
287 | { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, | |
288 | { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON }, | |
2d21ac55 A |
289 | }; |
290 | ||
291 | static dtrace_pops_t lockstat_pops = { | |
0a7de745 A |
292 | .dtps_provide = lockstat_provide, |
293 | .dtps_provide_module = NULL, | |
294 | .dtps_enable = lockstat_enable, | |
295 | .dtps_disable = lockstat_disable, | |
296 | .dtps_suspend = NULL, | |
297 | .dtps_resume = NULL, | |
298 | .dtps_getargdesc = lockstat_getargdesc, | |
299 | .dtps_getargval = NULL, | |
300 | .dtps_usermode = NULL, | |
301 | .dtps_destroy = lockstat_destroy | |
2d21ac55 A |
302 | }; |
303 | ||
304 | static int | |
d9a64523 | 305 | lockstat_attach(dev_info_t *devi) |
2d21ac55 | 306 | { |
2d21ac55 A |
307 | if (ddi_create_minor_node(devi, "lockstat", S_IFCHR, 0, |
308 | DDI_PSEUDO, 0) == DDI_FAILURE || | |
309 | dtrace_register("lockstat", &lockstat_attr, DTRACE_PRIV_KERNEL, | |
310 | NULL, &lockstat_pops, NULL, &lockstat_id) != 0) { | |
311 | ddi_remove_minor_node(devi, NULL); | |
0a7de745 | 312 | return DDI_FAILURE; |
2d21ac55 A |
313 | } |
314 | ||
b0d623f7 A |
315 | lockstat_probe = dtrace_probe; |
316 | membar_producer(); | |
317 | ||
0a7de745 | 318 | return DDI_SUCCESS; |
2d21ac55 A |
319 | } |
320 | ||
321 | d_open_t _lockstat_open; | |
322 | ||
0a7de745 A |
323 | int |
324 | _lockstat_open(dev_t dev, int flags, int devtype, struct proc *p) | |
2d21ac55 A |
325 | { |
326 | #pragma unused(dev,flags,devtype,p) | |
327 | return 0; | |
328 | } | |
329 | ||
330 | #define LOCKSTAT_MAJOR -24 /* let the kernel pick the device number */ | |
331 | ||
332 | /* | |
333 | * A struct describing which functions will get invoked for certain | |
334 | * actions. | |
335 | */ | |
336 | static struct cdevsw lockstat_cdevsw = | |
337 | { | |
0a7de745 A |
338 | _lockstat_open, /* open */ |
339 | eno_opcl, /* close */ | |
340 | eno_rdwrt, /* read */ | |
341 | eno_rdwrt, /* write */ | |
342 | eno_ioctl, /* ioctl */ | |
2d21ac55 A |
343 | (stop_fcn_t *)nulldev, /* stop */ |
344 | (reset_fcn_t *)nulldev, /* reset */ | |
0a7de745 A |
345 | NULL, /* tty's */ |
346 | eno_select, /* select */ | |
347 | eno_mmap, /* mmap */ | |
348 | eno_strat, /* strategy */ | |
349 | eno_getc, /* getc */ | |
350 | eno_putc, /* putc */ | |
351 | 0 /* type */ | |
2d21ac55 A |
352 | }; |
353 | ||
2d21ac55 A |
354 | void lockstat_init( void ); |
355 | ||
0a7de745 A |
356 | void |
357 | lockstat_init( void ) | |
2d21ac55 | 358 | { |
d9a64523 A |
359 | int majdevno = cdevsw_add(LOCKSTAT_MAJOR, &lockstat_cdevsw); |
360 | ||
361 | if (majdevno < 0) { | |
362 | printf("lockstat_init: failed to allocate a major number!\n"); | |
363 | return; | |
364 | } | |
2d21ac55 | 365 | |
d9a64523 | 366 | lockstat_attach((dev_info_t*)(uintptr_t)majdevno); |
2d21ac55 A |
367 | } |
368 | #undef LOCKSTAT_MAJOR |