git: 46eab86035a1 - main - callout: Simplify the inner loop in callout_process() a bit
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 17 Jul 2022 17:58:40 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=46eab86035a1d5d2b8bfd5aae3581e2604d3ae68
commit 46eab86035a1d5d2b8bfd5aae3581e2604d3ae68
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-07-01 00:16:33 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-07-17 17:58:19 +0000
callout: Simplify the inner loop in callout_process() a bit
- Use LIST_FOREACH_SAFE.
- Simplify control flow.
No functional change intended.
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
---
sys/kern/kern_timeout.c | 65 +++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 34 deletions(-)
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index 2bd469f94080..5c6c49ec93bd 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -434,7 +434,7 @@ callout_process(sbintime_t now)
struct thread *td;
sbintime_t now;
} entropy;
- struct callout *tmp, *tmpn;
+ struct callout *c, *next;
struct callout_cpu *cc;
struct callout_list *sc;
struct thread *td;
@@ -479,58 +479,55 @@ callout_process(sbintime_t now)
/* Iterate callwheel from firstb to nowb and then up to lastb. */
do {
sc = &cc->cc_callwheel[firstb & callwheelmask];
- tmp = LIST_FIRST(sc);
- while (tmp != NULL) {
+ LIST_FOREACH_SAFE(c, sc, c_links.le, next) {
/* Run the callout if present time within allowed. */
- if (tmp->c_time <= now) {
+ if (c->c_time <= now) {
/*
* Consumer told us the callout may be run
* directly from hardware interrupt context.
*/
- if (tmp->c_iflags & CALLOUT_DIRECT) {
+ if (c->c_iflags & CALLOUT_DIRECT) {
#ifdef CALLOUT_PROFILING
++depth_dir;
#endif
- cc_exec_next(cc) =
- LIST_NEXT(tmp, c_links.le);
+ cc_exec_next(cc) = next;
cc->cc_bucket = firstb & callwheelmask;
- LIST_REMOVE(tmp, c_links.le);
- softclock_call_cc(tmp, cc,
+ LIST_REMOVE(c, c_links.le);
+ softclock_call_cc(c, cc,
#ifdef CALLOUT_PROFILING
&mpcalls_dir, &lockcalls_dir, NULL,
#endif
1);
- tmp = cc_exec_next(cc);
+ next = cc_exec_next(cc);
cc_exec_next(cc) = NULL;
} else {
- tmpn = LIST_NEXT(tmp, c_links.le);
- LIST_REMOVE(tmp, c_links.le);
+ LIST_REMOVE(c, c_links.le);
TAILQ_INSERT_TAIL(&cc->cc_expireq,
- tmp, c_links.tqe);
- tmp->c_iflags |= CALLOUT_PROCESSED;
- tmp = tmpn;
+ c, c_links.tqe);
+ c->c_iflags |= CALLOUT_PROCESSED;
}
- continue;
- }
- /* Skip events from distant future. */
- if (tmp->c_time >= max)
- goto next;
- /*
- * Event minimal time is bigger than present maximal
- * time, so it cannot be aggregated.
- */
- if (tmp->c_time > last) {
+ } else if (c->c_time >= max) {
+ /*
+ * Skip events in the distant future.
+ */
+ ;
+ } else if (c->c_time > last) {
+ /*
+ * Event minimal time is bigger than present
+ * maximal time, so it cannot be aggregated.
+ */
lastb = nowb;
- goto next;
+ } else {
+ /*
+ * Update first and last time, respecting this
+ * event.
+ */
+ if (c->c_time < first)
+ first = c->c_time;
+ tmp_max = c->c_time + c->c_precision;
+ if (tmp_max < last)
+ last = tmp_max;
}
- /* Update first and last time, respecting this event. */
- if (tmp->c_time < first)
- first = tmp->c_time;
- tmp_max = tmp->c_time + tmp->c_precision;
- if (tmp_max < last)
- last = tmp_max;
-next:
- tmp = LIST_NEXT(tmp, c_links.le);
}
/* Proceed with the next bucket. */
firstb++;