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