Source-Changes-HG archive

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

[src/trunk]: src/sys/kern heartbeat(9): Test whether curcpu is stable, not kp...



details:   https://anonhg.NetBSD.org/src/rev/81ad257b8a8f
branches:  trunk
changeset: 377329:81ad257b8a8f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Jul 07 17:05:13 2023 +0000

description:
heartbeat(9): Test whether curcpu is stable, not kpreempt_disabled.

kpreempt_disabled worked for my testing because I tested on aarch64,
which doesn't have kpreemption.

XXX Should move curcpu_stable() to somewhere that other things can
use it.

diffstat:

 sys/kern/kern_heartbeat.c |  24 +++++++++++++++++-------
 sys/kern/kern_lock.c      |  25 ++++++++++++-------------
 2 files changed, 29 insertions(+), 20 deletions(-)

diffs (170 lines):

diff -r 3326fa5dee41 -r 81ad257b8a8f sys/kern/kern_heartbeat.c
--- a/sys/kern/kern_heartbeat.c Fri Jul 07 17:04:49 2023 +0000
+++ b/sys/kern/kern_heartbeat.c Fri Jul 07 17:05:13 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_heartbeat.c,v 1.1 2023/07/07 12:34:50 riastradh Exp $     */
+/*     $NetBSD: kern_heartbeat.c,v 1.2 2023/07/07 17:05:13 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.1 2023/07/07 12:34:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_heartbeat.c,v 1.2 2023/07/07 17:05:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -104,6 +104,16 @@
 #include <ddb/ddb.h>
 #endif
 
+static inline bool
+curcpu_stable(void)
+{
+
+       return kpreempt_disabled() ||
+           (curlwp->l_pflag & LP_BOUND) ||
+           cpu_intr_p() ||
+           cpu_softintr_p();
+}
+
 /*
  * Global state.
  *
@@ -132,7 +142,7 @@ void
 heartbeat_suspend(void)
 {
 
-       KASSERT(kpreempt_disabled());
+       KASSERT(curcpu_stable());
 
        /*
         * Nothing to do -- we just check the SPCF_OFFLINE flag.
@@ -155,7 +165,7 @@ heartbeat_resume(void)
        struct cpu_info *ci = curcpu();
        int s;
 
-       KASSERT(kpreempt_disabled());
+       KASSERT(curcpu_stable());
 
        /*
         * Block heartbeats while we reset the state so we don't
@@ -398,7 +408,7 @@ defibrillate(struct cpu_info *ci, unsign
        };
        unsigned countdown = 1000; /* 1sec */
 
-       KASSERT(kpreempt_disabled());
+       KASSERT(curcpu_stable());
 
        /*
         * First notify the console that the patient CPU's heart seems
@@ -449,7 +459,7 @@ select_patient(void)
        struct cpu_info *first = NULL, *patient = NULL, *ci;
        bool passedcur = false;
 
-       KASSERT(kpreempt_disabled());
+       KASSERT(curcpu_stable());
 
        /*
         * In the iteration order of all CPUs, find the next online CPU
@@ -528,7 +538,7 @@ heartbeat(void)
        unsigned count, uptime, cache, stamp, d;
        struct cpu_info *patient;
 
-       KASSERT(kpreempt_disabled());
+       KASSERT(curcpu_stable());
 
        period_ticks = atomic_load_relaxed(&heartbeat_max_period_ticks);
        period_secs = atomic_load_relaxed(&heartbeat_max_period_secs);
diff -r 3326fa5dee41 -r 81ad257b8a8f sys/kern/kern_lock.c
--- a/sys/kern/kern_lock.c      Fri Jul 07 17:04:49 2023 +0000
+++ b/sys/kern/kern_lock.c      Fri Jul 07 17:05:13 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lock.c,v 1.184 2023/04/09 08:17:36 riastradh Exp $        */
+/*     $NetBSD: kern_lock.c,v 1.185 2023/07/07 17:05:13 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2020 The NetBSD Foundation, Inc.
@@ -31,9 +31,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.184 2023/04/09 08:17:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.185 2023/07/07 17:05:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
+#include "opt_ddb.h"
 #include "opt_lockdebug.h"
 #endif
 
@@ -53,6 +54,10 @@
 #include <sys/ksyms.h>
 #endif
 
+#ifdef DDB
+#include <ddb/ddb.h>
+#endif
+
 #include <machine/lock.h>
 
 #include <dev/lockstat.h>
@@ -116,17 +121,17 @@ panic:    panic("%s: %s caller=%p", __func_
  * so that they show up in profiles.
  */
 
+#ifdef LOCKDEBUG
 #define        _KERNEL_LOCK_ABORT(msg)                                         \
     LOCKDEBUG_ABORT(__func__, __LINE__, kernel_lock, &_kernel_lock_ops, msg)
-
-#ifdef LOCKDEBUG
 #define        _KERNEL_LOCK_ASSERT(cond)                                       \
 do {                                                                   \
        if (!(cond))                                                    \
                _KERNEL_LOCK_ABORT("assertion failed: " #cond);         \
 } while (/* CONSTCOND */ 0)
 #else
-#define        _KERNEL_LOCK_ASSERT(cond)       /* nothing */
+#define        _KERNEL_LOCK_ABORT(cond)        __nothing
+#define        _KERNEL_LOCK_ASSERT(cond)       __nothing
 #endif
 
 static void    _kernel_lock_dump(const volatile void *, lockop_printer_t);
@@ -137,10 +142,6 @@ lockops_t _kernel_lock_ops = {
        .lo_dump = _kernel_lock_dump,
 };
 
-#ifdef LOCKDEBUG
-
-#include <ddb/ddb.h>
-
 static void
 kernel_lock_trace_ipi(void *cookie)
 {
@@ -148,11 +149,11 @@ kernel_lock_trace_ipi(void *cookie)
        printf("%s[%d %s]: hogging kernel lock\n", cpu_name(curcpu()),
            curlwp->l_lid,
            curlwp->l_name ? curlwp->l_name : curproc->p_comm);
+#ifdef DDB
        db_stacktrace();
+#endif
 }
 
-#endif
-
 /*
  * Initialize the kernel lock.
  */
@@ -195,11 +196,9 @@ void
        LOCKSTAT_TIMER(spintime);
        LOCKSTAT_FLAG(lsflag);
        struct lwp *owant;
-#ifdef LOCKDEBUG
        static struct cpu_info *kernel_lock_holder;
        u_int spins = 0;
        u_int starttime = getticks();
-#endif
        int s;
        struct lwp *l = curlwp;
 



Home | Main Index | Thread Index | Old Index