From 0d0053d7ed2cf9ce64915aa873285d5c3ad11541 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Wed, 2 Sep 2020 09:44:00 +0000 Subject: [PATCH] Micro optimise _callout_stop_safe() by removing dead code. The CS_DRAIN flag cannot be set at the same time like the async-drain function pointer is set. These are orthogonal features. Assert this at the beginning of the function. Before: if (flags & CS_DRAIN) { /* FALLTHROUGH */ } else if (xxx) { return yyy; } if (drain) { zzz = drain; } After: if (flags & CS_DRAIN) { /* FALLTHROUGH */ } else if (xxx) { return yyy; } else { if (drain) { zzz = drain; } } Reviewed by: markj@ Tested by: callout_test Differential Revision: https://reviews.freebsd.org/D26285 MFC after: 1 week Sponsored by: Mellanox Technologies // NVIDIA Networking --- sys/kern/kern_timeout.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index f804e279ec8..760491d8c21 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1075,6 +1075,9 @@ _callout_stop_safe(struct callout *c, int flags, callout_func_t *drain) WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, c->c_lock, "calling %s", __func__); + KASSERT((flags & CS_DRAIN) == 0 || drain == NULL, + ("Cannot set drain callback and CS_DRAIN flag at the same time")); + /* * Some old subsystems don't hold Giant while running a callout_stop(), * so just discard this check for the moment. @@ -1270,11 +1273,12 @@ _callout_stop_safe(struct callout *c, int flags, callout_func_t *drain) } CC_UNLOCK(cc); return ((flags & CS_EXECUTING) != 0); - } - CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p", - c, c->c_func, c->c_arg); - if (drain) { - cc_exec_drain(cc, direct) = drain; + } else { + CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p", + c, c->c_func, c->c_arg); + if (drain) { + cc_exec_drain(cc, direct) = drain; + } } KASSERT(!sq_locked, ("sleepqueue chain still locked")); cancelled = ((flags & CS_EXECUTING) != 0); -- 2.45.0