From: cheloha Date: Fri, 11 Nov 2022 18:09:58 +0000 (+0000) Subject: timeout(9): remove timeout_set_kclock(), TIMEOUT_INITIALIZER_KCLOCK() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7a7f8c7dd079fb1c77e110ada9b6a682912a4f24;p=openbsd timeout(9): remove timeout_set_kclock(), TIMEOUT_INITIALIZER_KCLOCK() We have too many timeout(9) initialization functions and macros. Let's slim it down and combine some interfaces. - Remove timeout_set_kclock(), TIMEOUT_INITIALIZER_KCLOCK(). - Expand timeout_set_flags(), TIMEOUT_INITIALIZER_FLAGS() to accept an additional "kclock" parameter. - Reimplement timeout_set(), timeout_set_proc() with timeout_set_flags(). - Reimplement TIMEOUT_INITIALIZER() with TIMEOUT_INITIALIZER_FLAGS(). - Update the sole timeout_set_flags() user to pass a kclock parameter. - Update the sole timeout_set_kclock() user to call timeout_set_flags(). - Update the sole TIMEOUT_INITIALIZER_FLAGS() user to provide a kclock parameter. The timeout(9) code is now a bit out of sync with the manpage. This will be corrected in a subsequent commit. ok kn@ --- diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index e02a40aa4a4..31fb7d61877 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.243 2022/11/02 07:20:07 guenther Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.244 2022/11/11 18:09:58 cheloha Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -198,7 +198,7 @@ process_initialize(struct process *pr, struct proc *p) rw_init(&pr->ps_lock, "pslock"); mtx_init(&pr->ps_mtx, IPL_HIGH); - timeout_set_kclock(&pr->ps_realit_to, realitexpire, pr, + timeout_set_flags(&pr->ps_realit_to, realitexpire, pr, KCLOCK_UPTIME, 0); timeout_set(&pr->ps_rucheck_to, rucheck, pr); } diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index df79bb4c82f..17d18394d4b 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_timeout.c,v 1.87 2022/11/09 17:12:50 cheloha Exp $ */ +/* $OpenBSD: kern_timeout.c,v 1.88 2022/11/11 18:09:58 cheloha Exp $ */ /* * Copyright (c) 2001 Thomas Nordin * Copyright (c) 2000-2001 Artur Grabowski @@ -251,39 +251,26 @@ timeout_proc_init(void) kthread_create_deferred(softclock_create_thread, NULL); } -static inline void -_timeout_set(struct timeout *to, void (*fn)(void *), void *arg, int kclock, - int flags) -{ - to->to_func = fn; - to->to_arg = arg; - to->to_kclock = kclock; - to->to_flags = flags | TIMEOUT_INITIALIZED; -} - void timeout_set(struct timeout *new, void (*fn)(void *), void *arg) { - _timeout_set(new, fn, arg, KCLOCK_NONE, 0); + timeout_set_flags(new, fn, arg, KCLOCK_NONE, 0); } void -timeout_set_flags(struct timeout *to, void (*fn)(void *), void *arg, int flags) +timeout_set_flags(struct timeout *to, void (*fn)(void *), void *arg, int kclock, + int flags) { - _timeout_set(to, fn, arg, KCLOCK_NONE, flags); + to->to_func = fn; + to->to_arg = arg; + to->to_kclock = kclock; + to->to_flags = flags | TIMEOUT_INITIALIZED; } void timeout_set_proc(struct timeout *new, void (*fn)(void *), void *arg) { - _timeout_set(new, fn, arg, KCLOCK_NONE, TIMEOUT_PROC); -} - -void -timeout_set_kclock(struct timeout *to, void (*fn)(void *), void *arg, - int kclock, int flags) -{ - _timeout_set(to, fn, arg, kclock, flags); + timeout_set_flags(new, fn, arg, KCLOCK_NONE, TIMEOUT_PROC); } int @@ -471,7 +458,8 @@ timeout_barrier(struct timeout *to) procflag = (to->to_flags & TIMEOUT_PROC); timeout_sync_order(procflag); - timeout_set_flags(&barrier, timeout_barrier_timeout, &c, procflag); + timeout_set_flags(&barrier, timeout_barrier_timeout, &c, KCLOCK_NONE, + procflag); barrier.to_process = curproc->p_p; cond_init(&c); diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c index 5da0622c337..b76314b69f5 100644 --- a/sys/netinet/ip_ipsp.c +++ b/sys/netinet/ip_ipsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipsp.c,v 1.274 2022/11/05 22:33:11 jan Exp $ */ +/* $OpenBSD: ip_ipsp.c,v 1.275 2022/11/11 18:09:58 cheloha Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -119,7 +119,7 @@ void ipsp_ids_gc(void *); LIST_HEAD(, ipsec_ids) ipsp_ids_gc_list = LIST_HEAD_INITIALIZER(ipsp_ids_gc_list); /* [F] */ struct timeout ipsp_ids_gc_timeout = - TIMEOUT_INITIALIZER_FLAGS(ipsp_ids_gc, NULL, TIMEOUT_PROC); + TIMEOUT_INITIALIZER_FLAGS(ipsp_ids_gc, NULL, KCLOCK_NONE, TIMEOUT_PROC); static inline int ipsp_ids_cmp(const struct ipsec_ids *, const struct ipsec_ids *); diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h index 5aa3322e379..bdb437c4c70 100644 --- a/sys/sys/timeout.h +++ b/sys/sys/timeout.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timeout.h,v 1.45 2022/11/09 17:12:50 cheloha Exp $ */ +/* $OpenBSD: timeout.h,v 1.46 2022/11/11 18:09:58 cheloha Exp $ */ /* * Copyright (c) 2000-2001 Artur Grabowski * All rights reserved. @@ -87,7 +87,7 @@ int timeout_sysctl(void *, size_t *, void *, size_t); #define KCLOCK_UPTIME 0 /* uptime clock; time since boot */ #define KCLOCK_MAX 1 -#define __TIMEOUT_INITIALIZER(_fn, _arg, _kclock, _flags) { \ +#define TIMEOUT_INITIALIZER_FLAGS(_fn, _arg, _kclock, _flags) { \ .to_list = { NULL, NULL }, \ .to_abstime = { .tv_sec = 0, .tv_nsec = 0 }, \ .to_func = (_fn), \ @@ -97,18 +97,11 @@ int timeout_sysctl(void *, size_t *, void *, size_t); .to_kclock = (_kclock) \ } -#define TIMEOUT_INITIALIZER_KCLOCK(_fn, _arg, _kclock, _flags) \ - __TIMEOUT_INITIALIZER((_fn), (_arg), (_kclock), (_flags)) - -#define TIMEOUT_INITIALIZER_FLAGS(_fn, _arg, _flags) \ - __TIMEOUT_INITIALIZER((_fn), (_arg), KCLOCK_NONE, (_flags)) - #define TIMEOUT_INITIALIZER(_f, _a) \ - __TIMEOUT_INITIALIZER((_f), (_a), KCLOCK_NONE, 0) + TIMEOUT_INITIALIZER_FLAGS((_f), (_a), KCLOCK_NONE, 0) void timeout_set(struct timeout *, void (*)(void *), void *); -void timeout_set_flags(struct timeout *, void (*)(void *), void *, int); -void timeout_set_kclock(struct timeout *, void (*)(void *), void *, int, int); +void timeout_set_flags(struct timeout *, void (*)(void *), void *, int, int); void timeout_set_proc(struct timeout *, void (*)(void *), void *); int timeout_add(struct timeout *, int);