BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / kern_clock.c
index 91d1061..3d2a6ac 100644 (file)
@@ -1,18 +1,45 @@
-/*
- * Copyright (c) 1982, 1986, 1991 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  *
  *
- *     @(#)kern_clock.c        7.12 (Berkeley) %G%
+ *     @(#)kern_clock.c        7.16 (Berkeley) 5/9/91
  */
 
 #include "param.h"
 #include "systm.h"
 #include "dkstat.h"
 #include "callout.h"
  */
 
 #include "param.h"
 #include "systm.h"
 #include "dkstat.h"
 #include "callout.h"
-#include "user.h"
 #include "kernel.h"
 #include "proc.h"
 #include "kernel.h"
 #include "proc.h"
+#include "resourcevar.h"
 
 #include "machine/cpu.h"
 
 
 #include "machine/cpu.h"
 
 #include "gprof.h"
 #endif
 
 #include "gprof.h"
 #endif
 
-#define ADJTIME                /* For now... */
-#define        ADJ_TICK 1000
-int    adjtimedelta;
-
 /*
  * Clock handling routines.
  *
 /*
  * Clock handling routines.
  *
@@ -69,8 +92,11 @@ hardclock(frame)
 {
        register struct callout *p1;
        register struct proc *p = curproc;
 {
        register struct callout *p1;
        register struct proc *p = curproc;
-       register struct pstats *pstats = p->p_stats;
+       register struct pstats *pstats;
        register int s;
        register int s;
+       int needsoft = 0;
+       extern int tickdelta;
+       extern long timedelta;
 
        /*
         * Update real-time timeout queue.
 
        /*
         * Update real-time timeout queue.
@@ -86,17 +112,27 @@ hardclock(frame)
        while (p1) {
                if (--p1->c_time > 0)
                        break;
        while (p1) {
                if (--p1->c_time > 0)
                        break;
+               needsoft = 1;
                if (p1->c_time == 0)
                        break;
                p1 = p1->c_next;
        }
 
                if (p1->c_time == 0)
                        break;
                p1 = p1->c_next;
        }
 
+       /*
+        * Curproc (now in p) is null if no process is running.
+        * We assume that curproc is set in user mode!
+        */
+       if (p)
+               pstats = p->p_stats;
        /*
         * Charge the time out based on the mode the cpu is in.
         * Here again we fudge for the lack of proper interval timers
         * assuming that the current state has been around at least
         * one tick.
         */
        /*
         * Charge the time out based on the mode the cpu is in.
         * Here again we fudge for the lack of proper interval timers
         * assuming that the current state has been around at least
         * one tick.
         */
+       if (CLKF_USERMODE(&frame)) {
+               if (pstats->p_prof.pr_scale)
+                       needsoft = 1;
                /*
                 * CPU was in user state.  Increment
                 * user time counter, and process process-virtual time
                /*
                 * CPU was in user state.  Increment
                 * user time counter, and process process-virtual time
@@ -110,7 +146,7 @@ hardclock(frame)
                /*
                 * CPU was in system state.
                 */
                /*
                 * CPU was in system state.
                 */
-               if (!noproc)
+               if (p)
                        BUMPTIME(&p->p_stime, tick);
        }
 
                        BUMPTIME(&p->p_stime, tick);
        }
 
@@ -122,7 +158,7 @@ hardclock(frame)
         * This assumes that the current process has been running
         * the entire last tick.
         */
         * This assumes that the current process has been running
         * the entire last tick.
         */
-       if (noproc == 0) {
+       if (p) {
                if ((p->p_utime.tv_sec+p->p_stime.tv_sec+1) >
                    p->p_rlimit[RLIMIT_CPU].rlim_cur) {
                        psignal(p, SIGXCPU);
                if ((p->p_utime.tv_sec+p->p_stime.tv_sec+1) >
                    p->p_rlimit[RLIMIT_CPU].rlim_cur) {
                        psignal(p, SIGXCPU);
@@ -172,19 +208,6 @@ hardclock(frame)
         * so we don't keep the relatively high clock interrupt
         * priority any longer than necessary.
         */
         * so we don't keep the relatively high clock interrupt
         * priority any longer than necessary.
         */
-#ifdef ADJTIME
-       if (adjtimedelta == 0)
-               bumptime(&time, tick);
-       else {
-               if (adjtimedelta < 0) {
-                       bumptime(&time, tick-ADJ_TICK);
-                       adjtimedelta++;
-               } else {
-                       bumptime(&time, tick+ADJ_TICK);
-                       adjtimedelta--;
-               }
-       }
-#else
        if (timedelta == 0)
                BUMPTIME(&time, tick)
        else {
        if (timedelta == 0)
                BUMPTIME(&time, tick)
        else {
@@ -199,8 +222,17 @@ hardclock(frame)
                }
                BUMPTIME(&time, delta);
        }
                }
                BUMPTIME(&time, delta);
        }
-#endif
-       setsoftclock();
+       if (needsoft) {
+               if (CLKF_BASEPRI(&frame)) {
+                       /*
+                        * Save the overhead of a software interrupt;
+                        * it will happen as soon as we return, so do it now.
+                        */
+                       (void) splsoftclock();
+                       softclock(frame);
+               } else
+                       setsoftclock();
+       }
 }
 
 int    dk_ndrive = DK_NDRIVE;
 }
 
 int    dk_ndrive = DK_NDRIVE;
@@ -241,7 +273,7 @@ gatherstats(framep)
                 * timers makes doing anything else difficult.
                 */
                cpstate = CP_SYS;
                 * timers makes doing anything else difficult.
                 */
                cpstate = CP_SYS;
-               if (noproc && CLKF_BASEPRI(framep))
+               if (curproc == NULL && CLKF_BASEPRI(framep))
                        cpstate = CP_IDLE;
 #ifdef GPROF
                s = CLKF_PC(framep) - s_lowpc;
                        cpstate = CP_IDLE;
 #ifdef GPROF
                s = CLKF_PC(framep) - s_lowpc;
@@ -397,23 +429,3 @@ hzto(tv)
        splx(s);
        return (ticks);
 }
        splx(s);
        return (ticks);
 }
-
-/* ARGSUSED */
-profil(p, uap, retval)
-       struct proc *p;
-       register struct args {
-               short   *bufbase;
-               unsigned bufsize;
-               unsigned pcoffset;
-               unsigned pcscale;
-       } *uap;
-       int *retval;
-{
-       register struct uprof *upp = &p->p_stats->p_prof;
-
-       upp->pr_base = uap->bufbase;
-       upp->pr_size = uap->bufsize;
-       upp->pr_off = uap->pcoffset;
-       upp->pr_scale = uap->pcscale;
-       return (0);
-}