From f2e7dc09fb2f409a01fd83b5f163766b8278c3f6 Mon Sep 17 00:00:00 2001 From: claudio Date: Fri, 14 Jul 2023 07:07:08 +0000 Subject: [PATCH] struct sleep_state is no longer used, remove it. Also remove the priority argument to sleep_finish() the code can use the p_flag P_SINTR flag to know if the signal check is needed or not. OK cheloha@ kettenis@ mpi@ --- sys/dev/dt/dt_dev.c | 7 +++---- sys/dev/pci/drm/drm_linux.c | 7 +++---- sys/dev/pci/if_myx.c | 7 +++---- sys/kern/kern_rwlock.c | 7 +++---- sys/kern/kern_sched.c | 7 +++---- sys/kern/kern_sig.c | 7 +++---- sys/kern/kern_synch.c | 34 ++++++++++++++-------------------- sys/kern/kern_timeout.c | 7 +++---- sys/kern/subr_log.c | 8 +++----- sys/sys/proc.h | 6 +----- sys/sys/systm.h | 8 +++----- 11 files changed, 42 insertions(+), 63 deletions(-) diff --git a/sys/dev/dt/dt_dev.c b/sys/dev/dt/dt_dev.c index 4236a6fc90f..a103c4067ef 100644 --- a/sys/dev/dt/dt_dev.c +++ b/sys/dev/dt/dt_dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_dev.c,v 1.27 2023/06/28 08:23:25 claudio Exp $ */ +/* $OpenBSD: dt_dev.c,v 1.28 2023/07/14 07:07:08 claudio Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -224,7 +224,6 @@ dtclose(dev_t dev, int flags, int mode, struct proc *p) int dtread(dev_t dev, struct uio *uio, int flags) { - struct sleep_state sls; struct dt_softc *sc; struct dt_evt *estq; struct dt_pcb *dp; @@ -240,8 +239,8 @@ dtread(dev_t dev, struct uio *uio, int flags) return (EMSGSIZE); while (!sc->ds_evtcnt) { - sleep_setup(&sls, sc, PWAIT | PCATCH, "dtread"); - error = sleep_finish(&sls, PWAIT | PCATCH, 0, !sc->ds_evtcnt); + sleep_setup(sc, PWAIT | PCATCH, "dtread"); + error = sleep_finish(0, !sc->ds_evtcnt); if (error == EINTR || error == ERESTART) break; } diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index d710aebc5f0..3b34d4285e3 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.99 2023/06/28 08:23:25 claudio Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.100 2023/07/14 07:07:08 claudio Exp $ */ /* * Copyright (c) 2013 Jonathan Gray * Copyright (c) 2015, 2016 Mark Kettenis @@ -133,7 +133,6 @@ schedule(void) long schedule_timeout(long timeout) { - struct sleep_state sls; unsigned long deadline; int wait, spl, prio, timo = 0; @@ -143,7 +142,7 @@ schedule_timeout(long timeout) if (timeout != MAX_SCHEDULE_TIMEOUT) timo = timeout; prio = sch_priority; - sleep_setup(&sls, sch_ident, prio, "schto"); + sleep_setup(sch_ident, prio, "schto"); wait = (sch_proc == curproc && timeout > 0); @@ -153,7 +152,7 @@ schedule_timeout(long timeout) if (timeout != MAX_SCHEDULE_TIMEOUT) deadline = jiffies + timeout; - sleep_finish(&sls, prio, timo, wait); + sleep_finish(timo, wait); if (timeout != MAX_SCHEDULE_TIMEOUT) timeout = deadline - jiffies; diff --git a/sys/dev/pci/if_myx.c b/sys/dev/pci/if_myx.c index 4b07f0b97dd..a4084487d32 100644 --- a/sys/dev/pci/if_myx.c +++ b/sys/dev/pci/if_myx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_myx.c,v 1.117 2023/06/28 08:23:25 claudio Exp $ */ +/* $OpenBSD: if_myx.c,v 1.118 2023/07/14 07:07:08 claudio Exp $ */ /* * Copyright (c) 2007 Reyk Floeter @@ -1377,7 +1377,6 @@ myx_down(struct myx_softc *sc) struct ifnet *ifp = &sc->sc_ac.ac_if; volatile struct myx_status *sts = sc->sc_sts; bus_dmamap_t map = sc->sc_sts_dma.mxm_map; - struct sleep_state sls; struct myx_cmd mc; int s; int ring; @@ -1397,9 +1396,9 @@ myx_down(struct myx_softc *sc) (void)myx_cmd(sc, MYXCMD_SET_IFDOWN, &mc, NULL); while (sc->sc_state != MYX_S_OFF) { - sleep_setup(&sls, sts, PWAIT, "myxdown"); + sleep_setup(sts, PWAIT, "myxdown"); membar_consumer(); - sleep_finish(&sls, PWAIT, 0, sc->sc_state != MYX_S_OFF); + sleep_finish(0, sc->sc_state != MYX_S_OFF); } s = splnet(); diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 17e00fedaa3..4e3ac524808 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_rwlock.c,v 1.49 2023/06/28 08:23:25 claudio Exp $ */ +/* $OpenBSD: kern_rwlock.c,v 1.50 2023/07/14 07:07:08 claudio Exp $ */ /* * Copyright (c) 2002, 2003 Artur Grabowski @@ -224,7 +224,6 @@ int rw_enter(struct rwlock *rwl, int flags) { const struct rwlock_op *op; - struct sleep_state sls; unsigned long inc, o; #ifdef MULTIPROCESSOR /* @@ -279,11 +278,11 @@ retry: prio = op->wait_prio; if (flags & RW_INTR) prio |= PCATCH; - sleep_setup(&sls, rwl, prio, rwl->rwl_name); + sleep_setup(rwl, prio, rwl->rwl_name); do_sleep = !rw_cas(&rwl->rwl_owner, o, set); - error = sleep_finish(&sls, prio, 0, do_sleep); + error = sleep_finish(0, do_sleep); if ((flags & RW_INTR) && (error != 0)) return (error); diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 7fae2f8df33..f4ac3817711 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.78 2023/07/11 07:02:43 claudio Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.79 2023/07/14 07:07:08 claudio Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski * @@ -669,13 +669,12 @@ sched_stop_secondary_cpus(void) } CPU_INFO_FOREACH(cii, ci) { struct schedstate_percpu *spc = &ci->ci_schedstate; - struct sleep_state sls; if (CPU_IS_PRIMARY(ci) || !CPU_IS_RUNNING(ci)) continue; while ((spc->spc_schedflags & SPCF_HALTED) == 0) { - sleep_setup(&sls, spc, PZERO, "schedstate"); - sleep_finish(&sls, PZERO, 0, + sleep_setup(spc, PZERO, "schedstate"); + sleep_finish(0, (spc->spc_schedflags & SPCF_HALTED) == 0); } } diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index d46b229acc9..fba5f72d8bf 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.309 2023/07/11 07:02:43 claudio Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.310 2023/07/14 07:07:08 claudio Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -2164,15 +2164,14 @@ single_thread_set(struct proc *p, enum single_thread_mode mode, int wait) int single_thread_wait(struct process *pr, int recheck) { - struct sleep_state sls; int wait; /* wait until they're all suspended */ wait = pr->ps_singlecount > 0; while (wait) { - sleep_setup(&sls, &pr->ps_singlecount, PWAIT, "suspend"); + sleep_setup(&pr->ps_singlecount, PWAIT, "suspend"); wait = pr->ps_singlecount > 0; - sleep_finish(&sls, PWAIT, 0, wait); + sleep_finish(0, wait); if (!recheck) break; } diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index c856ab7903d..d4087b5fcce 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.194 2023/07/11 07:02:43 claudio Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.195 2023/07/14 07:07:08 claudio Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -115,7 +115,6 @@ extern int safepri; int tsleep(const volatile void *ident, int priority, const char *wmesg, int timo) { - struct sleep_state sls; #ifdef MULTIPROCESSOR int hold_count; #endif @@ -151,8 +150,8 @@ tsleep(const volatile void *ident, int priority, const char *wmesg, int timo) return (0); } - sleep_setup(&sls, ident, priority, wmesg); - return sleep_finish(&sls, priority, timo, 1); + sleep_setup(ident, priority, wmesg); + return sleep_finish(timo, 1); } int @@ -206,7 +205,6 @@ int msleep(const volatile void *ident, struct mutex *mtx, int priority, const char *wmesg, int timo) { - struct sleep_state sls; int error, spl; #ifdef MULTIPROCESSOR int hold_count; @@ -244,11 +242,11 @@ msleep(const volatile void *ident, struct mutex *mtx, int priority, return (0); } - sleep_setup(&sls, ident, priority, wmesg); + sleep_setup(ident, priority, wmesg); mtx_leave(mtx); /* signal may stop the process, release mutex before that */ - error = sleep_finish(&sls, priority, timo, 1); + error = sleep_finish(timo, 1); if ((priority & PNORELOCK) == 0) mtx_enter(mtx); @@ -287,7 +285,6 @@ int rwsleep(const volatile void *ident, struct rwlock *rwl, int priority, const char *wmesg, int timo) { - struct sleep_state sls; int error, status; KASSERT((priority & ~(PRIMASK | PCATCH | PNORELOCK)) == 0); @@ -296,11 +293,11 @@ rwsleep(const volatile void *ident, struct rwlock *rwl, int priority, rw_assert_anylock(rwl); status = rw_status(rwl); - sleep_setup(&sls, ident, priority, wmesg); + sleep_setup(ident, priority, wmesg); rw_exit(rwl); /* signal may stop the process, release rwlock before that */ - error = sleep_finish(&sls, priority, timo, 1); + error = sleep_finish(timo, 1); if ((priority & PNORELOCK) == 0) rw_enter(rwl, status); @@ -332,8 +329,7 @@ rwsleep_nsec(const volatile void *ident, struct rwlock *rwl, int priority, } void -sleep_setup(struct sleep_state *sls, const volatile void *ident, int prio, - const char *wmesg) +sleep_setup(const volatile void *ident, int prio, const char *wmesg) { struct proc *p = curproc; int s; @@ -365,12 +361,12 @@ sleep_setup(struct sleep_state *sls, const volatile void *ident, int prio, } int -sleep_finish(struct sleep_state *sls, int prio, int timo, int do_sleep) +sleep_finish(int timo, int do_sleep) { struct proc *p = curproc; int s, catch, error = 0, error1 = 0; - catch = prio & PCATCH; + catch = p->p_flag & P_SINTR; if (timo != 0) { KASSERT((p->p_flag & P_TIMEOUT) == 0); @@ -825,7 +821,6 @@ refcnt_rele_wake(struct refcnt *r) void refcnt_finalize(struct refcnt *r, const char *wmesg) { - struct sleep_state sls; u_int refs; membar_exit_before_atomic(); @@ -833,9 +828,9 @@ refcnt_finalize(struct refcnt *r, const char *wmesg) KASSERT(refs != ~0); TRACEINDEX(refcnt, r->r_traceidx, r, refs + 1, -1); while (refs) { - sleep_setup(&sls, r, PWAIT, wmesg); + sleep_setup(r, PWAIT, wmesg); refs = atomic_load_int(&r->r_refs); - sleep_finish(&sls, PWAIT, 0, refs); + sleep_finish(0, refs); } TRACEINDEX(refcnt, r->r_traceidx, r, refs, 0); /* Order subsequent loads and stores after refs == 0 load. */ @@ -879,13 +874,12 @@ cond_signal(struct cond *c) void cond_wait(struct cond *c, const char *wmesg) { - struct sleep_state sls; unsigned int wait; wait = atomic_load_int(&c->c_wait); while (wait) { - sleep_setup(&sls, c, PWAIT, wmesg); + sleep_setup(c, PWAIT, wmesg); wait = atomic_load_int(&c->c_wait); - sleep_finish(&sls, PWAIT, 0, wait); + sleep_finish(0, wait); } } diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index b20616e7e3d..4ca81ad42df 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_timeout.c,v 1.93 2023/07/06 23:24:37 cheloha Exp $ */ +/* $OpenBSD: kern_timeout.c,v 1.94 2023/07/14 07:07:08 claudio Exp $ */ /* * Copyright (c) 2001 Thomas Nordin * Copyright (c) 2000-2001 Artur Grabowski @@ -735,7 +735,6 @@ softclock_thread(void *arg) { CPU_INFO_ITERATOR cii; struct cpu_info *ci; - struct sleep_state sls; struct timeout *to; int s; @@ -751,8 +750,8 @@ softclock_thread(void *arg) s = splsoftclock(); for (;;) { - sleep_setup(&sls, &timeout_proc, PSWP, "bored"); - sleep_finish(&sls, PSWP, 0, CIRCQ_EMPTY(&timeout_proc)); + sleep_setup(&timeout_proc, PSWP, "bored"); + sleep_finish(0, CIRCQ_EMPTY(&timeout_proc)); mtx_enter(&timeout_mutex); while (!CIRCQ_EMPTY(&timeout_proc)) { diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index 1f4ae515bfa..12bd44e7ca3 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_log.c,v 1.76 2023/06/28 08:23:25 claudio Exp $ */ +/* $OpenBSD: subr_log.c,v 1.77 2023/07/14 07:07:08 claudio Exp $ */ /* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */ /* @@ -233,7 +233,6 @@ logclose(dev_t dev, int flag, int mode, struct proc *p) int logread(dev_t dev, struct uio *uio, int flag) { - struct sleep_state sls; struct msgbuf *mbp = msgbufp; size_t l, rpos; int error = 0; @@ -250,9 +249,8 @@ logread(dev_t dev, struct uio *uio, int flag) * Set up and enter sleep manually instead of using msleep() * to keep log_mtx as a leaf lock. */ - sleep_setup(&sls, mbp, LOG_RDPRI | PCATCH, "klog"); - error = sleep_finish(&sls, LOG_RDPRI | PCATCH, 0, - logsoftc.sc_state & LOG_RDWAIT); + sleep_setup(mbp, LOG_RDPRI | PCATCH, "klog"); + error = sleep_finish(0, logsoftc.sc_state & LOG_RDWAIT); mtx_enter(&log_mtx); if (error) goto out; diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 619539e7f1b..e2013954966 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.345 2023/07/11 07:02:43 claudio Exp $ */ +/* $OpenBSD: proc.h,v 1.346 2023/07/14 07:07:08 claudio Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -585,10 +585,6 @@ void child_return(void *); int proc_cansugid(struct proc *); -struct sleep_state { - int sls_s; -}; - struct cond { unsigned int c_wait; /* [a] initialized and waiting */ }; diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 29115bc0368..8511338ef59 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.162 2023/06/28 08:23:25 claudio Exp $ */ +/* $OpenBSD: systm.h,v 1.163 2023/07/14 07:07:08 claudio Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -249,10 +249,8 @@ void setstatclockrate(int); void start_periodic_resettodr(void); void stop_periodic_resettodr(void); -struct sleep_state; -void sleep_setup(struct sleep_state *, const volatile void *, int, - const char *); -int sleep_finish(struct sleep_state *, int, int, int); +void sleep_setup(const volatile void *, int, const char *); +int sleep_finish(int, int); void sleep_queue_init(void); struct cond; -- 2.20.1