Module Name: src Committed By: pho Date: Tue Jun 27 01:17:43 UTC 2023
Modified Files: src/sys/kern: kern_timeout.c Log Message: callout(9): Tidy up the condition for "callout is running on another LWP" No functional changes. To generate a diff of this commit: cvs rdiff -u -r1.74 -r1.75 src/sys/kern/kern_timeout.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_timeout.c diff -u src/sys/kern/kern_timeout.c:1.74 src/sys/kern/kern_timeout.c:1.75 --- src/sys/kern/kern_timeout.c:1.74 Tue Jun 27 01:15:22 2023 +++ src/sys/kern/kern_timeout.c Tue Jun 27 01:17:43 2023 @@ -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. */