summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2010-09-28 20:27:57 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2010-09-28 20:27:57 +0000
commit15969dfa68e37d305dd11968e20ca0a425d2092a (patch)
treeff5f69008da4bbcba278d383b53bb927776d4644 /sys
parent23487e0f53f72934a66dcf7e42b399ec6562e966 (diff)
Implement a per-cpu held mutex counter if DIAGNOSTIC on all non-x86 platforms,
to complete matthew@'s commit of a few days ago, and drop __HAVE_CPU_MUTEX_LEVEL define. With help from, and ok deraadt@.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/alpha/alpha/mutex.c11
-rw-r--r--sys/arch/alpha/include/cpu.h5
-rw-r--r--sys/arch/amd64/include/cpu.h3
-rw-r--r--sys/arch/arm/include/cpu.h5
-rw-r--r--sys/arch/hppa/hppa/mutex.c11
-rw-r--r--sys/arch/hppa/include/cpu.h5
-rw-r--r--sys/arch/hppa64/hppa64/mutex.c11
-rw-r--r--sys/arch/hppa64/include/cpu.h5
-rw-r--r--sys/arch/i386/include/cpu.h3
-rw-r--r--sys/arch/loongson/loongson/mutex.c23
-rw-r--r--sys/arch/m68k/include/cpu.h5
-rw-r--r--sys/arch/m68k/m68k/mutex.c11
-rw-r--r--sys/arch/m88k/include/cpu.h6
-rw-r--r--sys/arch/m88k/m88k/genassym.cf7
-rw-r--r--sys/arch/m88k/m88k/mutex.S32
-rw-r--r--sys/arch/macppc/macppc/genassym.cf5
-rw-r--r--sys/arch/mips64/include/cpu.h6
-rw-r--r--sys/arch/octeon/octeon/mutex.c11
-rw-r--r--sys/arch/powerpc/include/cpu.h6
-rw-r--r--sys/arch/powerpc/powerpc/mutex.S17
-rw-r--r--sys/arch/sgi/sgi/mutex.c11
-rw-r--r--sys/arch/sh/include/cpu.h5
-rw-r--r--sys/arch/sh/sh/mutex.c11
-rw-r--r--sys/arch/socppc/socppc/genassym.cf5
-rw-r--r--sys/arch/sparc/sparc/cpuvar.h6
-rw-r--r--sys/arch/sparc/sparc/mutex.c11
-rw-r--r--sys/arch/sparc64/include/cpu.h6
-rw-r--r--sys/arch/sparc64/sparc64/genassym.cf5
-rw-r--r--sys/arch/sparc64/sparc64/mutex.S18
-rw-r--r--sys/arch/vax/include/cpu.h5
-rw-r--r--sys/arch/vax/vax/mutex.c11
-rw-r--r--sys/kern/subr_xxx.c4
32 files changed, 248 insertions, 38 deletions
diff --git a/sys/arch/alpha/alpha/mutex.c b/sys/arch/alpha/alpha/mutex.c
index 82e98c164d1..6b8f1e66b15 100644
--- a/sys/arch/alpha/alpha/mutex.c
+++ b/sys/arch/alpha/alpha/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.4 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.c,v 1.5 2010/09/28 20:27:52 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -54,6 +54,9 @@ mtx_enter(struct mutex *mtx)
mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl);
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
}
int
@@ -63,6 +66,9 @@ mtx_enter_try(struct mutex *mtx)
mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl);
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
@@ -72,6 +78,9 @@ mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
mtx->mtx_lock = 0;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
}
diff --git a/sys/arch/alpha/include/cpu.h b/sys/arch/alpha/include/cpu.h
index 7342a22ef13..586eb8a42b8 100644
--- a/sys/arch/alpha/include/cpu.h
+++ b/sys/arch/alpha/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.40 2010/07/24 12:18:55 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.41 2010/09/28 20:27:54 miod Exp $ */
/* $NetBSD: cpu.h,v 1.45 2000/08/21 02:03:12 thorpej Exp $ */
/*-
@@ -180,6 +180,9 @@ struct cpu_info {
u_long ci_spin_locks; /* # of spin locks held */
u_long ci_simple_locks; /* # of simple locks held */
#endif
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
struct proc *ci_curproc; /* current owner of the processor */
struct simplelock ci_slock; /* lock on this data structure */
cpuid_t ci_cpuid; /* our CPU ID */
diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h
index 08806916e7d..ef89b2c7c67 100644
--- a/sys/arch/amd64/include/cpu.h
+++ b/sys/arch/amd64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.56 2010/09/24 13:21:30 matthew Exp $ */
+/* $OpenBSD: cpu.h,v 1.57 2010/09/28 20:27:54 miod Exp $ */
/* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
/*-
@@ -89,7 +89,6 @@ struct cpu_info {
u_int32_t ci_iunmask[NIPL];
#ifdef DIAGNOSTIC
int ci_mutex_level;
-#define __HAVE_CPU_MUTEX_LEVEL
#endif
u_int ci_flags;
diff --git a/sys/arch/arm/include/cpu.h b/sys/arch/arm/include/cpu.h
index c9475e0a234..145718deec1 100644
--- a/sys/arch/arm/include/cpu.h
+++ b/sys/arch/arm/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.24 2009/03/26 17:24:33 oga Exp $ */
+/* $OpenBSD: cpu.h,v 1.25 2010/09/28 20:27:54 miod Exp $ */
/* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */
/*
@@ -208,6 +208,9 @@ struct cpu_info {
u_long ci_spin_locks; /* # of spin locks held */
u_long ci_simple_locks; /* # of simple locks held */
#endif
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
struct device *ci_dev; /* Device corresponding to this CPU */
u_int32_t ci_arm_cpuid; /* aggregate CPU id */
u_int32_t ci_arm_cputype; /* CPU type */
diff --git a/sys/arch/hppa/hppa/mutex.c b/sys/arch/hppa/hppa/mutex.c
index 66005b13ffd..2710cfb8d13 100644
--- a/sys/arch/hppa/hppa/mutex.c
+++ b/sys/arch/hppa/hppa/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.8 2010/06/26 00:45:05 jsing Exp $ */
+/* $OpenBSD: mutex.c,v 1.9 2010/09/28 20:27:54 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -72,6 +72,9 @@ mtx_enter(struct mutex *mtx)
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = s;
mtx->mtx_owner = curcpu();
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return;
}
if (mtx->mtx_wantipl != IPL_NONE)
@@ -90,6 +93,9 @@ mtx_enter_try(struct mutex *mtx)
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = s;
mtx->mtx_owner = curcpu();
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
if (mtx->mtx_wantipl != IPL_NONE)
@@ -105,6 +111,9 @@ mtx_leave(struct mutex *mtx)
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
s = mtx->mtx_oldipl;
mtx->mtx_owner = NULL;
diff --git a/sys/arch/hppa/include/cpu.h b/sys/arch/hppa/include/cpu.h
index 07868e52f3e..6e362534089 100644
--- a/sys/arch/hppa/include/cpu.h
+++ b/sys/arch/hppa/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.75 2010/06/29 00:50:40 jsing Exp $ */
+/* $OpenBSD: cpu.h,v 1.76 2010/09/28 20:27:54 miod Exp $ */
/*
* Copyright (c) 2000-2004 Michael Shalayeff
@@ -100,6 +100,9 @@ struct cpu_info {
struct schedstate_percpu ci_schedstate;
u_int32_t ci_randseed;
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
} __attribute__((__aligned__(64)));
#define CPUF_RUNNING 0x0001 /* CPU is running. */
diff --git a/sys/arch/hppa64/hppa64/mutex.c b/sys/arch/hppa64/hppa64/mutex.c
index 8f9d5ebf9a4..4f2c28b36fe 100644
--- a/sys/arch/hppa64/hppa64/mutex.c
+++ b/sys/arch/hppa64/hppa64/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.4 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.c,v 1.5 2010/09/28 20:27:54 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -52,6 +52,9 @@ mtx_enter(struct mutex *mtx)
mtx->mtx_oldipl = splraise(mtx->mtx_wantipl);
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
}
int
@@ -61,6 +64,9 @@ mtx_enter_try(struct mutex *mtx)
mtx->mtx_oldipl = splraise(mtx->mtx_wantipl);
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
@@ -69,6 +75,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
diff --git a/sys/arch/hppa64/include/cpu.h b/sys/arch/hppa64/include/cpu.h
index 76bf2fca2a0..41da51b3fdf 100644
--- a/sys/arch/hppa64/include/cpu.h
+++ b/sys/arch/hppa64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.17 2010/07/24 21:27:57 kettenis Exp $ */
+/* $OpenBSD: cpu.h,v 1.18 2010/09/28 20:27:54 miod Exp $ */
/*
* Copyright (c) 2005 Michael Shalayeff
@@ -137,6 +137,9 @@ struct cpu_info {
void *ci_initstack;
u_long ci_itmr;
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
struct cpu_info *curcpu(void);
diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h
index 5fafaa0618a..65f69dfcdd0 100644
--- a/sys/arch/i386/include/cpu.h
+++ b/sys/arch/i386/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.115 2010/09/24 13:21:30 matthew Exp $ */
+/* $OpenBSD: cpu.h,v 1.116 2010/09/28 20:27:54 miod Exp $ */
/* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */
/*-
@@ -108,7 +108,6 @@ struct cpu_info {
u_int32_t ci_iunmask[NIPL];
#ifdef DIAGNOSTIC
int ci_mutex_level;
-#define __HAVE_CPU_MUTEX_LEVEL
#endif
paddr_t ci_idle_pcb_paddr; /* PA of idle PCB */
diff --git a/sys/arch/loongson/loongson/mutex.c b/sys/arch/loongson/loongson/mutex.c
index 846032df169..adceeca014a 100644
--- a/sys/arch/loongson/loongson/mutex.c
+++ b/sys/arch/loongson/loongson/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.1 2009/11/19 19:23:35 miod Exp $ */
+/* $OpenBSD: mutex.c,v 1.2 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -55,12 +55,33 @@ mtx_enter(struct mutex *mtx)
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
+}
+
+int
+mtx_enter_try(struct mutex *mtx)
+{
+ if (mtx->mtx_wantipl != IPL_NONE)
+ mtx->mtx_oldipl = splraise(mtx->mtx_wantipl);
+
+ MUTEX_ASSERT_UNLOCKED(mtx);
+ mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
+
+ return 1;
}
void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
diff --git a/sys/arch/m68k/include/cpu.h b/sys/arch/m68k/include/cpu.h
index 2fd7b60f243..8a1d3bf1b46 100644
--- a/sys/arch/m68k/include/cpu.h
+++ b/sys/arch/m68k/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.22 2008/10/15 23:23:48 deraadt Exp $ */
+/* $OpenBSD: cpu.h,v 1.23 2010/09/28 20:27:55 miod Exp $ */
/* $NetBSD: cpu.h,v 1.3 1997/02/02 06:56:57 thorpej Exp $ */
/*
@@ -74,6 +74,9 @@ struct cpu_info {
struct schedstate_percpu ci_schedstate;
u_int32_t ci_randseed;
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
extern struct cpu_info cpu_info_store;
diff --git a/sys/arch/m68k/m68k/mutex.c b/sys/arch/m68k/m68k/mutex.c
index 684ec0974ed..e4c59d23734 100644
--- a/sys/arch/m68k/m68k/mutex.c
+++ b/sys/arch/m68k/m68k/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.5 2009/09/18 19:32:41 miod Exp $ */
+/* $OpenBSD: mutex.c,v 1.6 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -56,6 +56,9 @@ mtx_enter(struct mutex *mtx)
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
}
int
@@ -65,6 +68,9 @@ mtx_enter_try(struct mutex *mtx)
mtx->mtx_oldipl = _splraise(MD_IPLTOPSL(mtx->mtx_wantipl));
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
@@ -73,6 +79,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
diff --git a/sys/arch/m88k/include/cpu.h b/sys/arch/m88k/include/cpu.h
index f8d0aa987ee..a953169f5ff 100644
--- a/sys/arch/m88k/include/cpu.h
+++ b/sys/arch/m88k/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.49 2009/05/02 14:32:27 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.50 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 1996 Nivas Madhur
* Copyright (c) 1992, 1993
@@ -163,6 +163,10 @@ struct cpu_info {
#define CI_IPI_ICACHE_FLUSH 0x00000080
#define CI_IPI_DMA_CACHECTL 0x00000100
void (*ci_softipi_cb)(void); /* 88110 softipi callback */
+
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
extern cpuid_t master_cpu;
diff --git a/sys/arch/m88k/m88k/genassym.cf b/sys/arch/m88k/m88k/genassym.cf
index ba7a29ee1da..c8a34ae279f 100644
--- a/sys/arch/m88k/m88k/genassym.cf
+++ b/sys/arch/m88k/m88k/genassym.cf
@@ -1,4 +1,4 @@
-# $OpenBSD: genassym.cf,v 1.21 2009/05/02 14:32:29 miod Exp $
+# $OpenBSD: genassym.cf,v 1.22 2010/09/28 20:27:55 miod Exp $
#
# Copyright (c) 1982, 1990 The Regents of the University of California.
# All rights reserved.
@@ -28,7 +28,7 @@
# SUCH DAMAGE.
#
# @(#)genassym.c 7.8 (Berkeley) 5/7/91
-# $Id: genassym.cf,v 1.21 2009/05/02 14:32:29 miod Exp $
+# $Id: genassym.cf,v 1.22 2010/09/28 20:27:55 miod Exp $
#
include <sys/param.h>
@@ -70,6 +70,9 @@ member ci_pfsr_d0
member ci_pfsr_d1
member ci_want_resched
member ci_softipi_cb
+ifdef DIAGNOSTIC
+member ci_mutex_level
+endif
# pcb fields
struct pcb
diff --git a/sys/arch/m88k/m88k/mutex.S b/sys/arch/m88k/m88k/mutex.S
index 78c3e2b9791..007ca1482fc 100644
--- a/sys/arch/m88k/m88k/mutex.S
+++ b/sys/arch/m88k/m88k/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.8 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.S,v 1.9 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2005, Miodrag Vallat.
@@ -65,6 +65,11 @@ enter_again:
ldcr r3, CPU
st r2, r4, MTX_OLDIPL /* save into mtx_oldipl */
st r3, r4, MTX_CPU /* mtx->mtx_cpu = curcpu() */
+#ifdef DIAGNOSTIC
+ ld r2, r3, CI_MUTEX_LEVEL
+ addu r2, r2, 1 /* curcpu()->ci_mutex_level++ */
+ st r2, r3, CI_MUTEX_LEVEL
+#endif
ld r1, r31, 4
jmp.n r1
@@ -115,8 +120,13 @@ enter_panic:
st r2, r4, MTX_OLDIPL /* save into mtx_oldipl */
-#ifdef DIAGNOSTIC /* necessary for MUTEX_ASSERT_LOCKED */
+#ifdef DIAGNOSTIC
+ /* necessary for MUTEX_ASSERT_LOCKED */
st r3, r4, MTX_CPU /* mtx->mtx_cpu = curcpu() */
+
+ ld r2, r3, CI_MUTEX_LEVEL
+ addu r2, r2, 1 /* curcpu()->ci_mutex_level++ */
+ st r2, r3, CI_MUTEX_LEVEL
#endif
ld r1, r31, 4
@@ -148,6 +158,11 @@ enter_try_again:
ldcr r3, CPU
st r2, r4, MTX_OLDIPL /* save into mtx_oldipl */
st r3, r4, MTX_CPU /* mtx->mtx_cpu = curcpu() */
+#ifdef DIAGNOSTIC
+ ld r2, r3, CI_MUTEX_LEVEL
+ addu r2, r2, 1 /* curcpu()->ci_mutex_level++ */
+ st r2, r3, CI_MUTEX_LEVEL
+#endif
ld r1, r31, 4
or r2, r0, 1 /* return nonzero */
@@ -198,8 +213,13 @@ enter_try_panic:
st r2, r4, MTX_OLDIPL /* save into mtx_oldipl */
-#ifdef DIAGNOSTIC /* necessary for MUTEX_ASSERT_LOCKED */
+#ifdef DIAGNOSTIC
+ /* necessary for MUTEX_ASSERT_LOCKED */
st r3, r4, MTX_CPU /* mtx->mtx_cpu = curcpu() */
+
+ ld r2, r3, CI_MUTEX_LEVEL
+ addu r2, r2, 1 /* curcpu()->ci_mutex_level++ */
+ st r2, r3, CI_MUTEX_LEVEL
#endif
ld r1, r31, 4
@@ -215,6 +235,12 @@ enter_try_panic:
ENTRY(mtx_leave)
ld r3, r2, MTX_OLDIPL
ld r4, r2, MTX_WANTIPL
+#ifdef DIAGNOSTIC
+ ld r5, r2, MTX_CPU
+ ld r6, r5, CI_MUTEX_LEVEL
+ subu r6, r6, 1 /* curcpu()->ci_mutex_level++ */
+ st r6, r5, CI_MUTEX_LEVEL
+#endif
st r0, r2, MTX_CPU /* mtx->mtx_cpu = NULL */
bcnd.n eq0, r4, 2f
st r0, r2, MTX_LOCK /* mtx->mtx_lock = 0 */
diff --git a/sys/arch/macppc/macppc/genassym.cf b/sys/arch/macppc/macppc/genassym.cf
index 122f2615671..8c2c52bbe0c 100644
--- a/sys/arch/macppc/macppc/genassym.cf
+++ b/sys/arch/macppc/macppc/genassym.cf
@@ -1,4 +1,4 @@
-# $OpenBSD: genassym.cf,v 1.21 2009/06/09 01:12:38 deraadt Exp $
+# $OpenBSD: genassym.cf,v 1.22 2010/09/28 20:27:55 miod Exp $
#
# Copyright (c) 1982, 1990 The Regents of the University of California.
# All rights reserved.
@@ -92,6 +92,9 @@ member ci_intstk
member ci_tempsave
member ci_ddbsave
member ci_disisave
+ifdef DIAGNOSTIC
+member ci_mutex_level
+endif
struct mutex
member mtx_wantipl
diff --git a/sys/arch/mips64/include/cpu.h b/sys/arch/mips64/include/cpu.h
index 6913ad4a4f9..f50bf1e547f 100644
--- a/sys/arch/mips64/include/cpu.h
+++ b/sys/arch/mips64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.65 2010/09/21 20:29:17 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.66 2010/09/28 20:27:55 miod Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -384,6 +384,10 @@ struct cpu_info {
#define CI_DDB_STOPPED 2
#define CI_DDB_ENTERDDB 3
#define CI_DDB_INDDB 4
+
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
#define CPUF_PRIMARY 0x01 /* CPU is primary CPU */
diff --git a/sys/arch/octeon/octeon/mutex.c b/sys/arch/octeon/octeon/mutex.c
index e85f65a96b3..4135e53139f 100644
--- a/sys/arch/octeon/octeon/mutex.c
+++ b/sys/arch/octeon/octeon/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.1 2010/09/20 06:32:30 syuu Exp $ */
+/* $OpenBSD: mutex.c,v 1.2 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -76,6 +76,9 @@ mtx_enter(struct mutex *mtx)
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = s;
mtx->mtx_owner = curcpu();
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return;
}
if (mtx->mtx_wantipl != IPL_NONE)
@@ -96,6 +99,9 @@ mtx_enter_try(struct mutex *mtx)
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = s;
mtx->mtx_owner = curcpu();
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
if (mtx->mtx_wantipl != IPL_NONE)
@@ -107,6 +113,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
diff --git a/sys/arch/powerpc/include/cpu.h b/sys/arch/powerpc/include/cpu.h
index a19fe049301..fe996e04a5e 100644
--- a/sys/arch/powerpc/include/cpu.h
+++ b/sys/arch/powerpc/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.45 2009/08/24 21:44:21 dms Exp $ */
+/* $OpenBSD: cpu.h,v 1.46 2010/09/28 20:27:55 miod Exp $ */
/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */
/*
@@ -81,6 +81,10 @@ struct cpu_info {
#define CI_DDB_INDDB 4
u_int32_t ci_randseed;
+
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
static __inline struct cpu_info *
diff --git a/sys/arch/powerpc/powerpc/mutex.S b/sys/arch/powerpc/powerpc/mutex.S
index 079d50aa3b2..2b87dae2434 100644
--- a/sys/arch/powerpc/powerpc/mutex.S
+++ b/sys/arch/powerpc/powerpc/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.10 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.S,v 1.11 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2007 Dale Rahn
@@ -66,6 +66,11 @@ ENTRY(mtx_enter)
.L_mutex_free:
stwcx. %r4,%r5,%r3 # old owner was 0 cond store
bne- .L_mutex_locked # branch if reserve cancelled
+#ifdef DIAGNOSTIC
+ lwz %r6,CI_MUTEX_LEVEL(%r4)
+ addi %r6,%r6,1 # curpcu->ci_mutex_level++
+ stw %r6,CI_MUTEX_LEVEL(%r4)
+#endif
stw %r7,MTX_OLDCPL(%r3) # save old ipl
lwz %r0,36(%r1) # load return address
mtlr %r0
@@ -120,6 +125,11 @@ ENTRY(mtx_enter_try)
.L_mutex_try_free:
stwcx. %r4,%r5,%r3 # old owner was 0 cond store
bne- .L_mutex_try_locked # branch if reserve cancelled
+#ifdef DIAGNOSTIC
+ lwz %r6,CI_MUTEX_LEVEL(%r4)
+ addi %r6,%r6,1 # curpcu->ci_mutex_level++
+ stw %r6,CI_MUTEX_LEVEL(%r4)
+#endif
stw %r7,MTX_OLDCPL(%r3) # save old ipl
lwz %r0,36(%r1) # load return address
mtlr %r0
@@ -150,6 +160,11 @@ ENTRY(mtx_leave)
stw %r4,MTX_OLDCPL(%r3)
stw %r4,MTX_OWNER(%r3)
GET_CPUINFO(%r4)
+#ifdef DIAGNOSTIC
+ lwz %r6,CI_MUTEX_LEVEL(%r4)
+ addi %r6,%r6,-1 # curpcu->ci_mutex_level--
+ stw %r6,CI_MUTEX_LEVEL(%r4)
+#endif
mr %r3,%r5
lwz %r5,CI_CPL(%r4)
cmpl 0,%r3,%r5
diff --git a/sys/arch/sgi/sgi/mutex.c b/sys/arch/sgi/sgi/mutex.c
index 03b3aa0389c..9276f04752a 100644
--- a/sys/arch/sgi/sgi/mutex.c
+++ b/sys/arch/sgi/sgi/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.8 2009/11/04 02:26:24 syuu Exp $ */
+/* $OpenBSD: mutex.c,v 1.9 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -76,6 +76,9 @@ mtx_enter(struct mutex *mtx)
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = s;
mtx->mtx_owner = curcpu();
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return;
}
if (mtx->mtx_wantipl != IPL_NONE)
@@ -94,6 +97,9 @@ mtx_enter_try(struct mutex *mtx)
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = s;
mtx->mtx_owner = curcpu();
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
if (mtx->mtx_wantipl != IPL_NONE)
@@ -105,6 +111,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
diff --git a/sys/arch/sh/include/cpu.h b/sys/arch/sh/include/cpu.h
index 7311e10f37f..2963065e1f5 100644
--- a/sys/arch/sh/include/cpu.h
+++ b/sys/arch/sh/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.20 2010/04/25 18:11:36 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.21 2010/09/28 20:27:55 miod Exp $ */
/* $NetBSD: cpu.h,v 1.41 2006/01/21 04:24:12 uwe Exp $ */
/*-
@@ -62,6 +62,9 @@ struct cpu_info {
struct schedstate_percpu ci_schedstate; /* scheduler state */
u_int32_t ci_randseed;
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
extern struct cpu_info cpu_info_store;
diff --git a/sys/arch/sh/sh/mutex.c b/sys/arch/sh/sh/mutex.c
index 66f08391e9b..c862cb77989 100644
--- a/sys/arch/sh/sh/mutex.c
+++ b/sys/arch/sh/sh/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.4 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.c,v 1.5 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -55,6 +55,9 @@ mtx_enter(struct mutex *mtx)
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
}
int
@@ -64,6 +67,9 @@ mtx_enter_try(struct mutex *mtx)
mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl);
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
@@ -72,6 +78,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE << 4)
_cpu_intr_resume(mtx->mtx_oldipl);
diff --git a/sys/arch/socppc/socppc/genassym.cf b/sys/arch/socppc/socppc/genassym.cf
index 661b9bf852c..0b4d2696501 100644
--- a/sys/arch/socppc/socppc/genassym.cf
+++ b/sys/arch/socppc/socppc/genassym.cf
@@ -1,4 +1,4 @@
-# $OpenBSD: genassym.cf,v 1.1 2008/05/10 12:18:30 kettenis Exp $
+# $OpenBSD: genassym.cf,v 1.2 2010/09/28 20:27:55 miod Exp $
#
# Copyright (c) 1982, 1990 The Regents of the University of California.
# All rights reserved.
@@ -92,6 +92,9 @@ member ci_intstk
member ci_tempsave
member ci_ddbsave
member ci_disisave
+ifdef DIAGNOSTIC
+member ci_mutex_level
+endif
struct mutex
member mtx_wantipl
diff --git a/sys/arch/sparc/sparc/cpuvar.h b/sys/arch/sparc/sparc/cpuvar.h
index b0e0fbbf9c8..0208f9e2d6d 100644
--- a/sys/arch/sparc/sparc/cpuvar.h
+++ b/sys/arch/sparc/sparc/cpuvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpuvar.h,v 1.18 2010/07/06 20:37:33 miod Exp $ */
+/* $OpenBSD: cpuvar.h,v 1.19 2010/09/28 20:27:55 miod Exp $ */
/* $NetBSD: cpuvar.h,v 1.4 1997/07/06 21:14:25 pk Exp $ */
/*
@@ -80,6 +80,10 @@ struct cpu_info {
struct schedstate_percpu ci_schedstate;
u_int32_t ci_randseed;
+
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
#define curcpu() (&cpuinfo.ci)
diff --git a/sys/arch/sparc/sparc/mutex.c b/sys/arch/sparc/sparc/mutex.c
index 33605dcf826..4ed1528a275 100644
--- a/sys/arch/sparc/sparc/mutex.c
+++ b/sys/arch/sparc/sparc/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.4 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.c,v 1.5 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -61,6 +61,9 @@ mtx_enter(struct mutex *mtx)
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
}
int
@@ -77,6 +80,9 @@ mtx_enter_try(struct mutex *mtx)
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
@@ -85,6 +91,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE << 8)
splx(mtx->mtx_oldipl);
diff --git a/sys/arch/sparc64/include/cpu.h b/sys/arch/sparc64/include/cpu.h
index 2ac13e33306..dcee1819254 100644
--- a/sys/arch/sparc64/include/cpu.h
+++ b/sys/arch/sparc64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.72 2009/03/26 17:24:33 oga Exp $ */
+/* $OpenBSD: cpu.h,v 1.73 2010/09/28 20:27:55 miod Exp $ */
/* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */
/*
@@ -148,6 +148,10 @@ struct cpu_info {
paddr_t ci_cpuset;
paddr_t ci_mondo;
#endif
+
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
#define CPUF_RUNNING 0x0001 /* CPU is running */
diff --git a/sys/arch/sparc64/sparc64/genassym.cf b/sys/arch/sparc64/sparc64/genassym.cf
index 563d79ad446..5b19a21685e 100644
--- a/sys/arch/sparc64/sparc64/genassym.cf
+++ b/sys/arch/sparc64/sparc64/genassym.cf
@@ -1,4 +1,4 @@
-# $OpenBSD: genassym.cf,v 1.33 2008/08/07 18:46:04 kettenis Exp $
+# $OpenBSD: genassym.cf,v 1.34 2010/09/28 20:27:55 miod Exp $
# $NetBSD: genassym.cf,v 1.23 2001/08/08 00:09:30 eeh Exp $
#
@@ -158,6 +158,9 @@ member ci_mmfsa
member ci_cpumq
member ci_devmq
endif
+ifdef DIAGNOSTIC
+member ci_mutex_level
+endif
# FPU state
struct fpstate64
diff --git a/sys/arch/sparc64/sparc64/mutex.S b/sys/arch/sparc64/sparc64/mutex.S
index 5ae4267c361..987d801e554 100644
--- a/sys/arch/sparc64/sparc64/mutex.S
+++ b/sys/arch/sparc64/sparc64/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.6 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.S,v 1.7 2010/09/28 20:27:55 miod Exp $ */
/*
* Copyright (c) 2007 Mark Kettenis
@@ -72,6 +72,11 @@ ENTRY(mtx_enter)
ba,a 1b
4:
stw %g4, [%o0 + MTX_OLDIPL]
+#ifdef DIAGNOSTIC
+ ld [%g1 + CI_MUTEX_LEVEL], %g5
+ add %g5, 1, %g5
+ st %g5, [%g1 + CI_MUTEX_LEVEL]
+#endif
retl
membar #LoadLoad | #LoadStore
@@ -98,11 +103,22 @@ ENTRY(mtx_enter_try)
mov 0, %o0
3:
stw %g4, [%o0 + MTX_OLDIPL]
+#ifdef DIAGNOSTIC
+ ld [%g1 + CI_MUTEX_LEVEL], %g5
+ add %g5, 1, %g5
+ st %g5, [%g1 + CI_MUTEX_LEVEL]
+#endif
membar #LoadLoad | #LoadStore
retl
mov 1, %o0
ENTRY(mtx_leave)
+#ifdef DIAGNOSTIC
+ GET_CURCPU(%g1)
+ ld [%g1 + CI_MUTEX_LEVEL], %g5
+ sub %g5, 1, %g5
+ st %g5, [%g1 + CI_MUTEX_LEVEL]
+#endif
ld [%o0 + MTX_OLDIPL], %g1
membar #StoreStore | #LoadStore
stx %g0, [%o0 + MTX_OWNER]
diff --git a/sys/arch/vax/include/cpu.h b/sys/arch/vax/include/cpu.h
index 82f9ee60f2b..e2b276e805c 100644
--- a/sys/arch/vax/include/cpu.h
+++ b/sys/arch/vax/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.35 2009/03/26 17:24:33 oga Exp $ */
+/* $OpenBSD: cpu.h,v 1.36 2010/09/28 20:27:56 miod Exp $ */
/* $NetBSD: cpu.h,v 1.41 1999/10/21 20:01:36 ragge Exp $ */
/*
@@ -53,6 +53,9 @@ struct cpu_info {
struct schedstate_percpu ci_schedstate; /* scheduler state */
u_int32_t ci_randseed;
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
};
extern struct cpu_info cpu_info_store;
diff --git a/sys/arch/vax/vax/mutex.c b/sys/arch/vax/vax/mutex.c
index 4b1ba96ae0e..d960eab3f1e 100644
--- a/sys/arch/vax/vax/mutex.c
+++ b/sys/arch/vax/vax/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.4 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.c,v 1.5 2010/09/28 20:27:56 miod Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -55,6 +55,9 @@ mtx_enter(struct mutex *mtx)
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
}
int
@@ -64,6 +67,9 @@ mtx_enter_try(struct mutex *mtx)
mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl);
MUTEX_ASSERT_UNLOCKED(mtx);
mtx->mtx_lock = 1;
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level++;
+#endif
return 1;
}
@@ -72,6 +78,9 @@ void
mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
+#ifdef DIAGNOSTIC
+ curcpu()->ci_mutex_level--;
+#endif
mtx->mtx_lock = 0;
if (mtx->mtx_wantipl != IPL_NONE)
splx(mtx->mtx_oldipl);
diff --git a/sys/kern/subr_xxx.c b/sys/kern/subr_xxx.c
index fd6a6d6bbd6..e358a442fc7 100644
--- a/sys/kern/subr_xxx.c
+++ b/sys/kern/subr_xxx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_xxx.c,v 1.11 2010/09/24 13:21:30 matthew Exp $ */
+/* $OpenBSD: subr_xxx.c,v 1.12 2010/09/28 20:27:56 miod Exp $ */
/* $NetBSD: subr_xxx.c,v 1.10 1996/02/04 02:16:51 christos Exp $ */
/*
@@ -160,7 +160,7 @@ void
assertwaitok(void)
{
splassert(IPL_NONE);
-#ifdef __HAVE_CPU_MUTEX_LEVEL
+#ifdef DIAGNOSTIC
if (curcpu()->ci_mutex_level != 0)
panic("assertwaitok: non-zero mutex count: %d",
curcpu()->ci_mutex_level);