xref: /xnu-11215.41.3/bsd/dev/dtrace/lockstat.c (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1*33de042dSApple OSS Distributions /*
2*33de042dSApple OSS Distributions  * CDDL HEADER START
3*33de042dSApple OSS Distributions  *
4*33de042dSApple OSS Distributions  * The contents of this file are subject to the terms of the
5*33de042dSApple OSS Distributions  * Common Development and Distribution License (the "License").
6*33de042dSApple OSS Distributions  * You may not use this file except in compliance with the License.
7*33de042dSApple OSS Distributions  *
8*33de042dSApple OSS Distributions  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*33de042dSApple OSS Distributions  * or http://www.opensolaris.org/os/licensing.
10*33de042dSApple OSS Distributions  * See the License for the specific language governing permissions
11*33de042dSApple OSS Distributions  * and limitations under the License.
12*33de042dSApple OSS Distributions  *
13*33de042dSApple OSS Distributions  * When distributing Covered Code, include this CDDL HEADER in each
14*33de042dSApple OSS Distributions  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*33de042dSApple OSS Distributions  * If applicable, add the following below this CDDL HEADER, with the
16*33de042dSApple OSS Distributions  * fields enclosed by brackets "[]" replaced with your own identifying
17*33de042dSApple OSS Distributions  * information: Portions Copyright [yyyy] [name of copyright owner]
18*33de042dSApple OSS Distributions  *
19*33de042dSApple OSS Distributions  * CDDL HEADER END
20*33de042dSApple OSS Distributions  */
21*33de042dSApple OSS Distributions /*
22*33de042dSApple OSS Distributions  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*33de042dSApple OSS Distributions  * Use is subject to license terms.
24*33de042dSApple OSS Distributions  */
25*33de042dSApple OSS Distributions 
26*33de042dSApple OSS Distributions #include <sys/param.h>
27*33de042dSApple OSS Distributions #include <sys/systm.h>
28*33de042dSApple OSS Distributions #include <sys/errno.h>
29*33de042dSApple OSS Distributions #include <sys/stat.h>
30*33de042dSApple OSS Distributions #include <sys/ioctl.h>
31*33de042dSApple OSS Distributions #include <sys/conf.h>
32*33de042dSApple OSS Distributions #include <sys/fcntl.h>
33*33de042dSApple OSS Distributions #include <miscfs/devfs/devfs.h>
34*33de042dSApple OSS Distributions 
35*33de042dSApple OSS Distributions #include <sys/dtrace.h>
36*33de042dSApple OSS Distributions #include <sys/dtrace_impl.h>
37*33de042dSApple OSS Distributions 
38*33de042dSApple OSS Distributions #include <sys/dtrace_glue.h>
39*33de042dSApple OSS Distributions 
40*33de042dSApple OSS Distributions #include <sys/lockstat.h>
41*33de042dSApple OSS Distributions 
42*33de042dSApple OSS Distributions #include <kern/lock_stat.h>
43*33de042dSApple OSS Distributions 
44*33de042dSApple OSS Distributions #define PROBE_ARGS0(a, b, c, d, e) "\000"
45*33de042dSApple OSS Distributions #define PROBE_ARGS1(a, b, c, d, e) a "\000"
46*33de042dSApple OSS Distributions #define PROBE_ARGS2(a, b, c, d, e) a "\000" b "\000"
47*33de042dSApple OSS Distributions #define PROBE_ARGS3(a, b, c, d, e) a "\000" b "\000" c "\000"
48*33de042dSApple OSS Distributions #define PROBE_ARGS4(a, b, c, d, e) a "\000" b "\000" c "\000" d "\000"
49*33de042dSApple OSS Distributions #define PROBE_ARGS5(a, b, c, d, e) a "\000" b "\000" c "\000" d "\000" e "\000"
50*33de042dSApple OSS Distributions #define PROBE_ARGS_(a, b, c, d, e, n, ...) PROBE_ARGS##n(a, b, c, d, e)
51*33de042dSApple OSS Distributions #define PROBE_ARGS(...) PROBE_ARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0)
52*33de042dSApple OSS Distributions 
53*33de042dSApple OSS Distributions #define LOCKSTAT_PROBE(func, name, probe, ...) \
54*33de042dSApple OSS Distributions 	{func, name, probe, DTRACE_IDNONE, PROBE_ARGS(__VA_ARGS__)}
55*33de042dSApple OSS Distributions 
56*33de042dSApple OSS Distributions #if defined(__x86_64__)
57*33de042dSApple OSS Distributions #define LOCKSTAT_AFRAMES 1
58*33de042dSApple OSS Distributions #elif   defined(__arm64__)
59*33de042dSApple OSS Distributions #define LOCKSTAT_AFRAMES 2
60*33de042dSApple OSS Distributions #else
61*33de042dSApple OSS Distributions #error "architecture not supported"
62*33de042dSApple OSS Distributions #endif
63*33de042dSApple OSS Distributions 
64*33de042dSApple OSS Distributions typedef struct lockstat_probe {
65*33de042dSApple OSS Distributions 	const char      *lsp_func;
66*33de042dSApple OSS Distributions 	const char      *lsp_name;
67*33de042dSApple OSS Distributions 	int             lsp_probe;
68*33de042dSApple OSS Distributions 	dtrace_id_t     lsp_id;
69*33de042dSApple OSS Distributions 	const char      *lsp_args;
70*33de042dSApple OSS Distributions } lockstat_probe_t;
71*33de042dSApple OSS Distributions 
72*33de042dSApple OSS Distributions lockstat_probe_t lockstat_probes[] =
73*33de042dSApple OSS Distributions {
74*33de042dSApple OSS Distributions 	// Mutex probes
75*33de042dSApple OSS Distributions 	// .. acquire/release
76*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_ACQUIRE, LS_LCK_MTX_LOCK_ACQUIRE, "lck_mtx_t", "lck_grp_t"),
77*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_LOCK_SPIN, LSA_ACQUIRE, LS_LCK_MTX_LOCK_SPIN_ACQUIRE, "lck_mtx_t", "lck_grp_t"),
78*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_TRY_LOCK, LSA_ACQUIRE, LS_LCK_MTX_TRY_LOCK_ACQUIRE, "lck_mtx_t", "lck_grp_t"),
79*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_TRY_LOCK_SPIN, LSA_ACQUIRE, LS_LCK_MTX_TRY_LOCK_SPIN_ACQUIRE, "lck_mtx_t", "lck_grp_t"),
80*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_UNLOCK, LSA_RELEASE, LS_LCK_MTX_UNLOCK_RELEASE, "lck_mtx_t", "lck_grp_t"),
81*33de042dSApple OSS Distributions 
82*33de042dSApple OSS Distributions 	// .. blocking and spinning
83*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_BLOCK, LS_LCK_MTX_LOCK_BLOCK, "lck_mtx_t", "uint64_t", "lck_grp_t"),
84*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_LOCK, LSA_SPIN, LS_LCK_MTX_LOCK_ADAPTIVE_SPIN, "lck_mtx_t", "uint64_t", "lck_grp_t"),
85*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_MTX_LOCK_SPIN, LSA_SPIN, LS_LCK_MTX_LOCK_SPIN_SPIN, "lck_mtx_t", "uint64_t", "lck_grp_t"),
86*33de042dSApple OSS Distributions 
87*33de042dSApple OSS Distributions 	// RW lock probes
88*33de042dSApple OSS Distributions 	// TODO: This should not be a uint64_t !
89*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_ACQUIRE, LS_LCK_RW_LOCK_SHARED_ACQUIRE, "lck_rw_t", "uint64_t"),
90*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_BLOCK, LS_LCK_RW_LOCK_SHARED_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"),
91*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED, LSR_SPIN, LS_LCK_RW_LOCK_SHARED_SPIN, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"),
92*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_ACQUIRE, LS_LCK_RW_LOCK_EXCL_ACQUIRE, "lck_rw_t", "uint64_t"),
93*33de042dSApple OSS Distributions 	// TODO: This should NOT be a uint64_t
94*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_BLOCK, LS_LCK_RW_LOCK_EXCL_BLOCK, "lck_rw_t", "uint64_t", "_Bool", "_Bool", "int"),
95*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL, LSR_SPIN, LS_LCK_RW_LOCK_EXCL_SPIN, "lck_rw_t", "uint64_t", "int"),
96*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_DONE, LSR_RELEASE, LS_LCK_RW_DONE_RELEASE, "lck_rw_t", "_Bool"),
97*33de042dSApple OSS Distributions 	// TODO : This should NOT be a uint64_t
98*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_SHARED, LSR_ACQUIRE, LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE, "lck_rw_t", "uint64_t"),
99*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_TRY_LOCK_EXCL, LSR_ACQUIRE, LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE, "lck_rw_t", "uint64_t"),
100*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_UPGRADE, LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE, "lck_rw_t", "_Bool"),
101*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_SHARED_TO_EXCL, LSR_SPIN, LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN, "lck_rw_t", "uint64_t"),
102*33de042dSApple OSS Distributions 	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"),
103*33de042dSApple OSS Distributions 
104*33de042dSApple OSS Distributions 	// Spin lock probes
105*33de042dSApple OSS Distributions 	//TODO : Separate the probes for the hw_bit from the probe for the normal hw locks
106*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_SPIN_LOCK, LSS_ACQUIRE, LS_LCK_SPIN_LOCK_ACQUIRE, "hw_lock_t"),
107*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_SPIN_LOCK, LSS_SPIN, LS_LCK_SPIN_LOCK_SPIN, "hw_lock_t", "uint64_t", "uint64_t"),
108*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_SPIN_UNLOCK, LSS_RELEASE, LS_LCK_SPIN_UNLOCK_RELEASE, "hw_lock_t"),
109*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_RW_LOCK_EXCL_TO_SHARED, LSR_DOWNGRADE, LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE, "lck_rw_t"),
110*33de042dSApple OSS Distributions 	// Ticket lock probes
111*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_TICKET_LOCK, LST_ACQUIRE, LS_LCK_TICKET_LOCK_ACQUIRE, "lck_ticket_t"),
112*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_TICKET_LOCK, LST_RELEASE, LS_LCK_TICKET_LOCK_RELEASE, "lck_ticket_t"),
113*33de042dSApple OSS Distributions 	LOCKSTAT_PROBE(LS_LCK_TICKET_LOCK, LST_SPIN, LS_LCK_TICKET_LOCK_SPIN, "lck_ticket_t"),
114*33de042dSApple OSS Distributions 	{
115*33de042dSApple OSS Distributions 		NULL, NULL, 0, 0, NULL
116*33de042dSApple OSS Distributions 	}
117*33de042dSApple OSS Distributions };
118*33de042dSApple OSS Distributions 
119*33de042dSApple OSS Distributions dtrace_id_t lockstat_probemap[LS_NPROBES];
120*33de042dSApple OSS Distributions 
121*33de042dSApple OSS Distributions static dtrace_provider_id_t lockstat_id;
122*33de042dSApple OSS Distributions 
123*33de042dSApple OSS Distributions /*ARGSUSED*/
124*33de042dSApple OSS Distributions static int
lockstat_enable(void * arg,dtrace_id_t id,void * parg)125*33de042dSApple OSS Distributions lockstat_enable(void *arg, dtrace_id_t id, void *parg)
126*33de042dSApple OSS Distributions {
127*33de042dSApple OSS Distributions #pragma unused(arg) /* __APPLE__ */
128*33de042dSApple OSS Distributions 
129*33de042dSApple OSS Distributions 	lockstat_probe_t *probe = parg;
130*33de042dSApple OSS Distributions 
131*33de042dSApple OSS Distributions 	ASSERT(!lockstat_probemap[probe->lsp_probe]);
132*33de042dSApple OSS Distributions 
133*33de042dSApple OSS Distributions 	lockstat_probemap[probe->lsp_probe] = id;
134*33de042dSApple OSS Distributions 	lck_grp_enable_feature(LCK_DEBUG_LOCKSTAT);
135*33de042dSApple OSS Distributions 
136*33de042dSApple OSS Distributions 	return 0;
137*33de042dSApple OSS Distributions }
138*33de042dSApple OSS Distributions 
139*33de042dSApple OSS Distributions /*ARGSUSED*/
140*33de042dSApple OSS Distributions static void
lockstat_disable(void * arg,dtrace_id_t id,void * parg)141*33de042dSApple OSS Distributions lockstat_disable(void *arg, dtrace_id_t id, void *parg)
142*33de042dSApple OSS Distributions {
143*33de042dSApple OSS Distributions #pragma unused(arg, id) /* __APPLE__ */
144*33de042dSApple OSS Distributions 
145*33de042dSApple OSS Distributions 	lockstat_probe_t *probe = parg;
146*33de042dSApple OSS Distributions 
147*33de042dSApple OSS Distributions 	ASSERT(lockstat_probemap[probe->lsp_probe]);
148*33de042dSApple OSS Distributions 
149*33de042dSApple OSS Distributions 	lockstat_probemap[probe->lsp_probe] = 0;
150*33de042dSApple OSS Distributions 	lck_grp_disable_feature(LCK_DEBUG_LOCKSTAT);
151*33de042dSApple OSS Distributions }
152*33de042dSApple OSS Distributions 
153*33de042dSApple OSS Distributions /*ARGSUSED*/
154*33de042dSApple OSS Distributions static void
lockstat_provide(void * arg,const dtrace_probedesc_t * desc)155*33de042dSApple OSS Distributions lockstat_provide(void *arg, const dtrace_probedesc_t *desc)
156*33de042dSApple OSS Distributions {
157*33de042dSApple OSS Distributions #pragma unused(arg, desc) /* __APPLE__ */
158*33de042dSApple OSS Distributions 
159*33de042dSApple OSS Distributions 	int i = 0;
160*33de042dSApple OSS Distributions 
161*33de042dSApple OSS Distributions 	for (i = 0; lockstat_probes[i].lsp_func != NULL; i++) {
162*33de042dSApple OSS Distributions 		lockstat_probe_t *probe = &lockstat_probes[i];
163*33de042dSApple OSS Distributions 
164*33de042dSApple OSS Distributions 		if (dtrace_probe_lookup(lockstat_id, "mach_kernel",
165*33de042dSApple OSS Distributions 		    probe->lsp_func, probe->lsp_name) != 0) {
166*33de042dSApple OSS Distributions 			continue;
167*33de042dSApple OSS Distributions 		}
168*33de042dSApple OSS Distributions 
169*33de042dSApple OSS Distributions 		ASSERT(!probe->lsp_id);
170*33de042dSApple OSS Distributions 		probe->lsp_id = dtrace_probe_create(lockstat_id,
171*33de042dSApple OSS Distributions 		    "mach_kernel", probe->lsp_func, probe->lsp_name,
172*33de042dSApple OSS Distributions 		    LOCKSTAT_AFRAMES, probe);
173*33de042dSApple OSS Distributions 	}
174*33de042dSApple OSS Distributions }
175*33de042dSApple OSS Distributions 
176*33de042dSApple OSS Distributions 
177*33de042dSApple OSS Distributions /*ARGSUSED*/
178*33de042dSApple OSS Distributions static void
lockstat_destroy(void * arg,dtrace_id_t id,void * parg)179*33de042dSApple OSS Distributions lockstat_destroy(void *arg, dtrace_id_t id, void *parg)
180*33de042dSApple OSS Distributions {
181*33de042dSApple OSS Distributions #pragma unused(arg, id)
182*33de042dSApple OSS Distributions 
183*33de042dSApple OSS Distributions 	lockstat_probe_t *probe = parg;
184*33de042dSApple OSS Distributions 
185*33de042dSApple OSS Distributions 	ASSERT(!lockstat_probemap[probe->lsp_probe]);
186*33de042dSApple OSS Distributions 	probe->lsp_id = 0;
187*33de042dSApple OSS Distributions }
188*33de042dSApple OSS Distributions 
189*33de042dSApple OSS Distributions static void
lockstat_getargdesc(void * arg,dtrace_id_t id,void * parg,dtrace_argdesc_t * desc)190*33de042dSApple OSS Distributions lockstat_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
191*33de042dSApple OSS Distributions {
192*33de042dSApple OSS Distributions #pragma unused(arg, id)
193*33de042dSApple OSS Distributions 	lockstat_probe_t *probe = parg;
194*33de042dSApple OSS Distributions 	const char* argdesc = probe->lsp_args;
195*33de042dSApple OSS Distributions 	int narg = 0;
196*33de042dSApple OSS Distributions 
197*33de042dSApple OSS Distributions 	desc->dtargd_native[0] = '\0';
198*33de042dSApple OSS Distributions 	desc->dtargd_xlate[0] = '\0';
199*33de042dSApple OSS Distributions 
200*33de042dSApple OSS Distributions 	while (argdesc[0] != '\0') {
201*33de042dSApple OSS Distributions 		if (narg == desc->dtargd_ndx) {
202*33de042dSApple OSS Distributions 			strlcpy(desc->dtargd_native, argdesc, DTRACE_ARGTYPELEN);
203*33de042dSApple OSS Distributions 			return;
204*33de042dSApple OSS Distributions 		}
205*33de042dSApple OSS Distributions 		argdesc += strlen(argdesc) + 1;
206*33de042dSApple OSS Distributions 		narg++;
207*33de042dSApple OSS Distributions 	}
208*33de042dSApple OSS Distributions 
209*33de042dSApple OSS Distributions 	desc->dtargd_ndx = DTRACE_ARGNONE;
210*33de042dSApple OSS Distributions }
211*33de042dSApple OSS Distributions 
212*33de042dSApple OSS Distributions static dtrace_pattr_t lockstat_attr = {
213*33de042dSApple OSS Distributions 	{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
214*33de042dSApple OSS Distributions 	{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
215*33de042dSApple OSS Distributions 	{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
216*33de042dSApple OSS Distributions 	{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
217*33de042dSApple OSS Distributions 	{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
218*33de042dSApple OSS Distributions };
219*33de042dSApple OSS Distributions 
220*33de042dSApple OSS Distributions static dtrace_pops_t lockstat_pops = {
221*33de042dSApple OSS Distributions 	.dtps_provide =         lockstat_provide,
222*33de042dSApple OSS Distributions 	.dtps_provide_module =  NULL,
223*33de042dSApple OSS Distributions 	.dtps_enable =          lockstat_enable,
224*33de042dSApple OSS Distributions 	.dtps_disable =         lockstat_disable,
225*33de042dSApple OSS Distributions 	.dtps_suspend =         NULL,
226*33de042dSApple OSS Distributions 	.dtps_resume =          NULL,
227*33de042dSApple OSS Distributions 	.dtps_getargdesc =      lockstat_getargdesc,
228*33de042dSApple OSS Distributions 	.dtps_getargval =       NULL,
229*33de042dSApple OSS Distributions 	.dtps_usermode =        NULL,
230*33de042dSApple OSS Distributions 	.dtps_destroy =         lockstat_destroy
231*33de042dSApple OSS Distributions };
232*33de042dSApple OSS Distributions 
233*33de042dSApple OSS Distributions static int
lockstat_attach(dev_info_t * devi)234*33de042dSApple OSS Distributions lockstat_attach(dev_info_t *devi)
235*33de042dSApple OSS Distributions {
236*33de042dSApple OSS Distributions 	if (ddi_create_minor_node(devi, "lockstat", S_IFCHR, 0,
237*33de042dSApple OSS Distributions 	    DDI_PSEUDO, 0) == DDI_FAILURE ||
238*33de042dSApple OSS Distributions 	    dtrace_register("lockstat", &lockstat_attr, DTRACE_PRIV_KERNEL,
239*33de042dSApple OSS Distributions 	    NULL, &lockstat_pops, NULL, &lockstat_id) != 0) {
240*33de042dSApple OSS Distributions 		ddi_remove_minor_node(devi, NULL);
241*33de042dSApple OSS Distributions 		return DDI_FAILURE;
242*33de042dSApple OSS Distributions 	}
243*33de042dSApple OSS Distributions 
244*33de042dSApple OSS Distributions 	return DDI_SUCCESS;
245*33de042dSApple OSS Distributions }
246*33de042dSApple OSS Distributions 
247*33de042dSApple OSS Distributions static int
_lockstat_open(dev_t dev,int flags,int devtype,struct proc * p)248*33de042dSApple OSS Distributions _lockstat_open(dev_t dev, int flags, int devtype, struct proc *p)
249*33de042dSApple OSS Distributions {
250*33de042dSApple OSS Distributions #pragma unused(dev,flags,devtype,p)
251*33de042dSApple OSS Distributions 	return 0;
252*33de042dSApple OSS Distributions }
253*33de042dSApple OSS Distributions 
254*33de042dSApple OSS Distributions 
255*33de042dSApple OSS Distributions static const struct cdevsw lockstat_cdevsw =
256*33de042dSApple OSS Distributions {
257*33de042dSApple OSS Distributions 	.d_open = _lockstat_open,
258*33de042dSApple OSS Distributions 	.d_close = eno_opcl,
259*33de042dSApple OSS Distributions 	.d_read = eno_rdwrt,
260*33de042dSApple OSS Distributions 	.d_write = eno_rdwrt,
261*33de042dSApple OSS Distributions 	.d_ioctl = eno_ioctl,
262*33de042dSApple OSS Distributions 	.d_stop = eno_stop,
263*33de042dSApple OSS Distributions 	.d_reset = eno_reset,
264*33de042dSApple OSS Distributions 	.d_select = eno_select,
265*33de042dSApple OSS Distributions 	.d_mmap = eno_mmap,
266*33de042dSApple OSS Distributions 	.d_strategy = eno_strat,
267*33de042dSApple OSS Distributions 	.d_reserved_1 = eno_getc,
268*33de042dSApple OSS Distributions 	.d_reserved_2 = eno_putc,
269*33de042dSApple OSS Distributions };
270*33de042dSApple OSS Distributions 
271*33de042dSApple OSS Distributions void lockstat_init( void );
272*33de042dSApple OSS Distributions 
273*33de042dSApple OSS Distributions void
lockstat_init(void)274*33de042dSApple OSS Distributions lockstat_init( void )
275*33de042dSApple OSS Distributions {
276*33de042dSApple OSS Distributions 	int majdevno = cdevsw_add(-1, &lockstat_cdevsw);
277*33de042dSApple OSS Distributions 
278*33de042dSApple OSS Distributions 	if (majdevno < 0) {
279*33de042dSApple OSS Distributions 		printf("lockstat_init: failed to allocate a major number!\n");
280*33de042dSApple OSS Distributions 		return;
281*33de042dSApple OSS Distributions 	}
282*33de042dSApple OSS Distributions 
283*33de042dSApple OSS Distributions 	lockstat_attach((dev_info_t*)(uintptr_t)majdevno);
284*33de042dSApple OSS Distributions }
285