diff options
author | iedowse <iedowse@FreeBSD.org> | 2001-10-20 13:10:43 +0000 |
---|---|---|
committer | iedowse <iedowse@FreeBSD.org> | 2001-10-20 13:10:43 +0000 |
commit | 03bd269b0899fdb2d1b7556e544aa8c6e9bf0dfd (patch) | |
tree | 8ced6dd43c7824877be01d746a8de6b1bdfd0963 /sys/kern/kern_synch.c | |
parent | 6d757ee04c83c073886837db363ab65da13a40d4 (diff) | |
download | FreeBSD-src-03bd269b0899fdb2d1b7556e544aa8c6e9bf0dfd.zip FreeBSD-src-03bd269b0899fdb2d1b7556e544aa8c6e9bf0dfd.tar.gz |
Move the code that computes the system load average from vm_meter.c
to kern_synch.c in preparation for adding some jitter to the
inter-sample time.
Note that the "vm.loadavg" sysctl still lives in vm_meter.c which
isn't the right place, but it is appropriate for the current (bad)
name of that sysctl.
Suggested by: jhb (some time ago)
Reviewed by: bde
Diffstat (limited to 'sys/kern/kern_synch.c')
-rw-r--r-- | sys/kern/kern_synch.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 45a6190..db5d51a 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -57,8 +57,6 @@ #include <sys/sysctl.h> #include <sys/sysproto.h> #include <sys/vmmeter.h> -#include <vm/vm.h> -#include <vm/vm_extern.h> #ifdef DDB #include <ddb/ddb.h> #endif @@ -79,7 +77,20 @@ int sched_quantum; /* Roundrobin scheduling quantum in ticks. */ static struct callout schedcpu_callout; static struct callout roundrobin_callout; +struct loadavg averunnable = + { {0, 0, 0}, FSCALE }; /* load average, of runnable procs */ +/* + * Constants for averages over 1, 5, and 15 minutes + * when sampling at 5 second intervals. + */ +static fixpt_t cexp[3] = { + 0.9200444146293232 * FSCALE, /* exp(-1/12) */ + 0.9834714538216174 * FSCALE, /* exp(-1/60) */ + 0.9944598480048967 * FSCALE, /* exp(-1/180) */ +}; + static void endtsleep __P((void *)); +static void loadav __P((struct loadavg *)); static void roundrobin __P((void *arg)); static void schedcpu __P((void *arg)); @@ -328,7 +339,8 @@ schedcpu(arg) mtx_unlock_spin(&sched_lock); } /* end of process loop */ sx_sunlock(&allproc_lock); - vmmeter(); + if (time_second % 5 == 0) + loadav(&averunnable); wakeup((caddr_t)&lbolt); callout_reset(&schedcpu_callout, hz, schedcpu, NULL); } @@ -844,6 +856,40 @@ resetpriority(kg) mtx_unlock_spin(&sched_lock); } +/* + * Compute a tenex style load average of a quantity on + * 1, 5 and 15 minute intervals. + * XXXKSE Needs complete rewrite when correct info is available. + * Completely Bogus.. only works with 1:1 (but compiles ok now :-) + */ +static void +loadav(struct loadavg *avg) +{ + int i, nrun; + struct proc *p; + struct ksegrp *kg; + + sx_slock(&allproc_lock); + nrun = 0; + FOREACH_PROC_IN_SYSTEM(p) { + FOREACH_KSEGRP_IN_PROC(p, kg) { + switch (p->p_stat) { + case SRUN: + if ((p->p_flag & P_NOLOAD) != 0) + goto nextproc; + /* FALLTHROUGH */ + case SIDL: + nrun++; + } +nextproc: + } + } + sx_sunlock(&allproc_lock); + for (i = 0; i < 3; i++) + avg->ldavg[i] = (cexp[i] * avg->ldavg[i] + + nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT; +} + /* ARGSUSED */ static void sched_setup(dummy) |