Module Name:    src
Committed By:   bouyer
Date:           Sat Jan 16 17:39:01 UTC 2010

Modified Files:
        src/sys/kern [netbsd-5]: kern_runq.c

Log Message:
Pull up following revision(s) (requested by rmind in ticket #1240):
        sys/kern/kern_runq.c: revision 1.28
sched_catchlwp: fix the case when other CPU might see curlwp->l_cpu != curcpu()
while LWP is finishing context switch.  Should fix PR/42539, tested by mar...@.


To generate a diff of this commit:
cvs rdiff -u -r1.22.4.3 -r1.22.4.4 src/sys/kern/kern_runq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_runq.c
diff -u src/sys/kern/kern_runq.c:1.22.4.3 src/sys/kern/kern_runq.c:1.22.4.4
--- src/sys/kern/kern_runq.c:1.22.4.3	Mon Mar  2 19:51:01 2009
+++ src/sys/kern/kern_runq.c	Sat Jan 16 17:39:01 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_runq.c,v 1.22.4.3 2009/03/02 19:51:01 snj Exp $	*/
+/*	$NetBSD: kern_runq.c,v 1.22.4.4 2010/01/16 17:39:01 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.22.4.3 2009/03/02 19:51:01 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.22.4.4 2010/01/16 17:39:01 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -482,6 +482,17 @@
 
 		/* Grab the thread, and move to the local run queue */
 		sched_dequeue(l);
+
+		/*
+		 * If LWP is still context switching, we may need to
+		 * spin-wait before changing its CPU.
+		 */
+		if (__predict_false(l->l_ctxswtch != 0)) {
+			u_int count;
+			count = SPINLOCK_BACKOFF_MIN;
+			while (l->l_ctxswtch)
+				SPINLOCK_BACKOFF(count);
+		}
 		l->l_cpu = curci;
 		ci_rq->r_ev_pull.ev_count++;
 		lwp_unlock_to(l, curspc->spc_mutex);

Reply via email to