VFLUSHO -> VDISCARD
[unix-history] / usr / src / sys / kern / kern_clock.c
index dbe091e..1dc5898 100644 (file)
@@ -1,21 +1,30 @@
-/*     kern_clock.c    6.12    85/04/05        */
-
-#include "../machine/reg.h"
-#include "../machine/psl.h"
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)kern_clock.c        7.7 (Berkeley) %G%
+ */
 
 #include "param.h"
 #include "systm.h"
 
 #include "param.h"
 #include "systm.h"
-#include "dk.h"
+#include "dkstat.h"
 #include "callout.h"
 #include "callout.h"
-#include "dir.h"
 #include "user.h"
 #include "kernel.h"
 #include "proc.h"
 #include "vm.h"
 #include "text.h"
 
 #include "user.h"
 #include "kernel.h"
 #include "proc.h"
 #include "vm.h"
 #include "text.h"
 
-#ifdef vax
-#include "../vax/mtpr.h"
+#include "machine/reg.h"
+#include "machine/psl.h"
+
+#if defined(vax) || defined(tahoe)
+#include "machine/mtpr.h"
+#include "machine/clock.h"
+#endif
+#if defined(hp300)
+#include "machine/mtpr.h"
 #endif
 
 #ifdef GPROF
 #endif
 
 #ifdef GPROF
@@ -46,22 +55,10 @@ int adjtimedelta;
  *     time of day, system/user timing, timeouts, profiling on separate timers
  *     allocate more timeout table slots when table overflows.
  */
  *     time of day, system/user timing, timeouts, profiling on separate timers
  *     allocate more timeout table slots when table overflows.
  */
-#ifdef notdef
+
 /*
  * Bump a timeval by a small number of usec's.
  */
 /*
  * Bump a timeval by a small number of usec's.
  */
-bumptime(tp, usec)
-       register struct timeval *tp;
-       int usec;
-{
-
-       tp->tv_usec += usec;
-       if (tp->tv_usec >= 1000000) {
-               tp->tv_usec -= 1000000;
-               tp->tv_sec++;
-       }
-}
-#endif notdef
 #define BUMPTIME(t, usec) { \
        register struct timeval *tp = (t); \
  \
 #define BUMPTIME(t, usec) { \
        register struct timeval *tp = (t); \
  \
@@ -84,8 +81,8 @@ hardclock(pc, ps)
        int ps;
 {
        register struct callout *p1;
        int ps;
 {
        register struct callout *p1;
-       register struct proc *p;
-       register int s, cpstate;
+       register struct proc *p = u.u_procp;
+       register int s;
 
        /*
         * Update real-time timeout queue.
 
        /*
         * Update real-time timeout queue.
@@ -118,33 +115,16 @@ hardclock(pc, ps)
                 * user time counter, and process process-virtual time
                 * interval timer. 
                 */
                 * user time counter, and process process-virtual time
                 * interval timer. 
                 */
-               BUMPTIME(&u.u_ru.ru_utime, tick);
+               BUMPTIME(&p->p_utime, tick);
                if (timerisset(&u.u_timer[ITIMER_VIRTUAL].it_value) &&
                    itimerdecr(&u.u_timer[ITIMER_VIRTUAL], tick) == 0)
                if (timerisset(&u.u_timer[ITIMER_VIRTUAL].it_value) &&
                    itimerdecr(&u.u_timer[ITIMER_VIRTUAL], tick) == 0)
-                       psignal(u.u_procp, SIGVTALRM);
-               if (u.u_procp->p_nice > NZERO)
-                       cpstate = CP_NICE;
-               else
-                       cpstate = CP_USER;
+                       psignal(p, SIGVTALRM);
        } else {
                /*
        } 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.
+                * CPU was in system state.
                 */
                 */
-               cpstate = CP_SYS;
-               if (noproc) {
-                       if (BASEPRI(ps))
-                               cpstate = CP_IDLE;
-               } else {
-                       BUMPTIME(&u.u_ru.ru_stime, tick);
-               }
+               if (!noproc)
+                       BUMPTIME(&p->p_stime, tick);
        }
 
        /*
        }
 
        /*
@@ -156,20 +136,23 @@ hardclock(pc, ps)
         * the entire last tick.
         */
        if (noproc == 0) {
         * the entire last tick.
         */
        if (noproc == 0) {
-               if ((u.u_ru.ru_utime.tv_sec+u.u_ru.ru_stime.tv_sec+1) >
+               if ((p->p_utime.tv_sec+p->p_stime.tv_sec+1) >
                    u.u_rlimit[RLIMIT_CPU].rlim_cur) {
                    u.u_rlimit[RLIMIT_CPU].rlim_cur) {
-                       psignal(u.u_procp, SIGXCPU);
+                       psignal(p, SIGXCPU);
                        if (u.u_rlimit[RLIMIT_CPU].rlim_cur <
                            u.u_rlimit[RLIMIT_CPU].rlim_max)
                                u.u_rlimit[RLIMIT_CPU].rlim_cur += 5;
                }
                if (timerisset(&u.u_timer[ITIMER_PROF].it_value) &&
                    itimerdecr(&u.u_timer[ITIMER_PROF], tick) == 0)
                        if (u.u_rlimit[RLIMIT_CPU].rlim_cur <
                            u.u_rlimit[RLIMIT_CPU].rlim_max)
                                u.u_rlimit[RLIMIT_CPU].rlim_cur += 5;
                }
                if (timerisset(&u.u_timer[ITIMER_PROF].it_value) &&
                    itimerdecr(&u.u_timer[ITIMER_PROF], tick) == 0)
-                       psignal(u.u_procp, SIGPROF);
-               s = u.u_procp->p_rssize;
-               u.u_ru.ru_idrss += s; u.u_ru.ru_isrss += 0;     /* XXX */
-               if (u.u_procp->p_textp) {
-                       register int xrss = u.u_procp->p_textp->x_rssize;
+                       psignal(p, SIGPROF);
+               s = p->p_rssize;
+               u.u_ru.ru_idrss += s;
+#ifdef notdef
+               u.u_ru.ru_isrss += 0;           /* XXX (haven't got this) */
+#endif
+               if (p->p_textp) {
+                       register int xrss = p->p_textp->x_rssize;
 
                        s += xrss;
                        u.u_ru.ru_ixrss += xrss;
 
                        s += xrss;
                        u.u_ru.ru_ixrss += xrss;
@@ -193,7 +176,6 @@ hardclock(pc, ps)
         * much recently, and to round-robin among other processes.
         */
        if (!noproc) {
         * 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--;
                p->p_cpticks++;
                if (++p->p_cpu == 0)
                        p->p_cpu--;
@@ -230,17 +212,17 @@ hardclock(pc, ps)
                }
        }
 #else
                }
        }
 #else
-       if (adjtimedelta == 0)
+       if (timedelta == 0)
                BUMPTIME(&time, tick)
        else {
                register delta;
 
                BUMPTIME(&time, tick)
        else {
                register delta;
 
-               if (adjtimedelta < 0) {
-                       delta = tick - tickadj;
-                       adjtimedelta += tickadj;
+               if (timedelta < 0) {
+                       delta = tick - tickdelta;
+                       timedelta += tickdelta;
                } else {
                } else {
-                       delta = tick + tickadj;
-                       adjtimedelta -= tickadj;
+                       delta = tick + tickdelta;
+                       timedelta -= tickdelta;
                }
                BUMPTIME(&time, delta);
        }
                }
                BUMPTIME(&time, delta);
        }
@@ -262,7 +244,7 @@ gatherstats(pc, ps)
        caddr_t pc;
        int ps;
 {
        caddr_t pc;
        int ps;
 {
-       int cpstate, s;
+       register int cpstate, s;
 
        /*
         * Determine what state the cpu is in.
 
        /*
         * Determine what state the cpu is in.
@@ -278,7 +260,14 @@ gatherstats(pc, ps)
        } else {
                /*
                 * CPU was in system state.  If profiling kernel
        } else {
                /*
                 * CPU was in system state.  If profiling kernel
-                * increment a counter.
+                * 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_SYS;
                if (noproc && BASEPRI(ps))
@@ -316,7 +305,7 @@ softclock(pc, ps)
                register int (*func)();
                register int a, s;
 
                register int (*func)();
                register int a, s;
 
-               s = spl7();
+               s = splhigh();
                if ((p1 = calltodo.c_next) == 0 || p1->c_time > 0) {
                        splx(s);
                        break;
                if ((p1 = calltodo.c_next) == 0 || p1->c_time > 0) {
                        splx(s);
                        break;
@@ -345,7 +334,7 @@ softclock(pc, ps)
                 * reduce priority to give others a chance.
                 */
                if (p->p_uid && p->p_nice == NZERO &&
                 * reduce priority to give others a chance.
                 */
                if (p->p_uid && p->p_nice == NZERO &&
-                   u.u_ru.ru_utime.tv_sec > 10 * 60) {
+                   p->p_utime.tv_sec > 10 * 60) {
                        p->p_nice = NZERO+4;
                        (void) setpri(p);
                        p->p_pri = p->p_usrpri;
                        p->p_nice = NZERO+4;
                        (void) setpri(p);
                        p->p_pri = p->p_usrpri;
@@ -362,7 +351,7 @@ timeout(fun, arg, t)
        register int t;
 {
        register struct callout *p1, *p2, *pnew;
        register int t;
 {
        register struct callout *p1, *p2, *pnew;
-       register int s = spl7();
+       register int s = splhigh();
 
        if (t <= 0)
                t = 1;
 
        if (t <= 0)
                t = 1;
@@ -394,7 +383,7 @@ untimeout(fun, arg)
        register struct callout *p1, *p2;
        register int s;
 
        register struct callout *p1, *p2;
        register int s;
 
-       s = spl7();
+       s = splhigh();
        for (p1 = &calltodo; (p2 = p1->c_next) != 0; p1 = p2) {
                if (p2->c_func == fun && p2->c_arg == arg) {
                        if (p2->c_next && p2->c_time > 0)
        for (p1 = &calltodo; (p2 = p1->c_next) != 0; p1 = p2) {
                if (p2->c_func == fun && p2->c_arg == arg) {
                        if (p2->c_next && p2->c_time > 0)
@@ -418,7 +407,7 @@ hzto(tv)
 {
        register long ticks;
        register long sec;
 {
        register long ticks;
        register long sec;
-       int s = spl7();
+       int s = splhigh();
 
        /*
         * If number of milliseconds will fit in 32 bit arithmetic,
 
        /*
         * If number of milliseconds will fit in 32 bit arithmetic,
@@ -456,10 +445,3 @@ profil()
        upp->pr_off = uap->pcoffset;
        upp->pr_scale = uap->pcscale;
 }
        upp->pr_off = uap->pcoffset;
        upp->pr_scale = uap->pcscale;
 }
-
-opause()
-{
-
-       for (;;)
-               sleep((caddr_t)&u, PSLEP);
-}