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@.
This commit is contained in:
thorpej 2020-05-21 00:39:04 +00:00
parent db69dfa8a1
commit f20373e63a
1 changed files with 11 additions and 3 deletions

View File

@ -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, syncobj_t *sobj)
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);