Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/cddl/osnet/dev/lockstat Rewrite dtrace lockstat fro...
details: https://anonhg.NetBSD.org/src/rev/0194942fe32f
branches: trunk
changeset: 336657:0194942fe32f
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Mar 08 23:56:59 2015 +0000
description:
Rewrite dtrace lockstat from the Solaris version and simplify.
- Fix mutex_adaptive probes to use the right lockstat flags.
- Install lockstat_probe_func on module load, not trace enable.
- Use a more sensible memory barrier arrangement.
diffstat:
external/cddl/osnet/dev/lockstat/lockstat.c | 395 +++++++++------------------
1 files changed, 133 insertions(+), 262 deletions(-)
diffs (truncated from 492 to 300 lines):
diff -r 6159fa61eb48 -r 0194942fe32f external/cddl/osnet/dev/lockstat/lockstat.c
--- a/external/cddl/osnet/dev/lockstat/lockstat.c Sun Mar 08 23:37:56 2015 +0000
+++ b/external/cddl/osnet/dev/lockstat/lockstat.c Sun Mar 08 23:56:59 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lockstat.c,v 1.4 2015/03/08 04:13:46 christos Exp $ */
+/* $NetBSD: lockstat.c,v 1.5 2015/03/08 23:56:59 riastradh Exp $ */
/*
* CDDL HEADER START
@@ -19,167 +19,81 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Portions Copyright (c) 2008-2009 Stacey Son <sson%FreeBSD.org@localhost>
- *
- * $FreeBSD: src/sys/cddl/dev/lockstat/lockstat.c,v 1.2.2.1 2009/08/03 08:13:06 kensmith Exp $
- *
*/
-
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: lockstat.c,v 1.5 2015/03/08 23:56:59 riastradh Exp $");
+
+#include <sys/types.h>
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/conf.h>
-#include <sys/kernel.h>
-#include <sys/limits.h>
-#include <sys/lock.h>
-#include <sys/linker.h>
+#include <sys/dtrace.h>
#include <sys/module.h>
#include <sys/mutex.h>
-#ifdef __NetBSD__
-#include <sys/atomic.h>
+#include <sys/systm.h>
#include <sys/xcall.h>
-#endif
-
-#include <sys/dtrace.h>
-#ifdef __NetBSD__
-#include <dev/lockstat.h>
-#else
-#include <sys/lockstat.h>
-#endif
-
-#ifdef __NetBSD__
-#define ASSERT KASSERT
-#endif
-#if defined(__i386__) || defined(__amd64__) || defined(__arm__)
-#define LOCKSTAT_AFRAMES 1
-#else
-#error "architecture not supported"
-#endif
+#include <dev/lockstat.h>
-#if defined(__FreeBSD__)
-static d_open_t lockstat_open;
-#elif defined(__NetBSD__) && 0
-static dev_type_open(lockstat_open);
-#endif
-static void lockstat_provide(void *, const dtrace_probedesc_t *);
-static void lockstat_destroy(void *, dtrace_id_t, void *);
-static int lockstat_enable(void *, dtrace_id_t, void *);
-static void lockstat_disable(void *, dtrace_id_t, void *);
-static void lockstat_load(void *);
-static int lockstat_unload(void);
-
+#define ASSERT KASSERT
typedef struct lockstat_probe {
const char *lsp_func;
const char *lsp_name;
int lsp_probe;
dtrace_id_t lsp_id;
-#ifdef __FreeBSD__
- int lsp_frame;
-#endif
} lockstat_probe_t;
-#if defined(__FreeBSD__)
-lockstat_probe_t lockstat_probes[] =
-{
- /* Spin Locks */
- { LS_MTX_SPIN_LOCK, LSS_ACQUIRE, LS_MTX_SPIN_LOCK_ACQUIRE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_MTX_SPIN_LOCK, LSS_SPIN, LS_MTX_SPIN_LOCK_SPIN,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_MTX_SPIN_UNLOCK, LSS_RELEASE, LS_MTX_SPIN_UNLOCK_RELEASE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- /* Adaptive Locks */
- { LS_MTX_LOCK, LSA_ACQUIRE, LS_MTX_LOCK_ACQUIRE,
- DTRACE_IDNONE, (LOCKSTAT_AFRAMES + 1) },
- { LS_MTX_LOCK, LSA_BLOCK, LS_MTX_LOCK_BLOCK,
- DTRACE_IDNONE, (LOCKSTAT_AFRAMES + 1) },
- { LS_MTX_LOCK, LSA_SPIN, LS_MTX_LOCK_SPIN,
- DTRACE_IDNONE, (LOCKSTAT_AFRAMES + 1) },
- { LS_MTX_UNLOCK, LSA_RELEASE, LS_MTX_UNLOCK_RELEASE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_MTX_TRYLOCK, LSA_ACQUIRE, LS_MTX_TRYLOCK_ACQUIRE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- /* Reader/Writer Locks */
- { LS_RW_RLOCK, LSR_ACQUIRE, LS_RW_RLOCK_ACQUIRE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_RLOCK, LSR_BLOCK, LS_RW_RLOCK_BLOCK,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_RLOCK, LSR_SPIN, LS_RW_RLOCK_SPIN,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_RUNLOCK, LSR_RELEASE, LS_RW_RUNLOCK_RELEASE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_WLOCK, LSR_ACQUIRE, LS_RW_WLOCK_ACQUIRE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_WLOCK, LSR_BLOCK, LS_RW_WLOCK_BLOCK,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_WLOCK, LSR_SPIN, LS_RW_WLOCK_SPIN,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_WUNLOCK, LSR_RELEASE, LS_RW_WUNLOCK_RELEASE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_TRYUPGRADE, LSR_UPGRADE, LS_RW_TRYUPGRADE_UPGRADE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_RW_DOWNGRADE, LSR_DOWNGRADE, LS_RW_DOWNGRADE_DOWNGRADE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- /* Shared/Exclusive Locks */
- { LS_SX_SLOCK, LSX_ACQUIRE, LS_SX_SLOCK_ACQUIRE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_SLOCK, LSX_BLOCK, LS_SX_SLOCK_BLOCK,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_SLOCK, LSX_SPIN, LS_SX_SLOCK_SPIN,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_SUNLOCK, LSX_RELEASE, LS_SX_SUNLOCK_RELEASE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_XLOCK, LSX_ACQUIRE, LS_SX_XLOCK_ACQUIRE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_XLOCK, LSX_BLOCK, LS_SX_XLOCK_BLOCK,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_XLOCK, LSX_SPIN, LS_SX_XLOCK_SPIN,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_XUNLOCK, LSX_RELEASE, LS_SX_XUNLOCK_RELEASE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_TRYUPGRADE, LSX_UPGRADE, LS_SX_TRYUPGRADE_UPGRADE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { LS_SX_DOWNGRADE, LSX_DOWNGRADE, LS_SX_DOWNGRADE_DOWNGRADE,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- /* Thread Locks */
- { LS_THREAD_LOCK, LST_SPIN, LS_THREAD_LOCK_SPIN,
- DTRACE_IDNONE, LOCKSTAT_AFRAMES },
- { NULL }
-};
-#elif defined(__NetBSD__)
lockstat_probe_t lockstat_probes[] = {
{ "mutex_spin", "spin", LB_SPIN_MUTEX | LB_SPIN, 0 },
- { "mutex_adaptive", "sleep", LB_SPIN_MUTEX | LB_SLEEP1, 0 },
- { "mutex_adaptive", "spin", LB_SPIN_MUTEX | LB_SPIN, 0 },
+ { "mutex_adaptive", "sleep", LB_ADAPTIVE_MUTEX | LB_SLEEP1, 0 },
+ { "mutex_adaptive", "spin", LB_ADAPTIVE_MUTEX | LB_SPIN, 0 },
{ "rwlock", "sleep_writer", LB_RWLOCK | LB_SLEEP1, 0 },
{ "rwlock", "sleep_reader", LB_RWLOCK | LB_SLEEP2, 0 },
{ "rwlock", "spin", LB_RWLOCK | LB_SPIN, 0 },
{ "kernel", "spin", LB_KERNEL_LOCK | LB_SPIN, 0 },
{ "lwp", "spin", LB_NOPREEMPT | LB_SPIN, 0 },
};
-#else
-#error "OS not supported"
-#endif
+
+static dtrace_provider_id_t lockstat_id;
+/*ARGSUSED*/
+static int
+lockstat_enable(void *arg, dtrace_id_t id, void *parg)
+{
+ lockstat_probe_t *probe = parg;
+
+ ASSERT(!lockstat_probemap[probe->lsp_probe]);
+
+ lockstat_probemap[probe->lsp_probe] = id;
+
+ return 0;
+}
-#if defined(__FreeBSD__)
-static struct cdevsw lockstat_cdevsw = {
- .d_version = D_VERSION,
- .d_open = lockstat_open,
- .d_name = "lockstat",
-};
+/*ARGSUSED*/
+static void
+lockstat_disable(void *arg, dtrace_id_t id __unused, void *parg)
+{
+ lockstat_probe_t *probe = parg;
+
+ ASSERT(lockstat_probemap[probe->lsp_probe]);
-static struct cdev *lockstat_cdev;
-#elif defined(__NetBSD__) && 0
-static struct cdevsw lockstat_cdevsw = {
+ lockstat_probemap[probe->lsp_probe] = 0;
+}
+
+static int
+lockstat_open(dev_t dev __unused, int flags __unused, int mode __unused,
+ struct lwp *l __unused)
+{
+
+ return 0;
+}
+
+static const struct cdevsw lockstat_cdevsw = {
.d_open = lockstat_open,
.d_close = noclose,
.d_read = noread,
@@ -193,80 +107,6 @@
.d_discard = nodiscard,
.d_flag = D_OTHER,
};
-#endif
-
-static dtrace_provider_id_t lockstat_id;
-
-/*ARGSUSED*/
-static int
-lockstat_enable(void *arg, dtrace_id_t id, void *parg)
-{
- lockstat_probe_t *probe = parg;
-
- ASSERT(!lockstat_probemap[probe->lsp_probe]);
- if (lockstat_probe_func == lockstat_probe_stub) {
- lockstat_probe_func = dtrace_probe;
- membar_producer();
- } else {
- ASSERT(lockstat_probe_func == dtrace_probe);
- }
- lockstat_probemap[probe->lsp_probe] = id;
-
- return 0;
-}
-
-/*ARGSUSED*/
-static void
-lockstat_disable(void *arg, dtrace_id_t id, void *parg)
-{
- lockstat_probe_t *probe = parg;
- int i;
-
- ASSERT(lockstat_probe_func == dtrace_probe);
- ASSERT(lockstat_probemap[probe->lsp_probe]);
- lockstat_probemap[probe->lsp_probe] = 0;
- membar_producer();
-
- /*
- * 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;
- }
- }
-
- lockstat_probe_func = lockstat_probe_stub;
-
- /*
- * Trigger some activity on all CPUs to make sure they're not
- * in lockstat any more.
- */
- xc_wait(xc_broadcast(0, (void *)nullop, NULL, NULL));
-}
-
-#if defined(__FreeBSD__)
-/*ARGSUSED*/
-static int
-lockstat_open(struct cdev *dev __unused, int oflags __unused,
- int devtype __unused, struct thread *td __unused)
-{
- return (0);
-}
-#elif defined(__NetBSD__) && 0
-static int
-lockstat_open(dev_t dev __unused, int flags __unused, int mode __unused,
- struct lwp *l __unused)
-{
-
- return 0;
-}
-#endif
/*ARGSUSED*/
Home |
Main Index |
Thread Index |
Old Index