Home | History | Annotate | Line # | Download | only in uvm
uvm_meter.c revision 1.70
      1  1.70        ad /*	$NetBSD: uvm_meter.c,v 1.70 2019/12/16 22:47:55 ad 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.56     chuck  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       mrg  *    may be used to endorse or promote products derived from this software
     20   1.1       mrg  *    without specific prior written permission.
     21   1.1       mrg  *
     22   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       mrg  * SUCH DAMAGE.
     33   1.1       mrg  *
     34   1.1       mrg  *      @(#)vm_meter.c  8.4 (Berkeley) 1/4/94
     35   1.3       mrg  * from: Id: uvm_meter.c,v 1.1.2.1 1997/08/14 19:10:35 chuck Exp
     36   1.1       mrg  */
     37  1.22     lukem 
     38  1.22     lukem #include <sys/cdefs.h>
     39  1.70        ad __KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.70 2019/12/16 22:47:55 ad Exp $");
     40   1.1       mrg 
     41   1.1       mrg #include <sys/param.h>
     42  1.55      matt #include <sys/systm.h>
     43  1.55      matt #include <sys/cpu.h>
     44   1.1       mrg #include <sys/proc.h>
     45   1.1       mrg #include <sys/kernel.h>
     46  1.41      yamt #include <sys/sysctl.h>
     47  1.41      yamt 
     48  1.53  uebayasi #include <uvm/uvm.h>
     49  1.41      yamt #include <uvm/uvm_pdpolicy.h>
     50   1.1       mrg 
     51   1.1       mrg /*
     52   1.1       mrg  * maxslp: ???? XXXCDC
     53   1.1       mrg  */
     54   1.1       mrg 
     55   1.1       mrg int maxslp = MAXSLP;	/* patchable ... */
     56  1.14       chs struct loadavg averunnable;
     57   1.1       mrg 
     58  1.30  junyoung static void uvm_total(struct vmtotal *);
     59   1.1       mrg 
     60   1.1       mrg /*
     61  1.27    atatat  * sysctl helper routine for the vm.vmmeter node.
     62   1.1       mrg  */
     63  1.27    atatat static int
     64  1.27    atatat sysctl_vm_meter(SYSCTLFN_ARGS)
     65   1.1       mrg {
     66  1.27    atatat 	struct sysctlnode node;
     67   1.4       mrg 	struct vmtotal vmtotals;
     68   1.1       mrg 
     69  1.27    atatat 	node = *rnode;
     70  1.27    atatat 	node.sysctl_data = &vmtotals;
     71  1.27    atatat 	uvm_total(&vmtotals);
     72  1.23       chs 
     73  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
     74  1.27    atatat }
     75  1.23       chs 
     76  1.27    atatat /*
     77  1.27    atatat  * sysctl helper routine for the vm.uvmexp node.
     78  1.27    atatat  */
     79  1.27    atatat static int
     80  1.27    atatat sysctl_vm_uvmexp(SYSCTLFN_ARGS)
     81  1.27    atatat {
     82  1.27    atatat 	struct sysctlnode node;
     83  1.23       chs 
     84  1.70        ad 	uvm_update_uvmexp();
     85  1.70        ad 
     86  1.27    atatat 	node = *rnode;
     87  1.57  christos 	if (oldlenp)
     88  1.68  riastrad 		node.sysctl_size = uimin(*oldlenp, node.sysctl_size);
     89  1.23       chs 
     90  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
     91  1.15    simonb }
     92  1.15    simonb 
     93  1.15    simonb static int
     94  1.27    atatat sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
     95  1.15    simonb {
     96  1.27    atatat 	struct sysctlnode node;
     97  1.15    simonb 	struct uvmexp_sysctl u;
     98  1.41      yamt 	int active, inactive;
     99  1.41      yamt 
    100  1.70        ad 	cpu_count_sync_all();
    101  1.41      yamt 	uvm_estimatepageable(&active, &inactive);
    102  1.15    simonb 
    103  1.16    simonb 	memset(&u, 0, sizeof(u));
    104  1.16    simonb 
    105  1.16    simonb 	/* Entries here are in order of uvmexp_sysctl, not uvmexp */
    106  1.15    simonb 	u.pagesize = uvmexp.pagesize;
    107  1.15    simonb 	u.pagemask = uvmexp.pagemask;
    108  1.15    simonb 	u.pageshift = uvmexp.pageshift;
    109  1.15    simonb 	u.npages = uvmexp.npages;
    110  1.15    simonb 	u.free = uvmexp.free;
    111  1.41      yamt 	u.active = active;
    112  1.41      yamt 	u.inactive = inactive;
    113  1.15    simonb 	u.paging = uvmexp.paging;
    114  1.15    simonb 	u.wired = uvmexp.wired;
    115  1.70        ad 	u.zeropages = cpu_count_get(CPU_COUNT_ZEROPAGES);
    116  1.15    simonb 	u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
    117  1.15    simonb 	u.reserve_kernel = uvmexp.reserve_kernel;
    118  1.15    simonb 	u.freemin = uvmexp.freemin;
    119  1.15    simonb 	u.freetarg = uvmexp.freetarg;
    120  1.41      yamt 	u.inactarg = 0; /* unused */
    121  1.15    simonb 	u.wiredmax = uvmexp.wiredmax;
    122  1.15    simonb 	u.nswapdev = uvmexp.nswapdev;
    123  1.15    simonb 	u.swpages = uvmexp.swpages;
    124  1.15    simonb 	u.swpginuse = uvmexp.swpginuse;
    125  1.15    simonb 	u.swpgonly = uvmexp.swpgonly;
    126  1.15    simonb 	u.nswget = uvmexp.nswget;
    127  1.70        ad 	u.cpuhit = cpu_count_get(CPU_COUNT_CPUHIT);
    128  1.70        ad 	u.cpumiss = cpu_count_get(CPU_COUNT_CPUMISS);
    129  1.70        ad 	u.faults = cpu_count_get(CPU_COUNT_NFAULT);
    130  1.70        ad 	u.traps = cpu_count_get(CPU_COUNT_NTRAP);
    131  1.70        ad 	u.intrs = cpu_count_get(CPU_COUNT_NINTR);
    132  1.70        ad 	u.swtch = cpu_count_get(CPU_COUNT_NSWTCH);
    133  1.70        ad 	u.softs = cpu_count_get(CPU_COUNT_NSOFT);
    134  1.70        ad 	u.syscalls = cpu_count_get(CPU_COUNT_NSYSCALL);
    135  1.70        ad 	u.pageins = cpu_count_get(CPU_COUNT_PAGEINS);
    136  1.70        ad 	u.pgswapin = 0; /* unused */
    137  1.15    simonb 	u.pgswapout = uvmexp.pgswapout;
    138  1.70        ad 	u.forks = cpu_count_get(CPU_COUNT_FORKS);
    139  1.70        ad 	u.forks_ppwait = cpu_count_get(CPU_COUNT_FORKS_PPWAIT);
    140  1.70        ad 	u.forks_sharevm = cpu_count_get(CPU_COUNT_FORKS_SHAREVM);
    141  1.70        ad 	u.pga_zerohit = cpu_count_get(CPU_COUNT_PGA_ZEROHIT);
    142  1.70        ad 	u.pga_zeromiss = cpu_count_get(CPU_COUNT_PGA_ZEROMISS);
    143  1.70        ad 	u.zeroaborts = cpu_count_get(CPU_COUNT_ZEROABORTS);
    144  1.70        ad 	u.fltnoram = cpu_count_get(CPU_COUNT_FLTNORAM);
    145  1.70        ad 	u.fltnoanon = cpu_count_get(CPU_COUNT_FLTNOANON);
    146  1.70        ad 	u.fltpgwait = cpu_count_get(CPU_COUNT_FLTPGWAIT);
    147  1.70        ad 	u.fltpgrele = cpu_count_get(CPU_COUNT_FLTPGRELE);
    148  1.70        ad 	u.fltrelck = cpu_count_get(CPU_COUNT_FLTRELCK);
    149  1.70        ad 	u.fltrelckok = cpu_count_get(CPU_COUNT_FLTRELCKOK);
    150  1.70        ad 	u.fltanget = cpu_count_get(CPU_COUNT_FLTANGET);
    151  1.70        ad 	u.fltanretry = cpu_count_get(CPU_COUNT_FLTANRETRY);
    152  1.70        ad 	u.fltamcopy = cpu_count_get(CPU_COUNT_FLTAMCOPY);
    153  1.70        ad 	u.fltnamap = cpu_count_get(CPU_COUNT_FLTNAMAP);
    154  1.70        ad 	u.fltnomap = cpu_count_get(CPU_COUNT_FLTNOMAP);
    155  1.70        ad 	u.fltlget = cpu_count_get(CPU_COUNT_FLTLGET);
    156  1.70        ad 	u.fltget = cpu_count_get(CPU_COUNT_FLTGET);
    157  1.70        ad 	u.flt_anon = cpu_count_get(CPU_COUNT_FLT_ANON);
    158  1.70        ad 	u.flt_acow = cpu_count_get(CPU_COUNT_FLT_ACOW);
    159  1.70        ad 	u.flt_obj = cpu_count_get(CPU_COUNT_FLT_OBJ);
    160  1.70        ad 	u.flt_prcopy = cpu_count_get(CPU_COUNT_FLT_PRCOPY);
    161  1.70        ad 	u.flt_przero = cpu_count_get(CPU_COUNT_FLT_PRZERO);
    162  1.15    simonb 	u.pdwoke = uvmexp.pdwoke;
    163  1.15    simonb 	u.pdrevs = uvmexp.pdrevs;
    164  1.15    simonb 	u.pdfreed = uvmexp.pdfreed;
    165  1.15    simonb 	u.pdscans = uvmexp.pdscans;
    166  1.15    simonb 	u.pdanscan = uvmexp.pdanscan;
    167  1.15    simonb 	u.pdobscan = uvmexp.pdobscan;
    168  1.15    simonb 	u.pdreact = uvmexp.pdreact;
    169  1.15    simonb 	u.pdbusy = uvmexp.pdbusy;
    170  1.15    simonb 	u.pdpageouts = uvmexp.pdpageouts;
    171  1.15    simonb 	u.pdpending = uvmexp.pdpending;
    172  1.15    simonb 	u.pddeact = uvmexp.pddeact;
    173  1.70        ad 	u.anonpages = cpu_count_get(CPU_COUNT_ANONPAGES);
    174  1.70        ad 	u.filepages = cpu_count_get(CPU_COUNT_FILEPAGES);
    175  1.70        ad 	u.execpages = cpu_count_get(CPU_COUNT_EXECPAGES);
    176  1.70        ad 	u.colorhit = cpu_count_get(CPU_COUNT_COLORHIT);
    177  1.70        ad 	u.colormiss = cpu_count_get(CPU_COUNT_COLORMISS);
    178  1.64   msaitoh 	u.ncolors = uvmexp.ncolors;
    179  1.67       mrg 	u.bootpages = uvmexp.bootpages;
    180  1.67       mrg 	u.poolpages = pool_totalpages();
    181  1.70        ad 	u.countsyncone = cpu_count_get(CPU_COUNT_SYNC_ONE);
    182  1.70        ad 	u.countsyncall = cpu_count_get(CPU_COUNT_SYNC_ALL);
    183  1.15    simonb 
    184  1.27    atatat 	node = *rnode;
    185  1.27    atatat 	node.sysctl_data = &u;
    186  1.27    atatat 	node.sysctl_size = sizeof(u);
    187  1.58  christos 	if (oldlenp)
    188  1.68  riastrad 		node.sysctl_size = uimin(*oldlenp, node.sysctl_size);
    189  1.27    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    190  1.27    atatat }
    191  1.27    atatat 
    192  1.27    atatat /*
    193  1.38      yamt  * sysctl helper routine for uvm_pctparam.
    194  1.38      yamt  */
    195  1.38      yamt static int
    196  1.41      yamt uvm_sysctlpctparam(SYSCTLFN_ARGS)
    197  1.38      yamt {
    198  1.38      yamt 	int t, error;
    199  1.38      yamt 	struct sysctlnode node;
    200  1.38      yamt 	struct uvm_pctparam *pct;
    201  1.38      yamt 
    202  1.38      yamt 	pct = rnode->sysctl_data;
    203  1.38      yamt 	t = pct->pct_pct;
    204  1.38      yamt 
    205  1.38      yamt 	node = *rnode;
    206  1.38      yamt 	node.sysctl_data = &t;
    207  1.38      yamt 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    208  1.38      yamt 	if (error || newp == NULL)
    209  1.38      yamt 		return error;
    210  1.38      yamt 
    211  1.38      yamt 	if (t < 0 || t > 100)
    212  1.38      yamt 		return EINVAL;
    213  1.38      yamt 
    214  1.41      yamt 	error = uvm_pctparam_check(pct, t);
    215  1.41      yamt 	if (error) {
    216  1.41      yamt 		return error;
    217  1.41      yamt 	}
    218  1.38      yamt 	uvm_pctparam_set(pct, t);
    219  1.38      yamt 
    220  1.38      yamt 	return (0);
    221  1.38      yamt }
    222  1.38      yamt 
    223  1.38      yamt /*
    224  1.27    atatat  * uvm_sysctl: sysctl hook into UVM system.
    225  1.27    atatat  */
    226  1.27    atatat SYSCTL_SETUP(sysctl_vm_setup, "sysctl vm subtree setup")
    227  1.27    atatat {
    228  1.27    atatat 
    229  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    230  1.31    atatat 		       CTLFLAG_PERMANENT,
    231  1.32    atatat 		       CTLTYPE_STRUCT, "vmmeter",
    232  1.32    atatat 		       SYSCTL_DESCR("Simple system-wide virtual memory "
    233  1.32    atatat 				    "statistics"),
    234  1.27    atatat 		       sysctl_vm_meter, 0, NULL, sizeof(struct vmtotal),
    235  1.27    atatat 		       CTL_VM, VM_METER, CTL_EOL);
    236  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    237  1.31    atatat 		       CTLFLAG_PERMANENT,
    238  1.32    atatat 		       CTLTYPE_STRUCT, "loadavg",
    239  1.32    atatat 		       SYSCTL_DESCR("System load average history"),
    240  1.27    atatat 		       NULL, 0, &averunnable, sizeof(averunnable),
    241  1.27    atatat 		       CTL_VM, VM_LOADAVG, CTL_EOL);
    242  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    243  1.31    atatat 		       CTLFLAG_PERMANENT,
    244  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp",
    245  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    246  1.32    atatat 				    "statistics"),
    247  1.27    atatat 		       sysctl_vm_uvmexp, 0, &uvmexp, sizeof(uvmexp),
    248  1.27    atatat 		       CTL_VM, VM_UVMEXP, CTL_EOL);
    249  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    250  1.31    atatat 		       CTLFLAG_PERMANENT,
    251  1.32    atatat 		       CTLTYPE_STRUCT, "uvmexp2",
    252  1.32    atatat 		       SYSCTL_DESCR("Detailed system-wide virtual memory "
    253  1.32    atatat 				    "statistics (MI)"),
    254  1.27    atatat 		       sysctl_vm_uvmexp2, 0, NULL, 0,
    255  1.27    atatat 		       CTL_VM, VM_UVMEXP2, CTL_EOL);
    256  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    257  1.32    atatat 		       CTLFLAG_PERMANENT, CTLTYPE_INT, "maxslp",
    258  1.32    atatat 		       SYSCTL_DESCR("Maximum process sleep time before being "
    259  1.32    atatat 				    "swapped"),
    260  1.27    atatat 		       NULL, 0, &maxslp, 0,
    261  1.27    atatat 		       CTL_VM, VM_MAXSLP, CTL_EOL);
    262  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    263  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    264  1.32    atatat 		       CTLTYPE_INT, "uspace",
    265  1.32    atatat 		       SYSCTL_DESCR("Number of bytes allocated for a kernel "
    266  1.32    atatat 				    "stack"),
    267  1.27    atatat 		       NULL, USPACE, NULL, 0,
    268  1.27    atatat 		       CTL_VM, VM_USPACE, CTL_EOL);
    269  1.31    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    270  1.31    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    271  1.51       mrg 		       CTLTYPE_BOOL, "idlezero",
    272  1.33      yamt 		       SYSCTL_DESCR("Whether try to zero pages in idle loop"),
    273  1.33      yamt 		       NULL, 0, &vm_page_zero_enable, 0,
    274  1.33      yamt 		       CTL_VM, CTL_CREATE, CTL_EOL);
    275  1.62      matt 	sysctl_createv(clog, 0, NULL, NULL,
    276  1.62      matt 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    277  1.62      matt 		       CTLTYPE_LONG, "minaddress",
    278  1.62      matt 		       SYSCTL_DESCR("Minimum user address"),
    279  1.63    martin 		       NULL, VM_MIN_ADDRESS, NULL, 0,
    280  1.62      matt 		       CTL_VM, VM_MINADDRESS, CTL_EOL);
    281  1.62      matt 	sysctl_createv(clog, 0, NULL, NULL,
    282  1.62      matt 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    283  1.62      matt 		       CTLTYPE_LONG, "maxaddress",
    284  1.62      matt 		       SYSCTL_DESCR("Maximum user address"),
    285  1.63    martin 		       NULL, VM_MAX_ADDRESS, NULL, 0,
    286  1.62      matt 		       CTL_VM, VM_MAXADDRESS, CTL_EOL);
    287  1.66     joerg 	sysctl_createv(clog, 0, NULL, NULL,
    288  1.66     joerg 		       CTLFLAG_PERMANENT|CTLFLAG_UNSIGNED,
    289  1.66     joerg 		       CTLTYPE_INT, "guard_size",
    290  1.66     joerg 		       SYSCTL_DESCR("Guard size of main thread"),
    291  1.66     joerg 		       NULL, 0, &user_stack_guard_size, 0,
    292  1.66     joerg 		       CTL_VM, VM_GUARD_SIZE, CTL_EOL);
    293  1.66     joerg 	sysctl_createv(clog, 0, NULL, NULL,
    294  1.66     joerg 		       CTLFLAG_PERMANENT|CTLFLAG_UNSIGNED|CTLFLAG_READWRITE,
    295  1.66     joerg 		       CTLTYPE_INT, "thread_guard_size",
    296  1.66     joerg 		       SYSCTL_DESCR("Guard size of other threads"),
    297  1.66     joerg 		       NULL, 0, &user_thread_stack_guard_size, 0,
    298  1.66     joerg 		       CTL_VM, VM_THREAD_GUARD_SIZE, CTL_EOL);
    299  1.69  jdolecek #ifdef PMAP_DIRECT
    300  1.69  jdolecek 	sysctl_createv(clog, 0, NULL, NULL,
    301  1.69  jdolecek 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    302  1.69  jdolecek 		       CTLTYPE_BOOL, "ubc_direct",
    303  1.69  jdolecek 		       SYSCTL_DESCR("Use direct map for UBC I/O"),
    304  1.69  jdolecek 		       NULL, 0, &ubc_direct, 0,
    305  1.69  jdolecek 		       CTL_VM, CTL_CREATE, CTL_EOL);
    306  1.69  jdolecek #endif
    307  1.41      yamt 
    308  1.41      yamt 	uvmpdpol_sysctlsetup();
    309   1.1       mrg }
    310   1.1       mrg 
    311   1.1       mrg /*
    312   1.1       mrg  * uvm_total: calculate the current state of the system.
    313   1.1       mrg  */
    314   1.4       mrg static void
    315  1.35   thorpej uvm_total(struct vmtotal *totalp)
    316   1.1       mrg {
    317  1.24   thorpej 	struct lwp *l;
    318   1.1       mrg #if 0
    319  1.20       chs 	struct vm_map_entry *	entry;
    320  1.20       chs 	struct vm_map *map;
    321   1.4       mrg 	int paging;
    322   1.1       mrg #endif
    323  1.41      yamt 	int active;
    324   1.1       mrg 
    325   1.7     perry 	memset(totalp, 0, sizeof *totalp);
    326   1.1       mrg 
    327   1.4       mrg 	/*
    328   1.4       mrg 	 * calculate process statistics
    329   1.4       mrg 	 */
    330  1.48        ad 	mutex_enter(proc_lock);
    331  1.44        ad 	LIST_FOREACH(l, &alllwp, l_list) {
    332  1.46     pavel 		if (l->l_proc->p_flag & PK_SYSTEM)
    333   1.4       mrg 			continue;
    334  1.24   thorpej 		switch (l->l_stat) {
    335   1.4       mrg 		case 0:
    336   1.4       mrg 			continue;
    337   1.6       mrg 
    338  1.24   thorpej 		case LSSLEEP:
    339  1.24   thorpej 		case LSSTOP:
    340  1.54     enami 			if ((l->l_flag & LW_SINTR) == 0) {
    341  1.50     rmind 				totalp->t_dw++;
    342  1.50     rmind 			} else if (l->l_slptime < maxslp) {
    343  1.50     rmind 				totalp->t_sl++;
    344  1.50     rmind 			}
    345  1.24   thorpej 			if (l->l_slptime >= maxslp)
    346   1.4       mrg 				continue;
    347   1.4       mrg 			break;
    348   1.6       mrg 
    349  1.24   thorpej 		case LSRUN:
    350  1.24   thorpej 		case LSONPROC:
    351  1.24   thorpej 		case LSIDL:
    352  1.50     rmind 			totalp->t_rq++;
    353  1.24   thorpej 			if (l->l_stat == LSIDL)
    354   1.4       mrg 				continue;
    355   1.4       mrg 			break;
    356   1.4       mrg 		}
    357   1.4       mrg 		/*
    358   1.4       mrg 		 * note active objects
    359   1.4       mrg 		 */
    360   1.1       mrg #if 0
    361   1.4       mrg 		/*
    362  1.36    simonb 		 * XXXCDC: BOGUS!  rethink this.  in the mean time
    363   1.5       mrg 		 * don't do it.
    364   1.4       mrg 		 */
    365   1.4       mrg 		paging = 0;
    366   1.5       mrg 		vm_map_lock(map);
    367   1.4       mrg 		for (map = &p->p_vmspace->vm_map, entry = map->header.next;
    368   1.4       mrg 		    entry != &map->header; entry = entry->next) {
    369   1.4       mrg 			if (entry->is_a_map || entry->is_sub_map ||
    370   1.5       mrg 			    entry->object.uvm_obj == NULL)
    371   1.4       mrg 				continue;
    372   1.5       mrg 			/* XXX how to do this with uvm */
    373   1.4       mrg 		}
    374   1.5       mrg 		vm_map_unlock(map);
    375   1.4       mrg 		if (paging)
    376   1.4       mrg 			totalp->t_pw++;
    377   1.1       mrg #endif
    378   1.4       mrg 	}
    379  1.48        ad 	mutex_exit(proc_lock);
    380  1.44        ad 
    381   1.4       mrg 	/*
    382   1.4       mrg 	 * Calculate object memory usage statistics.
    383   1.4       mrg 	 */
    384  1.41      yamt 	uvm_estimatepageable(&active, NULL);
    385   1.5       mrg 	totalp->t_free = uvmexp.free;
    386   1.5       mrg 	totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
    387  1.41      yamt 	totalp->t_avm = active + uvmexp.swpginuse;	/* XXX */
    388   1.5       mrg 	totalp->t_rm = uvmexp.npages - uvmexp.free;
    389  1.41      yamt 	totalp->t_arm = active;
    390   1.5       mrg 	totalp->t_vmshr = 0;		/* XXX */
    391   1.5       mrg 	totalp->t_avmshr = 0;		/* XXX */
    392   1.5       mrg 	totalp->t_rmshr = 0;		/* XXX */
    393   1.5       mrg 	totalp->t_armshr = 0;		/* XXX */
    394   1.1       mrg }
    395  1.38      yamt 
    396  1.38      yamt void
    397  1.38      yamt uvm_pctparam_set(struct uvm_pctparam *pct, int val)
    398  1.38      yamt {
    399  1.38      yamt 
    400  1.38      yamt 	pct->pct_pct = val;
    401  1.38      yamt 	pct->pct_scaled = val * UVM_PCTPARAM_SCALE / 100;
    402  1.38      yamt }
    403  1.41      yamt 
    404  1.41      yamt int
    405  1.41      yamt uvm_pctparam_get(struct uvm_pctparam *pct)
    406  1.41      yamt {
    407  1.41      yamt 
    408  1.41      yamt 	return pct->pct_pct;
    409  1.41      yamt }
    410  1.41      yamt 
    411  1.41      yamt int
    412  1.41      yamt uvm_pctparam_check(struct uvm_pctparam *pct, int val)
    413  1.41      yamt {
    414  1.41      yamt 
    415  1.41      yamt 	if (pct->pct_check == NULL) {
    416  1.41      yamt 		return 0;
    417  1.41      yamt 	}
    418  1.41      yamt 	return (*pct->pct_check)(pct, val);
    419  1.41      yamt }
    420  1.41      yamt 
    421  1.41      yamt void
    422  1.41      yamt uvm_pctparam_init(struct uvm_pctparam *pct, int val,
    423  1.41      yamt     int (*fn)(struct uvm_pctparam *, int))
    424  1.41      yamt {
    425  1.41      yamt 
    426  1.41      yamt 	pct->pct_check = fn;
    427  1.41      yamt 	uvm_pctparam_set(pct, val);
    428  1.41      yamt }
    429  1.41      yamt 
    430  1.41      yamt int
    431  1.41      yamt uvm_pctparam_createsysctlnode(struct uvm_pctparam *pct, const char *name,
    432  1.43      yamt     const char *desc)
    433  1.41      yamt {
    434  1.41      yamt 
    435  1.41      yamt 	return sysctl_createv(NULL, 0, NULL, NULL,
    436  1.41      yamt 	    CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    437  1.41      yamt 	    CTLTYPE_INT, name, SYSCTL_DESCR(desc),
    438  1.60       dsl 	    uvm_sysctlpctparam, 0, (void *)pct, 0, CTL_VM, CTL_CREATE, CTL_EOL);
    439  1.41      yamt }
    440  1.70        ad 
    441  1.70        ad /*
    442  1.70        ad  * Update uvmexp with aggregate values from the per-CPU counters.
    443  1.70        ad  */
    444  1.70        ad void
    445  1.70        ad uvm_update_uvmexp(void)
    446  1.70        ad {
    447  1.70        ad 
    448  1.70        ad 	cpu_count_sync_all();
    449  1.70        ad 
    450  1.70        ad 	/* uvmexp.free = (int)cpu_count_get(CPU_COUNT_FREE); */
    451  1.70        ad 	uvmexp.zeropages = (int)cpu_count_get(CPU_COUNT_ZEROPAGES);
    452  1.70        ad 	uvmexp.cpuhit = (int)cpu_count_get(CPU_COUNT_CPUHIT);
    453  1.70        ad 	uvmexp.cpumiss = (int)cpu_count_get(CPU_COUNT_CPUMISS);
    454  1.70        ad 	uvmexp.faults = (int)cpu_count_get(CPU_COUNT_NFAULT);
    455  1.70        ad 	uvmexp.traps = (int)cpu_count_get(CPU_COUNT_NTRAP);
    456  1.70        ad 	uvmexp.intrs = (int)cpu_count_get(CPU_COUNT_NINTR);
    457  1.70        ad 	uvmexp.swtch = (int)cpu_count_get(CPU_COUNT_NSWTCH);
    458  1.70        ad 	uvmexp.softs = (int)cpu_count_get(CPU_COUNT_NSOFT);
    459  1.70        ad 	uvmexp.syscalls = (int)cpu_count_get(CPU_COUNT_NSYSCALL);
    460  1.70        ad 	uvmexp.pageins = (int)cpu_count_get(CPU_COUNT_PAGEINS);
    461  1.70        ad 	uvmexp.forks = (int)cpu_count_get(CPU_COUNT_FORKS);
    462  1.70        ad 	uvmexp.forks_ppwait = (int)cpu_count_get(CPU_COUNT_FORKS_PPWAIT);
    463  1.70        ad 	uvmexp.forks_sharevm = (int)cpu_count_get(CPU_COUNT_FORKS_SHAREVM);
    464  1.70        ad 	uvmexp.pga_zerohit = (int)cpu_count_get(CPU_COUNT_PGA_ZEROHIT);
    465  1.70        ad 	uvmexp.pga_zeromiss = (int)cpu_count_get(CPU_COUNT_PGA_ZEROMISS);
    466  1.70        ad 	uvmexp.fltnoram = (int)cpu_count_get(CPU_COUNT_FLTNORAM);
    467  1.70        ad 	uvmexp.fltnoanon = (int)cpu_count_get(CPU_COUNT_FLTNOANON);
    468  1.70        ad 	uvmexp.fltpgwait = (int)cpu_count_get(CPU_COUNT_FLTPGWAIT);
    469  1.70        ad 	uvmexp.fltpgrele = (int)cpu_count_get(CPU_COUNT_FLTPGRELE);
    470  1.70        ad 	uvmexp.fltrelck = (int)cpu_count_get(CPU_COUNT_FLTRELCK);
    471  1.70        ad 	uvmexp.fltrelckok = (int)cpu_count_get(CPU_COUNT_FLTRELCKOK);
    472  1.70        ad 	uvmexp.fltanget = (int)cpu_count_get(CPU_COUNT_FLTANGET);
    473  1.70        ad 	uvmexp.fltanretry = (int)cpu_count_get(CPU_COUNT_FLTANRETRY);
    474  1.70        ad 	uvmexp.fltamcopy = (int)cpu_count_get(CPU_COUNT_FLTAMCOPY);
    475  1.70        ad 	uvmexp.fltnamap = (int)cpu_count_get(CPU_COUNT_FLTNAMAP);
    476  1.70        ad 	uvmexp.fltnomap = (int)cpu_count_get(CPU_COUNT_FLTNOMAP);
    477  1.70        ad 	uvmexp.fltlget = (int)cpu_count_get(CPU_COUNT_FLTLGET);
    478  1.70        ad 	uvmexp.fltget = (int)cpu_count_get(CPU_COUNT_FLTGET);
    479  1.70        ad 	uvmexp.flt_anon = (int)cpu_count_get(CPU_COUNT_FLT_ANON);
    480  1.70        ad 	uvmexp.flt_acow = (int)cpu_count_get(CPU_COUNT_FLT_ACOW);
    481  1.70        ad 	uvmexp.flt_obj = (int)cpu_count_get(CPU_COUNT_FLT_OBJ);
    482  1.70        ad 	uvmexp.flt_prcopy = (int)cpu_count_get(CPU_COUNT_FLT_PRCOPY);
    483  1.70        ad 	uvmexp.flt_przero = (int)cpu_count_get(CPU_COUNT_FLT_PRZERO);
    484  1.70        ad 	uvmexp.anonpages = (int)cpu_count_get(CPU_COUNT_ANONPAGES);
    485  1.70        ad 	uvmexp.filepages = (int)cpu_count_get(CPU_COUNT_FILEPAGES);
    486  1.70        ad 	uvmexp.execpages = (int)cpu_count_get(CPU_COUNT_EXECPAGES);
    487  1.70        ad 	uvmexp.colorhit = (int)cpu_count_get(CPU_COUNT_COLORHIT);
    488  1.70        ad 	uvmexp.colormiss = (int)cpu_count_get(CPU_COUNT_COLORMISS);
    489  1.70        ad 	uvmexp.zeroaborts = (int)cpu_count_get(CPU_COUNT_ZEROABORTS);
    490  1.70        ad }
    491