4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / sys / vm / vm_meter.c
index c14da26..020aa7b 100644 (file)
@@ -1,24 +1,25 @@
 /*
 /*
- * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vm_meter.c  7.14 (Berkeley) %G%
+ *     @(#)vm_meter.c  8.1 (Berkeley) %G%
  */
 
  */
 
-#include "param.h"
-#include "proc.h"
-#include "systm.h"
-#include "kernel.h"
-#include "vm.h"
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <vm/vm.h>
+#include <sys/sysctl.h>
 
 struct loadavg averunnable;            /* load average, of runnable procs */
 
 int    maxslp = MAXSLP;
 int    saferss = SAFERSS;
 
 
 struct loadavg averunnable;            /* load average, of runnable procs */
 
 int    maxslp = MAXSLP;
 int    saferss = SAFERSS;
 
-
+void
 vmmeter()
 {
        register unsigned *cp, *rp, *sp;
 vmmeter()
 {
        register unsigned *cp, *rp, *sp;
@@ -43,13 +44,14 @@ fixpt_t     cexp[3] = {
  * Compute a tenex style load average of a quantity on
  * 1, 5 and 15 minute intervals.
  */
  * Compute a tenex style load average of a quantity on
  * 1, 5 and 15 minute intervals.
  */
+void
 loadav(avg)
        register struct loadavg *avg;
 {
        register int i, nrun;
        register struct proc *p;
 
 loadav(avg)
        register struct loadavg *avg;
 {
        register int i, nrun;
        register struct proc *p;
 
-       for (nrun = 0, p = allproc; p != NULL; p = p->p_nxt) {
+       for (nrun = 0, p = (struct proc *)allproc; p != NULL; p = p->p_nxt) {
                switch (p->p_stat) {
                case SSLEEP:
                        if (p->p_pri > PZERO || p->p_slptime != 0)
                switch (p->p_stat) {
                case SSLEEP:
                        if (p->p_pri > PZERO || p->p_slptime != 0)
@@ -63,71 +65,46 @@ loadav(avg)
        for (i = 0; i < 3; i++)
                avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
                        nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
        for (i = 0; i < 3; i++)
                avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
                        nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
-#if defined(COMPAT_43) && (defined(vax) || defined(tahoe))
-       for (i = 0; i < 3; i++)
-               avenrun[i] = (double) avg->ldavg[i] / FSCALE;
-#endif /* COMPAT_43 */
 }
 
 /*
 }
 
 /*
- * Load average information
+ * Attributes associated with virtual memory.
  */
  */
-/* ARGSUSED */
-kinfo_loadavg(op, where, acopysize, arg, aneeded)
-       int op;
-       register char *where;
-       int *acopysize, arg, *aneeded;
-{
-       int buflen, error;
-
-       *aneeded = sizeof(averunnable);
-       if (where == NULL)
-               return (0);
-       /*
-        * Check for enough buffering.
-        */
-       buflen = *acopysize;
-       if (buflen < sizeof(averunnable)) {
-               *acopysize = 0;
-               return (0);
-       }
-       /*
-        * Copyout averunnable structure.
-        */
-       averunnable.fscale = FSCALE;
-       if (error = copyout((caddr_t)&averunnable, where, sizeof(averunnable)))
-               return (error);
-       *acopysize = sizeof(averunnable);
-       return (0);
-}
-
-/*
- * Calculate and return vmtotals structure.
- */
-kinfo_meter(op, where, acopysize, arg, aneeded)
-       int op;
-       caddr_t where;
-       int *acopysize, arg, *aneeded;
+vm_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
+       int *name;
+       u_int namelen;
+       void *oldp;
+       size_t *oldlenp;
+       void *newp;
+       size_t newlen;
+       struct proc *p;
 {
        struct vmtotal vmtotals;
 {
        struct vmtotal vmtotals;
-       int error;
 
 
-       *aneeded = sizeof(struct vmtotal);
-       if (where == NULL)
-               return (0);
-       if (*acopysize < sizeof(struct vmtotal))
-               return (EINVAL);
-       vmtotal(&vmtotals);
-       if (error = copyout((caddr_t)&vmtotals, where, sizeof(struct vmtotal)))
-               return (error);
-       *acopysize = sizeof(struct vmtotal);
-       return (0);
+       /* all sysctl names at this level are terminal */
+       if (namelen != 1)
+               return (ENOTDIR);               /* overloaded */
+
+       switch (name[0]) {
+       case VM_LOADAVG:
+               averunnable.fscale = FSCALE;
+               return (sysctl_rdstruct(oldp, oldlenp, newp, &averunnable,
+                   sizeof(averunnable)));
+       case VM_METER:
+               vmtotal(&vmtotals);
+               return (sysctl_rdstruct(oldp, oldlenp, newp, &vmtotals,
+                   sizeof(vmtotals)));
+       default:
+               return (EOPNOTSUPP);
+       }
+       /* NOTREACHED */
 }
 
 /*
  * Calculate the current state of the system.
  * Done on demand from getkerninfo().
  */
 }
 
 /*
  * Calculate the current state of the system.
  * Done on demand from getkerninfo().
  */
+void
 vmtotal(totalp)
        register struct vmtotal *totalp;
 {
 vmtotal(totalp)
        register struct vmtotal *totalp;
 {
@@ -141,7 +118,6 @@ vmtotal(totalp)
        /*
         * Mark all objects as inactive.
         */
        /*
         * Mark all objects as inactive.
         */
-       simple_unlock(&vm_object_list_lock);
        simple_lock(&vm_object_list_lock);
        object = (vm_object_t) queue_first(&vm_object_list);
        while (!queue_end(&vm_object_list, (queue_entry_t) object)) {
        simple_lock(&vm_object_list_lock);
        object = (vm_object_t) queue_first(&vm_object_list);
        while (!queue_end(&vm_object_list, (queue_entry_t) object)) {
@@ -152,7 +128,7 @@ vmtotal(totalp)
        /*
         * Calculate process statistics.
         */
        /*
         * Calculate process statistics.
         */
-       for (p = allproc; p != NULL; p = p->p_nxt) {
+       for (p = (struct proc *)allproc; p != NULL; p = p->p_nxt) {
                if (p->p_flag & SSYS)
                        continue;
                switch (p->p_stat) {
                if (p->p_flag & SSYS)
                        continue;
                switch (p->p_stat) {