Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern In sleepq_insert(), in the SOBJ_SLEEPQ_SORTED case,...



details:   https://anonhg.NetBSD.org/src/rev/ea1bd8c231e4
branches:  trunk
changeset: 933178:ea1bd8c231e4
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu May 21 00:39:04 2020 +0000

description:
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@.

diffstat:

 sys/kern/kern_sleepq.c |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (43 lines):

diff -r cd02165accc6 -r ea1bd8c231e4 sys/kern/kern_sleepq.c
--- a/sys/kern/kern_sleepq.c    Wed May 20 21:05:21 2020 +0000
+++ b/sys/kern/kern_sleepq.c    Thu May 21 00:39:04 2020 +0000
@@ -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 @@
        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);



Home | Main Index | Thread Index | Old Index