Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jun 2002 10:46:28 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 12362 for review
Message-ID:  <200206041746.g54HkS563688@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=12362

Change 12362 by jhb@jhb_laptop on 2002/06/04 10:45:42

	- Add a thread_runnable() macro to make some code more readable
	  and make the KSE diff easier.
	- Fix the adaptive mutex spin optimization.  We need to stop
	  spinning not just when mtx_owner(m) changes, but also if the
	  owner stops running.

Affected files ...

... //depot/projects/smpng/sys/kern/kern_mutex.c#36 edit

Differences ...

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

@@ -70,6 +70,9 @@
 #define mtx_owner(m)	(mtx_unowned((m)) ? NULL \
 	: (struct thread *)((m)->mtx_lock & MTX_FLAGMASK))
 
+#define	thread_runnable(td)						\
+	((td)->td_kse != NULL && (td)->td_kse->ke_oncpu != NOCPU)
+    
 /*
  * Lock classes for sleep and spin mutexes.
  */
@@ -129,7 +132,7 @@
 		 * If lock holder is actually running, just bump priority.
 		 */
 		 /* XXXKSE this test is not sufficient */
-		if (td->td_kse && (td->td_kse->ke_oncpu != NOCPU)) { 
+		if (thread_runnable(td)) {
 			MPASS(td->td_proc->p_stat == SRUN
 			|| td->td_proc->p_stat == SZOMB
 			|| td->td_proc->p_stat == SSTOP);
@@ -531,10 +534,10 @@
 		 * CPU, spin instead of blocking.
 		 */
 		owner = (struct thread *)(v & MTX_FLAGMASK);
-		if (m != &Giant && owner->td_kse != NULL &&
-		    owner->td_kse->ke_oncpu != NOCPU) {
+		if (m != &Giant && thread_runnable(owner)) {
 			mtx_unlock_spin(&sched_lock);
-			while (mtx_owner(m) == owner) {
+			while (mtx_owner(m) == owner &&
+			    thread_runnable(owner)) {
 #ifdef __i386__
 				ia32_pause();
 #endif

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?200206041746.g54HkS563688>