- if (USERMODE(ps)) {
- /*
- * We do this last since it
- * may block on a page fault in user space.
- */
- if (u.u_prof.pr_scale)
- addupc(pc, &u.u_prof, 1);
+
+ /*
+ * We maintain statistics shown by user-level statistics
+ * programs: the amount of time in each cpu state, and
+ * the amount of time each of DK_NDRIVE ``drives'' is busy.
+ */
+ cp_time[cpstate]++;
+ for (s = 0; s < DK_NDRIVE; s++)
+ if (dk_busy&(1<<s))
+ dk_time[s]++;
+
+ /*
+ * 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);
+#endif
+ if ((p->p_cpu&3) == 0) {
+ (void) setpri(p);
+ if (p->p_pri >= PUSER)
+ p->p_pri = p->p_usrpri;
+ }