lockstat.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/lockstat.h>
typedef struct lockstat_probe {
const char *lsp_func;
const char *lsp_name;
int lsp_probe;
{
{ NULL }
};
static dtrace_provider_id_t lockstat_id;
/*ARGSUSED*/
static void
{
/*
* Immediately generate a record for the lockstat_test mutex
* to verify that the mutex hot-patch code worked as expected.
*/
}
/*ARGSUSED*/
static void
{
int i;
/*
* See if we have any probes left enabled.
*/
for (i = 0; i < LS_NPROBES; i++) {
if (lockstat_probemap[i]) {
/*
* This probe is still enabled. We don't need to deal
* with waiting for all threads to be out of the
* lockstat critical sections; just return.
*/
return;
}
}
/*
* The delay() here isn't as cheesy as you might think. We don't
* want to busy-loop in the kernel, so we have to give up the
* CPU between calls to lockstat_active_threads(); that much is
* obvious. But the reason it's a do..while loop rather than a
* while loop is subtle. The memory barrier above guarantees that
* no threads will enter the lockstat code from this point forward.
* However, another thread could already be executing lockstat code
* without our knowledge if the update to its t_lockstat field hasn't
* cleared its CPU's store buffer. Delaying for one clock tick
* guarantees that either (1) the thread will have *ample* time to
* complete its work, or (2) the thread will be preempted, in which
* case it will have to grab and release a dispatcher lock, which
* will flush that CPU's store buffer. Either way we're covered.
*/
do {
delay(1);
} while (lockstat_active_threads());
}
/*ARGSUSED*/
static int
{
return (0);
}
/* ARGSUSED */
static int
{
int error;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
*result = (void *) lockstat_devi;
error = DDI_SUCCESS;
break;
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)0;
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
}
return (error);
}
/*ARGSUSED*/
static void
{
int i = 0;
continue;
1, probe);
}
}
/*ARGSUSED*/
static void
{
}
static dtrace_pattr_t lockstat_attr = {
};
static dtrace_pops_t lockstat_pops = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
static int
{
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
DDI_PSEUDO, 0) == DDI_FAILURE ||
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
{
switch (cmd) {
case DDI_DETACH:
break;
case DDI_SUSPEND:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
if (dtrace_unregister(lockstat_id) != 0)
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*
* Configuration data structures
*/
static struct cb_ops lockstat_cb_ops = {
lockstat_open, /* open */
nodev, /* close */
nulldev, /* strategy */
nulldev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
nodev, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
0, /* streamtab */
};
static struct dev_ops lockstat_ops = {
DEVO_REV, /* devo_rev, */
0, /* refcnt */
lockstat_info, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
lockstat_attach, /* attach */
lockstat_detach, /* detach */
nulldev, /* reset */
&lockstat_cb_ops, /* cb_ops */
NULL, /* bus_ops */
};
&mod_driverops, /* Type of module. This one is a driver */
"Lock Statistics %I%", /* name of module */
&lockstat_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}