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