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.
This commit is contained in:
ad 2020-05-23 21:24:41 +00:00
parent bbfbd151dc
commit d4834fad58
3 changed files with 40 additions and 18 deletions

View File

@ -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 @@ sched_enqueue(struct lwp *l)
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);
}

View File

@ -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 @@ static void resetpriority(struct lwp *);
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 @@ sched_tick(struct cpu_info *ci)
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 @@ static int
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 @@ SYSCTL_SETUP(sysctl_sched_4bsd_setup, "sysctl sched setup")
if (node == NULL)
return;
rrticks = hz / 10;
sched_rrticks = hz / 10;
sysctl_createv(NULL, 0, &node, NULL,
CTLFLAG_PERMANENT,

View File

@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.38 2020/04/13 15:54:45 maxv Exp $");
*/
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 @@ sched_rqinit(void)
/* 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 @@ sched_precalcts(void)
/* 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 @@ static int
sysctl_sched_rtts(SYSCTLFN_ARGS)
{
struct sysctlnode node;
int rttsms = hztoms(rt_ts);
int rttsms = hztoms(sched_rrticks);
node = *rnode;
node.sysctl_data = &rttsms;