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