Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/kern Pull up following revision(s) (requested by ozak...



details:   https://anonhg.NetBSD.org/src/rev/bd003fd11bbb
branches:  netbsd-8
changeset: 434669:bd003fd11bbb
user:      snj <snj%NetBSD.org@localhost>
date:      Mon Feb 26 00:43:23 2018 +0000

description:
Pull up following revision(s) (requested by ozaki-r in ticket #573):
        sys/kern/kern_synch.c: 1.314
Avoid a race condition between an LWP migration and curlwp_bind
curlwp_bind sets the LP_BOUND flag to l_pflags of the current LWP, which
prevents it from migrating to another CPU until curlwp_bindx is called.
Meanwhile, there are several ways that an LWP is migrated to another CPU and in
any cases the scheduler postpones a migration if a target LWP is running.  One
example of LWP migrations is a load balancing; the scheduler periodically
explores CPU-hogging LWPs and schedule them to migrate (see sched_lwp_stats).
At that point the scheduler checks the LP_BOUND flag and if it's set to a LWP,
the scheduler doesn't schedule the LWP.  A scheduled LWP is tried to be migrated
when it is leaving a running CPU, i.e., mi_switch.  And mi_switch does NOT check
the LP_BOUND flag.  So if an LWP is scheduled first and then it sets the
LP_BOUND flag, the LWP can be migrated regardless of the flag.  To avoid this
race condition, we need to check the flag in mi_switch too.
For more details see
https://mail-index.netbsd.org/tech-kern/2018/02/13/msg023079.html

diffstat:

 sys/kern/kern_synch.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r 753263a0a59c -r bd003fd11bbb sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c     Mon Feb 26 00:41:13 2018 +0000
+++ b/sys/kern/kern_synch.c     Mon Feb 26 00:43:23 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_synch.c,v 1.311 2016/07/03 14:24:58 christos Exp $        */
+/*     $NetBSD: kern_synch.c,v 1.311.10.1 2018/02/26 00:43:23 snj Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.311 2016/07/03 14:24:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.311.10.1 2018/02/26 00:43:23 snj Exp $");
 
 #include "opt_kstack.h"
 #include "opt_perfctrs.h"
@@ -589,7 +589,8 @@
                         * be reset here, if interrupt/preemption happens
                         * early in idle LWP.
                         */
-                       if (l->l_target_cpu != NULL) {
+                       if (l->l_target_cpu != NULL &&
+                           (l->l_pflag & LP_BOUND) == 0) {
                                KASSERT((l->l_pflag & LP_INTR) == 0);
                                spc->spc_migrating = l;
                        }



Home | Main Index | Thread Index | Old Index