Just grab the SCHED_LOCK() once in donice() before walking the ps_threads
authorclaudio <claudio@openbsd.org>
Wed, 22 May 2024 09:20:22 +0000 (09:20 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 22 May 2024 09:20:22 +0000 (09:20 +0000)
list. setpriority() is trivial and probably faster than releasing and
relocking SCHED_LOCK().
OK jca@

sys/kern/kern_resource.c

index 04247e3..6bc28d5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_resource.c,v 1.82 2024/05/20 10:32:20 claudio Exp $      */
+/*     $OpenBSD: kern_resource.c,v 1.83 2024/05/22 09:20:22 claudio Exp $      */
 /*     $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $      */
 
 /*-
@@ -213,11 +213,11 @@ donice(struct proc *curp, struct process *chgpr, int n)
                return (EACCES);
        chgpr->ps_nice = n;
        mtx_enter(&chgpr->ps_mtx);
+       SCHED_LOCK(s);
        TAILQ_FOREACH(p, &chgpr->ps_threads, p_thr_link) {
-               SCHED_LOCK(s);
                setpriority(p, p->p_estcpu, n);
-               SCHED_UNLOCK(s);
        }
+       SCHED_UNLOCK(s);
        mtx_leave(&chgpr->ps_mtx);
        return (0);
 }