Source-Changes-HG archive

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

[src/trunk]: src/sys/kern callout(9): Tidy up the condition for "callout is r...



details:   https://anonhg.NetBSD.org/src/rev/43c8968bb147
branches:  trunk
changeset: 376641:43c8968bb147
user:      pho <pho%NetBSD.org@localhost>
date:      Tue Jun 27 01:17:43 2023 +0000

description:
callout(9): Tidy up the condition for "callout is running on another LWP"

No functional changes.

diffstat:

 sys/kern/kern_timeout.c |  23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diffs (72 lines):

diff -r fdbee7f6df9e -r 43c8968bb147 sys/kern/kern_timeout.c
--- a/sys/kern/kern_timeout.c   Tue Jun 27 01:15:22 2023 +0000
+++ b/sys/kern/kern_timeout.c   Tue Jun 27 01:17:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_timeout.c,v 1.74 2023/06/27 01:15:22 pho Exp $    */
+/*     $NetBSD: kern_timeout.c,v 1.75 2023/06/27 01:17:43 pho Exp $    */
 
 /*-
  * Copyright (c) 2003, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.74 2023/06/27 01:15:22 pho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.75 2023/06/27 01:17:43 pho Exp $");
 
 /*
  * Timeouts are kept in a hierarchical timing wheel.  The c_time is the
@@ -263,6 +263,17 @@ callout_lock(callout_impl_t *c)
 }
 
 /*
+ * Check if the callout is currently running on an LWP that isn't curlwp.
+ */
+static inline bool
+callout_running_somewhere_else(callout_impl_t *c, struct callout_cpu *cc)
+{
+       KASSERT(c->c_cpu == cc);
+
+       return cc->cc_active == c && cc->cc_lwp != curlwp;
+}
+
+/*
  * callout_startup:
  *
  *     Initialize the callout facility, called at system startup time.
@@ -378,7 +389,7 @@ callout_destroy(callout_t *cs)
        KASSERTMSG((c->c_flags & CALLOUT_PENDING) == 0,
            "pending callout %p: c_func (%p) c_flags (%#x) destroyed from %p",
            c, c->c_func, c->c_flags, __builtin_return_address(0));
-       KASSERTMSG(c->c_cpu->cc_lwp == curlwp || c->c_cpu->cc_active != c,
+       KASSERTMSG(!callout_running_somewhere_else(c, c->c_cpu),
            "running callout %p: c_func (%p) c_flags (%#x) destroyed from %p",
            c, c->c_func, c->c_flags, __builtin_return_address(0));
        c->c_magic = 0;
@@ -542,7 +553,6 @@ callout_halt(callout_t *cs, void *interl
 {
        callout_impl_t *c = (callout_impl_t *)cs;
        kmutex_t *lock;
-       struct callout_cpu *cc;
 
        KASSERT(c->c_magic == CALLOUT_MAGIC);
        KASSERT(!cpu_intr_p());
@@ -555,8 +565,7 @@ callout_halt(callout_t *cs, void *interl
        if ((c->c_flags & CALLOUT_PENDING) != 0)
                CIRCQ_REMOVE(&c->c_list);
        c->c_flags &= ~(CALLOUT_PENDING|CALLOUT_FIRED);
-       cc = c->c_cpu;
-       if (__predict_false(cc->cc_active == c && cc->cc_lwp != curlwp)) {
+       if (__predict_false(callout_running_somewhere_else(c, c->c_cpu))) {
                callout_wait(c, interlock, lock);
                return true;
        }
@@ -592,7 +601,7 @@ callout_wait(callout_impl_t *c, void *in
                 * - the callout itself has called callout_halt() (nice!)
                 */
                cc = c->c_cpu;
-               if (__predict_true(cc->cc_active != c || cc->cc_lwp == l))
+               if (__predict_true(!callout_running_somewhere_else(c, cc)))
                        break;
 
                /* It's running - need to wait for it to complete. */



Home | Main Index | Thread Index | Old Index