aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_timeout.c
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2020-09-02 09:44:00 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2020-09-02 09:44:00 +0000
commit0d0053d7ed2cf9ce64915aa873285d5c3ad11541 (patch)
tree9f9a44c23d9116a002cace0fecf25f257dbd7539 /sys/kern/kern_timeout.c
parent72d849c76142f00c8016fa1ba9d3e6c3eb5481c4 (diff)
downloadsrc-0d0053d7ed2cf9ce64915aa873285d5c3ad11541.tar.gz
src-0d0053d7ed2cf9ce64915aa873285d5c3ad11541.zip
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
Notes
Notes: svn path=/head/; revision=365237
Diffstat (limited to 'sys/kern/kern_timeout.c')
-rw-r--r--sys/kern/kern_timeout.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index f804e279ec8b..760491d8c216 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 @@ again:
}
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);