Home | History | Annotate | Line # | Download | only in uvm
uvm_meter.c revision 1.51
      1  1.51       mrg /*	$NetBSD: uvm_meter.c,v 1.51 2010/04/11 01:53:03 mrg Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4   1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5   1.1       mrg  * Copyright (c) 1982, 1986, 1989, 1993
      6  1.19       chs  *      The Regents of the University of California.
      7   1.1       mrg  *
      8   1.1       mrg  * All rights reserved.
      9   1.1       mrg  *
     10   1.1       mrg  * Redistribution and use in source and binary forms, with or without
     11   1.1       mrg  * modification, are permitted provided that the following conditions
     12   1.1       mrg  * are met:
     13   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     14   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     15   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     18   1.1       mrg  * 3. All advertising materials mentioning features or use of this software
     19   1.1       mrg  *    must display the following acknowledgement:
     20   1.1       mrg  *      This product includes software developed by Charles D. Cranor,
     21  1.19       chs  *      Washington University, and the University of California, Berkeley
     22   1.1       mrg  *      and its contributors.
     23   1.1       mrg  * 4. Neither the name of the University nor the names of its contributors
     24   1.1       mrg  *    may be used to endorse or promote products derived from this software
     25   1.1       mrg  *    without specific prior written permission.
     26   1.1       mrg  *
     27   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28   1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29   1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30   1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31   1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32   1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33   1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34   1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35   1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37   1.1       mrg  * SUCH DAMAGE.
     38   1.1       mrg  *
     39   1.1       mrg  *      @(#)vm_meter.c  8.4 (Berkeley) 1/4/94
     40   1.3       mrg  * from: Id: uvm_meter.c,v 1.1.2.1 1997/08/14 19:10:35 chuck Exp
     41   1.1       mrg  */
     42  1.22     lukem 
     43  1.22     lukem #include <sys/cdefs.h>
     44  1.51       mrg __KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.51 2010/04/11 01:53:03 mrg Exp $");
     45   1.1       mrg 
     46   1.1       mrg #include <sys/param.h>
     47   1.1       mrg #include <sys/proc.h>
     48   1.1       mrg #include <sys/systm.h>
     49   1.1       mrg #include <sys/kernel.h>
     50  1.41      yamt #include <sys/sysctl.h>
     51  1.41      yamt 
     52  1.13       mrg #include <uvm/uvm_extern.h>
     53  1.41      yamt #include <uvm/uvm_pdpolicy.h>
     54   1.1       mrg 
     55   1.1       mrg /*
     56   1.1       mrg  * maxslp: ???? XXXCDC
     57   1.1       mrg  */
     58   1.1       mrg 
     59   1.1       mrg int maxslp = MAXSLP;	/* patchable ... */
     60  1.14       chs struct loadavg averunnable;
     61   1.1       mrg 
     62   1.1       mrg /*
     63  1.19       chs  * constants for averages over 1, 5, and 15 minutes when sampling at
     64   1.1       mrg  * 5 second intervals.
     65   1.1       mrg  */
     66   1.1       mrg 
     67  1.35   thorpej static const fixpt_t cexp[3] = {
     68   1.1       mrg 	0.9200444146293232 * FSCALE,	/* exp(-1/12) */
     69   1.1       mrg 	0.9834714538216174 * FSCALE,	/* exp(-1/60) */
     70   1.1       mrg 	0.9944598480048967 * FSCALE,	/* exp(-1/180) */
     71   1.1       mrg };
     72   1.1       mrg 
     73   1.1       mrg /*
     74   1.1       mrg  * prototypes
     75   1.1       mrg  */
     76   1.1       mrg 
     77  1.30  junyoung static void uvm_loadav(struct loadavg *);
     78  1.30  junyoung static void uvm_total(struct vmtotal *);
     79   1.1       mrg 
     80   1.1       mrg /*
     81  1.50     rmind  * uvm_meter: calculate load average.
     82   1.1       mrg  */
     83   1.4       mrg void
     84  1.35   thorpej uvm_meter(void)
     85   1.1       mrg {
     86  1.45        ad 	static int count;
     87  1.45        ad 
     88  1.45        ad 	if (++count >= 5) {
     89  1.45        ad 		count = 0;
     90   1.4       mrg 		uvm_loadav(&averunnable);
     91  1.45        ad 	}
     92   1.1       mrg }
     93   1.1       mrg 
     94   1.1       mrg /*
     95  1.19       chs  * uvm_loadav: compute a tenex style load average of a quantity on
     96  1.45        ad  * 1, 5, and 15 minute intervals.
     97  1.45        ad  */
     98   1.4       mrg static void
     99  1.35   thorpej uvm_loadav(struct loadavg *avg)
    100   1.1       mrg {
    101   1.4       mrg 	int i, nrun;
    102  1.24   thorpej 	struct lwp *l;
    103   1.1       mrg 
    104  1.45        ad 	nrun = 0;
    105  1.45        ad 
    106  1.48        ad 	mutex_enter(proc_lock);
    107  1.24   thorpej 	LIST_FOREACH(l, &alllwp, l_list) {
    108  1.46     pavel 		if ((l->l_flag & (LW_SINTR | LW_SYSTEM)) != 0)
    109  1.45        ad 			continue;
    110  1.24   thorpej 		switch (l->l_stat) {
    111  1.24   thorpej 		case LSSLEEP:
    112  1.45        ad 			if (l->l_slptime > 1)
    113   1.4       mrg 				continue;
    114   1.4       mrg 		/* fall through */
    115  1.24   thorpej 		case LSRUN:
    116  1.24   thorpej 		case LSONPROC:
    117  1.24   thorpej 		case LSIDL:
    118   1.4       mrg 			nrun++;
    119   1.4       mrg 		}
    120   1.4       mrg 	}
    121  1.48        ad 	mutex_exit(proc_lock);
    122  1.45        ad 
    123   1.4       mrg 	for (i = 0; i < 3; i++)
    124   1.4       mrg 		avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
    125   1.4       mrg 		    nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
    126   1.1       mrg }
    127   1.1       mrg 
    128   1.1       mrg /*
    129  1.27    atatat  * sysctl helper routine for the vm.vmmeter node.
    130   1.1       mrg  */
    131  1.27    atatat static int
    132  1.27    atatat sysctl_vm_meter(SYSCTLFN_ARGS)
    133   1.1       mrg {
    134  1.27    atatat 	struct sysctlnode node;
    135   1.4       mrg 	struct vmtotal vmtotals;
    136   1.1       mrg 
    137  1.27    atatat 	node = *rnode;
    138  1.27    atatat 	node.sysctl_data = &vmtotals;
    139  1.27    atatat 	uvm_total(&vmtotals);
    140  1.23       chs 
    141  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    142  1.27    atatat }
    143  1.23       chs 
    144  1.27    atatat /*
    145  1.27    atatat  * sysctl helper routine for the vm.uvmexp node.
    146  1.27    atatat  */
    147  1.27    atatat static int
    148  1.27    atatat sysctl_vm_uvmexp(SYSCTLFN_ARGS)
    149  1.27    atatat {
    150  1.27    atatat 	struct sysctlnode node;
    151  1.23       chs 
    152  1.27    atatat 	node = *rnode;
    153  1.27    atatat 	if (oldp)
    154  1.27    atatat 		node.sysctl_size = min(*oldlenp, node.sysctl_size);
    155  1.23       chs 
    156  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    157  1.15    simonb }
    158  1.15    simonb 
    159  1.15    simonb static int
    160  1.27    atatat sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
    161  1.15    simonb {
    162  1.27    atatat 	struct sysctlnode node;
    163  1.15    simonb 	struct uvmexp_sysctl u;
    164  1.41      yamt 	int active, inactive;
    165  1.41      yamt 
    166  1.41      yamt 	uvm_estimatepageable(&active, &inactive);
    167  1.15    simonb 
    168  1.16    simonb 	memset(&u, 0, sizeof(u));
    169  1.16    simonb 
    170  1.16    simonb 	/* Entries here are in order of uvmexp_sysctl, not uvmexp */
    171  1.15    simonb 	u.pagesize = uvmexp.pagesize;
    172  1.15    simonb 	u.pagemask = uvmexp.pagemask;
    173  1.15    simonb 	u.pageshift = uvmexp.pageshift;
    174  1.15    simonb 	u.npages = uvmexp.npages;
    175  1.15    simonb 	u.free = uvmexp.free;
    176  1.41      yamt 	u.active = active;
    177  1.41      yamt 	u.inactive = inactive;
    178  1.15    simonb 	u.paging = uvmexp.paging;
    179  1.15    simonb 	u.wired = uvmexp.wired;
    180  1.15    simonb 	u.zeropages = uvmexp.zeropages;
    181  1.15    simonb 	u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
    182  1.15    simonb 	u.reserve_kernel = uvmexp.reserve_kernel;
    183  1.15    simonb 	u.freemin = uvmexp.freemin;
    184  1.15    simonb 	u.freetarg = uvmexp.freetarg;
    185  1.41      yamt 	u.inactarg = 0; /* unused */
    186  1.15    simonb 	u.wiredmax = uvmexp.wiredmax;
    187  1.15    simonb 	u.nswapdev = uvmexp.nswapdev;
    188  1.15    simonb 	u.swpages = uvmexp.swpages;
    189  1.15    simonb 	u.swpginuse = uvmexp.swpginuse;
    190  1.15    simonb 	u.swpgonly = uvmexp.swpgonly;
    191  1.15    simonb 	u.nswget = uvmexp.nswget;
    192  1.15    simonb 	u.faults = uvmexp.faults;
    193  1.15    simonb 	u.traps = uvmexp.traps;
    194  1.15    simonb 	u.intrs = uvmexp.intrs;
    195  1.15    simonb 	u.swtch = uvmexp.swtch;
    196  1.15    simonb 	u.softs = uvmexp.softs;
    197  1.15    simonb 	u.syscalls = uvmexp.syscalls;
    198  1.15    simonb 	u.pageins = uvmexp.pageins;
    199  1.15    simonb 	u.pgswapin = uvmexp.pgswapin;
    200  1.15    simonb 	u.pgswapout = uvmexp.pgswapout;
    201  1.15    simonb 	u.forks = uvmexp.forks;
    202  1.15    simonb 	u.forks_ppwait = uvmexp.forks_ppwait;
    203  1.15    simonb 	u.forks_sharevm = uvmexp.forks_sharevm;
    204  1.15    simonb 	u.pga_zerohit = uvmexp.pga_zerohit;
    205  1.15    simonb 	u.pga_zeromiss = uvmexp.pga_zeromiss;
    206  1.15    simonb 	u.zeroaborts = uvmexp.zeroaborts;
    207  1.15    simonb 	u.fltnoram = uvmexp.fltnoram;
    208  1.15    simonb 	u.fltnoanon = uvmexp.fltnoanon;
    209  1.15    simonb 	u.fltpgwait = uvmexp.fltpgwait;
    210  1.15    simonb 	u.fltpgrele = uvmexp.fltpgrele;
    211  1.15    simonb 	u.fltrelck = uvmexp.fltrelck;
    212  1.15    simonb 	u.fltrelckok = uvmexp.fltrelckok;
    213  1.15    simonb 	u.fltanget = uvmexp.fltanget;
    214  1.15    simonb 	u.fltanretry = uvmexp.fltanretry;
    215  1.15    simonb 	u.fltamcopy = uvmexp.fltamcopy;
    216  1.15    simonb 	u.fltnamap = uvmexp.fltnamap;
    217  1.15    simonb 	u.fltnomap = uvmexp.fltnomap;
    218  1.15    simonb 	u.fltlget = uvmexp.fltlget;
    219  1.15    simonb 	u.fltget = uvmexp.fltget;
    220  1.15    simonb 	u.flt_anon = uvmexp.flt_anon;
    221  1.15    simonb 	u.flt_acow = uvmexp.flt_acow;
    222  1.15    simonb 	u.flt_obj = uvmexp.flt_obj;
    223  1.15    simonb 	u.flt_prcopy = uvmexp.flt_prcopy;
    224  1.15    simonb 	u.flt_przero = uvmexp.flt_przero;
    225  1.15    simonb 	u.pdwoke = uvmexp.pdwoke;
    226  1.15    simonb 	u.pdrevs = uvmexp.pdrevs;
    227  1.15    simonb 	u.pdfreed = uvmexp.pdfreed;
    228  1.15    simonb 	u.pdscans = uvmexp.pdscans;
    229  1.15    simonb 	u.pdanscan = uvmexp.pdanscan;
    230  1.15    simonb 	u.pdobscan = uvmexp.pdobscan;
    231  1.15    simonb 	u.pdreact = uvmexp.pdreact;
    232  1.15    simonb 	u.pdbusy = uvmexp.pdbusy;
    233  1.15    simonb 	u.pdpageouts = uvmexp.pdpageouts;
    234  1.15    simonb 	u.pdpending = uvmexp.pdpending;
    235  1.15    simonb 	u.pddeact = uvmexp.pddeact;
    236  1.16    simonb 	u.anonpages = uvmexp.anonpages;
    237  1.23       chs 	u.filepages = uvmexp.filepages;
    238  1.23       chs 	u.execpages = uvmexp.execpages;
    239  1.18   thorpej 	u.colorhit = uvmexp.colorhit;
    240  1.18   thorpej 	u.colormiss = uvmexp.colormiss;
    241  1.49        ad 	u.cpuhit = uvmexp.cpuhit;
    242  1.49        ad 	u.cpumiss = uvmexp.cpumiss;
    243  1.15    simonb 
    244  1.27    atatat 	node = *rnode;
    245  1.27    atatat 	node.sysctl_data = &u;
    246  1.27    atatat 	node.sysctl_size = sizeof(u);
    247  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    248  1.27    atatat }
    249  1.27    atatat 
    250  1.27    atatat /*
    251  1.38      yamt  * sysctl helper routine for uvm_pctparam.
    252  1.38      yamt  */
    253  1.38      yamt static int
    254  1.41      yamt uvm_sysctlpctparam(SYSCTLFN_ARGS)
    255  1.38      yamt {
    256  1.38      yamt 	int t, error;
    257  1.38      yamt 	struct sysctlnode node;
    258  1.38      yamt 	struct uvm_pctparam *pct;
    259  1.38      yamt 
    260  1.38      yamt 	pct = rnode->sysctl_data;
    261  1.38      yamt 	t = pct->pct_pct;
    262  1.38      yamt 
    263  1.38      yamt 	node = *rnode;
    264  1.38      yamt 	node.sysctl_data = &t;
    265  1.38      yamt 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    266  1.38      yamt 	if (error || newp == NULL)
    267  1.38      yamt 		return error;
    268  1.38      yamt 
    269  1.38      yamt 	if (t < 0 || t > 100)
    270  1.38      yamt 		return EINVAL;
    271  1.38      yamt 
    272  1.41      yamt 	error = uvm_pctparam_check(pct, t);
    273  1.41      yamt 	if (error) {
    274  1.41      yamt 		return error;
    275  1.41      yamt 	}
    276  1.38      yamt 	uvm_pctparam_set(pct, t);
    277  1.38      yamt 
    278  1.38      yamt 	return (0);
    279  1.38      yamt }
    280  1.38      yamt 
    281  1.38      yamt /*
    282  1.27    atatat  * uvm_sysctl: sysctl hook into UVM system.
    283  1.27    atatat  */
    284  1.27    atatat SYSCTL_SETUP(sysctl_vm_setup, "sysctl vm subtree setup")
    285  1.27    atatat {
    286  1.27    atatat 
    287  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    288  1.31    atatat 		       CTLFLAG_PERMANENT,
    289  1.27    atatat 		       CTLTYPE_NODE, "vm", NULL,
    290  1.27    atatat 		       NULL, 0, NULL, 0,
    291  1.27    atatat 		       CTL_VM, CTL_EOL);
    292  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    293  1.31    atatat 		       CTLFLAG_PERMANENT,
    294  1.32    atatat 		       CTLTYPE_STRUCT, "vmmeter",
    295  1.32    atatat 		       SYSCTL_DESCR("Simple system-wide virtual memory "
    296  1.32    atatat 				    "statistics"),
    297  1.27    atatat 		       sysctl_vm_meter, 0, NULL, sizeof(struct vmtotal),
    298  1.27    atatat 		       CTL_VM, VM_METER, CTL_EOL);
    299  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    300  1.31    atatat 		       CTLFLAG_PERMANENT,
    301  1.32    atatat 		       CTLTYPE_STRUCT, "loadavg",
    302  1.32    atatat 		       SYSCTL_DESCR("System load average history"),
    303  1.27    atatat 		       NULL, 0, &averunnable, sizeof(averunnable),
    304  1.27    atatat 		       CTL_VM, VM_LOADAVG, CTL_EOL);
    305  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    306  1.31    atatat 		       CTLFLAG_PERMANENT,
    307  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp",
    308  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    309  1.32    atatat 				    "statistics"),
    310  1.27    atatat 		       sysctl_vm_uvmexp, 0, &uvmexp, sizeof(uvmexp),
    311  1.27    atatat 		       CTL_VM, VM_UVMEXP, CTL_EOL);
    312  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    313  1.31    atatat 		       CTLFLAG_PERMANENT,
    314  1.32    atatat 		       CTLTYPE_INT, "nkmempages",
    315  1.32    atatat 		       SYSCTL_DESCR("Default number of pages in kmem_map"),
    316  1.27    atatat 		       NULL, 0, &nkmempages, 0,
    317  1.27    atatat 		       CTL_VM, VM_NKMEMPAGES, CTL_EOL);
    318  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    319  1.31    atatat 		       CTLFLAG_PERMANENT,
    320  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp2",
    321  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    322  1.32    atatat 				    "statistics (MI)"),
    323  1.27    atatat 		       sysctl_vm_uvmexp2, 0, NULL, 0,
    324  1.27    atatat 		       CTL_VM, VM_UVMEXP2, CTL_EOL);
    325  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    326  1.32    atatat 		       CTLFLAG_PERMANENT, CTLTYPE_INT, "maxslp",
    327  1.32    atatat 		       SYSCTL_DESCR("Maximum process sleep time before being "
    328  1.32    atatat 				    "swapped"),
    329  1.27    atatat 		       NULL, 0, &maxslp, 0,
    330  1.27    atatat 		       CTL_VM, VM_MAXSLP, CTL_EOL);
    331  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    332  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    333  1.32    atatat 		       CTLTYPE_INT, "uspace",
    334  1.32    atatat 		       SYSCTL_DESCR("Number of bytes allocated for a kernel "
    335  1.32    atatat 				    "stack"),
    336  1.27    atatat 		       NULL, USPACE, NULL, 0,
    337  1.27    atatat 		       CTL_VM, VM_USPACE, CTL_EOL);
    338  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    339  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    340  1.51       mrg 		       CTLTYPE_BOOL, "idlezero",
    341  1.33      yamt 		       SYSCTL_DESCR("Whether try to zero pages in idle loop"),
    342  1.33      yamt 		       NULL, 0, &vm_page_zero_enable, 0,
    343  1.33      yamt 		       CTL_VM, CTL_CREATE, CTL_EOL);
    344  1.41      yamt 
    345  1.41      yamt 	uvmpdpol_sysctlsetup();
    346   1.1       mrg }
    347   1.1       mrg 
    348   1.1       mrg /*
    349   1.1       mrg  * uvm_total: calculate the current state of the system.
    350   1.1       mrg  */
    351   1.4       mrg static void
    352  1.35   thorpej uvm_total(struct vmtotal *totalp)
    353   1.1       mrg {
    354  1.24   thorpej 	struct lwp *l;
    355   1.1       mrg #if 0
    356  1.20       chs 	struct vm_map_entry *	entry;
    357  1.20       chs 	struct vm_map *map;
    358   1.4       mrg 	int paging;
    359   1.1       mrg #endif
    360  1.41      yamt 	int active;
    361   1.1       mrg 
    362   1.7     perry 	memset(totalp, 0, sizeof *totalp);
    363   1.1       mrg 
    364   1.4       mrg 	/*
    365   1.4       mrg 	 * calculate process statistics
    366   1.4       mrg 	 */
    367  1.48        ad 	mutex_enter(proc_lock);
    368  1.44        ad 	LIST_FOREACH(l, &alllwp, l_list) {
    369  1.46     pavel 		if (l->l_proc->p_flag & PK_SYSTEM)
    370   1.4       mrg 			continue;
    371  1.24   thorpej 		switch (l->l_stat) {
    372   1.4       mrg 		case 0:
    373   1.4       mrg 			continue;
    374   1.6       mrg 
    375  1.24   thorpej 		case LSSLEEP:
    376  1.24   thorpej 		case LSSTOP:
    377  1.50     rmind 			if (lwp_eprio(l) <= PZERO) {
    378  1.50     rmind 				totalp->t_dw++;
    379  1.50     rmind 			} else if (l->l_slptime < maxslp) {
    380  1.50     rmind 				totalp->t_sl++;
    381  1.50     rmind 			}
    382  1.24   thorpej 			if (l->l_slptime >= maxslp)
    383   1.4       mrg 				continue;
    384   1.4       mrg 			break;
    385   1.6       mrg 
    386  1.24   thorpej 		case LSRUN:
    387  1.24   thorpej 		case LSONPROC:
    388  1.24   thorpej 		case LSIDL:
    389  1.50     rmind 			totalp->t_rq++;
    390  1.24   thorpej 			if (l->l_stat == LSIDL)
    391   1.4       mrg 				continue;
    392   1.4       mrg 			break;
    393   1.4       mrg 		}
    394   1.4       mrg 		/*
    395   1.4       mrg 		 * note active objects
    396   1.4       mrg 		 */
    397   1.1       mrg #if 0
    398   1.4       mrg 		/*
    399  1.36    simonb 		 * XXXCDC: BOGUS!  rethink this.  in the mean time
    400   1.5       mrg 		 * don't do it.
    401   1.4       mrg 		 */
    402   1.4       mrg 		paging = 0;
    403   1.5       mrg 		vm_map_lock(map);
    404   1.4       mrg 		for (map = &p->p_vmspace->vm_map, entry = map->header.next;
    405   1.4       mrg 		    entry != &map->header; entry = entry->next) {
    406   1.4       mrg 			if (entry->is_a_map || entry->is_sub_map ||
    407   1.5       mrg 			    entry->object.uvm_obj == NULL)
    408   1.4       mrg 				continue;
    409   1.5       mrg 			/* XXX how to do this with uvm */
    410   1.4       mrg 		}
    411   1.5       mrg 		vm_map_unlock(map);
    412   1.4       mrg 		if (paging)
    413   1.4       mrg 			totalp->t_pw++;
    414   1.1       mrg #endif
    415   1.4       mrg 	}
    416  1.48        ad 	mutex_exit(proc_lock);
    417  1.44        ad 
    418   1.4       mrg 	/*
    419   1.4       mrg 	 * Calculate object memory usage statistics.
    420   1.4       mrg 	 */
    421  1.41      yamt 	uvm_estimatepageable(&active, NULL);
    422   1.5       mrg 	totalp->t_free = uvmexp.free;
    423   1.5       mrg 	totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
    424  1.41      yamt 	totalp->t_avm = active + uvmexp.swpginuse;	/* XXX */
    425   1.5       mrg 	totalp->t_rm = uvmexp.npages - uvmexp.free;
    426  1.41      yamt 	totalp->t_arm = active;
    427   1.5       mrg 	totalp->t_vmshr = 0;		/* XXX */
    428   1.5       mrg 	totalp->t_avmshr = 0;		/* XXX */
    429   1.5       mrg 	totalp->t_rmshr = 0;		/* XXX */
    430   1.5       mrg 	totalp->t_armshr = 0;		/* XXX */
    431   1.1       mrg }
    432  1.38      yamt 
    433  1.38      yamt void
    434  1.38      yamt uvm_pctparam_set(struct uvm_pctparam *pct, int val)
    435  1.38      yamt {
    436  1.38      yamt 
    437  1.38      yamt 	pct->pct_pct = val;
    438  1.38      yamt 	pct->pct_scaled = val * UVM_PCTPARAM_SCALE / 100;
    439  1.38      yamt }
    440  1.41      yamt 
    441  1.41      yamt int
    442  1.41      yamt uvm_pctparam_get(struct uvm_pctparam *pct)
    443  1.41      yamt {
    444  1.41      yamt 
    445  1.41      yamt 	return pct->pct_pct;
    446  1.41      yamt }
    447  1.41      yamt 
    448  1.41      yamt int
    449  1.41      yamt uvm_pctparam_check(struct uvm_pctparam *pct, int val)
    450  1.41      yamt {
    451  1.41      yamt 
    452  1.41      yamt 	if (pct->pct_check == NULL) {
    453  1.41      yamt 		return 0;
    454  1.41      yamt 	}
    455  1.41      yamt 	return (*pct->pct_check)(pct, val);
    456  1.41      yamt }
    457  1.41      yamt 
    458  1.41      yamt void
    459  1.41      yamt uvm_pctparam_init(struct uvm_pctparam *pct, int val,
    460  1.41      yamt     int (*fn)(struct uvm_pctparam *, int))
    461  1.41      yamt {
    462  1.41      yamt 
    463  1.41      yamt 	pct->pct_check = fn;
    464  1.41      yamt 	uvm_pctparam_set(pct, val);
    465  1.41      yamt }
    466  1.41      yamt 
    467  1.41      yamt int
    468  1.41      yamt uvm_pctparam_createsysctlnode(struct uvm_pctparam *pct, const char *name,
    469  1.43      yamt     const char *desc)
    470  1.41      yamt {
    471  1.41      yamt 
    472  1.41      yamt 	return sysctl_createv(NULL, 0, NULL, NULL,
    473  1.41      yamt 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    474  1.41      yamt 	    CTLTYPE_INT, name, SYSCTL_DESCR(desc),
    475  1.41      yamt 	    uvm_sysctlpctparam, 0, pct, 0, CTL_VM, CTL_CREATE, CTL_EOL);
    476  1.41      yamt }
    477