+int dk_ndrive = DK_NDRIVE;
+/*
+ * Gather statistics on resource utilization.
+ *
+ * We make a gross assumption: that the system has been in the
+ * state it is in (user state, kernel state, interrupt state,
+ * or idle state) for the entire last time interval, and
+ * update statistics accordingly.
+ */
+/*ARGSUSED*/
+gatherstats(pc, ps)
+ caddr_t pc;
+ int ps;
+{
+ register int cpstate, s;
+
+ /*
+ * Determine what state the cpu is in.
+ */
+ if (USERMODE(ps)) {
+ /*
+ * CPU was in user state.
+ */
+ if (u.u_procp->p_nice > NZERO)
+ cpstate = CP_NICE;
+ else
+ cpstate = CP_USER;
+ } else {
+ /*
+ * CPU was in system state. If profiling kernel
+ * increment a counter. If no process is running
+ * then this is a system tick if we were running
+ * at a non-zero IPL (in a driver). If a process is running,
+ * then we charge it with system time even if we were
+ * at a non-zero IPL, since the system often runs
+ * this way during processing of system calls.
+ * This is approximate, but the lack of true interval
+ * timers makes doing anything else difficult.
+ */
+ cpstate = CP_SYS;
+ if (noproc && BASEPRI(ps))
+ cpstate = CP_IDLE;
+#ifdef GPROF
+ s = pc - s_lowpc;
+ if (profiling < 2 && s < s_textsize)
+ kcount[s / (HISTFRACTION * sizeof (*kcount))]++;
+#endif
+ }
+ /*
+ * 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]++;
+}
+