Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern sched_catchlwp: fix the case when other CPU might s...



details:   https://anonhg.NetBSD.org/src/rev/b3dfcab47851
branches:  trunk
changeset: 750422:b3dfcab47851
user:      rmind <rmind%NetBSD.org@localhost>
date:      Wed Dec 30 23:49:59 2009 +0000

description:
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 martin@.

diffstat:

 sys/kern/kern_runq.c |  15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diffs (36 lines):

diff -r ea2a5f930c03 -r b3dfcab47851 sys/kern/kern_runq.c
--- a/sys/kern/kern_runq.c      Wed Dec 30 23:42:22 2009 +0000
+++ b/sys/kern/kern_runq.c      Wed Dec 30 23:49:59 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_runq.c,v 1.27 2009/10/21 21:12:06 rmind Exp $     */
+/*     $NetBSD: kern_runq.c,v 1.28 2009/12/30 23:49:59 rmind 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.27 2009/10/21 21:12:06 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.28 2009/12/30 23:49:59 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -486,6 +486,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);



Home | Main Index | Thread Index | Old Index