| File: | src/usr.bin/systat/uvm.c |
| Warning: | line 257, column 3 Value stored to 'maxline' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* $OpenBSD: uvm.c,v 1.5 2019/06/28 13:35:04 deraadt Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 2008 Can Erkin Acar <canacar@openbsd.org> |
| 4 | * Copyright (c) 2018 Kenneth R Westerback <krw@openbsd.org> |
| 5 | * |
| 6 | * Permission to use, copy, modify, and distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | #include <sys/types.h> |
| 20 | #include <sys/signal.h> |
| 21 | #include <sys/sysctl.h> |
| 22 | #include <sys/pool.h> |
| 23 | #include <ctype.h> |
| 24 | #include <err.h> |
| 25 | #include <errno(*__errno()).h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <limits.h> |
| 29 | |
| 30 | #include "systat.h" |
| 31 | |
| 32 | #ifndef nitems |
| 33 | #define nitems(_a)(sizeof((_a)) / sizeof((_a)[0])) (sizeof((_a)) / sizeof((_a)[0])) |
| 34 | #endif |
| 35 | |
| 36 | void print_uvm(void); |
| 37 | int read_uvm(void); |
| 38 | int select_uvm(void); |
| 39 | |
| 40 | void print_uvmexp_field(field_def *, field_def *, int *, int *, const char *); |
| 41 | void print_uvmexp_line(int); |
| 42 | |
| 43 | struct uvmexp uvmexp; |
| 44 | struct uvmexp last_uvmexp; |
| 45 | |
| 46 | struct uvmline { |
| 47 | int *v1; |
| 48 | int *ov1; |
| 49 | char *n1; |
| 50 | int *v2; |
| 51 | int *ov2; |
| 52 | char *n2; |
| 53 | int *v3; |
| 54 | int *ov3; |
| 55 | char *n3; |
| 56 | }; |
| 57 | |
| 58 | struct uvmline uvmline[] = { |
| 59 | { NULL((void *)0), NULL((void *)0), "Page Counters", |
| 60 | NULL((void *)0), NULL((void *)0), "Stats Counters", |
| 61 | NULL((void *)0), NULL((void *)0), "Fault Counters" }, |
| 62 | { &uvmexp.npages, &last_uvmexp.npages, "npages", |
| 63 | &uvmexp.faults, &last_uvmexp.faults, "faults", |
| 64 | &uvmexp.fltnoram, &last_uvmexp.fltnoram, "fltnoram" }, |
| 65 | { &uvmexp.free, &last_uvmexp.free, "free", |
| 66 | &uvmexp.traps, &last_uvmexp.traps, "traps", |
| 67 | &uvmexp.fltnoanon, &last_uvmexp.fltnoanon, "fltnoanon" }, |
| 68 | { &uvmexp.active, &last_uvmexp.active, "active", |
| 69 | &uvmexp.intrs, &last_uvmexp.intrs, "intrs", |
| 70 | &uvmexp.fltnoamap, &last_uvmexp.fltnoamap, "fltnoamap" }, |
| 71 | { &uvmexp.inactive, &last_uvmexp.inactive, "inactive", |
| 72 | &uvmexp.swtch, &last_uvmexp.swtch, "swtch", |
| 73 | &uvmexp.fltpgwait, &last_uvmexp.fltpgwait, "fltpgwait" }, |
| 74 | { &uvmexp.paging, &last_uvmexp.paging, "paging", |
| 75 | &uvmexp.softs, &last_uvmexp.softs, "softs", |
| 76 | &uvmexp.fltpgrele, &last_uvmexp.fltpgrele, "fltpgrele" }, |
| 77 | { &uvmexp.wired, &last_uvmexp.wired, "wired", |
| 78 | &uvmexp.syscalls, &last_uvmexp.syscalls, "syscalls", |
| 79 | &uvmexp.fltrelck, &last_uvmexp.fltrelck, "fltrelck" }, |
| 80 | { &uvmexp.zeropages, &last_uvmexp.zeropages, "zeropages", |
| 81 | &uvmexp.pageins, &last_uvmexp.pageins, "pageins", |
| 82 | &uvmexp.fltrelckok, &last_uvmexp.fltrelckok, "fltrelckok" }, |
| 83 | { &uvmexp.reserve_pagedaemon, &last_uvmexp.reserve_pagedaemon, |
| 84 | "reserve_pagedaemon", |
| 85 | &uvmexp.pgswapin, &last_uvmexp.pgswapin, "pgswapin", |
| 86 | &uvmexp.fltanget, &last_uvmexp.fltanget, "fltanget" }, |
| 87 | { &uvmexp.reserve_kernel, &last_uvmexp.reserve_kernel, "reserve_kernel", |
| 88 | &uvmexp.pgswapout, &last_uvmexp.pgswapout, "pgswapout", |
| 89 | &uvmexp.fltanretry, &last_uvmexp.fltanretry, "fltanretry" }, |
| 90 | { NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 91 | &uvmexp.forks, &last_uvmexp.forks, "forks", |
| 92 | &uvmexp.fltamcopy, &last_uvmexp.fltamcopy, "fltamcopy" }, |
| 93 | { NULL((void *)0), NULL((void *)0), "Pageout Params", |
| 94 | &uvmexp.forks_ppwait, &last_uvmexp.forks_ppwait, "forks_ppwait", |
| 95 | &uvmexp.fltnamap, &last_uvmexp.fltnamap, "fltnamap" }, |
| 96 | { &uvmexp.freemin, &last_uvmexp.freemin, "freemin", |
| 97 | &uvmexp.forks_sharevm, &last_uvmexp.forks_sharevm, "forks_sharevm", |
| 98 | &uvmexp.fltnomap, &last_uvmexp.fltnomap, "fltnomap" }, |
| 99 | { &uvmexp.freetarg, &last_uvmexp.freetarg, "freetarg", |
| 100 | &uvmexp.pga_zerohit, &last_uvmexp.pga_zerohit, "pga_zerohit", |
| 101 | &uvmexp.fltlget, &last_uvmexp.fltlget, "fltlget" }, |
| 102 | { &uvmexp.inactarg, &last_uvmexp.inactarg, "inactarg", |
| 103 | &uvmexp.pga_zeromiss, &last_uvmexp.pga_zeromiss, "pga_zeromiss", |
| 104 | &uvmexp.fltget, &last_uvmexp.fltget, "fltget" }, |
| 105 | { &uvmexp.wiredmax, &last_uvmexp.wiredmax, "wiredmax", |
| 106 | NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 107 | &uvmexp.flt_anon, &last_uvmexp.flt_anon, "flt_anon" }, |
| 108 | { &uvmexp.anonmin, &last_uvmexp.anonmin, "anonmin", |
| 109 | NULL((void *)0), NULL((void *)0), "Daemon Counters", |
| 110 | &uvmexp.flt_acow, &last_uvmexp.flt_acow, "flt_acow" }, |
| 111 | { &uvmexp.vtextmin, &last_uvmexp.vtextmin, "vtextmin", |
| 112 | &uvmexp.pdwoke, &last_uvmexp.pdwoke, "pdwoke", |
| 113 | &uvmexp.flt_obj, &last_uvmexp.flt_obj, "flt_obj" }, |
| 114 | { &uvmexp.vnodemin, &last_uvmexp.vnodemin, "vnodemin", |
| 115 | &uvmexp.pdrevs, &last_uvmexp.pdrevs, "pdrevs", |
| 116 | &uvmexp.flt_prcopy, &last_uvmexp.flt_prcopy, "flt_prcopy" }, |
| 117 | { &uvmexp.anonminpct, &last_uvmexp.anonminpct, "anonminpct", |
| 118 | &uvmexp.pdswout, &last_uvmexp.pdswout, "pdswout", |
| 119 | &uvmexp.flt_przero, &last_uvmexp.flt_przero, "flt_przero" }, |
| 120 | { &uvmexp.vtextminpct, &last_uvmexp.vtextminpct, "vtextminpct", |
| 121 | &uvmexp.swpgonly, &last_uvmexp.swpgonly, "swpgonly", |
| 122 | NULL((void *)0), NULL((void *)0), NULL((void *)0) }, |
| 123 | { &uvmexp.vnodeminpct, &last_uvmexp.vnodeminpct, "vnodeminpct", |
| 124 | &uvmexp.pdfreed, &last_uvmexp.pdfreed, "pdfreed", |
| 125 | NULL((void *)0), NULL((void *)0), "Swap Counters" }, |
| 126 | { NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 127 | &uvmexp.pdscans, &last_uvmexp.pdscans, "pdscans", |
| 128 | &uvmexp.nswapdev, &last_uvmexp.nswapdev, "nswapdev" }, |
| 129 | { NULL((void *)0), NULL((void *)0), "Misc Counters", |
| 130 | &uvmexp.pdanscan, &last_uvmexp.pdanscan, "pdanscan", |
| 131 | &uvmexp.swpages, &last_uvmexp.swpages, "swpages" }, |
| 132 | { &uvmexp.fpswtch, &last_uvmexp.fpswtch, "fpswtch", |
| 133 | &uvmexp.pdobscan, &last_uvmexp.pdobscan, "pdobscan", |
| 134 | &uvmexp.swpginuse, &last_uvmexp.swpginuse, "swpginuse" }, |
| 135 | { &uvmexp.kmapent, &last_uvmexp.kmapent, "kmapent", |
| 136 | &uvmexp.pdreact, &last_uvmexp.pdreact, "pdreact", |
| 137 | &uvmexp.nswget, &last_uvmexp.nswget, "nswget" }, |
| 138 | { NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 139 | &uvmexp.pdbusy, &last_uvmexp.pdbusy, "pdbusy", |
| 140 | NULL((void *)0), NULL((void *)0), NULL((void *)0) }, |
| 141 | { NULL((void *)0), NULL((void *)0), "Constants", |
| 142 | &uvmexp.pdpageouts, &last_uvmexp.pdpageouts, "pdpageouts", |
| 143 | NULL((void *)0), NULL((void *)0), NULL((void *)0) }, |
| 144 | { &uvmexp.pagesize, &last_uvmexp.pagesize, "pagesize", |
| 145 | &uvmexp.pdpending, &last_uvmexp.pdpending, "pdpending", |
| 146 | NULL((void *)0), NULL((void *)0), NULL((void *)0) }, |
| 147 | { &uvmexp.pagemask, &last_uvmexp.pagemask, "pagemask", |
| 148 | &uvmexp.pddeact, &last_uvmexp.pddeact, "pddeact", |
| 149 | NULL((void *)0), NULL((void *)0), NULL((void *)0) }, |
| 150 | { &uvmexp.pageshift, &last_uvmexp.pageshift, "pageshift", |
| 151 | NULL((void *)0), NULL((void *)0), NULL((void *)0), |
| 152 | NULL((void *)0), NULL((void *)0), NULL((void *)0) } |
| 153 | }; |
| 154 | |
| 155 | field_def fields_uvm[] = { |
| 156 | {"", 5,10,1, FLD_ALIGN_RIGHT1, -1,0,0,0 }, |
| 157 | {"", 18,19,1, FLD_ALIGN_LEFT0, -1,0,0,0 }, |
| 158 | {"", 5,10,1, FLD_ALIGN_RIGHT1, -1,0,0,0 }, |
| 159 | {"", 18,19,1, FLD_ALIGN_LEFT0, -1,0,0,0 }, |
| 160 | {"", 5,10,1, FLD_ALIGN_RIGHT1, -1,0,0,0 }, |
| 161 | {"", 18,19,1, FLD_ALIGN_LEFT0, -1,0,0,0 }, |
| 162 | }; |
| 163 | |
| 164 | #define FLD_VALUE1(&fields_uvm[0]) FIELD_ADDR(fields_uvm, 0)(&fields_uvm[0]) |
| 165 | #define FLD_NAME1(&fields_uvm[1]) FIELD_ADDR(fields_uvm, 1)(&fields_uvm[1]) |
| 166 | #define FLD_VALUE2(&fields_uvm[2]) FIELD_ADDR(fields_uvm, 2)(&fields_uvm[2]) |
| 167 | #define FLD_NAME2(&fields_uvm[3]) FIELD_ADDR(fields_uvm, 3)(&fields_uvm[3]) |
| 168 | #define FLD_VALUE3(&fields_uvm[4]) FIELD_ADDR(fields_uvm, 4)(&fields_uvm[4]) |
| 169 | #define FLD_NAME3(&fields_uvm[5]) FIELD_ADDR(fields_uvm, 5)(&fields_uvm[5]) |
| 170 | |
| 171 | /* Define views */ |
| 172 | field_def *view_uvm_0[] = { |
| 173 | FLD_VALUE1(&fields_uvm[0]), FLD_NAME1(&fields_uvm[1]), |
| 174 | FLD_VALUE2(&fields_uvm[2]), FLD_NAME2(&fields_uvm[3]), |
| 175 | FLD_VALUE3(&fields_uvm[4]), FLD_NAME3(&fields_uvm[5]), |
| 176 | NULL((void *)0) |
| 177 | }; |
| 178 | |
| 179 | /* Define view managers */ |
| 180 | struct view_manager uvm_mgr = { |
| 181 | "UVM", select_uvm, read_uvm, NULL((void *)0), print_header, |
| 182 | print_uvm, keyboard_callback, NULL((void *)0), NULL((void *)0) |
| 183 | }; |
| 184 | |
| 185 | field_view uvm_view = { |
| 186 | view_uvm_0, |
| 187 | "uvm", |
| 188 | '5', |
| 189 | &uvm_mgr |
| 190 | }; |
| 191 | |
| 192 | int |
| 193 | select_uvm(void) |
| 194 | { |
| 195 | return (0); |
| 196 | } |
| 197 | |
| 198 | int |
| 199 | read_uvm(void) |
| 200 | { |
| 201 | static int uvmexp_mib[2] = { CTL_VM2, VM_UVMEXP4 }; |
| 202 | size_t size; |
| 203 | |
| 204 | num_disp = nitems(uvmline)(sizeof((uvmline)) / sizeof((uvmline)[0])); |
| 205 | memcpy(&last_uvmexp, &uvmexp, sizeof(uvmexp)); |
| 206 | |
| 207 | size = sizeof(uvmexp); |
| 208 | if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL((void *)0), 0) == -1) { |
| 209 | error("Can't get VM_UVMEXP: %s\n", strerror(errno(*__errno()))); |
| 210 | memset(&uvmexp, 0, sizeof(uvmexp)); |
| 211 | } |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | void |
| 217 | print_uvmexp_field(field_def *fvalue, field_def *fname, int *new, int *old, |
| 218 | const char *name) |
| 219 | { |
| 220 | char *uppername; |
| 221 | size_t len, i; |
| 222 | |
| 223 | if (new == NULL((void *)0) && name == NULL((void *)0)) |
| 224 | return; |
| 225 | |
| 226 | if (new == NULL((void *)0)) { |
| 227 | print_fld_str(fvalue, "====="); |
| 228 | print_fld_str(fname, name); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | if (*new != 0) |
| 233 | print_fld_ssize(fvalue, *new); |
| 234 | if (*new == *old) { |
| 235 | print_fld_str(fname, name); |
| 236 | return; |
| 237 | } |
| 238 | len = strlen(name); |
| 239 | uppername = malloc(len + 1); |
| 240 | if (uppername == NULL((void *)0)) |
| 241 | err(1, "malloc"); |
| 242 | for (i = 0; i < len; i++) |
| 243 | uppername[i] = toupper(name[i]); |
| 244 | uppername[len] = '\0'; |
| 245 | print_fld_str(fname, uppername); |
| 246 | free(uppername); |
| 247 | } |
| 248 | |
| 249 | void |
| 250 | print_uvm(void) |
| 251 | { |
| 252 | struct uvmline *l; |
| 253 | int i, maxline; |
| 254 | |
| 255 | maxline = nitems(uvmline)(sizeof((uvmline)) / sizeof((uvmline)[0])); |
| 256 | if (maxline > (dispstart + maxprint)) |
| 257 | maxline = dispstart + maxprint; |
Value stored to 'maxline' is never read | |
| 258 | |
| 259 | for (i = dispstart; i < nitems(uvmline)(sizeof((uvmline)) / sizeof((uvmline)[0])); i++) { |
| 260 | l = &uvmline[i]; |
| 261 | print_uvmexp_field(FLD_VALUE1(&fields_uvm[0]), FLD_NAME1(&fields_uvm[1]), l->v1, l->ov1, l->n1); |
| 262 | print_uvmexp_field(FLD_VALUE2(&fields_uvm[2]), FLD_NAME2(&fields_uvm[3]), l->v2, l->ov2, l->n2); |
| 263 | print_uvmexp_field(FLD_VALUE3(&fields_uvm[4]), FLD_NAME3(&fields_uvm[5]), l->v3, l->ov3, l->n3); |
| 264 | end_line(); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | int |
| 269 | inituvm(void) |
| 270 | { |
| 271 | add_view(&uvm_view); |
| 272 | read_uvm(); |
| 273 | |
| 274 | return(0); |
| 275 | } |