sched_tick:

- Do timeslicing for SCHED_RR threads. At ~16Hz it's too slow but better
  than nothing. XXX

- If a SCHED_OTHER thread has hogged the CPU for 1/8s without taking a
  trip through mi_switch(), try to force a kernel preemption to give other
  threads a chance.
This commit is contained in:
ad 2008-05-25 22:04:50 +00:00
parent 5db879ef65
commit 90035a10c9

View File

@ -1,4 +1,4 @@
/* $NetBSD: sched_4bsd.c,v 1.22 2008/05/19 12:48:54 rmind Exp $ */
/* $NetBSD: sched_4bsd.c,v 1.23 2008/05/25 22:04:50 ad Exp $ */
/*-
* Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.22 2008/05/19 12:48:54 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.23 2008/05/25 22:04:50 ad Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@ -111,6 +111,7 @@ void
sched_tick(struct cpu_info *ci)
{
struct schedstate_percpu *spc = &ci->ci_schedstate;
lwp_t *l;
spc->spc_ticks = rrticks;
@ -118,19 +119,39 @@ sched_tick(struct cpu_info *ci)
cpu_need_resched(ci, 0);
return;
}
if (curlwp->l_class == SCHED_FIFO) {
l = ci->ci_data.cpu_onproc;
if (l == NULL) {
return;
}
if (spc->spc_flags & SPCF_SEENRR) {
/*
* The process has already been through a roundrobin
* without switching and may be hogging the CPU.
* Indicate that the process should yield.
*/
spc->spc_flags |= SPCF_SHOULDYIELD;
cpu_need_resched(ci, 0);
} else
spc->spc_flags |= SPCF_SEENRR;
switch (l->l_class) {
case SCHED_FIFO:
/* No timeslicing for FIFO jobs. */
break;
case SCHED_RR:
/* Force it into mi_switch() to look for other jobs to run. */
cpu_need_resched(ci, RESCHED_KPREEMPT);
break;
default:
if (spc->spc_flags & SPCF_SHOULDYIELD) {
/*
* Process is stuck in kernel somewhere, probably
* due to buggy or inefficient code. Force a
* kernel preemption.
*/
cpu_need_resched(ci, RESCHED_KPREEMPT);
} else if (spc->spc_flags & SPCF_SEENRR) {
/*
* The process has already been through a roundrobin
* without switching and may be hogging the CPU.
* Indicate that the process should yield.
*/
spc->spc_flags |= SPCF_SHOULDYIELD;
cpu_need_resched(ci, 0);
} else {
spc->spc_flags |= SPCF_SEENRR;
}
break;
}
}
/*