set hashfraction; enable getting gmonparam
[unix-history] / usr / src / sys / kern / kern_clock.c
index 6031678..9180b4f 100644 (file)
@@ -4,22 +4,21 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)kern_clock.c        7.23 (Berkeley) %G%
+ *     @(#)kern_clock.c        7.31 (Berkeley) %G%
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "dkstat.h"
-#include "callout.h"
-#include "kernel.h"
-#include "proc.h"
-#include "resourcevar.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/dkstat.h>
+#include <sys/callout.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/resourcevar.h>
 
 
-#include "machine/cpu.h"
+#include <machine/cpu.h>
 
 #ifdef GPROF
 
 #ifdef GPROF
-#include "gmon.h"
-extern u_short *kcount;
+#include <sys/gmon.h>
 #endif
 
 #define ADJTIME                /* For now... */
 #endif
 
 #define ADJTIME                /* For now... */
@@ -72,7 +71,9 @@ int   adjtimedelta;
 int    stathz;
 int    profhz;
 int    profprocs;
 int    stathz;
 int    profhz;
 int    profprocs;
-static int psratio, psdiv, pscnt;      /* prof => stat divider */
+int    ticks;
+static int psdiv, pscnt;       /* prof => stat divider */
+int    psratio;                /* ratio: prof / stat */
 
 volatile struct        timeval time;
 volatile struct        timeval mono_time;
 
 volatile struct        timeval time;
 volatile struct        timeval mono_time;
@@ -148,8 +149,10 @@ hardclock(frame)
                statclock(frame);
 
        /*
                statclock(frame);
 
        /*
-        * Increment the time-of-day.
+        * Increment the time-of-day.  The increment is just ``tick'' unless
+        * we are still adjusting the clock; see adjtime().
         */
         */
+       ticks++;
 #ifdef ADJTIME
        if (adjtimedelta == 0)
                bumptime(&time, tick);
 #ifdef ADJTIME
        if (adjtimedelta == 0)
                bumptime(&time, tick);
@@ -163,22 +166,14 @@ hardclock(frame)
                }
        }
 #else
                }
        }
 #else
-       if (timedelta == 0) {
-               BUMPTIME(&time, tick);
-               BUMPTIME(&mono_time, tick);
-       } else {
-               register int delta;
-
-               if (timedelta < 0) {
-                       delta = tick - tickdelta;
-                       timedelta += tickdelta;
-               } else {
-                       delta = tick + tickdelta;
-                       timedelta -= tickdelta;
-               }
-               BUMPTIME(&time, delta);
-               BUMPTIME(&mono_time, delta);
+       if (timedelta == 0)
+               delta = tick;
+       else {
+               delta = tick + tickdelta;
+               timedelta -= tickdelta;
        }
        }
+       BUMPTIME(&time, delta);
+       BUMPTIME(&mono_time, delta);
 
        /*
         * Process callouts at a very low cpu priority, so we don't keep the
 
        /*
         * Process callouts at a very low cpu priority, so we don't keep the
@@ -389,8 +384,10 @@ statclock(frame)
                g = &_gmonparam;
                if (g->state == GMON_PROF_ON) {
                        i = CLKF_PC(frame) - g->lowpc;
                g = &_gmonparam;
                if (g->state == GMON_PROF_ON) {
                        i = CLKF_PC(frame) - g->lowpc;
-                       if (i < g->textsize)
-                               kcount[i / (HISTFRACTION * sizeof(*kcount))]++;
+                       if (i < g->textsize) {
+                               i /= HISTFRACTION * sizeof(*g->kcount);
+                               g->kcount[i]++;
+                       }
                }
 #endif
                if (--pscnt > 0)
                }
 #endif
                if (--pscnt > 0)
@@ -462,35 +459,18 @@ statclock(frame)
 /*
  * Return information about system clocks.
  */
 /*
  * Return information about system clocks.
  */
-/* ARGSUSED */
-kinfo_clockrate(op, where, acopysize, arg, aneeded)
-       int op;
+sysctl_clockrate(where, sizep)
        register char *where;
        register char *where;
-       int *acopysize, arg, *aneeded;
+       size_t *sizep;
 {
 {
-       int buflen, error;
-       struct clockinfo clockinfo;
+       struct clockinfo clkinfo;
 
 
-       *aneeded = sizeof(clockinfo);
-       if (where == NULL)
-               return (0);
-       /*
-        * Check for enough buffering.
-        */
-       buflen = *acopysize;
-       if (buflen < sizeof(clockinfo)) {
-               *acopysize = 0;
-               return (0);
-       }
        /*
        /*
-        * Copyout clockinfo structure.
+        * Construct clockinfo structure.
         */
         */
-       clockinfo.hz = hz;
-       clockinfo.tick = tick;
-       clockinfo.profhz = profhz;
-       clockinfo.stathz = stathz ? stathz : hz;
-       if (error = copyout((caddr_t)&clockinfo, where, sizeof(clockinfo)))
-               return (error);
-       *acopysize = sizeof(clockinfo);
-       return (0);
+       clkinfo.hz = hz;
+       clkinfo.tick = tick;
+       clkinfo.profhz = profhz;
+       clkinfo.stathz = stathz ? stathz : hz;
+       return (sysctl_rdstruct(where, sizep, NULL, &clkinfo, sizeof(clkinfo)));
 }
 }