Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Dec 2002 10:37:41 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 22140 for review
Message-ID:  <200212101837.gBAIbfqE026165@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=22140

Change 22140 by jhb@jhb_laptop on 2002/12/10 10:37:10

	Add some hokie code to witness so that if we panic from spinning
	too long on a spin lock, we try to use witness info to determine
	where the other CPU acquired the lock in question.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_mutex.c#55 edit
.. //depot/projects/smpng/sys/kern/subr_witness.c#66 edit
.. //depot/projects/smpng/sys/sys/lock.h#23 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_mutex.c#55 (text+ko) ====

@@ -681,12 +681,18 @@
 			if (i < 60000000)
 				DELAY(1);
 #ifdef DDB
-			else if (!db_active)
+			else if (!db_active) {
 #else
-			else
+			else {
 #endif
-				panic("spin lock %s held by %p for > 5 seconds",
+				printf("spin lock %s held by %p for > 5 seconds\n",
 				    m->mtx_object.lo_name, (void *)m->mtx_lock);
+#ifdef WITNESS
+				witness_display_spinlock(&m->mtx_object,
+				    mtx_owner(m));
+#endif
+				panic("spin lock held too long");
+			}
 #ifdef __i386__
 			ia32_pause();
 #endif

==== //depot/projects/smpng/sys/kern/subr_witness.c#66 (text+ko) ====

@@ -1399,6 +1399,28 @@
 }
 
 /*
+ * This is a bit risky at best.  We have call this when we have timed out
+ * acquiring a spin lock and are assuming that the other CPU is stuck with
+ * this lock held.  So, we go groveling around in the other CPU's per-cpu
+ * data to try and find the lock instance for this spin lock to see when it
+ * was last acquired.
+ */
+void
+witness_display_spinlock(struct lock_object *lock, struct thread *owner)
+{
+	struct lock_instance *instance;
+	struct pcpu *pc;
+
+	if (owner->td_critnest == 0 || owner->td_kse != NULL ||
+	    owner->td_kse->ke_oncpu == NOCPU)
+		return;
+	pc = pcpu_find(owner->td_kse->ke_oncpu);
+	instance = find_instance(pc->pc_spinlocks, lock);
+	if (instance != NULL)
+		witness_list_lock(instance);
+}
+
+/*
  * Calling this on td != curthread is bad unless we are in ddb.
  */
 static int

==== //depot/projects/smpng/sys/sys/lock.h#23 (text+ko) ====

@@ -208,6 +208,7 @@
 int	witness_warn(int, struct lock_object *, const char *, int,
 	    const char *, ...);
 void	witness_assert(struct lock_object *, int, const char *, int);
+void	witness_display_spinlock(struct lock_object *, struct thread *);
 int	witness_line(struct lock_object *);
 const char *witness_file(struct lock_object *);
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212101837.gBAIbfqE026165>