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
This commit is contained in:
Ian Dowse 2001-10-20 13:10:43 +00:00
parent 41494fa079
commit 0eb6ce3169
3 changed files with 49 additions and 59 deletions

View File

@ -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)

View File

@ -85,7 +85,6 @@ void vm_waitproc __P((struct proc *));
int vm_mmap __P((vm_map_t, vm_offset_t *, vm_size_t, vm_prot_t, vm_prot_t, int, void *, vm_ooffset_t));
vm_offset_t vm_page_alloc_contig __P((vm_offset_t, vm_offset_t, vm_offset_t, vm_offset_t));
void vm_set_page_size __P((void));
void vmmeter __P((void));
struct vmspace *vmspace_alloc __P((vm_offset_t, vm_offset_t));
struct vmspace *vmspace_fork __P((struct vmspace *));
void vmspace_exec __P((struct proc *));

View File

@ -53,65 +53,10 @@
#include <vm/vm_object.h>
#include <sys/sysctl.h>
struct loadavg averunnable =
{ {0, 0, 0}, FSCALE }; /* load average, of runnable procs */
struct vmmeter cnt;
int maxslp = MAXSLP;
/*
* 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) */
};
/*
* 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;
}
void
vmmeter()
{
if (time_second % 5 == 0)
loadav(&averunnable);
}
SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min,
CTLFLAG_RW, &cnt.v_free_min, 0, "");
SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target,