summaryrefslogtreecommitdiffstats
path: root/sys/i386
diff options
context:
space:
mode:
authorfsmp <fsmp@FreeBSD.org>1997-08-31 03:17:48 +0000
committerfsmp <fsmp@FreeBSD.org>1997-08-31 03:17:48 +0000
commit53cd3a6e283516523cbdacf36340687e233d6ba8 (patch)
tree9e1ad83a6fdf24736bad3da3ddafb94f85346735 /sys/i386
parent92287f9b58f359eb2a68d5c728235f5ffd89c1cd (diff)
downloadFreeBSD-src-53cd3a6e283516523cbdacf36340687e233d6ba8.zip
FreeBSD-src-53cd3a6e283516523cbdacf36340687e233d6ba8.tar.gz
Debug version of simple_lock. This will store the CPU id of the
holding CPU along with the lock. When a CPU fails to get the lock it compares its own id to the holder id. If they are the same it panic()s, as simple locks are binary, and this would cause a deadlock. Controlled by smptests.h: SL_DEBUG, ON by default. Some minor cleanup.
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/i386/mp_machdep.c31
-rw-r--r--sys/i386/i386/mptable.c31
-rw-r--r--sys/i386/i386/simplelock.s89
-rw-r--r--sys/i386/include/lock.h17
-rw-r--r--sys/i386/include/mptable.h31
-rw-r--r--sys/i386/include/smptests.h16
6 files changed, 144 insertions, 71 deletions
diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c
index 955a3a1..322f0f1 100644
--- a/sys/i386/i386/mp_machdep.c
+++ b/sys/i386/i386/mp_machdep.c
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: mp_machdep.c,v 1.32 1997/08/30 01:25:13 smp Exp smp $
+ * $Id: mp_machdep.c,v 1.34 1997/08/31 03:05:56 smp Exp smp $
*/
#include "opt_smp.h"
@@ -1446,16 +1446,18 @@ struct simplelock fast_intr_lock;
/* critical region around INTR() routines */
struct simplelock intr_lock;
+/* lock regions around the clock hardware */
+struct simplelock clock_lock;
+
#ifdef SIMPLE_MPINTRLOCK
-/* critical region around INTR() routines */
+/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
-struct simplelock clock_lock;
#endif
-#if 0
-/* lock the com (tty) data structures */
+#ifdef USE_COMLOCK
+/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
-#endif
+#endif /* USE_COMLOCK */
static void
init_locks(void)
@@ -1470,27 +1472,16 @@ init_locks(void)
isr_lock = FREE_LOCK;
#ifdef SIMPLE_MPINTRLOCK
- /* lock regions protected in UP kernel via cli/sti */
s_lock_init((struct simplelock*)&mpintr_lock);
- s_lock_init((struct simplelock*)&clock_lock);
#endif
-
- /* serializes FAST_INTR() accesses */
+ s_lock_init((struct simplelock*)&clock_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
-
- /* serializes INTR() accesses */
s_lock_init((struct simplelock*)&intr_lock);
-
- /* locks the IO APIC and apic_imen accesses */
s_lock_init((struct simplelock*)&imen_lock);
-
- /* locks cpl/cml/cim/ipending accesses */
s_lock_init((struct simplelock*)&cpl_lock);
-
-#if 0
- /* locks com (tty) data/hardware accesses: a FASTINTR() */
+#ifdef USE_COMLOCK
s_lock_init((struct simplelock*)&com_lock);
-#endif
+#endif /* USE_COMLOCK */
}
diff --git a/sys/i386/i386/mptable.c b/sys/i386/i386/mptable.c
index 955a3a1..322f0f1 100644
--- a/sys/i386/i386/mptable.c
+++ b/sys/i386/i386/mptable.c
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: mp_machdep.c,v 1.32 1997/08/30 01:25:13 smp Exp smp $
+ * $Id: mp_machdep.c,v 1.34 1997/08/31 03:05:56 smp Exp smp $
*/
#include "opt_smp.h"
@@ -1446,16 +1446,18 @@ struct simplelock fast_intr_lock;
/* critical region around INTR() routines */
struct simplelock intr_lock;
+/* lock regions around the clock hardware */
+struct simplelock clock_lock;
+
#ifdef SIMPLE_MPINTRLOCK
-/* critical region around INTR() routines */
+/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
-struct simplelock clock_lock;
#endif
-#if 0
-/* lock the com (tty) data structures */
+#ifdef USE_COMLOCK
+/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
-#endif
+#endif /* USE_COMLOCK */
static void
init_locks(void)
@@ -1470,27 +1472,16 @@ init_locks(void)
isr_lock = FREE_LOCK;
#ifdef SIMPLE_MPINTRLOCK
- /* lock regions protected in UP kernel via cli/sti */
s_lock_init((struct simplelock*)&mpintr_lock);
- s_lock_init((struct simplelock*)&clock_lock);
#endif
-
- /* serializes FAST_INTR() accesses */
+ s_lock_init((struct simplelock*)&clock_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
-
- /* serializes INTR() accesses */
s_lock_init((struct simplelock*)&intr_lock);
-
- /* locks the IO APIC and apic_imen accesses */
s_lock_init((struct simplelock*)&imen_lock);
-
- /* locks cpl/cml/cim/ipending accesses */
s_lock_init((struct simplelock*)&cpl_lock);
-
-#if 0
- /* locks com (tty) data/hardware accesses: a FASTINTR() */
+#ifdef USE_COMLOCK
s_lock_init((struct simplelock*)&com_lock);
-#endif
+#endif /* USE_COMLOCK */
}
diff --git a/sys/i386/i386/simplelock.s b/sys/i386/i386/simplelock.s
index 07d147e..f38d38f 100644
--- a/sys/i386/i386/simplelock.s
+++ b/sys/i386/i386/simplelock.s
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: simplelock.s,v 1.8 1997/08/29 07:26:27 smp Exp smp $
+ * $Id: simplelock.s,v 1.9 1997/08/31 03:05:56 smp Exp smp $
*/
/*
@@ -83,6 +83,8 @@ ENTRY(s_lock_init)
* the local cache (and thus causing external bus writes) with repeated
* writes to the lock.
*/
+#ifndef SL_DEBUG
+
ENTRY(s_lock)
movl 4(%esp), %eax /* get the address of the lock */
movl $1, %ecx
@@ -97,6 +99,43 @@ wait:
gotit:
ret
+#else /* SL_DEBUG */
+
+ENTRY(s_lock)
+ cmpl $0, _smp_active
+ je gotit
+
+ movl 4(%esp), %eax /* get the address of the lock */
+setlock:
+ movl _cpu_lockid, %ecx /* add cpu id portion */
+ incl %ecx /* add lock portion */
+ xchgl %ecx, (%eax)
+ testl %ecx, %ecx
+ jz gotit /* it was clear, return */
+ pushl %ecx /* save what we xchanged */
+ decl %ecx /* remove lock portion */
+ cmpl _cpu_lockid, %ecx /* do we hold it? */
+ je bad_slock /* yes, thats not good... */
+ addl $4, %esp /* clear the stack */
+wait:
+ cmpl $0, (%eax) /* wait to empty */
+ jne wait /* still set... */
+ jmp setlock /* empty again, try once more */
+gotit:
+ ret
+
+ ALIGN_TEXT
+bad_slock:
+ /* %ecx (current lock) is already on the stack */
+ pushl %eax
+ pushl _cpuid
+ pushl $bsl1
+ call _panic
+
+bsl1: .asciz "rslock: cpu: %d, addr: 0x%08x, lock: 0x%08x"
+
+#endif /* SL_DEBUG */
+
/*
* int
@@ -168,6 +207,8 @@ ENTRY(test_and_set)
/*
* void ss_lock(struct simplelock *lkp)
*/
+#ifndef SL_DEBUG
+
ENTRY(ss_lock)
movl 4(%esp), %eax /* get the address of the lock */
movl $1, %ecx /* value for a held lock */
@@ -190,6 +231,52 @@ sgotit:
popl _ss_tpr /* save the old task priority */
ret
+#else /* SL_DEBUG */
+
+ENTRY(ss_lock)
+ cmpl $0, _smp_active
+ je sgotit2
+
+ movl 4(%esp), %eax /* get the address of the lock */
+ssetlock:
+ movl _cpu_lockid, %ecx /* add cpu id portion */
+ incl %ecx /* add lock portion */
+ pushl lapic_tpr /* save current task priority */
+#ifdef FAST_HI
+ movl $TPR_BLOCK_FHWI, lapic_tpr /* block FAST hw INTs */
+#else
+ movl $TPR_BLOCK_HWI, lapic_tpr /* block hw INTs */
+#endif
+ xchgl %ecx, (%eax) /* compete */
+ testl %ecx, %ecx
+ jz sgotit /* it was clear, return */
+ pushl %ecx /* save what we xchanged */
+ decl %ecx /* remove lock portion */
+ cmpl _cpu_lockid, %ecx /* do we hold it? */
+ je sbad_slock /* yes, thats not good... */
+ addl $4, %esp /* clear the stack */
+ popl lapic_tpr /* previous value while waiting */
+swait:
+ cmpl $0, (%eax) /* wait to empty */
+ jne swait /* still set... */
+ jmp ssetlock /* empty again, try once more */
+sgotit:
+ popl _ss_tpr /* save the old task priority */
+sgotit2:
+ ret
+
+ ALIGN_TEXT
+sbad_slock:
+ /* %ecx (current lock) is already on the stack */
+ pushl %eax
+ pushl _cpuid
+ pushl $sbsl1
+ call _panic
+
+sbsl1: .asciz "rsslock: cpu: %d, addr: 0x%08x, lock: 0x%08x"
+
+#endif /* SL_DEBUG */
+
/*
* void ss_unlock(struct simplelock *lkp)
*/
diff --git a/sys/i386/include/lock.h b/sys/i386/include/lock.h
index 39b474d..6c55714 100644
--- a/sys/i386/include/lock.h
+++ b/sys/i386/include/lock.h
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: lock.h,v 1.2 1997/08/30 07:51:10 smp Exp smp $
+ * $Id: lock.h,v 1.3 1997/08/31 03:03:48 smp Exp smp $
*/
@@ -152,16 +152,14 @@
* sys/i386/isa/ipl_funcs.c: DO_SETBITS, softclockpending(), GENSPL,
* spl0(), splx(), splq()
*/
-
-/* Bottom half */
-#define CPL_LOCK() s_lock(&cpl_lock)
+#define CPL_LOCK() s_lock(&cpl_lock) /* Bottom end */
#define CPL_UNLOCK() s_unlock(&cpl_lock)
-
-/* INT safe version for top half of kernel */
-#define SCPL_LOCK() ss_lock(&cpl_lock)
+#define SCPL_LOCK() ss_lock(&cpl_lock) /* INT safe: top end */
#define SCPL_UNLOCK() ss_unlock(&cpl_lock)
-/* lock regions protected in UP kernel via cli/sti */
+/*
+ * Locks regions protected in UP kernel via cli/sti.
+ */
#if defined(SIMPLE_MPINTRLOCK)
#define MPINTR_LOCK() s_lock(&mpintr_lock)
#define MPINTR_UNLOCK() s_unlock(&mpintr_lock)
@@ -204,10 +202,11 @@ extern struct simplelock imen_lock;
extern struct simplelock cpl_lock;
extern struct simplelock fast_intr_lock;
extern struct simplelock intr_lock;
+extern struct simplelock clock_lock;
+extern struct simplelock com_lock;
#ifdef SIMPLE_MPINTRLOCK
extern struct simplelock mpintr_lock;
-extern struct simplelock clock_lock;
#endif/* SIMPLE_MPINTRLOCK */
#if !defined(SIMPLELOCK_DEBUG) && NCPUS > 1
diff --git a/sys/i386/include/mptable.h b/sys/i386/include/mptable.h
index 955a3a1..322f0f1 100644
--- a/sys/i386/include/mptable.h
+++ b/sys/i386/include/mptable.h
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: mp_machdep.c,v 1.32 1997/08/30 01:25:13 smp Exp smp $
+ * $Id: mp_machdep.c,v 1.34 1997/08/31 03:05:56 smp Exp smp $
*/
#include "opt_smp.h"
@@ -1446,16 +1446,18 @@ struct simplelock fast_intr_lock;
/* critical region around INTR() routines */
struct simplelock intr_lock;
+/* lock regions around the clock hardware */
+struct simplelock clock_lock;
+
#ifdef SIMPLE_MPINTRLOCK
-/* critical region around INTR() routines */
+/* lock regions protected in UP kernel via cli/sti */
struct simplelock mpintr_lock;
-struct simplelock clock_lock;
#endif
-#if 0
-/* lock the com (tty) data structures */
+#ifdef USE_COMLOCK
+/* locks com (tty) data/hardware accesses: a FASTINTR() */
struct simplelock com_lock;
-#endif
+#endif /* USE_COMLOCK */
static void
init_locks(void)
@@ -1470,27 +1472,16 @@ init_locks(void)
isr_lock = FREE_LOCK;
#ifdef SIMPLE_MPINTRLOCK
- /* lock regions protected in UP kernel via cli/sti */
s_lock_init((struct simplelock*)&mpintr_lock);
- s_lock_init((struct simplelock*)&clock_lock);
#endif
-
- /* serializes FAST_INTR() accesses */
+ s_lock_init((struct simplelock*)&clock_lock);
s_lock_init((struct simplelock*)&fast_intr_lock);
-
- /* serializes INTR() accesses */
s_lock_init((struct simplelock*)&intr_lock);
-
- /* locks the IO APIC and apic_imen accesses */
s_lock_init((struct simplelock*)&imen_lock);
-
- /* locks cpl/cml/cim/ipending accesses */
s_lock_init((struct simplelock*)&cpl_lock);
-
-#if 0
- /* locks com (tty) data/hardware accesses: a FASTINTR() */
+#ifdef USE_COMLOCK
s_lock_init((struct simplelock*)&com_lock);
-#endif
+#endif /* USE_COMLOCK */
}
diff --git a/sys/i386/include/smptests.h b/sys/i386/include/smptests.h
index c93cefd..3cfc27b 100644
--- a/sys/i386/include/smptests.h
+++ b/sys/i386/include/smptests.h
@@ -22,7 +22,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: smptests.h,v 1.22 1997/08/29 17:58:30 fsmp Exp $
+ * $Id: smptests.h,v 1.27 1997/08/31 03:02:19 smp Exp smp $
*/
#ifndef _MACHINE_SMPTESTS_H_
@@ -35,6 +35,16 @@
/*
+ * Debug version of simple_lock. This will store the CPU id of the
+ * holding CPU along with the lock. When a CPU fails to get the lock
+ * it compares its own id to the holder id. If they are the same it
+ * panic()s, as simple locks are binary, and this would cause a deadlock.
+ *
+ */
+#define SL_DEBUG
+
+
+/*
* Put FAST_INTR() ISRs at an APIC priority above the regular INTs.
* Allow the mp_lock() routines to handle FAST interrupts while spinning.
*/
@@ -59,6 +69,10 @@
#define SIMPLE_MPINTRLOCK
+/* */
+#define USE_COMLOCK
+
+
/*
* Regular INTerrupts without the giant lock, NOT READY YET!!!
*
OpenPOWER on IntegriCloud