From: claudio Date: Thu, 1 Jun 2023 10:21:26 +0000 (+0000) Subject: Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e1b95daa9c75b7a97465b33c5093d2e4513e3d52;p=openbsd Change wakeup_proc() to no longer grab the SCHED_LOCK() instead it must be called with SCHED_LOCK() held. Also add an extra argument to update the process flags p_flag so that the timeout handler can set the P_TIMEOUT flag before making the process runnable. OK mpi@ --- diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index bcec033e2a1..fb2dfe029d2 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.97 2023/03/15 08:24:56 jsg Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.98 2023/06/01 10:21:26 claudio Exp $ */ /* * Copyright (c) 2013 Jonathan Gray * Copyright (c) 2015, 2016 Mark Kettenis @@ -173,8 +173,13 @@ schedule_timeout_uninterruptible(long timeout) int wake_up_process(struct proc *p) { + int s, rv; + + SCHED_LOCK(s); atomic_cas_ptr(&sch_proc, p, NULL); - return wakeup_proc(p, NULL); + rv = wakeup_proc(p, NULL, 0); + SCHED_UNLOCK(s); + return rv; } void diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index fd97013cb26..8165d2f27b8 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.191 2023/02/15 20:43:41 mvs Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.192 2023/06/01 10:21:26 claudio Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -470,20 +470,22 @@ sleep_signal_check(void) } int -wakeup_proc(struct proc *p, const volatile void *chan) +wakeup_proc(struct proc *p, const volatile void *chan, int flags) { - int s, awakened = 0; + int awakened = 0; + + SCHED_ASSERT_LOCKED(); - SCHED_LOCK(s); if (p->p_wchan != NULL && ((chan == NULL) || (p->p_wchan == chan))) { awakened = 1; + if (flags) + atomic_setbits_int(&p->p_flag, flags); if (p->p_stat == SSLEEP) setrunnable(p); else unsleep(p); } - SCHED_UNLOCK(s); return awakened; } @@ -502,8 +504,7 @@ endtsleep(void *arg) int s; SCHED_LOCK(s); - if (wakeup_proc(p, NULL)) - atomic_setbits_int(&p->p_flag, P_TIMEOUT); + wakeup_proc(p, NULL, P_TIMEOUT); SCHED_UNLOCK(s); } @@ -548,7 +549,7 @@ wakeup_n(const volatile void *ident, int n) if (p->p_stat != SSLEEP && p->p_stat != SSTOP) panic("wakeup: p_stat is %d", (int)p->p_stat); #endif - if (wakeup_proc(p, ident)) + if (wakeup_proc(p, ident, 0)) --n; } SCHED_UNLOCK(s); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 60003397cd8..d25db222d61 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.340 2023/04/25 18:14:06 claudio Exp $ */ +/* $OpenBSD: proc.h,v 1.341 2023/06/01 10:21:26 claudio Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -542,7 +542,7 @@ void procinit(void); void setpriority(struct proc *, uint32_t, uint8_t); void setrunnable(struct proc *); void endtsleep(void *); -int wakeup_proc(struct proc *, const volatile void *); +int wakeup_proc(struct proc *, const volatile void *, int); void unsleep(struct proc *); void reaper(void *); __dead void exit1(struct proc *, int, int, int);