change %cpu constant; new disk monitoring/cpu scheme
[unix-history] / usr / src / sys / kern / kern_clock.c
index 4535d2f..3247eda 100644 (file)
@@ -1,4 +1,4 @@
-/*     %H%     3.14    kern_clock.c    */
+/*     %H%     3.21    kern_clock.c    */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/vm.h"
 #include "../h/buf.h"
 #include "../h/text.h"
 #include "../h/vm.h"
 #include "../h/buf.h"
 #include "../h/text.h"
+#include "../h/vlimit.h"
+#include "../h/mtpr.h"
+#include "../h/clock.h"
 
 #define        SCHMAG  9/10
 
 
 #define        SCHMAG  9/10
 
+/*
+ * Constant for decay filter for cpu usage.
+ */
+double ccpu = 0.95122942450071400909;          /* exp(-1/20) */
 
 /*
 
 /*
- * clock is called straight from
+ * Clock is called straight from
  * the real time clock interrupt.
  *
  * Functions:
  * the real time clock interrupt.
  *
  * Functions:
@@ -47,7 +54,7 @@ caddr_t pc;
        register struct callo *p1, *p2;
        register struct proc *pp;
        register int s;
        register struct callo *p1, *p2;
        register struct proc *pp;
        register int s;
-       int a, cpstate;
+       int a, cpstate, i;
 
        /*
         * reprime clock
 
        /*
         * reprime clock
@@ -125,6 +132,11 @@ out:
                }
                if (s > u.u_vm.vm_maxrss)
                        u.u_vm.vm_maxrss = s;
                }
                if (s > u.u_vm.vm_maxrss)
                        u.u_vm.vm_maxrss = s;
+               if ((u.u_vm.vm_utime+u.u_vm.vm_stime+1)/HZ > u.u_limit[LIM_CPU]) {
+                       psignal(u.u_procp, SIGXCPU);
+                       if (u.u_limit[LIM_CPU] < INFINITY - 5)
+                               u.u_limit[LIM_CPU] += 5;
+               }
        }
        if (USERMODE(ps)) {
                u.u_vm.vm_utime++;
        }
        if (USERMODE(ps)) {
                u.u_vm.vm_utime++;
@@ -139,9 +151,13 @@ out:
                else
                        u.u_vm.vm_stime++;
        }
                else
                        u.u_vm.vm_stime++;
        }
-       dk_time[cpstate][dk_busy&(DK_NSTATES-1)]++;
+       cp_time[cpstate]++;
+       for (i = 0; i < DK_NDRIVE; i++)
+               if (dk_busy&(1<<i))
+                       dk_time[i]++;
        if (!noproc) {
                pp = u.u_procp;
        if (!noproc) {
                pp = u.u_procp;
+               pp->p_cpticks++;
                if(++pp->p_cpu == 0)
                        pp->p_cpu--;
                if(pp->p_cpu % 16 == 0) {
                if(++pp->p_cpu == 0)
                        pp->p_cpu--;
                if(pp->p_cpu % 16 == 0) {
@@ -156,15 +172,25 @@ out:
                runrun++;
        }
        if (lbolt >= HZ) {
                runrun++;
        }
        if (lbolt >= HZ) {
+               extern int hangcnt;
+
                if (BASEPRI(ps))
                        return;
                lbolt -= HZ;
                ++time;
                (void) spl1();
                if (BASEPRI(ps))
                        return;
                lbolt -= HZ;
                ++time;
                (void) spl1();
+               /*
+                * machdep.c:unhang uses hangcnt to make sure uba
+                * doesn't forget to interrupt (this has been observed).
+                * This prevents an accumulation of < 5 second uba failures
+                * from summing to a uba reset.
+                */
+               if (hangcnt)
+                       hangcnt--;
                runrun++;
                wakeup((caddr_t)&lbolt);
                for(pp = &proc[0]; pp < &proc[NPROC]; pp++)
                runrun++;
                wakeup((caddr_t)&lbolt);
                for(pp = &proc[0]; pp < &proc[NPROC]; pp++)
-               if (pp->p_stat && pp->p_stat<SZOMB) {
+               if (pp->p_stat && pp->p_stat!=SZOMB) {
                        if(pp->p_time != 127)
                                pp->p_time++;
                        if(pp->p_clktim)
                        if(pp->p_time != 127)
                                pp->p_time++;
                        if(pp->p_clktim)
@@ -188,10 +214,10 @@ out:
                        if(pp->p_stat==SSLEEP||pp->p_stat==SSTOP)
                                if (pp->p_slptime != 127)
                                        pp->p_slptime++;
                        if(pp->p_stat==SSLEEP||pp->p_stat==SSTOP)
                                if (pp->p_slptime != 127)
                                        pp->p_slptime++;
-                       if(pp->p_flag&SLOAD) {
-                               ave(pp->p_aveflt, pp->p_faults, 5);
-                               pp->p_faults = 0;
-                       }
+                       if (pp->p_flag&SLOAD)
+                               pp->p_pctcpu = ccpu * pp->p_pctcpu +
+                                   (1.0 - ccpu) * (pp->p_cpticks/(float)HZ);
+                       pp->p_cpticks = 0;
                        a = (pp->p_cpu & 0377)*SCHMAG + pp->p_nice - NZERO;
                        if(a < 0)
                                a = 0;
                        a = (pp->p_cpu & 0377)*SCHMAG + pp->p_nice - NZERO;
                        if(a < 0)
                                a = 0;
@@ -236,8 +262,6 @@ out:
                        (void) setpri(pp);
                        pp->p_pri = pp->p_usrpri;
 #endif
                        (void) setpri(pp);
                        pp->p_pri = pp->p_usrpri;
 #endif
-                       if (u.u_vm.vm_utime+u.u_vm.vm_stime > u.u_limit[LIM_CPU])
-                               psignal(pp, SIGXCPU);
                }
        }
        if (!BASEPRI(ps))
                }
        }
        if (!BASEPRI(ps))