- case SSTOP:
- unsleep(pp);
- break;
- }
- pp->p_flag &= ~STIMO;
- splx(s);
- } else
- psignal(pp, SIGALRM);
- 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;
- }
- a = (pp->p_cpu & 0377)*SCHMAG + pp->p_nice - NZERO;
- if(a < 0)
- a = 0;
- if(a > 255)
- a = 255;
- pp->p_cpu = a;
- (void) setpri(pp);
- s = spl6();
- if(pp->p_pri >= PUSER) {
- if ((pp != u.u_procp || noproc) &&
- pp->p_stat == SRUN &&
- (pp->p_flag & SLOAD) &&
- pp->p_pri != pp->p_usrpri) {
- remrq(pp);
- pp->p_pri = pp->p_usrpri;
- setrq(pp);
- } else
- pp->p_pri = pp->p_usrpri;
- }
- splx(s);
- }
- vmmeter();
- if(runin!=0) {
- runin = 0;
- wakeup((caddr_t)&runin);
- }
- /*
- * If there are pages that have been cleaned,
- * jolt the pageout daemon to process them.
- * We do this here so that these pages will be
- * freed if there is an abundance of memory and the
- * daemon would not be awakened otherwise.
- */
- if (bclnlist != NULL)
- wakeup((caddr_t)&proc[2]);
- if (USERMODE(ps)) {
- pp = u.u_procp;
-#ifdef ERNIE
- if (pp->p_uid)
- if (pp->p_nice == NZERO && u.u_vm.vm_utime > 600 * HZ)
- pp->p_nice = NZERO+4;
- (void) setpri(pp);
- pp->p_pri = pp->p_usrpri;
+ /*
+ * 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_cpu) is increased here
+ * and the formula for computing priorities (in kern_synch.c)
+ * will compute a different value each time the p_cpu 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 a 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.
+ */
+ if (!noproc) {
+ p = u.u_procp;
+ p->p_cpticks++;
+ if (++p->p_cpu == 0)
+ p->p_cpu--;
+#ifdef MUSH
+ p->p_quota->q_cost += (p->p_nice > NZERO ?
+ (shconsts.sc_tic * ((2*NZERO)-p->p_nice)) / NZERO :
+ shconsts.sc_tic) * (((int)avenrun[0]+2)/3);