Module Name: src Committed By: thorpej Date: Thu May 21 00:39:04 UTC 2020
Modified Files: src/sys/kern: kern_sleepq.c Log Message: In sleepq_insert(), in the SOBJ_SLEEPQ_SORTED case, if there are existing waiters of lower priority, then the new LWP will be inserted in FIFO order with respect to other LWPs of the same priority. However, if all other LWPs are of equal priority to the LWP being inserted, the new LWP would be inserted in LIFO order. Fix this to always insert in FIFO order with respect to equal priority LWPs. OK ad@. To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 src/sys/kern/kern_sleepq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_sleepq.c diff -u src/sys/kern/kern_sleepq.c:1.67 src/sys/kern/kern_sleepq.c:1.68 --- src/sys/kern/kern_sleepq.c:1.67 Fri May 8 03:26:51 2020 +++ src/sys/kern/kern_sleepq.c Thu May 21 00:39:04 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sleepq.c,v 1.67 2020/05/08 03:26:51 thorpej Exp $ */ +/* $NetBSD: kern_sleepq.c,v 1.68 2020/05/21 00:39:04 thorpej Exp $ */ /*- * Copyright (c) 2006, 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.67 2020/05/08 03:26:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.68 2020/05/21 00:39:04 thorpej Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -188,15 +188,23 @@ sleepq_insert(sleepq_t *sq, lwp_t *l, sy KASSERT(sq != NULL); if ((sobj->sobj_flag & SOBJ_SLEEPQ_SORTED) != 0) { - lwp_t *l2; + lwp_t *l2, *l_last = NULL; const pri_t pri = lwp_eprio(l); LIST_FOREACH(l2, sq, l_sleepchain) { + l_last = l2; if (lwp_eprio(l2) < pri) { LIST_INSERT_BEFORE(l2, l, l_sleepchain); return; } } + /* + * Ensure FIFO ordering if no waiters are of lower priority. + */ + if (l_last != NULL) { + LIST_INSERT_AFTER(l_last, l, l_sleepchain); + return; + } } LIST_INSERT_HEAD(sq, l, l_sleepchain);