From 14edc67da50a85d8cd0bdaf6ecbdc84586572985 Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Fri, 3 Mar 2000 16:49:26 +0000 Subject: Keep track of the number of times we trigger a reschedule before the context switch actually happens. --- sys/kern/kern_synch.c | 18 +++++++++++++++++- sys/sys/kernel.h | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 4262d75af69..99b9abc9f20 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.19 2000/03/03 11:46:09 art Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.20 2000/03/03 16:49:25 art Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -64,6 +64,14 @@ u_char curpriority; /* usrpri of curproc */ int lbolt; /* once a second sleep address */ +/* + * We need to keep track on how many times we call roundrobin before we + * actually attempt a switch (that is when we call mi_switch()). + * This is done so that some slow kernel subsystems can yield instead of + * blocking the scheduling. + */ +int roundrobin_attempts; + void roundrobin __P((void *)); void schedcpu __P((void *)); void updatepri __P((struct proc *)); @@ -79,6 +87,7 @@ roundrobin(arg) { need_resched(); + roundrobin_attempts++; timeout(roundrobin, NULL, hz / 10); } @@ -630,6 +639,13 @@ mi_switch() #endif cpu_switch(p); microtime(&runtime); + + /* + * We reset roundrobin_attempts at exit, because cpu_switch could + * have looped in the idle loop and the attempts would increase + * leading to unjust punishment of an innocent process. + */ + roundrobin_attempts = 0; } /* diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h index 6267f752a36..cfe2685c801 100644 --- a/sys/sys/kernel.h +++ b/sys/sys/kernel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kernel.h,v 1.5 1996/08/11 20:39:07 niklas Exp $ */ +/* $OpenBSD: kernel.h,v 1.6 2000/03/03 16:49:24 art Exp $ */ /* $NetBSD: kernel.h,v 1.11 1995/03/03 01:24:16 cgd Exp $ */ /*- @@ -67,5 +67,5 @@ extern int profhz; /* profiling clock's frequency */ extern int lbolt; /* once a second sleep address */ extern int tickdelta; extern long timedelta; - +extern int roundrobin_attempts; /* number switch attempts before switch */ -- cgit v1.2.3