patch-2.4.17 linux/arch/sparc64/lib/debuglocks.c

Next file: linux/arch/sparc64/lib/dec_and_lock.S
Previous file: linux/arch/sparc64/lib/blockops.S
Back to the patch index
Back to the overall index

diff -Naur -X /home/marcelo/lib/dontdiff linux-2.4.16/arch/sparc64/lib/debuglocks.c linux/arch/sparc64/lib/debuglocks.c
@@ -1,4 +1,4 @@
-/* $Id: debuglocks.c,v 1.6 2001/04/24 01:09:12 davem Exp $
+/* $Id: debuglocks.c,v 1.9 2001/11/17 00:10:48 davem Exp $
  * debuglocks.c: Debugging versions of SMP locking primitives.
  *
  * Copyright (C) 1998 David S. Miller (davem@redhat.com)
@@ -10,10 +10,7 @@
 #include <linux/spinlock.h>
 #include <asm/system.h>
 
-#ifdef CONFIG_SMP
-
-/* To enable this code, just define SPIN_LOCK_DEBUG in asm/spinlock.h */
-#ifdef SPIN_LOCK_DEBUG
+#if defined(CONFIG_SMP) && defined(CONFIG_DEBUG_SPINLOCK)
 
 #define GET_CALLER(PC) __asm__ __volatile__("mov %%i7, %0" : "=r" (PC))
 
@@ -56,6 +53,7 @@
 	unsigned long caller, val;
 	int stuck = INIT_STUCK;
 	int cpu = smp_processor_id();
+	int shown = 0;
 
 	GET_CALLER(caller);
 again:
@@ -67,7 +65,8 @@
 	if (val) {
 		while (lock->lock) {
 			if (!--stuck) {
-				show(str, lock, caller);
+				if (shown++ <= 2)
+					show(str, lock, caller);
 				stuck = INIT_STUCK;
 			}
 			membar("#LoadLoad");
@@ -76,6 +75,8 @@
 	}
 	lock->owner_pc = ((unsigned int)caller);
 	lock->owner_cpu = cpu;
+	current->thread.smp_lock_count++;
+	current->thread.smp_lock_pc = ((unsigned int)caller);
 }
 
 int _spin_trylock(spinlock_t *lock)
@@ -92,6 +93,8 @@
 	if (!val) {
 		lock->owner_pc = ((unsigned int)caller);
 		lock->owner_cpu = cpu;
+		current->thread.smp_lock_count++;
+		current->thread.smp_lock_pc = ((unsigned int)caller);
 	}
 	return val == 0;
 }
@@ -102,6 +105,7 @@
 	lock->owner_cpu = NO_PROC_ID;
 	membar("#StoreStore | #LoadStore");
 	lock->lock = 0;
+	current->thread.smp_lock_count--;
 }
 
 /* Keep INIT_STUCK the same... */
@@ -111,13 +115,15 @@
 	unsigned long caller, val;
 	int stuck = INIT_STUCK;
 	int cpu = smp_processor_id();
+	int shown = 0;
 
 	GET_CALLER(caller);
 wlock_again:
 	/* Wait for any writer to go away.  */
 	while (((long)(rw->lock)) < 0) {
 		if (!--stuck) {
-			show_read(str, rw, caller);
+			if (shown++ <= 2)
+				show_read(str, rw, caller);
 			stuck = INIT_STUCK;
 		}
 		membar("#LoadLoad");
@@ -137,6 +143,8 @@
 	if (val)
 		goto wlock_again;
 	rw->reader_pc[cpu] = ((unsigned int)caller);
+	current->thread.smp_lock_count++;
+	current->thread.smp_lock_pc = ((unsigned int)caller);
 }
 
 void _do_read_unlock (rwlock_t *rw, char *str)
@@ -144,11 +152,13 @@
 	unsigned long caller, val;
 	int stuck = INIT_STUCK;
 	int cpu = smp_processor_id();
+	int shown = 0;
 
 	GET_CALLER(caller);
 
 	/* Drop our identity _first_. */
 	rw->reader_pc[cpu] = 0;
+	current->thread.smp_lock_count--;
 runlock_again:
 	/* Spin trying to decrement the counter using casx.  */
 	__asm__ __volatile__(
@@ -162,7 +172,8 @@
 	: "g5", "g7", "memory");
 	if (val) {
 		if (!--stuck) {
-			show_read(str, rw, caller);
+			if (shown++ <= 2)
+				show_read(str, rw, caller);
 			stuck = INIT_STUCK;
 		}
 		goto runlock_again;
@@ -174,13 +185,15 @@
 	unsigned long caller, val;
 	int stuck = INIT_STUCK;
 	int cpu = smp_processor_id();
+	int shown = 0;
 
 	GET_CALLER(caller);
 wlock_again:
 	/* Spin while there is another writer. */
 	while (((long)rw->lock) < 0) {
 		if (!--stuck) {
-			show_write(str, rw, caller);
+			if (shown++ <= 2)
+				show_write(str, rw, caller);
 			stuck = INIT_STUCK;
 		}
 		membar("#LoadLoad");
@@ -204,7 +217,8 @@
 	if (val) {
 		/* We couldn't get the write bit. */
 		if (!--stuck) {
-			show_write(str, rw, caller);
+			if (shown++ <= 2)
+				show_write(str, rw, caller);
 			stuck = INIT_STUCK;
 		}
 		goto wlock_again;
@@ -214,7 +228,8 @@
 		 * lock, spin, and try again.
 		 */
 		if (!--stuck) {
-			show_write(str, rw, caller);
+			if (shown++ <= 2)
+				show_write(str, rw, caller);
 			stuck = INIT_STUCK;
 		}
 		__asm__ __volatile__(
@@ -231,7 +246,8 @@
 		: "g3", "g5", "g7", "cc", "memory");
 		while(rw->lock != 0) {
 			if (!--stuck) {
-				show_write(str, rw, caller);
+				if (shown++ <= 2)
+					show_write(str, rw, caller);
 				stuck = INIT_STUCK;
 			}
 			membar("#LoadLoad");
@@ -242,18 +258,22 @@
 	/* We have it, say who we are. */
 	rw->writer_pc = ((unsigned int)caller);
 	rw->writer_cpu = cpu;
+	current->thread.smp_lock_count++;
+	current->thread.smp_lock_pc = ((unsigned int)caller);
 }
 
 void _do_write_unlock(rwlock_t *rw)
 {
 	unsigned long caller, val;
 	int stuck = INIT_STUCK;
+	int shown = 0;
 
 	GET_CALLER(caller);
 
 	/* Drop our identity _first_ */
 	rw->writer_pc = 0;
 	rw->writer_cpu = NO_PROC_ID;
+	current->thread.smp_lock_count--;
 wlock_again:
 	__asm__ __volatile__(
 "	mov	1, %%g3\n"
@@ -268,12 +288,21 @@
 	: "g3", "g5", "g7", "memory");
 	if (val) {
 		if (!--stuck) {
-			show_write("write_unlock", rw, caller);
+			if (shown++ <= 2)
+				show_write("write_unlock", rw, caller);
 			stuck = INIT_STUCK;
 		}
 		goto wlock_again;
 	}
 }
 
-#endif /* SPIN_LOCK_DEBUG */
-#endif /* CONFIG_SMP */
+int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
+{
+	spin_lock(lock);
+	if (atomic_dec_and_test(atomic))
+		return 1;
+	spin_unlock(lock);
+	return 0;
+}
+
+#endif /* CONFIG_SMP && CONFIG_DEBUG_SPINLOCK */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)