Module Name: src Committed By: rmind Date: Wed Dec 30 23:49:59 UTC 2009
Modified Files: src/sys/kern: kern_runq.c Log Message: 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.27 -r1.28 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.27 src/sys/kern/kern_runq.c:1.28 --- src/sys/kern/kern_runq.c:1.27 Wed Oct 21 21:12:06 2009 +++ src/sys/kern/kern_runq.c Wed Dec 30 23:49:59 2009 @@ -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);