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