Source-Changes-HG archive

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

[src/trunk]: src/sys - Move the LW_RUNNING flag back into l_pflag: updating l...



details:   https://anonhg.NetBSD.org/src/rev/8c8d23a1cb87
branches:  trunk
changeset: 744888:8c8d23a1cb87
user:      ad <ad%NetBSD.org@localhost>
date:      Sat Feb 15 18:12:14 2020 +0000

description:
- Move the LW_RUNNING flag back into l_pflag: updating l_flag without lock
  in softint_dispatch() is risky.  May help with the "softint screwup"
  panic.

- Correct the memory barriers around zombies switching into oblivion.

diffstat:

 sys/arch/vax/vax/pmap.c               |   6 ++--
 sys/ddb/db_proc.c                     |  12 +++++-----
 sys/kern/init_main.c                  |   6 ++--
 sys/kern/kern_exit.c                  |   9 ++-----
 sys/kern/kern_idle.c                  |   8 +++---
 sys/kern/kern_lwp.c                   |  32 +++++++++++++++++----------
 sys/kern/kern_resource.c              |   6 ++--
 sys/kern/kern_sleepq.c                |   6 ++--
 sys/kern/kern_softint.c               |  10 ++++----
 sys/kern/kern_synch.c                 |  39 ++++++++++++++++++++--------------
 sys/rump/librump/rumpkern/lwproc.c    |  12 +++++-----
 sys/rump/librump/rumpkern/scheduler.c |   6 ++--
 sys/sys/lwp.h                         |  21 ++++++++++++++----
 13 files changed, 98 insertions(+), 75 deletions(-)

diffs (truncated from 607 to 300 lines):

diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/arch/vax/vax/pmap.c
--- a/sys/arch/vax/vax/pmap.c   Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/arch/vax/vax/pmap.c   Sat Feb 15 18:12:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.188 2020/01/08 17:38:42 ad Exp $       */
+/*     $NetBSD: pmap.c,v 1.189 2020/02/15 18:12:14 ad Exp $       */
 /*
  * Copyright (c) 1994, 1998, 1999, 2003 Ludd, University of Lule}, Sweden.
  * All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.188 2020/01/08 17:38:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.189 2020/02/15 18:12:14 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_cputype.h"
@@ -699,7 +699,7 @@
                return false;
        if (l->l_proc->p_vmspace->vm_map.pmap == pm)
                return false;
-       if ((l->l_flag & LW_RUNNING) != 0)
+       if ((l->l_pflag & LP_RUNNING) != 0)
                return false;
        if (l->l_class != SCHED_OTHER)
                return false;
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/ddb/db_proc.c
--- a/sys/ddb/db_proc.c Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/ddb/db_proc.c Sat Feb 15 18:12:14 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: db_proc.c,v 1.9 2020/01/08 17:38:42 ad Exp $   */
+/*     $NetBSD: db_proc.c,v 1.10 2020/02/15 18:12:14 ad Exp $  */
 
 /*-
- * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2009, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_proc.c,v 1.9 2020/01/08 17:38:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_proc.c,v 1.10 2020/02/15 18:12:14 ad Exp $");
 
 #ifndef _KERNEL
 #include <stdbool.h>
@@ -196,7 +196,7 @@
                                            sizeof(db_nbuf));
                                }
                                run = (l.l_stat == LSONPROC ||
-                                   (l.l_flag & LW_RUNNING) != 0);
+                                   (l.l_pflag & LP_RUNNING) != 0);
                                if (l.l_cpu != NULL) {
                                        db_read_bytes((db_addr_t)
                                            &l.l_cpu->ci_data.cpu_index,
@@ -254,7 +254,7 @@
                                        wbuf[0] = '\0';
                                }
                                run = (l.l_stat == LSONPROC ||
-                                   (l.l_flag & LW_RUNNING) != 0);
+                                   (l.l_pflag & LP_RUNNING) != 0);
                                db_read_bytes((db_addr_t)&p.p_emul->e_name,
                                    sizeof(ename), (char *)&ename);
 
@@ -332,7 +332,7 @@
                db_read_bytes((db_addr_t)lp, sizeof(l), (char *)&l);
 
                run = (l.l_stat == LSONPROC ||
-                   (l.l_flag & LW_RUNNING) != 0);
+                   (l.l_pflag & LP_RUNNING) != 0);
 
                db_printf("%slwp %d", (run ? "> " : "  "), l.l_lid);
                if (l.l_name != NULL) {
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/kern/init_main.c
--- a/sys/kern/init_main.c      Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/kern/init_main.c      Sat Feb 15 18:12:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.519 2020/01/28 16:35:39 ad Exp $       */
+/*     $NetBSD: init_main.c,v 1.520 2020/02/15 18:12:15 ad Exp $       */
 
 /*-
  * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.519 2020/01/28 16:35:39 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.520 2020/02/15 18:12:15 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -290,7 +290,7 @@
 #ifndef LWP0_CPU_INFO
        l->l_cpu = curcpu();
 #endif
-       l->l_flag |= LW_RUNNING;
+       l->l_pflag |= LP_RUNNING;
 
        /*
         * Attempt to find console and initialize
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/kern/kern_exit.c      Sat Feb 15 18:12:14 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: kern_exit.c,v 1.282 2020/01/29 15:47:52 ad Exp $       */
+/*     $NetBSD: kern_exit.c,v 1.283 2020/02/15 18:12:15 ad Exp $       */
 
 /*-
- * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.282 2020/01/29 15:47:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.283 2020/02/15 18:12:15 ad Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -592,9 +592,6 @@
         */
        cpu_lwp_free(l, 1);
 
-       /* For the LW_RUNNING check in lwp_free(). */
-       membar_exit();
-
        /* Switch away into oblivion. */
        lwp_lock(l);
        spc_lock(l->l_cpu);
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/kern/kern_idle.c
--- a/sys/kern/kern_idle.c      Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/kern/kern_idle.c      Sat Feb 15 18:12:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_idle.c,v 1.31 2020/01/25 20:29:43 ad Exp $        */
+/*     $NetBSD: kern_idle.c,v 1.32 2020/02/15 18:12:15 ad Exp $        */
 
 /*-
  * Copyright (c)2002, 2006, 2007 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.31 2020/01/25 20:29:43 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.32 2020/02/15 18:12:15 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -57,7 +57,7 @@
        binuptime(&l->l_stime);
        spc->spc_flags |= SPCF_RUNNING;
        KASSERT(l->l_stat == LSONPROC);
-       KASSERT((l->l_flag & LW_RUNNING) != 0);
+       KASSERT((l->l_pflag & LP_RUNNING) != 0);
        lwp_unlock(l);
 
        /*
@@ -120,7 +120,7 @@
                 * takes an interrupt before it calls idle_loop().
                 */
                l->l_stat = LSONPROC;
-               l->l_flag |= LW_RUNNING;
+               l->l_pflag |= LP_RUNNING;
                ci->ci_onproc = l;
        }
        lwp_unlock(l);
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/kern/kern_lwp.c       Sat Feb 15 18:12:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lwp.c,v 1.226 2020/02/15 17:13:55 ad Exp $        */
+/*     $NetBSD: kern_lwp.c,v 1.227 2020/02/15 18:12:15 ad Exp $        */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
@@ -80,7 +80,7 @@
  *     LWP.  The LWP may in fact be executing on a processor, may be
  *     sleeping or idle. It is expected to take the necessary action to
  *     stop executing or become "running" again within a short timeframe.
- *     The LW_RUNNING flag in lwp::l_flag indicates that an LWP is running.
+ *     The LP_RUNNING flag in lwp::l_pflag indicates that an LWP is running.
  *     Importantly, it indicates that its state is tied to a CPU.
  *
  *     LSZOMB:
@@ -211,7 +211,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.226 2020/02/15 17:13:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.227 2020/02/15 18:12:15 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1044,16 +1044,26 @@
 void
 lwp_startup(struct lwp *prev, struct lwp *new_lwp)
 {
+       kmutex_t *lock;
 
        KASSERTMSG(new_lwp == curlwp, "l %p curlwp %p prevlwp %p", new_lwp, curlwp, prev);
        KASSERT(kpreempt_disabled());
        KASSERT(prev != NULL);
-       KASSERT((prev->l_flag & LW_RUNNING) != 0);
+       KASSERT((prev->l_pflag & LP_RUNNING) != 0);
        KASSERT(curcpu()->ci_mtx_count == -2);
 
-       /* Immediately mark previous LWP as no longer running, and unlock. */
-       prev->l_flag &= ~LW_RUNNING;
-       lwp_unlock(prev);
+       /*
+        * Immediately mark the previous LWP as no longer running and unlock
+        * (to keep lock wait times short as possible).  If a zombie, don't
+        * touch after clearing LP_RUNNING as it could be reaped by another
+        * CPU.  Issue a memory barrier to ensure this.
+        */
+       lock = prev->l_mutex;
+       if (__predict_false(prev->l_stat == LSZOMB)) {
+               membar_sync();
+       }
+       prev->l_pflag &= ~LP_RUNNING;
+       mutex_spin_exit(lock);
 
        /* Correct spin mutex count after mi_switch(). */
        curcpu()->ci_mtx_count = 0;
@@ -1224,8 +1234,6 @@
        cpu_lwp_free(l, 0);
 
        if (current) {
-               /* For the LW_RUNNING check in lwp_free(). */
-               membar_exit();
                /* Switch away into oblivion. */
                lwp_lock(l);
                spc_lock(l->l_cpu);
@@ -1304,8 +1312,8 @@
         * all locks to avoid deadlock against interrupt handlers on
         * the target CPU.
         */
-       membar_enter();
-       while (__predict_false((l->l_flag & LW_RUNNING) != 0)) {
+       membar_consumer();
+       while (__predict_false((l->l_pflag & LP_RUNNING) != 0)) {
                SPINLOCK_BACKOFF_HOOK;
        }
 #endif
@@ -1371,7 +1379,7 @@
        KASSERT(tci != NULL);
 
        /* If LWP is still on the CPU, it must be handled like LSONPROC */
-       if ((l->l_flag & LW_RUNNING) != 0) {
+       if ((l->l_pflag & LP_RUNNING) != 0) {
                lstat = LSONPROC;
        }
 
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/kern/kern_resource.c
--- a/sys/kern/kern_resource.c  Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/kern/kern_resource.c  Sat Feb 15 18:12:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_resource.c,v 1.184 2020/01/08 17:38:42 ad Exp $   */
+/*     $NetBSD: kern_resource.c,v 1.185 2020/02/15 18:12:15 ad Exp $   */
 
 /*-
  * Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.184 2020/01/08 17:38:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.185 2020/02/15 18:12:15 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -506,7 +506,7 @@
        LIST_FOREACH(l, &p->p_lwps, l_sibling) {
                lwp_lock(l);
                bintime_add(&tm, &l->l_rtime);
-               if ((l->l_flag & LW_RUNNING) != 0 &&
+               if ((l->l_pflag & LP_RUNNING) != 0 &&
                    (l->l_pflag & (LP_INTR | LP_TIMEINTR)) != LP_INTR) {
                        struct bintime diff;
                        /*
diff -r 1ec729ccb21e -r 8c8d23a1cb87 sys/kern/kern_sleepq.c
--- a/sys/kern/kern_sleepq.c    Sat Feb 15 17:14:30 2020 +0000
+++ b/sys/kern/kern_sleepq.c    Sat Feb 15 18:12:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sleepq.c,v 1.60 2020/02/01 19:29:27 christos Exp $        */
+/*     $NetBSD: kern_sleepq.c,v 1.61 2020/02/15 18:12:15 ad Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.60 2020/02/01 19:29:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.61 2020/02/15 18:12:15 ad Exp $");



Home | Main Index | Thread Index | Old Index