Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Oops. If a SCHED_RR thread is preempted and has ex...
details: https://anonhg.NetBSD.org/src/rev/260c75d078d0
branches: trunk
changeset: 1010360:260c75d078d0
user: ad <ad%NetBSD.org@localhost>
date: Sat May 23 21:24:41 2020 +0000
description:
Oops. If a SCHED_RR thread is preempted and has exceeded its timeslice it
needs to go to the back of the run queue so round-robin actually happens,
otherwise it should go to the front.
diffstat:
sys/kern/kern_runq.c | 32 +++++++++++++++++++++++++++-----
sys/kern/sched_4bsd.c | 14 +++++++-------
sys/kern/sched_m2.c | 12 ++++++------
3 files changed, 40 insertions(+), 18 deletions(-)
diffs (168 lines):
diff -r 699637bcab4c -r 260c75d078d0 sys/kern/kern_runq.c
--- a/sys/kern/kern_runq.c Sat May 23 21:14:55 2020 +0000
+++ b/sys/kern/kern_runq.c Sat May 23 21:24:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_runq.c,v 1.68 2020/05/23 21:14:55 ad Exp $ */
+/* $NetBSD: kern_runq.c,v 1.69 2020/05/23 21:24:41 ad Exp $ */
/*-
* Copyright (c) 2019, 2020 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.68 2020/05/23 21:14:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.69 2020/05/23 21:24:41 ad Exp $");
#include "opt_dtrace.h"
@@ -206,9 +206,31 @@
KASSERT((spc->spc_bitmap[i] & q) == 0);
spc->spc_bitmap[i] |= q;
}
- /* Preempted SCHED_RR and SCHED_FIFO LWPs go to the queue head. */
- if (l->l_class != SCHED_OTHER && (l->l_pflag & LP_PREEMPTING) != 0) {
- TAILQ_INSERT_HEAD(q_head, l, l_runq);
+
+ /*
+ * Determine run queue position according to POSIX. XXX Explicitly
+ * lowering a thread's priority with pthread_setschedparam() is not
+ * handled.
+ */
+ if ((l->l_pflag & LP_PREEMPTING) != 0) {
+ switch (l->l_class) {
+ case SCHED_OTHER:
+ TAILQ_INSERT_TAIL(q_head, l, l_runq);
+ break;
+ case SCHED_FIFO:
+ TAILQ_INSERT_HEAD(q_head, l, l_runq);
+ break;
+ case SCHED_RR:
+ if (getticks() - l->l_rticks >= sched_rrticks) {
+ TAILQ_INSERT_TAIL(q_head, l, l_runq);
+ } else {
+ TAILQ_INSERT_HEAD(q_head, l, l_runq);
+ }
+ break;
+ default: /* SCHED_OTHER */
+ panic("sched_enqueue: LWP %p has class %d\n",
+ l, l->l_class);
+ }
} else {
TAILQ_INSERT_TAIL(q_head, l, l_runq);
}
diff -r 699637bcab4c -r 260c75d078d0 sys/kern/sched_4bsd.c
--- a/sys/kern/sched_4bsd.c Sat May 23 21:14:55 2020 +0000
+++ b/sys/kern/sched_4bsd.c Sat May 23 21:24:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sched_4bsd.c,v 1.43 2020/03/12 10:44:00 ad Exp $ */
+/* $NetBSD: sched_4bsd.c,v 1.44 2020/05/23 21:24:41 ad Exp $ */
/*
* Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2019, 2020
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.43 2020/03/12 10:44:00 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.44 2020/05/23 21:24:41 ad Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@@ -93,11 +93,11 @@
extern unsigned int sched_pstats_ticks; /* defined in kern_synch.c */
/* Number of hardclock ticks per sched_tick() */
-static int rrticks __read_mostly;
+u_int sched_rrticks __read_mostly;
/*
* Force switch among equal priority processes every 100ms.
- * Called from hardclock every hz/10 == rrticks hardclock ticks.
+ * Called from hardclock every hz/10 == sched_rrticks hardclock ticks.
*/
/* ARGSUSED */
void
@@ -107,7 +107,7 @@
pri_t pri = PRI_NONE;
lwp_t *l;
- spc->spc_ticks = rrticks;
+ spc->spc_ticks = sched_rrticks;
if (CURCPU_IDLE_P()) {
spc_lock(ci);
@@ -534,7 +534,7 @@
sysctl_sched_rtts(SYSCTLFN_ARGS)
{
struct sysctlnode node;
- int rttsms = hztoms(rrticks);
+ int rttsms = hztoms(sched_rrticks);
node = *rnode;
node.sysctl_data = &rttsms;
@@ -555,7 +555,7 @@
if (node == NULL)
return;
- rrticks = hz / 10;
+ sched_rrticks = hz / 10;
sysctl_createv(NULL, 0, &node, NULL,
CTLFLAG_PERMANENT,
diff -r 699637bcab4c -r 260c75d078d0 sys/kern/sched_m2.c
--- a/sys/kern/sched_m2.c Sat May 23 21:14:55 2020 +0000
+++ b/sys/kern/sched_m2.c Sat May 23 21:24:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sched_m2.c,v 1.38 2020/04/13 15:54:45 maxv Exp $ */
+/* $NetBSD: sched_m2.c,v 1.39 2020/05/23 21:24:41 ad Exp $ */
/*
* Copyright (c) 2007, 2008 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.38 2020/04/13 15:54:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.39 2020/05/23 21:24:41 ad Exp $");
#include <sys/param.h>
@@ -68,9 +68,9 @@
*/
static u_int min_ts; /* Minimal time-slice */
static u_int max_ts; /* Maximal time-slice */
-static u_int rt_ts; /* Real-time time-slice */
static u_int ts_map[PRI_COUNT]; /* Map of time-slices */
static pri_t high_pri[PRI_COUNT]; /* Map for priority increase */
+u_int sched_rrticks; /* Real-time time-slice */
static void sched_precalcts(void);
@@ -88,7 +88,7 @@
/* Default timing ranges */
min_ts = mstohz(20); /* ~20 ms */
max_ts = mstohz(150); /* ~150 ms */
- rt_ts = mstohz(100); /* ~100 ms */
+ sched_rrticks = mstohz(100); /* ~100 ms */
sched_precalcts();
#ifdef notdef
@@ -117,7 +117,7 @@
/* Real-time range */
for (p = (PRI_HIGHEST_TS + 1); p < PRI_COUNT; p++) {
- ts_map[p] = rt_ts;
+ ts_map[p] = sched_rrticks;
high_pri[p] = p;
}
}
@@ -346,7 +346,7 @@
sysctl_sched_rtts(SYSCTLFN_ARGS)
{
struct sysctlnode node;
- int rttsms = hztoms(rt_ts);
+ int rttsms = hztoms(sched_rrticks);
node = *rnode;
node.sysctl_data = &rttsms;
Home |
Main Index |
Thread Index |
Old Index