uvm_meter.c revision 1.44 1 1.44 ad /* $NetBSD: uvm_meter.c,v 1.44 2007/02/09 21:55:43 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.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.44 ad __KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.44 2007/02/09 21:55:43 ad 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.1 mrg * uvm_meter: calculate load average and wake up the swapper (if needed)
82 1.1 mrg */
83 1.4 mrg void
84 1.35 thorpej uvm_meter(void)
85 1.1 mrg {
86 1.40 kardel if ((time_second % 5) == 0)
87 1.4 mrg uvm_loadav(&averunnable);
88 1.24 thorpej if (lwp0.l_slptime > (maxslp / 2))
89 1.14 chs wakeup(&proc0);
90 1.1 mrg }
91 1.1 mrg
92 1.1 mrg /*
93 1.19 chs * uvm_loadav: compute a tenex style load average of a quantity on
94 1.44 ad * 1, 5, and 15 minute intervals. */
95 1.4 mrg static void
96 1.35 thorpej uvm_loadav(struct loadavg *avg)
97 1.1 mrg {
98 1.4 mrg int i, nrun;
99 1.24 thorpej struct lwp *l;
100 1.1 mrg
101 1.44 ad mutex_enter(&proclist_mutex);
102 1.14 chs nrun = 0;
103 1.24 thorpej LIST_FOREACH(l, &alllwp, l_list) {
104 1.24 thorpej switch (l->l_stat) {
105 1.24 thorpej case LSSLEEP:
106 1.24 thorpej if (l->l_priority > PZERO || l->l_slptime > 1)
107 1.4 mrg continue;
108 1.4 mrg /* fall through */
109 1.24 thorpej case LSRUN:
110 1.24 thorpej case LSONPROC:
111 1.24 thorpej case LSIDL:
112 1.4 mrg nrun++;
113 1.4 mrg }
114 1.4 mrg }
115 1.44 ad mutex_exit(&proclist_mutex);
116 1.4 mrg for (i = 0; i < 3; i++)
117 1.4 mrg avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
118 1.4 mrg nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
119 1.1 mrg }
120 1.1 mrg
121 1.1 mrg /*
122 1.27 atatat * sysctl helper routine for the vm.vmmeter node.
123 1.1 mrg */
124 1.27 atatat static int
125 1.27 atatat sysctl_vm_meter(SYSCTLFN_ARGS)
126 1.1 mrg {
127 1.27 atatat struct sysctlnode node;
128 1.4 mrg struct vmtotal vmtotals;
129 1.1 mrg
130 1.27 atatat node = *rnode;
131 1.27 atatat node.sysctl_data = &vmtotals;
132 1.27 atatat uvm_total(&vmtotals);
133 1.23 chs
134 1.27 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
135 1.27 atatat }
136 1.23 chs
137 1.27 atatat /*
138 1.27 atatat * sysctl helper routine for the vm.uvmexp node.
139 1.27 atatat */
140 1.27 atatat static int
141 1.27 atatat sysctl_vm_uvmexp(SYSCTLFN_ARGS)
142 1.27 atatat {
143 1.27 atatat struct sysctlnode node;
144 1.23 chs
145 1.27 atatat node = *rnode;
146 1.27 atatat if (oldp)
147 1.27 atatat node.sysctl_size = min(*oldlenp, node.sysctl_size);
148 1.23 chs
149 1.27 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
150 1.15 simonb }
151 1.15 simonb
152 1.15 simonb static int
153 1.27 atatat sysctl_vm_uvmexp2(SYSCTLFN_ARGS)
154 1.15 simonb {
155 1.27 atatat struct sysctlnode node;
156 1.15 simonb struct uvmexp_sysctl u;
157 1.41 yamt int active, inactive;
158 1.41 yamt
159 1.41 yamt uvm_estimatepageable(&active, &inactive);
160 1.15 simonb
161 1.16 simonb memset(&u, 0, sizeof(u));
162 1.16 simonb
163 1.16 simonb /* Entries here are in order of uvmexp_sysctl, not uvmexp */
164 1.15 simonb u.pagesize = uvmexp.pagesize;
165 1.15 simonb u.pagemask = uvmexp.pagemask;
166 1.15 simonb u.pageshift = uvmexp.pageshift;
167 1.15 simonb u.npages = uvmexp.npages;
168 1.15 simonb u.free = uvmexp.free;
169 1.41 yamt u.active = active;
170 1.41 yamt u.inactive = inactive;
171 1.15 simonb u.paging = uvmexp.paging;
172 1.15 simonb u.wired = uvmexp.wired;
173 1.15 simonb u.zeropages = uvmexp.zeropages;
174 1.15 simonb u.reserve_pagedaemon = uvmexp.reserve_pagedaemon;
175 1.15 simonb u.reserve_kernel = uvmexp.reserve_kernel;
176 1.15 simonb u.freemin = uvmexp.freemin;
177 1.15 simonb u.freetarg = uvmexp.freetarg;
178 1.41 yamt u.inactarg = 0; /* unused */
179 1.15 simonb u.wiredmax = uvmexp.wiredmax;
180 1.15 simonb u.nswapdev = uvmexp.nswapdev;
181 1.15 simonb u.swpages = uvmexp.swpages;
182 1.15 simonb u.swpginuse = uvmexp.swpginuse;
183 1.15 simonb u.swpgonly = uvmexp.swpgonly;
184 1.15 simonb u.nswget = uvmexp.nswget;
185 1.15 simonb u.faults = uvmexp.faults;
186 1.15 simonb u.traps = uvmexp.traps;
187 1.15 simonb u.intrs = uvmexp.intrs;
188 1.15 simonb u.swtch = uvmexp.swtch;
189 1.15 simonb u.softs = uvmexp.softs;
190 1.15 simonb u.syscalls = uvmexp.syscalls;
191 1.15 simonb u.pageins = uvmexp.pageins;
192 1.15 simonb u.swapins = uvmexp.swapins;
193 1.15 simonb u.swapouts = uvmexp.swapouts;
194 1.15 simonb u.pgswapin = uvmexp.pgswapin;
195 1.15 simonb u.pgswapout = uvmexp.pgswapout;
196 1.15 simonb u.forks = uvmexp.forks;
197 1.15 simonb u.forks_ppwait = uvmexp.forks_ppwait;
198 1.15 simonb u.forks_sharevm = uvmexp.forks_sharevm;
199 1.15 simonb u.pga_zerohit = uvmexp.pga_zerohit;
200 1.15 simonb u.pga_zeromiss = uvmexp.pga_zeromiss;
201 1.15 simonb u.zeroaborts = uvmexp.zeroaborts;
202 1.15 simonb u.fltnoram = uvmexp.fltnoram;
203 1.15 simonb u.fltnoanon = uvmexp.fltnoanon;
204 1.15 simonb u.fltpgwait = uvmexp.fltpgwait;
205 1.15 simonb u.fltpgrele = uvmexp.fltpgrele;
206 1.15 simonb u.fltrelck = uvmexp.fltrelck;
207 1.15 simonb u.fltrelckok = uvmexp.fltrelckok;
208 1.15 simonb u.fltanget = uvmexp.fltanget;
209 1.15 simonb u.fltanretry = uvmexp.fltanretry;
210 1.15 simonb u.fltamcopy = uvmexp.fltamcopy;
211 1.15 simonb u.fltnamap = uvmexp.fltnamap;
212 1.15 simonb u.fltnomap = uvmexp.fltnomap;
213 1.15 simonb u.fltlget = uvmexp.fltlget;
214 1.15 simonb u.fltget = uvmexp.fltget;
215 1.15 simonb u.flt_anon = uvmexp.flt_anon;
216 1.15 simonb u.flt_acow = uvmexp.flt_acow;
217 1.15 simonb u.flt_obj = uvmexp.flt_obj;
218 1.15 simonb u.flt_prcopy = uvmexp.flt_prcopy;
219 1.15 simonb u.flt_przero = uvmexp.flt_przero;
220 1.15 simonb u.pdwoke = uvmexp.pdwoke;
221 1.15 simonb u.pdrevs = uvmexp.pdrevs;
222 1.15 simonb u.pdswout = uvmexp.pdswout;
223 1.15 simonb u.pdfreed = uvmexp.pdfreed;
224 1.15 simonb u.pdscans = uvmexp.pdscans;
225 1.15 simonb u.pdanscan = uvmexp.pdanscan;
226 1.15 simonb u.pdobscan = uvmexp.pdobscan;
227 1.15 simonb u.pdreact = uvmexp.pdreact;
228 1.15 simonb u.pdbusy = uvmexp.pdbusy;
229 1.15 simonb u.pdpageouts = uvmexp.pdpageouts;
230 1.15 simonb u.pdpending = uvmexp.pdpending;
231 1.15 simonb u.pddeact = uvmexp.pddeact;
232 1.16 simonb u.anonpages = uvmexp.anonpages;
233 1.23 chs u.filepages = uvmexp.filepages;
234 1.23 chs u.execpages = uvmexp.execpages;
235 1.18 thorpej u.colorhit = uvmexp.colorhit;
236 1.18 thorpej u.colormiss = uvmexp.colormiss;
237 1.15 simonb
238 1.27 atatat node = *rnode;
239 1.27 atatat node.sysctl_data = &u;
240 1.27 atatat node.sysctl_size = sizeof(u);
241 1.27 atatat return (sysctl_lookup(SYSCTLFN_CALL(&node)));
242 1.27 atatat }
243 1.27 atatat
244 1.27 atatat /*
245 1.38 yamt * sysctl helper routine for uvm_pctparam.
246 1.38 yamt */
247 1.38 yamt static int
248 1.41 yamt uvm_sysctlpctparam(SYSCTLFN_ARGS)
249 1.38 yamt {
250 1.38 yamt int t, error;
251 1.38 yamt struct sysctlnode node;
252 1.38 yamt struct uvm_pctparam *pct;
253 1.38 yamt
254 1.38 yamt pct = rnode->sysctl_data;
255 1.38 yamt t = pct->pct_pct;
256 1.38 yamt
257 1.38 yamt node = *rnode;
258 1.38 yamt node.sysctl_data = &t;
259 1.38 yamt error = sysctl_lookup(SYSCTLFN_CALL(&node));
260 1.38 yamt if (error || newp == NULL)
261 1.38 yamt return error;
262 1.38 yamt
263 1.38 yamt if (t < 0 || t > 100)
264 1.38 yamt return EINVAL;
265 1.38 yamt
266 1.41 yamt error = uvm_pctparam_check(pct, t);
267 1.41 yamt if (error) {
268 1.41 yamt return error;
269 1.41 yamt }
270 1.38 yamt uvm_pctparam_set(pct, t);
271 1.38 yamt
272 1.38 yamt return (0);
273 1.38 yamt }
274 1.38 yamt
275 1.38 yamt /*
276 1.27 atatat * uvm_sysctl: sysctl hook into UVM system.
277 1.27 atatat */
278 1.27 atatat SYSCTL_SETUP(sysctl_vm_setup, "sysctl vm subtree setup")
279 1.27 atatat {
280 1.27 atatat
281 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
282 1.31 atatat CTLFLAG_PERMANENT,
283 1.27 atatat CTLTYPE_NODE, "vm", NULL,
284 1.27 atatat NULL, 0, NULL, 0,
285 1.27 atatat CTL_VM, CTL_EOL);
286 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
287 1.31 atatat CTLFLAG_PERMANENT,
288 1.32 atatat CTLTYPE_STRUCT, "vmmeter",
289 1.32 atatat SYSCTL_DESCR("Simple system-wide virtual memory "
290 1.32 atatat "statistics"),
291 1.27 atatat sysctl_vm_meter, 0, NULL, sizeof(struct vmtotal),
292 1.27 atatat CTL_VM, VM_METER, CTL_EOL);
293 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
294 1.31 atatat CTLFLAG_PERMANENT,
295 1.32 atatat CTLTYPE_STRUCT, "loadavg",
296 1.32 atatat SYSCTL_DESCR("System load average history"),
297 1.27 atatat NULL, 0, &averunnable, sizeof(averunnable),
298 1.27 atatat CTL_VM, VM_LOADAVG, CTL_EOL);
299 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
300 1.31 atatat CTLFLAG_PERMANENT,
301 1.32 atatat CTLTYPE_STRUCT, "uvmexp",
302 1.32 atatat SYSCTL_DESCR("Detailed system-wide virtual memory "
303 1.32 atatat "statistics"),
304 1.27 atatat sysctl_vm_uvmexp, 0, &uvmexp, sizeof(uvmexp),
305 1.27 atatat CTL_VM, VM_UVMEXP, CTL_EOL);
306 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
307 1.31 atatat CTLFLAG_PERMANENT,
308 1.32 atatat CTLTYPE_INT, "nkmempages",
309 1.32 atatat SYSCTL_DESCR("Default number of pages in kmem_map"),
310 1.27 atatat NULL, 0, &nkmempages, 0,
311 1.27 atatat CTL_VM, VM_NKMEMPAGES, CTL_EOL);
312 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
313 1.31 atatat CTLFLAG_PERMANENT,
314 1.32 atatat CTLTYPE_STRUCT, "uvmexp2",
315 1.32 atatat SYSCTL_DESCR("Detailed system-wide virtual memory "
316 1.32 atatat "statistics (MI)"),
317 1.27 atatat sysctl_vm_uvmexp2, 0, NULL, 0,
318 1.27 atatat CTL_VM, VM_UVMEXP2, CTL_EOL);
319 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
320 1.32 atatat CTLFLAG_PERMANENT, CTLTYPE_INT, "maxslp",
321 1.32 atatat SYSCTL_DESCR("Maximum process sleep time before being "
322 1.32 atatat "swapped"),
323 1.27 atatat NULL, 0, &maxslp, 0,
324 1.27 atatat CTL_VM, VM_MAXSLP, CTL_EOL);
325 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
326 1.31 atatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
327 1.32 atatat CTLTYPE_INT, "uspace",
328 1.32 atatat SYSCTL_DESCR("Number of bytes allocated for a kernel "
329 1.32 atatat "stack"),
330 1.27 atatat NULL, USPACE, NULL, 0,
331 1.27 atatat CTL_VM, VM_USPACE, CTL_EOL);
332 1.31 atatat sysctl_createv(clog, 0, NULL, NULL,
333 1.31 atatat CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
334 1.33 yamt CTLTYPE_INT, "idlezero",
335 1.33 yamt SYSCTL_DESCR("Whether try to zero pages in idle loop"),
336 1.33 yamt NULL, 0, &vm_page_zero_enable, 0,
337 1.33 yamt CTL_VM, CTL_CREATE, CTL_EOL);
338 1.41 yamt
339 1.41 yamt uvmpdpol_sysctlsetup();
340 1.1 mrg }
341 1.1 mrg
342 1.1 mrg /*
343 1.1 mrg * uvm_total: calculate the current state of the system.
344 1.1 mrg */
345 1.4 mrg static void
346 1.35 thorpej uvm_total(struct vmtotal *totalp)
347 1.1 mrg {
348 1.24 thorpej struct lwp *l;
349 1.1 mrg #if 0
350 1.20 chs struct vm_map_entry * entry;
351 1.20 chs struct vm_map *map;
352 1.4 mrg int paging;
353 1.1 mrg #endif
354 1.41 yamt int active;
355 1.1 mrg
356 1.7 perry memset(totalp, 0, sizeof *totalp);
357 1.1 mrg
358 1.4 mrg /*
359 1.4 mrg * calculate process statistics
360 1.4 mrg */
361 1.44 ad mutex_enter(&proclist_mutex);
362 1.44 ad LIST_FOREACH(l, &alllwp, l_list) {
363 1.24 thorpej if (l->l_proc->p_flag & P_SYSTEM)
364 1.4 mrg continue;
365 1.24 thorpej switch (l->l_stat) {
366 1.4 mrg case 0:
367 1.4 mrg continue;
368 1.6 mrg
369 1.24 thorpej case LSSLEEP:
370 1.24 thorpej case LSSTOP:
371 1.24 thorpej if (l->l_flag & L_INMEM) {
372 1.24 thorpej if (l->l_priority <= PZERO)
373 1.4 mrg totalp->t_dw++;
374 1.24 thorpej else if (l->l_slptime < maxslp)
375 1.4 mrg totalp->t_sl++;
376 1.24 thorpej } else if (l->l_slptime < maxslp)
377 1.4 mrg totalp->t_sw++;
378 1.24 thorpej if (l->l_slptime >= maxslp)
379 1.4 mrg continue;
380 1.4 mrg break;
381 1.6 mrg
382 1.24 thorpej case LSRUN:
383 1.24 thorpej case LSONPROC:
384 1.24 thorpej case LSIDL:
385 1.24 thorpej if (l->l_flag & L_INMEM)
386 1.4 mrg totalp->t_rq++;
387 1.4 mrg else
388 1.4 mrg totalp->t_sw++;
389 1.24 thorpej if (l->l_stat == LSIDL)
390 1.4 mrg continue;
391 1.4 mrg break;
392 1.4 mrg }
393 1.4 mrg /*
394 1.4 mrg * note active objects
395 1.4 mrg */
396 1.1 mrg #if 0
397 1.4 mrg /*
398 1.36 simonb * XXXCDC: BOGUS! rethink this. in the mean time
399 1.5 mrg * don't do it.
400 1.4 mrg */
401 1.4 mrg paging = 0;
402 1.5 mrg vm_map_lock(map);
403 1.4 mrg for (map = &p->p_vmspace->vm_map, entry = map->header.next;
404 1.4 mrg entry != &map->header; entry = entry->next) {
405 1.4 mrg if (entry->is_a_map || entry->is_sub_map ||
406 1.5 mrg entry->object.uvm_obj == NULL)
407 1.4 mrg continue;
408 1.5 mrg /* XXX how to do this with uvm */
409 1.4 mrg }
410 1.5 mrg vm_map_unlock(map);
411 1.4 mrg if (paging)
412 1.4 mrg totalp->t_pw++;
413 1.1 mrg #endif
414 1.4 mrg }
415 1.44 ad mutex_exit(&proclist_mutex);
416 1.44 ad
417 1.4 mrg /*
418 1.4 mrg * Calculate object memory usage statistics.
419 1.4 mrg */
420 1.41 yamt uvm_estimatepageable(&active, NULL);
421 1.5 mrg totalp->t_free = uvmexp.free;
422 1.5 mrg totalp->t_vm = uvmexp.npages - uvmexp.free + uvmexp.swpginuse;
423 1.41 yamt totalp->t_avm = active + uvmexp.swpginuse; /* XXX */
424 1.5 mrg totalp->t_rm = uvmexp.npages - uvmexp.free;
425 1.41 yamt totalp->t_arm = active;
426 1.5 mrg totalp->t_vmshr = 0; /* XXX */
427 1.5 mrg totalp->t_avmshr = 0; /* XXX */
428 1.5 mrg totalp->t_rmshr = 0; /* XXX */
429 1.5 mrg totalp->t_armshr = 0; /* XXX */
430 1.1 mrg }
431 1.38 yamt
432 1.38 yamt void
433 1.38 yamt uvm_pctparam_set(struct uvm_pctparam *pct, int val)
434 1.38 yamt {
435 1.38 yamt
436 1.38 yamt pct->pct_pct = val;
437 1.38 yamt pct->pct_scaled = val * UVM_PCTPARAM_SCALE / 100;
438 1.38 yamt }
439 1.41 yamt
440 1.41 yamt int
441 1.41 yamt uvm_pctparam_get(struct uvm_pctparam *pct)
442 1.41 yamt {
443 1.41 yamt
444 1.41 yamt return pct->pct_pct;
445 1.41 yamt }
446 1.41 yamt
447 1.41 yamt int
448 1.41 yamt uvm_pctparam_check(struct uvm_pctparam *pct, int val)
449 1.41 yamt {
450 1.41 yamt
451 1.41 yamt if (pct->pct_check == NULL) {
452 1.41 yamt return 0;
453 1.41 yamt }
454 1.41 yamt return (*pct->pct_check)(pct, val);
455 1.41 yamt }
456 1.41 yamt
457 1.41 yamt void
458 1.41 yamt uvm_pctparam_init(struct uvm_pctparam *pct, int val,
459 1.41 yamt int (*fn)(struct uvm_pctparam *, int))
460 1.41 yamt {
461 1.41 yamt
462 1.41 yamt pct->pct_check = fn;
463 1.41 yamt uvm_pctparam_set(pct, val);
464 1.41 yamt }
465 1.41 yamt
466 1.41 yamt int
467 1.41 yamt uvm_pctparam_createsysctlnode(struct uvm_pctparam *pct, const char *name,
468 1.43 yamt const char *desc)
469 1.41 yamt {
470 1.41 yamt
471 1.41 yamt return sysctl_createv(NULL, 0, NULL, NULL,
472 1.41 yamt CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
473 1.41 yamt CTLTYPE_INT, name, SYSCTL_DESCR(desc),
474 1.41 yamt uvm_sysctlpctparam, 0, pct, 0, CTL_VM, CTL_CREATE, CTL_EOL);
475 1.41 yamt }
476