summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1999-11-27 12:32:27 +0000
committerbde <bde@FreeBSD.org>1999-11-27 12:32:27 +0000
commit4955977bad69ae0939c6eede4d50f3c8e9f843bf (patch)
tree5e379c99576655a86acc625c1e7b89043b3b1cfe /sys/kern/kern_synch.c
parent6661b59c9e36f23b9cbcf25f513565c3a64a7392 (diff)
downloadFreeBSD-src-4955977bad69ae0939c6eede4d50f3c8e9f843bf.zip
FreeBSD-src-4955977bad69ae0939c6eede4d50f3c8e9f843bf.tar.gz
Moved scheduling-related code to kern_synch.c so that it is easier to fix
and extend. The new function containing the code is named schedclock() as in NetBSD, but it has slightly different semantics (it already handles incrementation of p->p_cpticks, and it should handle any calling frequency). Agreed with in principle by: dufault
Diffstat (limited to 'sys/kern/kern_synch.c')
-rw-r--r--sys/kern/kern_synch.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 4811669..f14980b 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -899,3 +899,29 @@ sched_setup(dummy)
schedcpu(NULL);
}
+/*
+ * We adjust the priority of the current process. The priority of
+ * a process gets worse as it accumulates CPU time. The cpu usage
+ * estimator (p_estcpu) is increased here. The formula for computing
+ * priorities (in kern_synch.c) will compute a different value each
+ * time p_estcpu increases by 4. The cpu usage estimator ramps up
+ * quite quickly when the process is running (linearly), and decays
+ * away exponentially, at a rate which is proportionally slower when
+ * the system is busy. The basic principal is that the system will
+ * 90% forget that the process used a lot of CPU time in 5 * loadav
+ * seconds. This causes the system to favor processes which haven't
+ * run much recently, and to round-robin among other processes.
+ */
+void
+schedclock(p)
+ struct proc *p;
+{
+ p->p_cpticks++;
+ if (++p->p_estcpu == 0)
+ p->p_estcpu--;
+ if ((p->p_estcpu & 3) == 0) {
+ resetpriority(p);
+ if (p->p_priority >= PUSER)
+ p->p_priority = p->p_usrpri;
+ }
+}
OpenPOWER on IntegriCloud