From: cheloha Date: Wed, 9 Nov 2022 17:12:50 +0000 (+0000) Subject: timeout(9): remove TIMEOUT_KCLOCK flag X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c6921acfdc5aaaf8afdf7a58b840de1d1587129c;p=openbsd timeout(9): remove TIMEOUT_KCLOCK flag I never should have added the TIMEOUT_KCLOCK flag. It is redundant and only serves to complicate the timeout(9) logic. In every place where we check for the flag we can just use timeout.to_kclock. So, remove the flag from and rewrite all affected logic to use the value of timeout.to_kclock instead. ok kn@ --- diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index 44a4918db19..df79bb4c82f 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_timeout.c,v 1.86 2022/11/08 19:09:53 cheloha Exp $ */ +/* $OpenBSD: kern_timeout.c,v 1.87 2022/11/09 17:12:50 cheloha Exp $ */ /* * Copyright (c) 2001 Thomas Nordin * Copyright (c) 2000-2001 Artur Grabowski @@ -283,7 +283,7 @@ void timeout_set_kclock(struct timeout *to, void (*fn)(void *), void *arg, int kclock, int flags) { - _timeout_set(to, fn, arg, kclock, flags | TIMEOUT_KCLOCK); + _timeout_set(to, fn, arg, kclock, flags); } int @@ -293,7 +293,6 @@ timeout_add(struct timeout *new, int to_ticks) int ret = 1; KASSERT(ISSET(new->to_flags, TIMEOUT_INITIALIZED)); - KASSERT(!ISSET(new->to_flags, TIMEOUT_KCLOCK)); KASSERT(new->to_kclock == KCLOCK_NONE); KASSERT(to_ticks >= 0); @@ -401,7 +400,7 @@ timeout_at_ts(struct timeout *to, const struct timespec *abstime) mtx_enter(&timeout_mutex); - KASSERT(ISSET(to->to_flags, TIMEOUT_INITIALIZED | TIMEOUT_KCLOCK)); + KASSERT(ISSET(to->to_flags, TIMEOUT_INITIALIZED)); KASSERT(to->to_kclock != KCLOCK_NONE); old_abstime = to->to_abstime; @@ -506,13 +505,14 @@ timeout_barrier_timeout(void *arg) uint32_t timeout_bucket(const struct timeout *to) { - struct kclock *kc = &timeout_kclock[to->to_kclock]; struct timespec diff, shifted_abstime; + struct kclock *kc; uint32_t level; - KASSERT(ISSET(to->to_flags, TIMEOUT_KCLOCK)); - KASSERT(timespeccmp(&kc->kc_lastscan, &to->to_abstime, <)); + KASSERT(to->to_kclock == KCLOCK_UPTIME); + kc = &timeout_kclock[to->to_kclock]; + KASSERT(timespeccmp(&kc->kc_lastscan, &to->to_abstime, <)); timespecsub(&to->to_abstime, &kc->kc_lastscan, &diff); for (level = 0; level < nitems(timeout_level_width) - 1; level++) { if (diff.tv_sec < timeout_level_width[level]) @@ -725,7 +725,7 @@ softclock(void *arg) CIRCQ_REMOVE(&to->to_list); if (to == first_new) new = 1; - if (ISSET(to->to_flags, TIMEOUT_KCLOCK)) + if (to->to_kclock != KCLOCK_NONE) softclock_process_kclock_timeout(to, new); else softclock_process_tick_timeout(to, new); @@ -890,7 +890,7 @@ db_show_timeout(struct timeout *to, struct circq *bucket) else if (bucket == &timeout_proc) where = "thread"; else { - if (ISSET(to->to_flags, TIMEOUT_KCLOCK)) + if (to->to_kclock != KCLOCK_NONE) wheel = timeout_wheel_kc; else wheel = timeout_wheel; @@ -899,7 +899,7 @@ db_show_timeout(struct timeout *to, struct circq *bucket) (bucket - wheel) / WHEELSIZE); where = buf; } - if (ISSET(to->to_flags, TIMEOUT_KCLOCK)) { + if (to->to_kclock != KCLOCK_NONE) { kc = &timeout_kclock[to->to_kclock]; timespecsub(&to->to_abstime, &kc->kc_lastscan, &remaining); db_printf("%20s %8s %7s 0x%0*lx %s\n", diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h index 72874341f01..5aa3322e379 100644 --- a/sys/sys/timeout.h +++ b/sys/sys/timeout.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timeout.h,v 1.44 2022/11/08 19:09:53 cheloha Exp $ */ +/* $OpenBSD: timeout.h,v 1.45 2022/11/09 17:12:50 cheloha Exp $ */ /* * Copyright (c) 2000-2001 Artur Grabowski * All rights reserved. @@ -54,7 +54,6 @@ struct timeout { #define TIMEOUT_ONQUEUE 0x02 /* on any timeout queue */ #define TIMEOUT_INITIALIZED 0x04 /* initialized */ #define TIMEOUT_TRIGGERED 0x08 /* running or ran */ -#define TIMEOUT_KCLOCK 0x10 /* clock-based timeout */ struct timeoutstat { uint64_t tos_added; /* timeout_add*(9) calls */ @@ -99,7 +98,7 @@ int timeout_sysctl(void *, size_t *, void *, size_t); } #define TIMEOUT_INITIALIZER_KCLOCK(_fn, _arg, _kclock, _flags) \ - __TIMEOUT_INITIALIZER((_fn), (_arg), (_kclock), (_flags) | TIMEOUT_KCLOCK) + __TIMEOUT_INITIALIZER((_fn), (_arg), (_kclock), (_flags)) #define TIMEOUT_INITIALIZER_FLAGS(_fn, _arg, _flags) \ __TIMEOUT_INITIALIZER((_fn), (_arg), KCLOCK_NONE, (_flags))