Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/common/modules/genunix/genunix.c
+++ new/usr/src/cmd/mdb/common/modules/genunix/genunix.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright 2017 Joyent, Inc.
24 + * Copyright (c) 2018, Joyent, Inc.
25 25 * Copyright (c) 2013 by Delphix. All rights reserved.
26 26 */
27 27
28 28 #include <mdb/mdb_param.h>
29 29 #include <mdb/mdb_modapi.h>
30 30 #include <mdb/mdb_ks.h>
31 31 #include <mdb/mdb_ctf.h>
32 32
33 33 #include <sys/types.h>
34 34 #include <sys/thread.h>
35 35 #include <sys/session.h>
36 36 #include <sys/user.h>
37 37 #include <sys/proc.h>
38 38 #include <sys/var.h>
39 39 #include <sys/t_lock.h>
40 40 #include <sys/callo.h>
41 41 #include <sys/priocntl.h>
42 42 #include <sys/class.h>
43 43 #include <sys/regset.h>
44 44 #include <sys/stack.h>
45 45 #include <sys/cpuvar.h>
46 46 #include <sys/vnode.h>
47 47 #include <sys/vfs.h>
48 48 #include <sys/flock_impl.h>
49 49 #include <sys/kmem_impl.h>
50 50 #include <sys/vmem_impl.h>
51 51 #include <sys/kstat.h>
52 52 #include <sys/dditypes.h>
53 53 #include <sys/ddi_impldefs.h>
54 54 #include <sys/sysmacros.h>
55 55 #include <sys/sysconf.h>
56 56 #include <sys/task.h>
57 57 #include <sys/project.h>
58 58 #include <sys/errorq_impl.h>
59 59 #include <sys/cred_impl.h>
60 60 #include <sys/zone.h>
61 61 #include <sys/panic.h>
62 62 #include <regex.h>
63 63 #include <sys/port_impl.h>
64 64
65 65 #include "avl.h"
66 66 #include "bio.h"
67 67 #include "bitset.h"
68 68 #include "combined.h"
69 69 #include "contract.h"
70 70 #include "cpupart_mdb.h"
71 71 #include "cred.h"
72 72 #include "ctxop.h"
73 73 #include "cyclic.h"
74 74 #include "damap.h"
75 75 #include "ddi_periodic.h"
76 76 #include "devinfo.h"
77 77 #include "dnlc.h"
78 78 #include "findstack.h"
79 79 #include "fm.h"
80 80 #include "gcore.h"
81 81 #include "group.h"
82 82 #include "irm.h"
83 83 #include "kgrep.h"
84 84 #include "kmem.h"
85 85 #include "ldi.h"
86 86 #include "leaky.h"
87 87 #include "lgrp.h"
88 88 #include "list.h"
89 89 #include "log.h"
90 90 #include "mdi.h"
91 91 #include "memory.h"
92 92 #include "mmd.h"
93 93 #include "modhash.h"
94 94 #include "ndievents.h"
95 95 #include "net.h"
96 96 #include "netstack.h"
97 97 #include "nvpair.h"
98 98 #include "pg.h"
99 99 #include "rctl.h"
100 100 #include "sobj.h"
101 101 #include "streams.h"
102 102 #include "sysevent.h"
103 103 #include "taskq.h"
104 104 #include "thread.h"
105 105 #include "tsd.h"
106 106 #include "tsol.h"
107 107 #include "typegraph.h"
108 108 #include "vfs.h"
109 109 #include "zone.h"
110 110 #include "hotplug.h"
111 111
112 112 /*
113 113 * Surely this is defined somewhere...
114 114 */
115 115 #define NINTR 16
116 116
117 117 #define KILOS 10
118 118 #define MEGS 20
119 119 #define GIGS 30
120 120
121 121 #ifndef STACK_BIAS
122 122 #define STACK_BIAS 0
123 123 #endif
124 124
125 125 static char
126 126 pstat2ch(uchar_t state)
127 127 {
128 128 switch (state) {
129 129 case SSLEEP: return ('S');
130 130 case SRUN: return ('R');
131 131 case SZOMB: return ('Z');
132 132 case SIDL: return ('I');
133 133 case SONPROC: return ('O');
134 134 case SSTOP: return ('T');
135 135 case SWAIT: return ('W');
136 136 default: return ('?');
137 137 }
138 138 }
139 139
140 140 #define PS_PRTTHREADS 0x1
141 141 #define PS_PRTLWPS 0x2
142 142 #define PS_PSARGS 0x4
143 143 #define PS_TASKS 0x8
144 144 #define PS_PROJECTS 0x10
145 145 #define PS_ZONES 0x20
146 146
147 147 static int
148 148 ps_threadprint(uintptr_t addr, const void *data, void *private)
149 149 {
150 150 const kthread_t *t = (const kthread_t *)data;
151 151 uint_t prt_flags = *((uint_t *)private);
152 152
153 153 static const mdb_bitmask_t t_state_bits[] = {
154 154 { "TS_FREE", UINT_MAX, TS_FREE },
155 155 { "TS_SLEEP", TS_SLEEP, TS_SLEEP },
156 156 { "TS_RUN", TS_RUN, TS_RUN },
↓ open down ↓ |
122 lines elided |
↑ open up ↑ |
157 157 { "TS_ONPROC", TS_ONPROC, TS_ONPROC },
158 158 { "TS_ZOMB", TS_ZOMB, TS_ZOMB },
159 159 { "TS_STOPPED", TS_STOPPED, TS_STOPPED },
160 160 { "TS_WAIT", TS_WAIT, TS_WAIT },
161 161 { NULL, 0, 0 }
162 162 };
163 163
164 164 if (prt_flags & PS_PRTTHREADS)
165 165 mdb_printf("\tT %?a <%b>\n", addr, t->t_state, t_state_bits);
166 166
167 - if (prt_flags & PS_PRTLWPS)
168 - mdb_printf("\tL %?a ID: %u\n", t->t_lwp, t->t_tid);
167 + if (prt_flags & PS_PRTLWPS) {
168 + char desc[128] = "";
169 169
170 + (void) thread_getdesc(addr, B_FALSE, desc, sizeof (desc));
171 +
172 + mdb_printf("\tL %?a ID: %s\n", t->t_lwp, desc);
173 + }
174 +
170 175 return (WALK_NEXT);
171 176 }
172 177
173 178 typedef struct mdb_pflags_proc {
174 - struct pid *p_pidp;
179 + struct pid *p_pidp;
175 180 ushort_t p_pidflag;
176 181 uint_t p_proc_flag;
177 182 uint_t p_flag;
178 183 } mdb_pflags_proc_t;
179 184
180 185 static int
181 186 pflags(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
182 187 {
183 188 mdb_pflags_proc_t pr;
184 189 struct pid pid;
185 190
186 191 static const mdb_bitmask_t p_flag_bits[] = {
187 192 { "SSYS", SSYS, SSYS },
188 193 { "SEXITING", SEXITING, SEXITING },
189 194 { "SITBUSY", SITBUSY, SITBUSY },
190 195 { "SFORKING", SFORKING, SFORKING },
191 196 { "SWATCHOK", SWATCHOK, SWATCHOK },
192 197 { "SKILLED", SKILLED, SKILLED },
193 198 { "SSCONT", SSCONT, SSCONT },
194 199 { "SZONETOP", SZONETOP, SZONETOP },
195 200 { "SEXTKILLED", SEXTKILLED, SEXTKILLED },
196 201 { "SUGID", SUGID, SUGID },
197 202 { "SEXECED", SEXECED, SEXECED },
198 203 { "SJCTL", SJCTL, SJCTL },
199 204 { "SNOWAIT", SNOWAIT, SNOWAIT },
200 205 { "SVFORK", SVFORK, SVFORK },
201 206 { "SVFWAIT", SVFWAIT, SVFWAIT },
202 207 { "SEXITLWPS", SEXITLWPS, SEXITLWPS },
203 208 { "SHOLDFORK", SHOLDFORK, SHOLDFORK },
204 209 { "SHOLDFORK1", SHOLDFORK1, SHOLDFORK1 },
205 210 { "SCOREDUMP", SCOREDUMP, SCOREDUMP },
206 211 { "SMSACCT", SMSACCT, SMSACCT },
207 212 { "SLWPWRAP", SLWPWRAP, SLWPWRAP },
208 213 { "SAUTOLPG", SAUTOLPG, SAUTOLPG },
209 214 { "SNOCD", SNOCD, SNOCD },
210 215 { "SHOLDWATCH", SHOLDWATCH, SHOLDWATCH },
211 216 { "SMSFORK", SMSFORK, SMSFORK },
212 217 { "SDOCORE", SDOCORE, SDOCORE },
213 218 { NULL, 0, 0 }
214 219 };
215 220
216 221 static const mdb_bitmask_t p_pidflag_bits[] = {
217 222 { "CLDPEND", CLDPEND, CLDPEND },
218 223 { "CLDCONT", CLDCONT, CLDCONT },
219 224 { "CLDNOSIGCHLD", CLDNOSIGCHLD, CLDNOSIGCHLD },
220 225 { "CLDWAITPID", CLDWAITPID, CLDWAITPID },
221 226 { NULL, 0, 0 }
222 227 };
223 228
224 229 static const mdb_bitmask_t p_proc_flag_bits[] = {
225 230 { "P_PR_TRACE", P_PR_TRACE, P_PR_TRACE },
226 231 { "P_PR_PTRACE", P_PR_PTRACE, P_PR_PTRACE },
227 232 { "P_PR_FORK", P_PR_FORK, P_PR_FORK },
228 233 { "P_PR_LOCK", P_PR_LOCK, P_PR_LOCK },
229 234 { "P_PR_ASYNC", P_PR_ASYNC, P_PR_ASYNC },
230 235 { "P_PR_EXEC", P_PR_EXEC, P_PR_EXEC },
231 236 { "P_PR_BPTADJ", P_PR_BPTADJ, P_PR_BPTADJ },
232 237 { "P_PR_RUNLCL", P_PR_RUNLCL, P_PR_RUNLCL },
233 238 { "P_PR_KILLCL", P_PR_KILLCL, P_PR_KILLCL },
234 239 { NULL, 0, 0 }
235 240 };
236 241
237 242 if (!(flags & DCMD_ADDRSPEC)) {
238 243 if (mdb_walk_dcmd("proc", "pflags", argc, argv) == -1) {
239 244 mdb_warn("can't walk 'proc'");
240 245 return (DCMD_ERR);
241 246 }
242 247 return (DCMD_OK);
243 248 }
244 249
245 250 if (mdb_ctf_vread(&pr, "proc_t", "mdb_pflags_proc_t", addr, 0) == -1 ||
246 251 mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp) == -1) {
247 252 mdb_warn("cannot read proc_t or pid");
248 253 return (DCMD_ERR);
249 254 }
250 255
251 256 mdb_printf("%p [pid %d]:\n", addr, pid.pid_id);
252 257 mdb_printf("\tp_flag: %08x <%b>\n", pr.p_flag, pr.p_flag,
253 258 p_flag_bits);
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
254 259 mdb_printf("\tp_pidflag: %08x <%b>\n", pr.p_pidflag, pr.p_pidflag,
255 260 p_pidflag_bits);
256 261 mdb_printf("\tp_proc_flag: %08x <%b>\n", pr.p_proc_flag, pr.p_proc_flag,
257 262 p_proc_flag_bits);
258 263
259 264 return (DCMD_OK);
260 265 }
261 266
262 267 typedef struct mdb_ps_proc {
263 268 char p_stat;
264 - struct pid *p_pidp;
265 - struct pid *p_pgidp;
269 + struct pid *p_pidp;
270 + struct pid *p_pgidp;
266 271 struct cred *p_cred;
267 272 struct sess *p_sessp;
268 273 struct task *p_task;
269 274 struct zone *p_zone;
270 275 pid_t p_ppid;
271 276 uint_t p_flag;
272 277 struct {
273 278 char u_comm[MAXCOMLEN + 1];
274 279 char u_psargs[PSARGSZ];
275 280 } p_user;
276 281 } mdb_ps_proc_t;
277 282
278 283 int
279 284 ps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
280 285 {
281 286 uint_t prt_flags = 0;
282 287 mdb_ps_proc_t pr;
283 288 struct pid pid, pgid, sid;
284 289 sess_t session;
285 290 cred_t cred;
286 291 task_t tk;
287 292 kproject_t pj;
288 293 zone_t zn;
289 294
290 295 if (!(flags & DCMD_ADDRSPEC)) {
291 296 if (mdb_walk_dcmd("proc", "ps", argc, argv) == -1) {
292 297 mdb_warn("can't walk 'proc'");
293 298 return (DCMD_ERR);
294 299 }
295 300 return (DCMD_OK);
296 301 }
297 302
298 303 if (mdb_getopts(argc, argv,
299 304 'f', MDB_OPT_SETBITS, PS_PSARGS, &prt_flags,
300 305 'l', MDB_OPT_SETBITS, PS_PRTLWPS, &prt_flags,
301 306 'T', MDB_OPT_SETBITS, PS_TASKS, &prt_flags,
302 307 'P', MDB_OPT_SETBITS, PS_PROJECTS, &prt_flags,
303 308 'z', MDB_OPT_SETBITS, PS_ZONES, &prt_flags,
304 309 't', MDB_OPT_SETBITS, PS_PRTTHREADS, &prt_flags, NULL) != argc)
305 310 return (DCMD_USAGE);
306 311
307 312 if (DCMD_HDRSPEC(flags)) {
308 313 mdb_printf("%<u>%1s %6s %6s %6s %6s ",
309 314 "S", "PID", "PPID", "PGID", "SID");
310 315 if (prt_flags & PS_TASKS)
311 316 mdb_printf("%5s ", "TASK");
312 317 if (prt_flags & PS_PROJECTS)
313 318 mdb_printf("%5s ", "PROJ");
314 319 if (prt_flags & PS_ZONES)
315 320 mdb_printf("%5s ", "ZONE");
316 321 mdb_printf("%6s %10s %?s %s%</u>\n",
317 322 "UID", "FLAGS", "ADDR", "NAME");
318 323 }
319 324
320 325 if (mdb_ctf_vread(&pr, "proc_t", "mdb_ps_proc_t", addr, 0) == -1)
321 326 return (DCMD_ERR);
322 327
323 328 mdb_vread(&pid, sizeof (pid), (uintptr_t)pr.p_pidp);
324 329 mdb_vread(&pgid, sizeof (pgid), (uintptr_t)pr.p_pgidp);
325 330 mdb_vread(&cred, sizeof (cred), (uintptr_t)pr.p_cred);
326 331 mdb_vread(&session, sizeof (session), (uintptr_t)pr.p_sessp);
327 332 mdb_vread(&sid, sizeof (sid), (uintptr_t)session.s_sidp);
328 333 if (prt_flags & (PS_TASKS | PS_PROJECTS))
329 334 mdb_vread(&tk, sizeof (tk), (uintptr_t)pr.p_task);
330 335 if (prt_flags & PS_PROJECTS)
331 336 mdb_vread(&pj, sizeof (pj), (uintptr_t)tk.tk_proj);
332 337 if (prt_flags & PS_ZONES)
333 338 mdb_vread(&zn, sizeof (zn), (uintptr_t)pr.p_zone);
334 339
335 340 mdb_printf("%c %6d %6d %6d %6d ",
336 341 pstat2ch(pr.p_stat), pid.pid_id, pr.p_ppid, pgid.pid_id,
337 342 sid.pid_id);
338 343 if (prt_flags & PS_TASKS)
339 344 mdb_printf("%5d ", tk.tk_tkid);
340 345 if (prt_flags & PS_PROJECTS)
341 346 mdb_printf("%5d ", pj.kpj_id);
342 347 if (prt_flags & PS_ZONES)
343 348 mdb_printf("%5d ", zn.zone_id);
344 349 mdb_printf("%6d 0x%08x %0?p %s\n",
345 350 cred.cr_uid, pr.p_flag, addr,
346 351 (prt_flags & PS_PSARGS) ? pr.p_user.u_psargs : pr.p_user.u_comm);
347 352
348 353 if (prt_flags & ~PS_PSARGS)
349 354 (void) mdb_pwalk("thread", ps_threadprint, &prt_flags, addr);
350 355
351 356 return (DCMD_OK);
352 357 }
353 358
354 359 #define PG_NEWEST 0x0001
355 360 #define PG_OLDEST 0x0002
356 361 #define PG_PIPE_OUT 0x0004
357 362 #define PG_EXACT_MATCH 0x0008
358 363
359 364 typedef struct pgrep_data {
360 365 uint_t pg_flags;
361 366 uint_t pg_psflags;
362 367 uintptr_t pg_xaddr;
363 368 hrtime_t pg_xstart;
364 369 const char *pg_pat;
365 370 #ifndef _KMDB
366 371 regex_t pg_reg;
367 372 #endif
368 373 } pgrep_data_t;
369 374
370 375 typedef struct mdb_pgrep_proc {
371 376 struct {
372 377 timestruc_t u_start;
373 378 char u_comm[MAXCOMLEN + 1];
374 379 } p_user;
375 380 } mdb_pgrep_proc_t;
376 381
377 382 /*ARGSUSED*/
378 383 static int
379 384 pgrep_cb(uintptr_t addr, const void *ignored, void *data)
380 385 {
381 386 mdb_pgrep_proc_t p;
382 387 pgrep_data_t *pgp = data;
383 388 #ifndef _KMDB
384 389 regmatch_t pmatch;
385 390 #endif
386 391
387 392 if (mdb_ctf_vread(&p, "proc_t", "mdb_pgrep_proc_t", addr, 0) == -1)
388 393 return (WALK_ERR);
389 394
390 395 /*
391 396 * kmdb doesn't have access to the reg* functions, so we fall back
392 397 * to strstr/strcmp.
393 398 */
394 399 #ifdef _KMDB
395 400 if ((pgp->pg_flags & PG_EXACT_MATCH) ?
396 401 (strcmp(p.p_user.u_comm, pgp->pg_pat) != 0) :
397 402 (strstr(p.p_user.u_comm, pgp->pg_pat) == NULL))
398 403 return (WALK_NEXT);
399 404 #else
400 405 if (regexec(&pgp->pg_reg, p.p_user.u_comm, 1, &pmatch, 0) != 0)
401 406 return (WALK_NEXT);
402 407
403 408 if ((pgp->pg_flags & PG_EXACT_MATCH) &&
404 409 (pmatch.rm_so != 0 || p.p_user.u_comm[pmatch.rm_eo] != '\0'))
405 410 return (WALK_NEXT);
406 411 #endif
407 412
408 413 if (pgp->pg_flags & (PG_NEWEST | PG_OLDEST)) {
409 414 hrtime_t start;
410 415
411 416 start = (hrtime_t)p.p_user.u_start.tv_sec * NANOSEC +
412 417 p.p_user.u_start.tv_nsec;
413 418
414 419 if (pgp->pg_flags & PG_NEWEST) {
415 420 if (pgp->pg_xaddr == NULL || start > pgp->pg_xstart) {
416 421 pgp->pg_xaddr = addr;
417 422 pgp->pg_xstart = start;
418 423 }
419 424 } else {
420 425 if (pgp->pg_xaddr == NULL || start < pgp->pg_xstart) {
421 426 pgp->pg_xaddr = addr;
422 427 pgp->pg_xstart = start;
423 428 }
424 429 }
425 430
426 431 } else if (pgp->pg_flags & PG_PIPE_OUT) {
427 432 mdb_printf("%p\n", addr);
428 433
429 434 } else {
430 435 if (mdb_call_dcmd("ps", addr, pgp->pg_psflags, 0, NULL) != 0) {
431 436 mdb_warn("can't invoke 'ps'");
432 437 return (WALK_DONE);
433 438 }
434 439 pgp->pg_psflags &= ~DCMD_LOOPFIRST;
435 440 }
436 441
437 442 return (WALK_NEXT);
438 443 }
439 444
440 445 /*ARGSUSED*/
441 446 int
442 447 pgrep(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
443 448 {
444 449 pgrep_data_t pg;
445 450 int i;
446 451 #ifndef _KMDB
447 452 int err;
448 453 #endif
449 454
450 455 if (flags & DCMD_ADDRSPEC)
451 456 return (DCMD_USAGE);
452 457
453 458 pg.pg_flags = 0;
454 459 pg.pg_xaddr = 0;
455 460
456 461 i = mdb_getopts(argc, argv,
457 462 'n', MDB_OPT_SETBITS, PG_NEWEST, &pg.pg_flags,
458 463 'o', MDB_OPT_SETBITS, PG_OLDEST, &pg.pg_flags,
459 464 'x', MDB_OPT_SETBITS, PG_EXACT_MATCH, &pg.pg_flags,
460 465 NULL);
461 466
462 467 argc -= i;
463 468 argv += i;
464 469
465 470 if (argc != 1)
466 471 return (DCMD_USAGE);
467 472
468 473 /*
469 474 * -n and -o are mutually exclusive.
470 475 */
471 476 if ((pg.pg_flags & PG_NEWEST) && (pg.pg_flags & PG_OLDEST))
472 477 return (DCMD_USAGE);
473 478
474 479 if (argv->a_type != MDB_TYPE_STRING)
475 480 return (DCMD_USAGE);
476 481
477 482 if (flags & DCMD_PIPE_OUT)
478 483 pg.pg_flags |= PG_PIPE_OUT;
479 484
480 485 pg.pg_pat = argv->a_un.a_str;
481 486 if (DCMD_HDRSPEC(flags))
482 487 pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP | DCMD_LOOPFIRST;
483 488 else
484 489 pg.pg_psflags = DCMD_ADDRSPEC | DCMD_LOOP;
485 490
486 491 #ifndef _KMDB
487 492 if ((err = regcomp(&pg.pg_reg, pg.pg_pat, REG_EXTENDED)) != 0) {
488 493 size_t nbytes;
489 494 char *buf;
490 495
491 496 nbytes = regerror(err, &pg.pg_reg, NULL, 0);
492 497 buf = mdb_alloc(nbytes + 1, UM_SLEEP | UM_GC);
493 498 (void) regerror(err, &pg.pg_reg, buf, nbytes);
494 499 mdb_warn("%s\n", buf);
495 500
496 501 return (DCMD_ERR);
497 502 }
498 503 #endif
499 504
500 505 if (mdb_walk("proc", pgrep_cb, &pg) != 0) {
501 506 mdb_warn("can't walk 'proc'");
502 507 return (DCMD_ERR);
503 508 }
504 509
505 510 if (pg.pg_xaddr != 0 && (pg.pg_flags & (PG_NEWEST | PG_OLDEST))) {
506 511 if (pg.pg_flags & PG_PIPE_OUT) {
507 512 mdb_printf("%p\n", pg.pg_xaddr);
508 513 } else {
509 514 if (mdb_call_dcmd("ps", pg.pg_xaddr, pg.pg_psflags,
510 515 0, NULL) != 0) {
511 516 mdb_warn("can't invoke 'ps'");
512 517 return (DCMD_ERR);
513 518 }
514 519 }
515 520 }
516 521
517 522 return (DCMD_OK);
518 523 }
519 524
520 525 int
521 526 task(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
522 527 {
523 528 task_t tk;
524 529 kproject_t pj;
525 530
526 531 if (!(flags & DCMD_ADDRSPEC)) {
527 532 if (mdb_walk_dcmd("task_cache", "task", argc, argv) == -1) {
528 533 mdb_warn("can't walk task_cache");
529 534 return (DCMD_ERR);
530 535 }
531 536 return (DCMD_OK);
532 537 }
533 538 if (DCMD_HDRSPEC(flags)) {
534 539 mdb_printf("%<u>%?s %6s %6s %6s %6s %10s%</u>\n",
535 540 "ADDR", "TASKID", "PROJID", "ZONEID", "REFCNT", "FLAGS");
536 541 }
537 542 if (mdb_vread(&tk, sizeof (task_t), addr) == -1) {
538 543 mdb_warn("can't read task_t structure at %p", addr);
539 544 return (DCMD_ERR);
540 545 }
541 546 if (mdb_vread(&pj, sizeof (kproject_t), (uintptr_t)tk.tk_proj) == -1) {
542 547 mdb_warn("can't read project_t structure at %p", addr);
543 548 return (DCMD_ERR);
544 549 }
545 550 mdb_printf("%0?p %6d %6d %6d %6u 0x%08x\n",
546 551 addr, tk.tk_tkid, pj.kpj_id, pj.kpj_zoneid, tk.tk_hold_count,
547 552 tk.tk_flags);
548 553 return (DCMD_OK);
549 554 }
550 555
551 556 int
552 557 project(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
553 558 {
554 559 kproject_t pj;
555 560
556 561 if (!(flags & DCMD_ADDRSPEC)) {
557 562 if (mdb_walk_dcmd("projects", "project", argc, argv) == -1) {
558 563 mdb_warn("can't walk projects");
559 564 return (DCMD_ERR);
560 565 }
561 566 return (DCMD_OK);
562 567 }
563 568 if (DCMD_HDRSPEC(flags)) {
564 569 mdb_printf("%<u>%?s %6s %6s %6s%</u>\n",
565 570 "ADDR", "PROJID", "ZONEID", "REFCNT");
566 571 }
567 572 if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
568 573 mdb_warn("can't read kproject_t structure at %p", addr);
569 574 return (DCMD_ERR);
570 575 }
571 576 mdb_printf("%0?p %6d %6d %6u\n", addr, pj.kpj_id, pj.kpj_zoneid,
572 577 pj.kpj_count);
573 578 return (DCMD_OK);
574 579 }
575 580
576 581 /* walk callouts themselves, either by list or id hash. */
577 582 int
578 583 callout_walk_init(mdb_walk_state_t *wsp)
579 584 {
580 585 if (wsp->walk_addr == NULL) {
581 586 mdb_warn("callout doesn't support global walk");
582 587 return (WALK_ERR);
583 588 }
584 589 wsp->walk_data = mdb_alloc(sizeof (callout_t), UM_SLEEP);
585 590 return (WALK_NEXT);
586 591 }
587 592
588 593 #define CALLOUT_WALK_BYLIST 0
589 594 #define CALLOUT_WALK_BYID 1
590 595
591 596 /* the walker arg switches between walking by list (0) and walking by id (1). */
592 597 int
593 598 callout_walk_step(mdb_walk_state_t *wsp)
594 599 {
595 600 int retval;
596 601
597 602 if (wsp->walk_addr == NULL) {
598 603 return (WALK_DONE);
599 604 }
600 605 if (mdb_vread(wsp->walk_data, sizeof (callout_t),
601 606 wsp->walk_addr) == -1) {
602 607 mdb_warn("failed to read callout at %p", wsp->walk_addr);
603 608 return (WALK_DONE);
604 609 }
605 610 retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
606 611 wsp->walk_cbdata);
607 612
608 613 if ((ulong_t)wsp->walk_arg == CALLOUT_WALK_BYID) {
609 614 wsp->walk_addr =
610 615 (uintptr_t)(((callout_t *)wsp->walk_data)->c_idnext);
611 616 } else {
612 617 wsp->walk_addr =
613 618 (uintptr_t)(((callout_t *)wsp->walk_data)->c_clnext);
614 619 }
615 620
616 621 return (retval);
617 622 }
618 623
619 624 void
620 625 callout_walk_fini(mdb_walk_state_t *wsp)
621 626 {
622 627 mdb_free(wsp->walk_data, sizeof (callout_t));
623 628 }
624 629
625 630 /*
626 631 * walker for callout lists. This is different from hashes and callouts.
627 632 * Thankfully, it's also simpler.
628 633 */
629 634 int
630 635 callout_list_walk_init(mdb_walk_state_t *wsp)
631 636 {
632 637 if (wsp->walk_addr == NULL) {
633 638 mdb_warn("callout list doesn't support global walk");
634 639 return (WALK_ERR);
635 640 }
636 641 wsp->walk_data = mdb_alloc(sizeof (callout_list_t), UM_SLEEP);
637 642 return (WALK_NEXT);
638 643 }
639 644
640 645 int
641 646 callout_list_walk_step(mdb_walk_state_t *wsp)
642 647 {
643 648 int retval;
644 649
645 650 if (wsp->walk_addr == NULL) {
646 651 return (WALK_DONE);
647 652 }
648 653 if (mdb_vread(wsp->walk_data, sizeof (callout_list_t),
649 654 wsp->walk_addr) != sizeof (callout_list_t)) {
650 655 mdb_warn("failed to read callout_list at %p", wsp->walk_addr);
651 656 return (WALK_ERR);
652 657 }
653 658 retval = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
654 659 wsp->walk_cbdata);
655 660
656 661 wsp->walk_addr = (uintptr_t)
657 662 (((callout_list_t *)wsp->walk_data)->cl_next);
658 663
659 664 return (retval);
660 665 }
661 666
662 667 void
663 668 callout_list_walk_fini(mdb_walk_state_t *wsp)
664 669 {
665 670 mdb_free(wsp->walk_data, sizeof (callout_list_t));
666 671 }
667 672
668 673 /* routines/structs to walk callout table(s) */
669 674 typedef struct cot_data {
670 675 callout_table_t *ct0;
671 676 callout_table_t ct;
672 677 callout_hash_t cot_idhash[CALLOUT_BUCKETS];
673 678 callout_hash_t cot_clhash[CALLOUT_BUCKETS];
674 679 kstat_named_t ct_kstat_data[CALLOUT_NUM_STATS];
675 680 int cotndx;
676 681 int cotsize;
677 682 } cot_data_t;
678 683
679 684 int
680 685 callout_table_walk_init(mdb_walk_state_t *wsp)
681 686 {
682 687 int max_ncpus;
683 688 cot_data_t *cot_walk_data;
684 689
685 690 cot_walk_data = mdb_alloc(sizeof (cot_data_t), UM_SLEEP);
686 691
687 692 if (wsp->walk_addr == NULL) {
688 693 if (mdb_readvar(&cot_walk_data->ct0, "callout_table") == -1) {
689 694 mdb_warn("failed to read 'callout_table'");
690 695 return (WALK_ERR);
691 696 }
692 697 if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
693 698 mdb_warn("failed to get callout_table array size");
694 699 return (WALK_ERR);
695 700 }
696 701 cot_walk_data->cotsize = CALLOUT_NTYPES * max_ncpus;
697 702 wsp->walk_addr = (uintptr_t)cot_walk_data->ct0;
698 703 } else {
699 704 /* not a global walk */
700 705 cot_walk_data->cotsize = 1;
701 706 }
702 707
703 708 cot_walk_data->cotndx = 0;
704 709 wsp->walk_data = cot_walk_data;
705 710
706 711 return (WALK_NEXT);
707 712 }
708 713
709 714 int
710 715 callout_table_walk_step(mdb_walk_state_t *wsp)
711 716 {
712 717 int retval;
713 718 cot_data_t *cotwd = (cot_data_t *)wsp->walk_data;
714 719 size_t size;
715 720
716 721 if (cotwd->cotndx >= cotwd->cotsize) {
717 722 return (WALK_DONE);
718 723 }
719 724 if (mdb_vread(&(cotwd->ct), sizeof (callout_table_t),
720 725 wsp->walk_addr) != sizeof (callout_table_t)) {
721 726 mdb_warn("failed to read callout_table at %p", wsp->walk_addr);
722 727 return (WALK_ERR);
723 728 }
724 729
725 730 size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
726 731 if (cotwd->ct.ct_idhash != NULL) {
727 732 if (mdb_vread(cotwd->cot_idhash, size,
728 733 (uintptr_t)(cotwd->ct.ct_idhash)) != size) {
729 734 mdb_warn("failed to read id_hash at %p",
730 735 cotwd->ct.ct_idhash);
731 736 return (WALK_ERR);
732 737 }
733 738 }
734 739 if (cotwd->ct.ct_clhash != NULL) {
735 740 if (mdb_vread(&(cotwd->cot_clhash), size,
736 741 (uintptr_t)cotwd->ct.ct_clhash) == -1) {
737 742 mdb_warn("failed to read cl_hash at %p",
738 743 cotwd->ct.ct_clhash);
739 744 return (WALK_ERR);
740 745 }
741 746 }
742 747 size = sizeof (kstat_named_t) * CALLOUT_NUM_STATS;
743 748 if (cotwd->ct.ct_kstat_data != NULL) {
744 749 if (mdb_vread(&(cotwd->ct_kstat_data), size,
745 750 (uintptr_t)cotwd->ct.ct_kstat_data) == -1) {
746 751 mdb_warn("failed to read kstats at %p",
747 752 cotwd->ct.ct_kstat_data);
748 753 return (WALK_ERR);
749 754 }
750 755 }
751 756 retval = wsp->walk_callback(wsp->walk_addr, (void *)cotwd,
752 757 wsp->walk_cbdata);
753 758
754 759 cotwd->cotndx++;
755 760 if (cotwd->cotndx >= cotwd->cotsize) {
756 761 return (WALK_DONE);
757 762 }
758 763 wsp->walk_addr = (uintptr_t)((char *)wsp->walk_addr +
759 764 sizeof (callout_table_t));
760 765
761 766 return (retval);
762 767 }
763 768
764 769 void
765 770 callout_table_walk_fini(mdb_walk_state_t *wsp)
766 771 {
767 772 mdb_free(wsp->walk_data, sizeof (cot_data_t));
768 773 }
769 774
770 775 static const char *co_typenames[] = { "R", "N" };
771 776
772 777 #define CO_PLAIN_ID(xid) ((xid) & CALLOUT_ID_MASK)
773 778
774 779 #define TABLE_TO_SEQID(x) ((x) >> CALLOUT_TYPE_BITS)
775 780
776 781 /* callout flags, in no particular order */
777 782 #define COF_REAL 0x00000001
778 783 #define COF_NORM 0x00000002
779 784 #define COF_LONG 0x00000004
780 785 #define COF_SHORT 0x00000008
781 786 #define COF_EMPTY 0x00000010
782 787 #define COF_TIME 0x00000020
783 788 #define COF_BEFORE 0x00000040
784 789 #define COF_AFTER 0x00000080
785 790 #define COF_SEQID 0x00000100
786 791 #define COF_FUNC 0x00000200
787 792 #define COF_ADDR 0x00000400
788 793 #define COF_EXEC 0x00000800
789 794 #define COF_HIRES 0x00001000
790 795 #define COF_ABS 0x00002000
791 796 #define COF_TABLE 0x00004000
792 797 #define COF_BYIDH 0x00008000
793 798 #define COF_FREE 0x00010000
794 799 #define COF_LIST 0x00020000
795 800 #define COF_EXPREL 0x00040000
796 801 #define COF_HDR 0x00080000
797 802 #define COF_VERBOSE 0x00100000
798 803 #define COF_LONGLIST 0x00200000
799 804 #define COF_THDR 0x00400000
800 805 #define COF_LHDR 0x00800000
801 806 #define COF_CHDR 0x01000000
802 807 #define COF_PARAM 0x02000000
803 808 #define COF_DECODE 0x04000000
804 809 #define COF_HEAP 0x08000000
805 810 #define COF_QUEUE 0x10000000
806 811
807 812 /* show real and normal, short and long, expired and unexpired. */
808 813 #define COF_DEFAULT (COF_REAL | COF_NORM | COF_LONG | COF_SHORT)
809 814
810 815 #define COF_LIST_FLAGS \
811 816 (CALLOUT_LIST_FLAG_HRESTIME | CALLOUT_LIST_FLAG_ABSOLUTE)
812 817
813 818 /* private callout data for callback functions */
814 819 typedef struct callout_data {
815 820 uint_t flags; /* COF_* */
816 821 cpu_t *cpu; /* cpu pointer if given */
817 822 int seqid; /* cpu seqid, or -1 */
818 823 hrtime_t time; /* expiration time value */
819 824 hrtime_t atime; /* expiration before value */
820 825 hrtime_t btime; /* expiration after value */
821 826 uintptr_t funcaddr; /* function address or NULL */
822 827 uintptr_t param; /* parameter to function or NULL */
823 828 hrtime_t now; /* current system time */
824 829 int nsec_per_tick; /* for conversions */
825 830 ulong_t ctbits; /* for decoding xid */
826 831 callout_table_t *co_table; /* top of callout table array */
827 832 int ndx; /* table index. */
828 833 int bucket; /* which list/id bucket are we in */
829 834 hrtime_t exp; /* expire time */
830 835 int list_flags; /* copy of cl_flags */
831 836 } callout_data_t;
832 837
833 838 /* this callback does the actual callback itself (finally). */
834 839 /*ARGSUSED*/
835 840 static int
836 841 callouts_cb(uintptr_t addr, const void *data, void *priv)
837 842 {
838 843 callout_data_t *coargs = (callout_data_t *)priv;
839 844 callout_t *co = (callout_t *)data;
840 845 int tableid, list_flags;
841 846 callout_id_t coid;
842 847
843 848 if ((coargs == NULL) || (co == NULL)) {
844 849 return (WALK_ERR);
845 850 }
846 851
847 852 if ((coargs->flags & COF_FREE) && !(co->c_xid & CALLOUT_ID_FREE)) {
848 853 /*
849 854 * The callout must have been reallocated. No point in
850 855 * walking any more.
851 856 */
852 857 return (WALK_DONE);
853 858 }
854 859 if (!(coargs->flags & COF_FREE) && (co->c_xid & CALLOUT_ID_FREE)) {
855 860 /*
856 861 * The callout must have been freed. No point in
857 862 * walking any more.
858 863 */
859 864 return (WALK_DONE);
860 865 }
861 866 if ((coargs->flags & COF_FUNC) &&
862 867 (coargs->funcaddr != (uintptr_t)co->c_func)) {
863 868 return (WALK_NEXT);
864 869 }
865 870 if ((coargs->flags & COF_PARAM) &&
866 871 (coargs->param != (uintptr_t)co->c_arg)) {
867 872 return (WALK_NEXT);
868 873 }
869 874 if (!(coargs->flags & COF_LONG) && (co->c_xid & CALLOUT_LONGTERM)) {
870 875 return (WALK_NEXT);
871 876 }
872 877 if (!(coargs->flags & COF_SHORT) && !(co->c_xid & CALLOUT_LONGTERM)) {
873 878 return (WALK_NEXT);
874 879 }
875 880 if ((coargs->flags & COF_EXEC) && !(co->c_xid & CALLOUT_EXECUTING)) {
876 881 return (WALK_NEXT);
877 882 }
878 883 /* it is possible we don't have the exp time or flags */
879 884 if (coargs->flags & COF_BYIDH) {
880 885 if (!(coargs->flags & COF_FREE)) {
881 886 /* we have to fetch the expire time ourselves. */
882 887 if (mdb_vread(&coargs->exp, sizeof (hrtime_t),
883 888 (uintptr_t)co->c_list + offsetof(callout_list_t,
884 889 cl_expiration)) == -1) {
885 890 mdb_warn("failed to read expiration "
886 891 "time from %p", co->c_list);
887 892 coargs->exp = 0;
888 893 }
889 894 /* and flags. */
890 895 if (mdb_vread(&coargs->list_flags, sizeof (int),
891 896 (uintptr_t)co->c_list + offsetof(callout_list_t,
892 897 cl_flags)) == -1) {
893 898 mdb_warn("failed to read list flags"
894 899 "from %p", co->c_list);
895 900 coargs->list_flags = 0;
896 901 }
897 902 } else {
898 903 /* free callouts can't use list pointer. */
899 904 coargs->exp = 0;
900 905 coargs->list_flags = 0;
901 906 }
902 907 if (coargs->exp != 0) {
903 908 if ((coargs->flags & COF_TIME) &&
904 909 (coargs->exp != coargs->time)) {
905 910 return (WALK_NEXT);
906 911 }
907 912 if ((coargs->flags & COF_BEFORE) &&
908 913 (coargs->exp > coargs->btime)) {
909 914 return (WALK_NEXT);
910 915 }
911 916 if ((coargs->flags & COF_AFTER) &&
912 917 (coargs->exp < coargs->atime)) {
913 918 return (WALK_NEXT);
914 919 }
915 920 }
916 921 /* tricky part, since both HIRES and ABS can be set */
917 922 list_flags = coargs->list_flags;
918 923 if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) {
919 924 /* both flags are set, only skip "regular" ones */
920 925 if (! (list_flags & COF_LIST_FLAGS)) {
921 926 return (WALK_NEXT);
922 927 }
923 928 } else {
924 929 /* individual flags, or no flags */
925 930 if ((coargs->flags & COF_HIRES) &&
926 931 !(list_flags & CALLOUT_LIST_FLAG_HRESTIME)) {
927 932 return (WALK_NEXT);
928 933 }
929 934 if ((coargs->flags & COF_ABS) &&
930 935 !(list_flags & CALLOUT_LIST_FLAG_ABSOLUTE)) {
931 936 return (WALK_NEXT);
932 937 }
933 938 }
934 939 /*
935 940 * We do the checks for COF_HEAP and COF_QUEUE here only if we
936 941 * are traversing BYIDH. If the traversal is by callout list,
937 942 * we do this check in callout_list_cb() to be more
938 943 * efficient.
939 944 */
940 945 if ((coargs->flags & COF_HEAP) &&
941 946 !(list_flags & CALLOUT_LIST_FLAG_HEAPED)) {
942 947 return (WALK_NEXT);
943 948 }
944 949
945 950 if ((coargs->flags & COF_QUEUE) &&
946 951 !(list_flags & CALLOUT_LIST_FLAG_QUEUED)) {
947 952 return (WALK_NEXT);
948 953 }
949 954 }
950 955
951 956 #define callout_table_mask ((1 << coargs->ctbits) - 1)
952 957 tableid = CALLOUT_ID_TO_TABLE(co->c_xid);
953 958 #undef callout_table_mask
954 959 coid = CO_PLAIN_ID(co->c_xid);
955 960
956 961 if ((coargs->flags & COF_CHDR) && !(coargs->flags & COF_ADDR)) {
957 962 /*
958 963 * We need to print the headers. If walking by id, then
959 964 * the list header isn't printed, so we must include
960 965 * that info here.
961 966 */
962 967 if (!(coargs->flags & COF_VERBOSE)) {
963 968 mdb_printf("%<u>%3s %-1s %-14s %</u>",
964 969 "SEQ", "T", "EXP");
965 970 } else if (coargs->flags & COF_BYIDH) {
966 971 mdb_printf("%<u>%-14s %</u>", "EXP");
967 972 }
968 973 mdb_printf("%<u>%-4s %-?s %-20s%</u>",
969 974 "XHAL", "XID", "FUNC(ARG)");
970 975 if (coargs->flags & COF_LONGLIST) {
971 976 mdb_printf("%<u> %-?s %-?s %-?s %-?s%</u>",
972 977 "PREVID", "NEXTID", "PREVL", "NEXTL");
973 978 mdb_printf("%<u> %-?s %-4s %-?s%</u>",
974 979 "DONE", "UTOS", "THREAD");
975 980 }
976 981 mdb_printf("\n");
977 982 coargs->flags &= ~COF_CHDR;
978 983 coargs->flags |= (COF_THDR | COF_LHDR);
979 984 }
980 985
981 986 if (!(coargs->flags & COF_ADDR)) {
982 987 if (!(coargs->flags & COF_VERBOSE)) {
983 988 mdb_printf("%-3d %1s %-14llx ",
984 989 TABLE_TO_SEQID(tableid),
985 990 co_typenames[tableid & CALLOUT_TYPE_MASK],
986 991 (coargs->flags & COF_EXPREL) ?
987 992 coargs->exp - coargs->now : coargs->exp);
988 993 } else if (coargs->flags & COF_BYIDH) {
989 994 mdb_printf("%-14x ",
990 995 (coargs->flags & COF_EXPREL) ?
991 996 coargs->exp - coargs->now : coargs->exp);
992 997 }
993 998 list_flags = coargs->list_flags;
994 999 mdb_printf("%1s%1s%1s%1s %-?llx %a(%p)",
995 1000 (co->c_xid & CALLOUT_EXECUTING) ? "X" : " ",
996 1001 (list_flags & CALLOUT_LIST_FLAG_HRESTIME) ? "H" : " ",
997 1002 (list_flags & CALLOUT_LIST_FLAG_ABSOLUTE) ? "A" : " ",
998 1003 (co->c_xid & CALLOUT_LONGTERM) ? "L" : " ",
999 1004 (long long)coid, co->c_func, co->c_arg);
1000 1005 if (coargs->flags & COF_LONGLIST) {
1001 1006 mdb_printf(" %-?p %-?p %-?p %-?p",
1002 1007 co->c_idprev, co->c_idnext, co->c_clprev,
1003 1008 co->c_clnext);
1004 1009 mdb_printf(" %-?p %-4d %-0?p",
1005 1010 co->c_done, co->c_waiting, co->c_executor);
1006 1011 }
1007 1012 } else {
1008 1013 /* address only */
1009 1014 mdb_printf("%-0p", addr);
1010 1015 }
1011 1016 mdb_printf("\n");
1012 1017 return (WALK_NEXT);
1013 1018 }
1014 1019
1015 1020 /* this callback is for callout list handling. idhash is done by callout_t_cb */
1016 1021 /*ARGSUSED*/
1017 1022 static int
1018 1023 callout_list_cb(uintptr_t addr, const void *data, void *priv)
1019 1024 {
1020 1025 callout_data_t *coargs = (callout_data_t *)priv;
1021 1026 callout_list_t *cl = (callout_list_t *)data;
1022 1027 callout_t *coptr;
1023 1028 int list_flags;
1024 1029
1025 1030 if ((coargs == NULL) || (cl == NULL)) {
1026 1031 return (WALK_ERR);
1027 1032 }
1028 1033
1029 1034 coargs->exp = cl->cl_expiration;
1030 1035 coargs->list_flags = cl->cl_flags;
1031 1036 if ((coargs->flags & COF_FREE) &&
1032 1037 !(cl->cl_flags & CALLOUT_LIST_FLAG_FREE)) {
1033 1038 /*
1034 1039 * The callout list must have been reallocated. No point in
1035 1040 * walking any more.
1036 1041 */
1037 1042 return (WALK_DONE);
1038 1043 }
1039 1044 if (!(coargs->flags & COF_FREE) &&
1040 1045 (cl->cl_flags & CALLOUT_LIST_FLAG_FREE)) {
1041 1046 /*
1042 1047 * The callout list must have been freed. No point in
1043 1048 * walking any more.
1044 1049 */
1045 1050 return (WALK_DONE);
1046 1051 }
1047 1052 if ((coargs->flags & COF_TIME) &&
1048 1053 (cl->cl_expiration != coargs->time)) {
1049 1054 return (WALK_NEXT);
1050 1055 }
1051 1056 if ((coargs->flags & COF_BEFORE) &&
1052 1057 (cl->cl_expiration > coargs->btime)) {
1053 1058 return (WALK_NEXT);
1054 1059 }
1055 1060 if ((coargs->flags & COF_AFTER) &&
1056 1061 (cl->cl_expiration < coargs->atime)) {
1057 1062 return (WALK_NEXT);
1058 1063 }
1059 1064 if (!(coargs->flags & COF_EMPTY) &&
1060 1065 (cl->cl_callouts.ch_head == NULL)) {
1061 1066 return (WALK_NEXT);
1062 1067 }
1063 1068 /* FOUR cases, each different, !A!B, !AB, A!B, AB */
1064 1069 if ((coargs->flags & COF_HIRES) && (coargs->flags & COF_ABS)) {
1065 1070 /* both flags are set, only skip "regular" ones */
1066 1071 if (! (cl->cl_flags & COF_LIST_FLAGS)) {
1067 1072 return (WALK_NEXT);
1068 1073 }
1069 1074 } else {
1070 1075 if ((coargs->flags & COF_HIRES) &&
1071 1076 !(cl->cl_flags & CALLOUT_LIST_FLAG_HRESTIME)) {
1072 1077 return (WALK_NEXT);
1073 1078 }
1074 1079 if ((coargs->flags & COF_ABS) &&
1075 1080 !(cl->cl_flags & CALLOUT_LIST_FLAG_ABSOLUTE)) {
1076 1081 return (WALK_NEXT);
1077 1082 }
1078 1083 }
1079 1084
1080 1085 if ((coargs->flags & COF_HEAP) &&
1081 1086 !(coargs->list_flags & CALLOUT_LIST_FLAG_HEAPED)) {
1082 1087 return (WALK_NEXT);
1083 1088 }
1084 1089
1085 1090 if ((coargs->flags & COF_QUEUE) &&
1086 1091 !(coargs->list_flags & CALLOUT_LIST_FLAG_QUEUED)) {
1087 1092 return (WALK_NEXT);
1088 1093 }
1089 1094
1090 1095 if ((coargs->flags & COF_LHDR) && !(coargs->flags & COF_ADDR) &&
1091 1096 (coargs->flags & (COF_LIST | COF_VERBOSE))) {
1092 1097 if (!(coargs->flags & COF_VERBOSE)) {
1093 1098 /* don't be redundant again */
1094 1099 mdb_printf("%<u>SEQ T %</u>");
1095 1100 }
1096 1101 mdb_printf("%<u>EXP HA BUCKET "
1097 1102 "CALLOUTS %</u>");
1098 1103
1099 1104 if (coargs->flags & COF_LONGLIST) {
1100 1105 mdb_printf("%<u> %-?s %-?s%</u>",
1101 1106 "PREV", "NEXT");
1102 1107 }
1103 1108 mdb_printf("\n");
1104 1109 coargs->flags &= ~COF_LHDR;
1105 1110 coargs->flags |= (COF_THDR | COF_CHDR);
1106 1111 }
1107 1112 if (coargs->flags & (COF_LIST | COF_VERBOSE)) {
1108 1113 if (!(coargs->flags & COF_ADDR)) {
1109 1114 if (!(coargs->flags & COF_VERBOSE)) {
1110 1115 mdb_printf("%3d %1s ",
1111 1116 TABLE_TO_SEQID(coargs->ndx),
1112 1117 co_typenames[coargs->ndx &
1113 1118 CALLOUT_TYPE_MASK]);
1114 1119 }
1115 1120
1116 1121 list_flags = coargs->list_flags;
1117 1122 mdb_printf("%-14llx %1s%1s %-6d %-0?p ",
1118 1123 (coargs->flags & COF_EXPREL) ?
1119 1124 coargs->exp - coargs->now : coargs->exp,
1120 1125 (list_flags & CALLOUT_LIST_FLAG_HRESTIME) ?
1121 1126 "H" : " ",
1122 1127 (list_flags & CALLOUT_LIST_FLAG_ABSOLUTE) ?
1123 1128 "A" : " ",
1124 1129 coargs->bucket, cl->cl_callouts.ch_head);
1125 1130
1126 1131 if (coargs->flags & COF_LONGLIST) {
1127 1132 mdb_printf(" %-?p %-?p",
1128 1133 cl->cl_prev, cl->cl_next);
1129 1134 }
1130 1135 } else {
1131 1136 /* address only */
1132 1137 mdb_printf("%-0p", addr);
1133 1138 }
1134 1139 mdb_printf("\n");
1135 1140 if (coargs->flags & COF_LIST) {
1136 1141 return (WALK_NEXT);
1137 1142 }
1138 1143 }
1139 1144 /* yet another layer as we walk the actual callouts via list. */
1140 1145 if (cl->cl_callouts.ch_head == NULL) {
1141 1146 return (WALK_NEXT);
1142 1147 }
1143 1148 /* free list structures do not have valid callouts off of them. */
1144 1149 if (coargs->flags & COF_FREE) {
1145 1150 return (WALK_NEXT);
1146 1151 }
1147 1152 coptr = (callout_t *)cl->cl_callouts.ch_head;
1148 1153
1149 1154 if (coargs->flags & COF_VERBOSE) {
1150 1155 mdb_inc_indent(4);
1151 1156 }
1152 1157 /*
1153 1158 * walk callouts using yet another callback routine.
1154 1159 * we use callouts_bytime because id hash is handled via
1155 1160 * the callout_t_cb callback.
1156 1161 */
1157 1162 if (mdb_pwalk("callouts_bytime", callouts_cb, coargs,
1158 1163 (uintptr_t)coptr) == -1) {
1159 1164 mdb_warn("cannot walk callouts at %p", coptr);
1160 1165 return (WALK_ERR);
1161 1166 }
1162 1167 if (coargs->flags & COF_VERBOSE) {
1163 1168 mdb_dec_indent(4);
1164 1169 }
1165 1170
1166 1171 return (WALK_NEXT);
1167 1172 }
1168 1173
1169 1174 /* this callback handles the details of callout table walking. */
1170 1175 static int
1171 1176 callout_t_cb(uintptr_t addr, const void *data, void *priv)
1172 1177 {
1173 1178 callout_data_t *coargs = (callout_data_t *)priv;
1174 1179 cot_data_t *cotwd = (cot_data_t *)data;
1175 1180 callout_table_t *ct = &(cotwd->ct);
1176 1181 int index, seqid, cotype;
1177 1182 int i;
1178 1183 callout_list_t *clptr;
1179 1184 callout_t *coptr;
1180 1185
1181 1186 if ((coargs == NULL) || (ct == NULL) || (coargs->co_table == NULL)) {
1182 1187 return (WALK_ERR);
1183 1188 }
1184 1189
1185 1190 index = ((char *)addr - (char *)coargs->co_table) /
1186 1191 sizeof (callout_table_t);
1187 1192 cotype = index & CALLOUT_TYPE_MASK;
1188 1193 seqid = TABLE_TO_SEQID(index);
1189 1194
1190 1195 if ((coargs->flags & COF_SEQID) && (coargs->seqid != seqid)) {
1191 1196 return (WALK_NEXT);
1192 1197 }
1193 1198
1194 1199 if (!(coargs->flags & COF_REAL) && (cotype == CALLOUT_REALTIME)) {
1195 1200 return (WALK_NEXT);
1196 1201 }
1197 1202
1198 1203 if (!(coargs->flags & COF_NORM) && (cotype == CALLOUT_NORMAL)) {
1199 1204 return (WALK_NEXT);
1200 1205 }
1201 1206
1202 1207 if (!(coargs->flags & COF_EMPTY) && (
1203 1208 (ct->ct_heap == NULL) || (ct->ct_cyclic == NULL))) {
1204 1209 return (WALK_NEXT);
1205 1210 }
1206 1211
1207 1212 if ((coargs->flags & COF_THDR) && !(coargs->flags & COF_ADDR) &&
1208 1213 (coargs->flags & (COF_TABLE | COF_VERBOSE))) {
1209 1214 /* print table hdr */
1210 1215 mdb_printf("%<u>%-3s %-1s %-?s %-?s %-?s %-?s%</u>",
1211 1216 "SEQ", "T", "FREE", "LFREE", "CYCLIC", "HEAP");
1212 1217 coargs->flags &= ~COF_THDR;
1213 1218 coargs->flags |= (COF_LHDR | COF_CHDR);
1214 1219 if (coargs->flags & COF_LONGLIST) {
1215 1220 /* more info! */
1216 1221 mdb_printf("%<u> %-T%-7s %-7s %-?s %-?s %-?s"
1217 1222 " %-?s %-?s %-?s%</u>",
1218 1223 "HEAPNUM", "HEAPMAX", "TASKQ", "EXPQ", "QUE",
1219 1224 "PEND", "FREE", "LOCK");
1220 1225 }
1221 1226 mdb_printf("\n");
1222 1227 }
1223 1228 if (coargs->flags & (COF_TABLE | COF_VERBOSE)) {
1224 1229 if (!(coargs->flags & COF_ADDR)) {
1225 1230 mdb_printf("%-3d %-1s %-0?p %-0?p %-0?p %-?p",
1226 1231 seqid, co_typenames[cotype],
1227 1232 ct->ct_free, ct->ct_lfree, ct->ct_cyclic,
1228 1233 ct->ct_heap);
1229 1234 if (coargs->flags & COF_LONGLIST) {
1230 1235 /* more info! */
1231 1236 mdb_printf(" %-7d %-7d %-?p %-?p %-?p"
1232 1237 " %-?lld %-?lld %-?p",
1233 1238 ct->ct_heap_num, ct->ct_heap_max,
1234 1239 ct->ct_taskq, ct->ct_expired.ch_head,
1235 1240 ct->ct_queue.ch_head,
1236 1241 cotwd->ct_timeouts_pending,
1237 1242 cotwd->ct_allocations -
1238 1243 cotwd->ct_timeouts_pending,
1239 1244 ct->ct_mutex);
1240 1245 }
1241 1246 } else {
1242 1247 /* address only */
1243 1248 mdb_printf("%-0?p", addr);
1244 1249 }
1245 1250 mdb_printf("\n");
1246 1251 if (coargs->flags & COF_TABLE) {
1247 1252 return (WALK_NEXT);
1248 1253 }
1249 1254 }
1250 1255
1251 1256 coargs->ndx = index;
1252 1257 if (coargs->flags & COF_VERBOSE) {
1253 1258 mdb_inc_indent(4);
1254 1259 }
1255 1260 /* keep digging. */
1256 1261 if (!(coargs->flags & COF_BYIDH)) {
1257 1262 /* walk the list hash table */
1258 1263 if (coargs->flags & COF_FREE) {
1259 1264 clptr = ct->ct_lfree;
1260 1265 coargs->bucket = 0;
1261 1266 if (clptr == NULL) {
1262 1267 return (WALK_NEXT);
1263 1268 }
1264 1269 if (mdb_pwalk("callout_list", callout_list_cb, coargs,
1265 1270 (uintptr_t)clptr) == -1) {
1266 1271 mdb_warn("cannot walk callout free list at %p",
1267 1272 clptr);
1268 1273 return (WALK_ERR);
1269 1274 }
1270 1275 } else {
1271 1276 /* first print the expired list. */
1272 1277 clptr = (callout_list_t *)ct->ct_expired.ch_head;
1273 1278 if (clptr != NULL) {
1274 1279 coargs->bucket = -1;
1275 1280 if (mdb_pwalk("callout_list", callout_list_cb,
1276 1281 coargs, (uintptr_t)clptr) == -1) {
1277 1282 mdb_warn("cannot walk callout_list"
1278 1283 " at %p", clptr);
1279 1284 return (WALK_ERR);
1280 1285 }
1281 1286 }
1282 1287 /* then, print the callout queue */
1283 1288 clptr = (callout_list_t *)ct->ct_queue.ch_head;
1284 1289 if (clptr != NULL) {
1285 1290 coargs->bucket = -1;
1286 1291 if (mdb_pwalk("callout_list", callout_list_cb,
1287 1292 coargs, (uintptr_t)clptr) == -1) {
1288 1293 mdb_warn("cannot walk callout_list"
1289 1294 " at %p", clptr);
1290 1295 return (WALK_ERR);
1291 1296 }
1292 1297 }
1293 1298 for (i = 0; i < CALLOUT_BUCKETS; i++) {
1294 1299 if (ct->ct_clhash == NULL) {
1295 1300 /* nothing to do */
1296 1301 break;
1297 1302 }
1298 1303 if (cotwd->cot_clhash[i].ch_head == NULL) {
1299 1304 continue;
1300 1305 }
1301 1306 clptr = (callout_list_t *)
1302 1307 cotwd->cot_clhash[i].ch_head;
1303 1308 coargs->bucket = i;
1304 1309 /* walk list with callback routine. */
1305 1310 if (mdb_pwalk("callout_list", callout_list_cb,
1306 1311 coargs, (uintptr_t)clptr) == -1) {
1307 1312 mdb_warn("cannot walk callout_list"
1308 1313 " at %p", clptr);
1309 1314 return (WALK_ERR);
1310 1315 }
1311 1316 }
1312 1317 }
1313 1318 } else {
1314 1319 /* walk the id hash table. */
1315 1320 if (coargs->flags & COF_FREE) {
1316 1321 coptr = ct->ct_free;
1317 1322 coargs->bucket = 0;
1318 1323 if (coptr == NULL) {
1319 1324 return (WALK_NEXT);
1320 1325 }
1321 1326 if (mdb_pwalk("callouts_byid", callouts_cb, coargs,
1322 1327 (uintptr_t)coptr) == -1) {
1323 1328 mdb_warn("cannot walk callout id free list"
1324 1329 " at %p", coptr);
1325 1330 return (WALK_ERR);
1326 1331 }
1327 1332 } else {
1328 1333 for (i = 0; i < CALLOUT_BUCKETS; i++) {
1329 1334 if (ct->ct_idhash == NULL) {
1330 1335 break;
1331 1336 }
1332 1337 coptr = (callout_t *)
1333 1338 cotwd->cot_idhash[i].ch_head;
1334 1339 if (coptr == NULL) {
1335 1340 continue;
1336 1341 }
1337 1342 coargs->bucket = i;
1338 1343
1339 1344 /*
1340 1345 * walk callouts directly by id. For id
1341 1346 * chain, the callout list is just a header,
1342 1347 * so there's no need to walk it.
1343 1348 */
1344 1349 if (mdb_pwalk("callouts_byid", callouts_cb,
1345 1350 coargs, (uintptr_t)coptr) == -1) {
1346 1351 mdb_warn("cannot walk callouts at %p",
1347 1352 coptr);
1348 1353 return (WALK_ERR);
1349 1354 }
1350 1355 }
1351 1356 }
1352 1357 }
1353 1358 if (coargs->flags & COF_VERBOSE) {
1354 1359 mdb_dec_indent(4);
1355 1360 }
1356 1361 return (WALK_NEXT);
1357 1362 }
1358 1363
1359 1364 /*
1360 1365 * initialize some common info for both callout dcmds.
1361 1366 */
1362 1367 int
1363 1368 callout_common_init(callout_data_t *coargs)
1364 1369 {
1365 1370 /* we need a couple of things */
1366 1371 if (mdb_readvar(&(coargs->co_table), "callout_table") == -1) {
1367 1372 mdb_warn("failed to read 'callout_table'");
1368 1373 return (DCMD_ERR);
1369 1374 }
1370 1375 /* need to get now in nsecs. Approximate with hrtime vars */
1371 1376 if (mdb_readsym(&(coargs->now), sizeof (hrtime_t), "hrtime_last") !=
1372 1377 sizeof (hrtime_t)) {
1373 1378 if (mdb_readsym(&(coargs->now), sizeof (hrtime_t),
1374 1379 "hrtime_base") != sizeof (hrtime_t)) {
1375 1380 mdb_warn("Could not determine current system time");
1376 1381 return (DCMD_ERR);
1377 1382 }
1378 1383 }
1379 1384
1380 1385 if (mdb_readvar(&(coargs->ctbits), "callout_table_bits") == -1) {
1381 1386 mdb_warn("failed to read 'callout_table_bits'");
1382 1387 return (DCMD_ERR);
1383 1388 }
1384 1389 if (mdb_readvar(&(coargs->nsec_per_tick), "nsec_per_tick") == -1) {
1385 1390 mdb_warn("failed to read 'nsec_per_tick'");
1386 1391 return (DCMD_ERR);
1387 1392 }
1388 1393 return (DCMD_OK);
1389 1394 }
1390 1395
1391 1396 /*
1392 1397 * dcmd to print callouts. Optional addr limits to specific table.
1393 1398 * Parses lots of options that get passed to callbacks for walkers.
1394 1399 * Has it's own help function.
1395 1400 */
1396 1401 /*ARGSUSED*/
1397 1402 int
1398 1403 callout(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1399 1404 {
1400 1405 callout_data_t coargs;
1401 1406 /* getopts doesn't help much with stuff like this */
1402 1407 boolean_t Sflag, Cflag, tflag, aflag, bflag, dflag, kflag;
1403 1408 char *funcname = NULL;
1404 1409 char *paramstr = NULL;
1405 1410 uintptr_t Stmp, Ctmp; /* for getopt. */
1406 1411 int retval;
1407 1412
1408 1413 coargs.flags = COF_DEFAULT;
1409 1414 Sflag = Cflag = tflag = bflag = aflag = dflag = kflag = FALSE;
1410 1415 coargs.seqid = -1;
1411 1416
1412 1417 if (mdb_getopts(argc, argv,
1413 1418 'r', MDB_OPT_CLRBITS, COF_NORM, &coargs.flags,
1414 1419 'n', MDB_OPT_CLRBITS, COF_REAL, &coargs.flags,
1415 1420 'l', MDB_OPT_CLRBITS, COF_SHORT, &coargs.flags,
1416 1421 's', MDB_OPT_CLRBITS, COF_LONG, &coargs.flags,
1417 1422 'x', MDB_OPT_SETBITS, COF_EXEC, &coargs.flags,
1418 1423 'h', MDB_OPT_SETBITS, COF_HIRES, &coargs.flags,
1419 1424 'B', MDB_OPT_SETBITS, COF_ABS, &coargs.flags,
1420 1425 'E', MDB_OPT_SETBITS, COF_EMPTY, &coargs.flags,
1421 1426 'd', MDB_OPT_SETBITS, 1, &dflag,
1422 1427 'C', MDB_OPT_UINTPTR_SET, &Cflag, &Ctmp,
1423 1428 'S', MDB_OPT_UINTPTR_SET, &Sflag, &Stmp,
1424 1429 't', MDB_OPT_UINTPTR_SET, &tflag, (uintptr_t *)&coargs.time,
1425 1430 'a', MDB_OPT_UINTPTR_SET, &aflag, (uintptr_t *)&coargs.atime,
1426 1431 'b', MDB_OPT_UINTPTR_SET, &bflag, (uintptr_t *)&coargs.btime,
1427 1432 'k', MDB_OPT_SETBITS, 1, &kflag,
1428 1433 'f', MDB_OPT_STR, &funcname,
1429 1434 'p', MDB_OPT_STR, ¶mstr,
1430 1435 'T', MDB_OPT_SETBITS, COF_TABLE, &coargs.flags,
1431 1436 'D', MDB_OPT_SETBITS, COF_EXPREL, &coargs.flags,
1432 1437 'L', MDB_OPT_SETBITS, COF_LIST, &coargs.flags,
1433 1438 'V', MDB_OPT_SETBITS, COF_VERBOSE, &coargs.flags,
1434 1439 'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags,
1435 1440 'i', MDB_OPT_SETBITS, COF_BYIDH, &coargs.flags,
1436 1441 'F', MDB_OPT_SETBITS, COF_FREE, &coargs.flags,
1437 1442 'H', MDB_OPT_SETBITS, COF_HEAP, &coargs.flags,
1438 1443 'Q', MDB_OPT_SETBITS, COF_QUEUE, &coargs.flags,
1439 1444 'A', MDB_OPT_SETBITS, COF_ADDR, &coargs.flags,
1440 1445 NULL) != argc) {
1441 1446 return (DCMD_USAGE);
1442 1447 }
1443 1448
1444 1449 /* initialize from kernel variables */
1445 1450 if ((retval = callout_common_init(&coargs)) != DCMD_OK) {
1446 1451 return (retval);
1447 1452 }
1448 1453
1449 1454 /* do some option post-processing */
1450 1455 if (kflag) {
1451 1456 coargs.time *= coargs.nsec_per_tick;
1452 1457 coargs.atime *= coargs.nsec_per_tick;
1453 1458 coargs.btime *= coargs.nsec_per_tick;
1454 1459 }
1455 1460
1456 1461 if (dflag) {
1457 1462 coargs.time += coargs.now;
1458 1463 coargs.atime += coargs.now;
1459 1464 coargs.btime += coargs.now;
1460 1465 }
1461 1466 if (Sflag) {
1462 1467 if (flags & DCMD_ADDRSPEC) {
1463 1468 mdb_printf("-S option conflicts with explicit"
1464 1469 " address\n");
1465 1470 return (DCMD_USAGE);
1466 1471 }
1467 1472 coargs.flags |= COF_SEQID;
1468 1473 coargs.seqid = (int)Stmp;
1469 1474 }
1470 1475 if (Cflag) {
1471 1476 if (flags & DCMD_ADDRSPEC) {
1472 1477 mdb_printf("-C option conflicts with explicit"
1473 1478 " address\n");
1474 1479 return (DCMD_USAGE);
1475 1480 }
1476 1481 if (coargs.flags & COF_SEQID) {
1477 1482 mdb_printf("-C and -S are mutually exclusive\n");
1478 1483 return (DCMD_USAGE);
1479 1484 }
1480 1485 coargs.cpu = (cpu_t *)Ctmp;
1481 1486 if (mdb_vread(&coargs.seqid, sizeof (processorid_t),
1482 1487 (uintptr_t)&(coargs.cpu->cpu_seqid)) == -1) {
1483 1488 mdb_warn("failed to read cpu_t at %p", Ctmp);
1484 1489 return (DCMD_ERR);
1485 1490 }
1486 1491 coargs.flags |= COF_SEQID;
1487 1492 }
1488 1493 /* avoid null outputs. */
1489 1494 if (!(coargs.flags & (COF_REAL | COF_NORM))) {
1490 1495 coargs.flags |= COF_REAL | COF_NORM;
1491 1496 }
1492 1497 if (!(coargs.flags & (COF_LONG | COF_SHORT))) {
1493 1498 coargs.flags |= COF_LONG | COF_SHORT;
1494 1499 }
1495 1500 if (tflag) {
1496 1501 if (aflag || bflag) {
1497 1502 mdb_printf("-t and -a|b are mutually exclusive\n");
1498 1503 return (DCMD_USAGE);
1499 1504 }
1500 1505 coargs.flags |= COF_TIME;
1501 1506 }
1502 1507 if (aflag) {
1503 1508 coargs.flags |= COF_AFTER;
1504 1509 }
1505 1510 if (bflag) {
1506 1511 coargs.flags |= COF_BEFORE;
1507 1512 }
1508 1513 if ((aflag && bflag) && (coargs.btime <= coargs.atime)) {
1509 1514 mdb_printf("value for -a must be earlier than the value"
1510 1515 " for -b.\n");
1511 1516 return (DCMD_USAGE);
1512 1517 }
1513 1518
1514 1519 if ((coargs.flags & COF_HEAP) && (coargs.flags & COF_QUEUE)) {
1515 1520 mdb_printf("-H and -Q are mutually exclusive\n");
1516 1521 return (DCMD_USAGE);
1517 1522 }
1518 1523
1519 1524 if (funcname != NULL) {
1520 1525 GElf_Sym sym;
1521 1526
1522 1527 if (mdb_lookup_by_name(funcname, &sym) != 0) {
1523 1528 coargs.funcaddr = mdb_strtoull(funcname);
1524 1529 } else {
1525 1530 coargs.funcaddr = sym.st_value;
1526 1531 }
1527 1532 coargs.flags |= COF_FUNC;
1528 1533 }
1529 1534
1530 1535 if (paramstr != NULL) {
1531 1536 GElf_Sym sym;
1532 1537
1533 1538 if (mdb_lookup_by_name(paramstr, &sym) != 0) {
1534 1539 coargs.param = mdb_strtoull(paramstr);
1535 1540 } else {
1536 1541 coargs.param = sym.st_value;
1537 1542 }
1538 1543 coargs.flags |= COF_PARAM;
1539 1544 }
1540 1545
1541 1546 if (!(flags & DCMD_ADDRSPEC)) {
1542 1547 /* don't pass "dot" if no addr. */
1543 1548 addr = NULL;
1544 1549 }
1545 1550 if (addr != NULL) {
1546 1551 /*
1547 1552 * a callout table was specified. Ignore -r|n option
1548 1553 * to avoid null output.
1549 1554 */
1550 1555 coargs.flags |= (COF_REAL | COF_NORM);
1551 1556 }
1552 1557
1553 1558 if (DCMD_HDRSPEC(flags) || (coargs.flags & COF_VERBOSE)) {
1554 1559 coargs.flags |= COF_THDR | COF_LHDR | COF_CHDR;
1555 1560 }
1556 1561 if (coargs.flags & COF_FREE) {
1557 1562 coargs.flags |= COF_EMPTY;
1558 1563 /* -F = free callouts, -FL = free lists */
1559 1564 if (!(coargs.flags & COF_LIST)) {
1560 1565 coargs.flags |= COF_BYIDH;
1561 1566 }
1562 1567 }
1563 1568
1564 1569 /* walk table, using specialized callback routine. */
1565 1570 if (mdb_pwalk("callout_table", callout_t_cb, &coargs, addr) == -1) {
1566 1571 mdb_warn("cannot walk callout_table");
1567 1572 return (DCMD_ERR);
1568 1573 }
1569 1574 return (DCMD_OK);
1570 1575 }
1571 1576
1572 1577
1573 1578 /*
1574 1579 * Given an extended callout id, dump its information.
1575 1580 */
1576 1581 /*ARGSUSED*/
1577 1582 int
1578 1583 calloutid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1579 1584 {
1580 1585 callout_data_t coargs;
1581 1586 callout_table_t *ctptr;
1582 1587 callout_table_t ct;
1583 1588 callout_id_t coid;
1584 1589 callout_t *coptr;
1585 1590 int tableid;
1586 1591 callout_id_t xid;
1587 1592 ulong_t idhash;
1588 1593 int i, retval;
1589 1594 const mdb_arg_t *arg;
1590 1595 size_t size;
1591 1596 callout_hash_t cot_idhash[CALLOUT_BUCKETS];
1592 1597
1593 1598 coargs.flags = COF_DEFAULT | COF_BYIDH;
1594 1599 i = mdb_getopts(argc, argv,
1595 1600 'd', MDB_OPT_SETBITS, COF_DECODE, &coargs.flags,
1596 1601 'v', MDB_OPT_SETBITS, COF_LONGLIST, &coargs.flags,
1597 1602 NULL);
1598 1603 argc -= i;
1599 1604 argv += i;
1600 1605
1601 1606 if (argc != 1) {
1602 1607 return (DCMD_USAGE);
1603 1608 }
1604 1609 arg = &argv[0];
1605 1610
1606 1611 if (arg->a_type == MDB_TYPE_IMMEDIATE) {
1607 1612 xid = arg->a_un.a_val;
1608 1613 } else {
1609 1614 xid = (callout_id_t)mdb_strtoull(arg->a_un.a_str);
1610 1615 }
1611 1616
1612 1617 if (DCMD_HDRSPEC(flags)) {
1613 1618 coargs.flags |= COF_CHDR;
1614 1619 }
1615 1620
1616 1621
1617 1622 /* initialize from kernel variables */
1618 1623 if ((retval = callout_common_init(&coargs)) != DCMD_OK) {
1619 1624 return (retval);
1620 1625 }
1621 1626
1622 1627 /* we must massage the environment so that the macros will play nice */
1623 1628 #define callout_table_mask ((1 << coargs.ctbits) - 1)
1624 1629 #define callout_table_bits coargs.ctbits
1625 1630 #define nsec_per_tick coargs.nsec_per_tick
1626 1631 tableid = CALLOUT_ID_TO_TABLE(xid);
1627 1632 idhash = CALLOUT_IDHASH(xid);
1628 1633 #undef callouts_table_bits
1629 1634 #undef callout_table_mask
1630 1635 #undef nsec_per_tick
1631 1636 coid = CO_PLAIN_ID(xid);
1632 1637
1633 1638 if (flags & DCMD_ADDRSPEC) {
1634 1639 mdb_printf("calloutid does not accept explicit address.\n");
1635 1640 return (DCMD_USAGE);
1636 1641 }
1637 1642
1638 1643 if (coargs.flags & COF_DECODE) {
1639 1644 if (DCMD_HDRSPEC(flags)) {
1640 1645 mdb_printf("%<u>%3s %1s %2s %-?s %-6s %</u>\n",
1641 1646 "SEQ", "T", "XL", "XID", "IDHASH");
1642 1647 }
1643 1648 mdb_printf("%-3d %1s %1s%1s %-?llx %-6d\n",
1644 1649 TABLE_TO_SEQID(tableid),
1645 1650 co_typenames[tableid & CALLOUT_TYPE_MASK],
1646 1651 (xid & CALLOUT_EXECUTING) ? "X" : " ",
1647 1652 (xid & CALLOUT_LONGTERM) ? "L" : " ",
1648 1653 (long long)coid, idhash);
1649 1654 return (DCMD_OK);
1650 1655 }
1651 1656
1652 1657 /* get our table. Note this relies on the types being correct */
1653 1658 ctptr = coargs.co_table + tableid;
1654 1659 if (mdb_vread(&ct, sizeof (callout_table_t), (uintptr_t)ctptr) == -1) {
1655 1660 mdb_warn("failed to read callout_table at %p", ctptr);
1656 1661 return (DCMD_ERR);
1657 1662 }
1658 1663 size = sizeof (callout_hash_t) * CALLOUT_BUCKETS;
1659 1664 if (ct.ct_idhash != NULL) {
1660 1665 if (mdb_vread(&(cot_idhash), size,
1661 1666 (uintptr_t)ct.ct_idhash) == -1) {
1662 1667 mdb_warn("failed to read id_hash at %p",
1663 1668 ct.ct_idhash);
1664 1669 return (WALK_ERR);
1665 1670 }
1666 1671 }
1667 1672
1668 1673 /* callout at beginning of hash chain */
1669 1674 if (ct.ct_idhash == NULL) {
1670 1675 mdb_printf("id hash chain for this xid is empty\n");
1671 1676 return (DCMD_ERR);
1672 1677 }
1673 1678 coptr = (callout_t *)cot_idhash[idhash].ch_head;
1674 1679 if (coptr == NULL) {
1675 1680 mdb_printf("id hash chain for this xid is empty\n");
1676 1681 return (DCMD_ERR);
1677 1682 }
1678 1683
1679 1684 coargs.ndx = tableid;
1680 1685 coargs.bucket = idhash;
1681 1686
1682 1687 /* use the walker, luke */
1683 1688 if (mdb_pwalk("callouts_byid", callouts_cb, &coargs,
1684 1689 (uintptr_t)coptr) == -1) {
1685 1690 mdb_warn("cannot walk callouts at %p", coptr);
1686 1691 return (WALK_ERR);
1687 1692 }
1688 1693
1689 1694 return (DCMD_OK);
1690 1695 }
1691 1696
1692 1697 void
1693 1698 callout_help(void)
1694 1699 {
1695 1700 mdb_printf("callout: display callouts.\n"
1696 1701 "Given a callout table address, display callouts from table.\n"
1697 1702 "Without an address, display callouts from all tables.\n"
1698 1703 "options:\n"
1699 1704 " -r|n : limit display to (r)ealtime or (n)ormal type callouts\n"
1700 1705 " -s|l : limit display to (s)hort-term ids or (l)ong-term ids\n"
1701 1706 " -x : limit display to callouts which are executing\n"
1702 1707 " -h : limit display to callouts based on hrestime\n"
1703 1708 " -B : limit display to callouts based on absolute time\n"
1704 1709 " -t|a|b nsec: limit display to callouts that expire a(t) time,"
1705 1710 " (a)fter time,\n or (b)efore time. Use -a and -b together "
1706 1711 " to specify a range.\n For \"now\", use -d[t|a|b] 0.\n"
1707 1712 " -d : interpret time option to -t|a|b as delta from current time\n"
1708 1713 " -k : use ticks instead of nanoseconds as arguments to"
1709 1714 " -t|a|b. Note that\n ticks are less accurate and may not"
1710 1715 " match other tick times (ie: lbolt).\n"
1711 1716 " -D : display exiration time as delta from current time\n"
1712 1717 " -S seqid : limit display to callouts for this cpu sequence id\n"
1713 1718 " -C addr : limit display to callouts for this cpu pointer\n"
1714 1719 " -f name|addr : limit display to callouts with this function\n"
1715 1720 " -p name|addr : limit display to callouts functions with this"
1716 1721 " parameter\n"
1717 1722 " -T : display the callout table itself, instead of callouts\n"
1718 1723 " -L : display callout lists instead of callouts\n"
1719 1724 " -E : with -T or L, display empty data structures.\n"
1720 1725 " -i : traverse callouts by id hash instead of list hash\n"
1721 1726 " -F : walk free callout list (free list with -i) instead\n"
1722 1727 " -v : display more info for each item\n"
1723 1728 " -V : show details of each level of info as it is traversed\n"
1724 1729 " -H : limit display to callouts in the callout heap\n"
1725 1730 " -Q : limit display to callouts in the callout queue\n"
1726 1731 " -A : show only addresses. Useful for pipelines.\n");
1727 1732 }
1728 1733
1729 1734 void
1730 1735 calloutid_help(void)
1731 1736 {
1732 1737 mdb_printf("calloutid: display callout by id.\n"
1733 1738 "Given an extended callout id, display the callout infomation.\n"
1734 1739 "options:\n"
1735 1740 " -d : do not dereference callout, just decode the id.\n"
1736 1741 " -v : verbose display more info about the callout\n");
1737 1742 }
1738 1743
1739 1744 /*ARGSUSED*/
1740 1745 int
1741 1746 class(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1742 1747 {
1743 1748 long num_classes, i;
1744 1749 sclass_t *class_tbl;
1745 1750 GElf_Sym g_sclass;
1746 1751 char class_name[PC_CLNMSZ];
1747 1752 size_t tbl_size;
1748 1753
1749 1754 if (mdb_lookup_by_name("sclass", &g_sclass) == -1) {
1750 1755 mdb_warn("failed to find symbol sclass\n");
1751 1756 return (DCMD_ERR);
1752 1757 }
1753 1758
1754 1759 tbl_size = (size_t)g_sclass.st_size;
1755 1760 num_classes = tbl_size / (sizeof (sclass_t));
1756 1761 class_tbl = mdb_alloc(tbl_size, UM_SLEEP | UM_GC);
1757 1762
1758 1763 if (mdb_readsym(class_tbl, tbl_size, "sclass") == -1) {
1759 1764 mdb_warn("failed to read sclass");
1760 1765 return (DCMD_ERR);
1761 1766 }
1762 1767
1763 1768 mdb_printf("%<u>%4s %-10s %-24s %-24s%</u>\n", "SLOT", "NAME",
1764 1769 "INIT FCN", "CLASS FCN");
1765 1770
1766 1771 for (i = 0; i < num_classes; i++) {
1767 1772 if (mdb_vread(class_name, sizeof (class_name),
1768 1773 (uintptr_t)class_tbl[i].cl_name) == -1)
1769 1774 (void) strcpy(class_name, "???");
1770 1775
1771 1776 mdb_printf("%4ld %-10s %-24a %-24a\n", i, class_name,
1772 1777 class_tbl[i].cl_init, class_tbl[i].cl_funcs);
1773 1778 }
1774 1779
1775 1780 return (DCMD_OK);
1776 1781 }
1777 1782
1778 1783 #define FSNAMELEN 32 /* Max len of FS name we read from vnodeops */
1779 1784
1780 1785 int
1781 1786 vnode2path(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1782 1787 {
1783 1788 uintptr_t rootdir;
1784 1789 vnode_t vn;
1785 1790 char buf[MAXPATHLEN];
1786 1791
1787 1792 uint_t opt_F = FALSE;
1788 1793
1789 1794 if (mdb_getopts(argc, argv,
1790 1795 'F', MDB_OPT_SETBITS, TRUE, &opt_F, NULL) != argc)
1791 1796 return (DCMD_USAGE);
1792 1797
1793 1798 if (!(flags & DCMD_ADDRSPEC)) {
1794 1799 mdb_warn("expected explicit vnode_t address before ::\n");
1795 1800 return (DCMD_USAGE);
1796 1801 }
1797 1802
1798 1803 if (mdb_readvar(&rootdir, "rootdir") == -1) {
1799 1804 mdb_warn("failed to read rootdir");
1800 1805 return (DCMD_ERR);
1801 1806 }
1802 1807
1803 1808 if (mdb_vnode2path(addr, buf, sizeof (buf)) == -1)
1804 1809 return (DCMD_ERR);
1805 1810
1806 1811 if (*buf == '\0') {
1807 1812 mdb_printf("??\n");
1808 1813 return (DCMD_OK);
1809 1814 }
1810 1815
1811 1816 mdb_printf("%s", buf);
1812 1817 if (opt_F && buf[strlen(buf)-1] != '/' &&
1813 1818 mdb_vread(&vn, sizeof (vn), addr) == sizeof (vn))
1814 1819 mdb_printf("%c", mdb_vtype2chr(vn.v_type, 0));
1815 1820 mdb_printf("\n");
1816 1821
1817 1822 return (DCMD_OK);
1818 1823 }
1819 1824
1820 1825 int
1821 1826 ld_walk_init(mdb_walk_state_t *wsp)
1822 1827 {
1823 1828 wsp->walk_data = (void *)wsp->walk_addr;
1824 1829 return (WALK_NEXT);
1825 1830 }
1826 1831
1827 1832 int
1828 1833 ld_walk_step(mdb_walk_state_t *wsp)
1829 1834 {
1830 1835 int status;
1831 1836 lock_descriptor_t ld;
1832 1837
1833 1838 if (mdb_vread(&ld, sizeof (lock_descriptor_t), wsp->walk_addr) == -1) {
1834 1839 mdb_warn("couldn't read lock_descriptor_t at %p\n",
1835 1840 wsp->walk_addr);
1836 1841 return (WALK_ERR);
1837 1842 }
1838 1843
1839 1844 status = wsp->walk_callback(wsp->walk_addr, &ld, wsp->walk_cbdata);
1840 1845 if (status == WALK_ERR)
1841 1846 return (WALK_ERR);
1842 1847
1843 1848 wsp->walk_addr = (uintptr_t)ld.l_next;
1844 1849 if (wsp->walk_addr == (uintptr_t)wsp->walk_data)
1845 1850 return (WALK_DONE);
1846 1851
1847 1852 return (status);
1848 1853 }
1849 1854
1850 1855 int
1851 1856 lg_walk_init(mdb_walk_state_t *wsp)
1852 1857 {
1853 1858 GElf_Sym sym;
1854 1859
1855 1860 if (mdb_lookup_by_name("lock_graph", &sym) == -1) {
1856 1861 mdb_warn("failed to find symbol 'lock_graph'\n");
1857 1862 return (WALK_ERR);
1858 1863 }
1859 1864
1860 1865 wsp->walk_addr = (uintptr_t)sym.st_value;
1861 1866 wsp->walk_data = (void *)(uintptr_t)(sym.st_value + sym.st_size);
1862 1867
1863 1868 return (WALK_NEXT);
1864 1869 }
1865 1870
1866 1871 typedef struct lg_walk_data {
1867 1872 uintptr_t startaddr;
1868 1873 mdb_walk_cb_t callback;
1869 1874 void *data;
1870 1875 } lg_walk_data_t;
1871 1876
1872 1877 /*
1873 1878 * We can't use ::walk lock_descriptor directly, because the head of each graph
1874 1879 * is really a dummy lock. Rather than trying to dynamically determine if this
1875 1880 * is a dummy node or not, we just filter out the initial element of the
1876 1881 * list.
1877 1882 */
1878 1883 static int
1879 1884 lg_walk_cb(uintptr_t addr, const void *data, void *priv)
1880 1885 {
1881 1886 lg_walk_data_t *lw = priv;
1882 1887
1883 1888 if (addr != lw->startaddr)
1884 1889 return (lw->callback(addr, data, lw->data));
1885 1890
1886 1891 return (WALK_NEXT);
1887 1892 }
1888 1893
1889 1894 int
1890 1895 lg_walk_step(mdb_walk_state_t *wsp)
1891 1896 {
1892 1897 graph_t *graph;
1893 1898 lg_walk_data_t lw;
1894 1899
1895 1900 if (wsp->walk_addr >= (uintptr_t)wsp->walk_data)
1896 1901 return (WALK_DONE);
1897 1902
1898 1903 if (mdb_vread(&graph, sizeof (graph), wsp->walk_addr) == -1) {
1899 1904 mdb_warn("failed to read graph_t at %p", wsp->walk_addr);
1900 1905 return (WALK_ERR);
1901 1906 }
1902 1907
1903 1908 wsp->walk_addr += sizeof (graph);
1904 1909
1905 1910 if (graph == NULL)
1906 1911 return (WALK_NEXT);
1907 1912
1908 1913 lw.callback = wsp->walk_callback;
1909 1914 lw.data = wsp->walk_cbdata;
1910 1915
1911 1916 lw.startaddr = (uintptr_t)&(graph->active_locks);
1912 1917 if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
1913 1918 mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
1914 1919 return (WALK_ERR);
1915 1920 }
1916 1921
1917 1922 lw.startaddr = (uintptr_t)&(graph->sleeping_locks);
1918 1923 if (mdb_pwalk("lock_descriptor", lg_walk_cb, &lw, lw.startaddr)) {
1919 1924 mdb_warn("couldn't walk lock_descriptor at %p\n", lw.startaddr);
1920 1925 return (WALK_ERR);
1921 1926 }
1922 1927
1923 1928 return (WALK_NEXT);
1924 1929 }
1925 1930
1926 1931 /*
1927 1932 * The space available for the path corresponding to the locked vnode depends
1928 1933 * on whether we are printing 32- or 64-bit addresses.
1929 1934 */
1930 1935 #ifdef _LP64
1931 1936 #define LM_VNPATHLEN 20
1932 1937 #else
1933 1938 #define LM_VNPATHLEN 30
1934 1939 #endif
1935 1940
1936 1941 typedef struct mdb_lminfo_proc {
1937 1942 struct {
1938 1943 char u_comm[MAXCOMLEN + 1];
1939 1944 } p_user;
1940 1945 } mdb_lminfo_proc_t;
1941 1946
1942 1947 /*ARGSUSED*/
1943 1948 static int
1944 1949 lminfo_cb(uintptr_t addr, const void *data, void *priv)
1945 1950 {
1946 1951 const lock_descriptor_t *ld = data;
1947 1952 char buf[LM_VNPATHLEN];
1948 1953 mdb_lminfo_proc_t p;
1949 1954 uintptr_t paddr = 0;
1950 1955
1951 1956 if (ld->l_flock.l_pid != 0)
1952 1957 paddr = mdb_pid2proc(ld->l_flock.l_pid, NULL);
1953 1958
1954 1959 if (paddr != 0)
1955 1960 mdb_ctf_vread(&p, "proc_t", "mdb_lminfo_proc_t", paddr, 0);
1956 1961
1957 1962 mdb_printf("%-?p %2s %04x %6d %-16s %-?p ",
1958 1963 addr, ld->l_type == F_RDLCK ? "RD" :
1959 1964 ld->l_type == F_WRLCK ? "WR" : "??",
1960 1965 ld->l_state, ld->l_flock.l_pid,
1961 1966 ld->l_flock.l_pid == 0 ? "<kernel>" :
1962 1967 paddr == 0 ? "<defunct>" : p.p_user.u_comm, ld->l_vnode);
1963 1968
1964 1969 mdb_vnode2path((uintptr_t)ld->l_vnode, buf,
1965 1970 sizeof (buf));
1966 1971 mdb_printf("%s\n", buf);
1967 1972
1968 1973 return (WALK_NEXT);
1969 1974 }
1970 1975
1971 1976 /*ARGSUSED*/
1972 1977 int
1973 1978 lminfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1974 1979 {
1975 1980 if (DCMD_HDRSPEC(flags))
1976 1981 mdb_printf("%<u>%-?s %2s %4s %6s %-16s %-?s %s%</u>\n",
1977 1982 "ADDR", "TP", "FLAG", "PID", "COMM", "VNODE", "PATH");
1978 1983
1979 1984 return (mdb_pwalk("lock_graph", lminfo_cb, NULL, NULL));
1980 1985 }
1981 1986
1982 1987 /*ARGSUSED*/
1983 1988 int
1984 1989 whereopen_fwalk(uintptr_t addr, struct file *f, uintptr_t *target)
1985 1990 {
1986 1991 if ((uintptr_t)f->f_vnode == *target) {
1987 1992 mdb_printf("file %p\n", addr);
1988 1993 *target = NULL;
1989 1994 }
1990 1995
1991 1996 return (WALK_NEXT);
1992 1997 }
1993 1998
1994 1999 /*ARGSUSED*/
1995 2000 int
1996 2001 whereopen_pwalk(uintptr_t addr, void *ignored, uintptr_t *target)
1997 2002 {
1998 2003 uintptr_t t = *target;
1999 2004
2000 2005 if (mdb_pwalk("file", (mdb_walk_cb_t)whereopen_fwalk, &t, addr) == -1) {
2001 2006 mdb_warn("couldn't file walk proc %p", addr);
2002 2007 return (WALK_ERR);
2003 2008 }
2004 2009
2005 2010 if (t == NULL)
2006 2011 mdb_printf("%p\n", addr);
2007 2012
2008 2013 return (WALK_NEXT);
2009 2014 }
2010 2015
2011 2016 /*ARGSUSED*/
2012 2017 int
2013 2018 whereopen(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2014 2019 {
2015 2020 uintptr_t target = addr;
2016 2021
2017 2022 if (!(flags & DCMD_ADDRSPEC) || addr == NULL)
2018 2023 return (DCMD_USAGE);
2019 2024
2020 2025 if (mdb_walk("proc", (mdb_walk_cb_t)whereopen_pwalk, &target) == -1) {
2021 2026 mdb_warn("can't proc walk");
2022 2027 return (DCMD_ERR);
2023 2028 }
2024 2029
2025 2030 return (DCMD_OK);
2026 2031 }
2027 2032
2028 2033 typedef struct datafmt {
2029 2034 char *hdr1;
2030 2035 char *hdr2;
2031 2036 char *dashes;
2032 2037 char *fmt;
2033 2038 } datafmt_t;
2034 2039
2035 2040 static datafmt_t kmemfmt[] = {
2036 2041 { "cache ", "name ",
2037 2042 "-------------------------", "%-25s " },
2038 2043 { " buf", " size", "------", "%6u " },
2039 2044 { " buf", "in use", "------", "%6u " },
2040 2045 { " buf", " total", "------", "%6u " },
2041 2046 { " memory", " in use", "----------", "%10lu%c " },
2042 2047 { " alloc", " succeed", "---------", "%9u " },
2043 2048 { "alloc", " fail", "-----", "%5u " },
2044 2049 { NULL, NULL, NULL, NULL }
2045 2050 };
2046 2051
2047 2052 static datafmt_t vmemfmt[] = {
2048 2053 { "vmem ", "name ",
2049 2054 "-------------------------", "%-*s " },
2050 2055 { " memory", " in use", "----------", "%9llu%c " },
2051 2056 { " memory", " total", "-----------", "%10llu%c " },
2052 2057 { " memory", " import", "----------", "%9llu%c " },
2053 2058 { " alloc", " succeed", "---------", "%9llu " },
2054 2059 { "alloc", " fail", "-----", "%5llu " },
2055 2060 { NULL, NULL, NULL, NULL }
2056 2061 };
2057 2062
2058 2063 /*ARGSUSED*/
2059 2064 static int
2060 2065 kmastat_cpu_avail(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *avail)
2061 2066 {
2062 2067 short rounds, prounds;
2063 2068
2064 2069 if (KMEM_DUMPCC(ccp)) {
2065 2070 rounds = ccp->cc_dump_rounds;
2066 2071 prounds = ccp->cc_dump_prounds;
2067 2072 } else {
2068 2073 rounds = ccp->cc_rounds;
2069 2074 prounds = ccp->cc_prounds;
2070 2075 }
2071 2076 if (rounds > 0)
2072 2077 *avail += rounds;
2073 2078 if (prounds > 0)
2074 2079 *avail += prounds;
2075 2080
2076 2081 return (WALK_NEXT);
2077 2082 }
2078 2083
2079 2084 /*ARGSUSED*/
2080 2085 static int
2081 2086 kmastat_cpu_alloc(uintptr_t addr, const kmem_cpu_cache_t *ccp, int *alloc)
2082 2087 {
2083 2088 *alloc += ccp->cc_alloc;
2084 2089
2085 2090 return (WALK_NEXT);
2086 2091 }
2087 2092
2088 2093 /*ARGSUSED*/
2089 2094 static int
2090 2095 kmastat_slab_avail(uintptr_t addr, const kmem_slab_t *sp, int *avail)
2091 2096 {
2092 2097 *avail += sp->slab_chunks - sp->slab_refcnt;
2093 2098
2094 2099 return (WALK_NEXT);
2095 2100 }
2096 2101
2097 2102 typedef struct kmastat_vmem {
2098 2103 uintptr_t kv_addr;
2099 2104 struct kmastat_vmem *kv_next;
2100 2105 size_t kv_meminuse;
2101 2106 int kv_alloc;
2102 2107 int kv_fail;
2103 2108 } kmastat_vmem_t;
2104 2109
2105 2110 typedef struct kmastat_args {
2106 2111 kmastat_vmem_t **ka_kvpp;
2107 2112 uint_t ka_shift;
2108 2113 } kmastat_args_t;
2109 2114
2110 2115 static int
2111 2116 kmastat_cache(uintptr_t addr, const kmem_cache_t *cp, kmastat_args_t *kap)
2112 2117 {
2113 2118 kmastat_vmem_t **kvpp = kap->ka_kvpp;
2114 2119 kmastat_vmem_t *kv;
2115 2120 datafmt_t *dfp = kmemfmt;
2116 2121 int magsize;
2117 2122
2118 2123 int avail, alloc, total;
2119 2124 size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) *
2120 2125 cp->cache_slabsize;
2121 2126
2122 2127 mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)kmastat_cpu_avail;
2123 2128 mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)kmastat_cpu_alloc;
2124 2129 mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)kmastat_slab_avail;
2125 2130
2126 2131 magsize = kmem_get_magsize(cp);
2127 2132
2128 2133 alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc;
2129 2134 avail = cp->cache_full.ml_total * magsize;
2130 2135 total = cp->cache_buftotal;
2131 2136
2132 2137 (void) mdb_pwalk("kmem_cpu_cache", cpu_alloc, &alloc, addr);
2133 2138 (void) mdb_pwalk("kmem_cpu_cache", cpu_avail, &avail, addr);
2134 2139 (void) mdb_pwalk("kmem_slab_partial", slab_avail, &avail, addr);
2135 2140
2136 2141 for (kv = *kvpp; kv != NULL; kv = kv->kv_next) {
2137 2142 if (kv->kv_addr == (uintptr_t)cp->cache_arena)
2138 2143 goto out;
2139 2144 }
2140 2145
2141 2146 kv = mdb_zalloc(sizeof (kmastat_vmem_t), UM_SLEEP | UM_GC);
2142 2147 kv->kv_next = *kvpp;
2143 2148 kv->kv_addr = (uintptr_t)cp->cache_arena;
2144 2149 *kvpp = kv;
2145 2150 out:
2146 2151 kv->kv_meminuse += meminuse;
2147 2152 kv->kv_alloc += alloc;
2148 2153 kv->kv_fail += cp->cache_alloc_fail;
2149 2154
2150 2155 mdb_printf((dfp++)->fmt, cp->cache_name);
2151 2156 mdb_printf((dfp++)->fmt, cp->cache_bufsize);
2152 2157 mdb_printf((dfp++)->fmt, total - avail);
2153 2158 mdb_printf((dfp++)->fmt, total);
2154 2159 mdb_printf((dfp++)->fmt, meminuse >> kap->ka_shift,
2155 2160 kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
2156 2161 kap->ka_shift == KILOS ? 'K' : 'B');
2157 2162 mdb_printf((dfp++)->fmt, alloc);
2158 2163 mdb_printf((dfp++)->fmt, cp->cache_alloc_fail);
2159 2164 mdb_printf("\n");
2160 2165
2161 2166 return (WALK_NEXT);
2162 2167 }
2163 2168
2164 2169 static int
2165 2170 kmastat_vmem_totals(uintptr_t addr, const vmem_t *v, kmastat_args_t *kap)
2166 2171 {
2167 2172 kmastat_vmem_t *kv = *kap->ka_kvpp;
2168 2173 size_t len;
2169 2174
2170 2175 while (kv != NULL && kv->kv_addr != addr)
2171 2176 kv = kv->kv_next;
2172 2177
2173 2178 if (kv == NULL || kv->kv_alloc == 0)
2174 2179 return (WALK_NEXT);
2175 2180
2176 2181 len = MIN(17, strlen(v->vm_name));
2177 2182
2178 2183 mdb_printf("Total [%s]%*s %6s %6s %6s %10lu%c %9u %5u\n", v->vm_name,
2179 2184 17 - len, "", "", "", "",
2180 2185 kv->kv_meminuse >> kap->ka_shift,
2181 2186 kap->ka_shift == GIGS ? 'G' : kap->ka_shift == MEGS ? 'M' :
2182 2187 kap->ka_shift == KILOS ? 'K' : 'B', kv->kv_alloc, kv->kv_fail);
2183 2188
2184 2189 return (WALK_NEXT);
2185 2190 }
2186 2191
2187 2192 /*ARGSUSED*/
2188 2193 static int
2189 2194 kmastat_vmem(uintptr_t addr, const vmem_t *v, const uint_t *shiftp)
2190 2195 {
2191 2196 datafmt_t *dfp = vmemfmt;
2192 2197 const vmem_kstat_t *vkp = &v->vm_kstat;
2193 2198 uintptr_t paddr;
2194 2199 vmem_t parent;
2195 2200 int ident = 0;
2196 2201
2197 2202 for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) {
2198 2203 if (mdb_vread(&parent, sizeof (parent), paddr) == -1) {
2199 2204 mdb_warn("couldn't trace %p's ancestry", addr);
2200 2205 ident = 0;
2201 2206 break;
2202 2207 }
2203 2208 paddr = (uintptr_t)parent.vm_source;
2204 2209 }
2205 2210
2206 2211 mdb_printf("%*s", ident, "");
2207 2212 mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name);
2208 2213 mdb_printf((dfp++)->fmt, vkp->vk_mem_inuse.value.ui64 >> *shiftp,
2209 2214 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
2210 2215 *shiftp == KILOS ? 'K' : 'B');
2211 2216 mdb_printf((dfp++)->fmt, vkp->vk_mem_total.value.ui64 >> *shiftp,
2212 2217 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
2213 2218 *shiftp == KILOS ? 'K' : 'B');
2214 2219 mdb_printf((dfp++)->fmt, vkp->vk_mem_import.value.ui64 >> *shiftp,
2215 2220 *shiftp == GIGS ? 'G' : *shiftp == MEGS ? 'M' :
2216 2221 *shiftp == KILOS ? 'K' : 'B');
2217 2222 mdb_printf((dfp++)->fmt, vkp->vk_alloc.value.ui64);
2218 2223 mdb_printf((dfp++)->fmt, vkp->vk_fail.value.ui64);
2219 2224
2220 2225 mdb_printf("\n");
2221 2226
2222 2227 return (WALK_NEXT);
2223 2228 }
2224 2229
2225 2230 /*ARGSUSED*/
2226 2231 int
2227 2232 kmastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2228 2233 {
2229 2234 kmastat_vmem_t *kv = NULL;
2230 2235 datafmt_t *dfp;
2231 2236 kmastat_args_t ka;
2232 2237
2233 2238 ka.ka_shift = 0;
2234 2239 if (mdb_getopts(argc, argv,
2235 2240 'k', MDB_OPT_SETBITS, KILOS, &ka.ka_shift,
2236 2241 'm', MDB_OPT_SETBITS, MEGS, &ka.ka_shift,
2237 2242 'g', MDB_OPT_SETBITS, GIGS, &ka.ka_shift, NULL) != argc)
2238 2243 return (DCMD_USAGE);
2239 2244
2240 2245 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
2241 2246 mdb_printf("%s ", dfp->hdr1);
2242 2247 mdb_printf("\n");
2243 2248
2244 2249 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
2245 2250 mdb_printf("%s ", dfp->hdr2);
2246 2251 mdb_printf("\n");
2247 2252
2248 2253 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
2249 2254 mdb_printf("%s ", dfp->dashes);
2250 2255 mdb_printf("\n");
2251 2256
2252 2257 ka.ka_kvpp = &kv;
2253 2258 if (mdb_walk("kmem_cache", (mdb_walk_cb_t)kmastat_cache, &ka) == -1) {
2254 2259 mdb_warn("can't walk 'kmem_cache'");
2255 2260 return (DCMD_ERR);
2256 2261 }
2257 2262
2258 2263 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
2259 2264 mdb_printf("%s ", dfp->dashes);
2260 2265 mdb_printf("\n");
2261 2266
2262 2267 if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem_totals, &ka) == -1) {
2263 2268 mdb_warn("can't walk 'vmem'");
2264 2269 return (DCMD_ERR);
2265 2270 }
2266 2271
2267 2272 for (dfp = kmemfmt; dfp->hdr1 != NULL; dfp++)
2268 2273 mdb_printf("%s ", dfp->dashes);
2269 2274 mdb_printf("\n");
2270 2275
2271 2276 mdb_printf("\n");
2272 2277
2273 2278 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
2274 2279 mdb_printf("%s ", dfp->hdr1);
2275 2280 mdb_printf("\n");
2276 2281
2277 2282 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
2278 2283 mdb_printf("%s ", dfp->hdr2);
2279 2284 mdb_printf("\n");
2280 2285
2281 2286 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
2282 2287 mdb_printf("%s ", dfp->dashes);
2283 2288 mdb_printf("\n");
2284 2289
2285 2290 if (mdb_walk("vmem", (mdb_walk_cb_t)kmastat_vmem, &ka.ka_shift) == -1) {
2286 2291 mdb_warn("can't walk 'vmem'");
2287 2292 return (DCMD_ERR);
2288 2293 }
2289 2294
2290 2295 for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++)
2291 2296 mdb_printf("%s ", dfp->dashes);
2292 2297 mdb_printf("\n");
2293 2298 return (DCMD_OK);
2294 2299 }
2295 2300
2296 2301 /*
2297 2302 * Our ::kgrep callback scans the entire kernel VA space (kas). kas is made
2298 2303 * up of a set of 'struct seg's. We could just scan each seg en masse, but
2299 2304 * unfortunately, a few of the segs are both large and sparse, so we could
2300 2305 * spend quite a bit of time scanning VAs which have no backing pages.
2301 2306 *
2302 2307 * So for the few very sparse segs, we skip the segment itself, and scan
2303 2308 * the allocated vmem_segs in the vmem arena which manages that part of kas.
2304 2309 * Currently, we do this for:
2305 2310 *
2306 2311 * SEG VMEM ARENA
2307 2312 * kvseg heap_arena
2308 2313 * kvseg32 heap32_arena
2309 2314 * kvseg_core heap_core_arena
2310 2315 *
2311 2316 * In addition, we skip the segkpm segment in its entirety, since it is very
2312 2317 * sparse, and contains no new kernel data.
2313 2318 */
2314 2319 typedef struct kgrep_walk_data {
2315 2320 kgrep_cb_func *kg_cb;
2316 2321 void *kg_cbdata;
2317 2322 uintptr_t kg_kvseg;
2318 2323 uintptr_t kg_kvseg32;
2319 2324 uintptr_t kg_kvseg_core;
2320 2325 uintptr_t kg_segkpm;
2321 2326 uintptr_t kg_heap_lp_base;
2322 2327 uintptr_t kg_heap_lp_end;
2323 2328 } kgrep_walk_data_t;
2324 2329
2325 2330 static int
2326 2331 kgrep_walk_seg(uintptr_t addr, const struct seg *seg, kgrep_walk_data_t *kg)
2327 2332 {
2328 2333 uintptr_t base = (uintptr_t)seg->s_base;
2329 2334
2330 2335 if (addr == kg->kg_kvseg || addr == kg->kg_kvseg32 ||
2331 2336 addr == kg->kg_kvseg_core)
2332 2337 return (WALK_NEXT);
2333 2338
2334 2339 if ((uintptr_t)seg->s_ops == kg->kg_segkpm)
2335 2340 return (WALK_NEXT);
2336 2341
2337 2342 return (kg->kg_cb(base, base + seg->s_size, kg->kg_cbdata));
2338 2343 }
2339 2344
2340 2345 /*ARGSUSED*/
2341 2346 static int
2342 2347 kgrep_walk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
2343 2348 {
2344 2349 /*
2345 2350 * skip large page heap address range - it is scanned by walking
2346 2351 * allocated vmem_segs in the heap_lp_arena
2347 2352 */
2348 2353 if (seg->vs_start == kg->kg_heap_lp_base &&
2349 2354 seg->vs_end == kg->kg_heap_lp_end)
2350 2355 return (WALK_NEXT);
2351 2356
2352 2357 return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
2353 2358 }
2354 2359
2355 2360 /*ARGSUSED*/
2356 2361 static int
2357 2362 kgrep_xwalk_vseg(uintptr_t addr, const vmem_seg_t *seg, kgrep_walk_data_t *kg)
2358 2363 {
2359 2364 return (kg->kg_cb(seg->vs_start, seg->vs_end, kg->kg_cbdata));
2360 2365 }
2361 2366
2362 2367 static int
2363 2368 kgrep_walk_vmem(uintptr_t addr, const vmem_t *vmem, kgrep_walk_data_t *kg)
2364 2369 {
2365 2370 mdb_walk_cb_t walk_vseg = (mdb_walk_cb_t)kgrep_walk_vseg;
2366 2371
2367 2372 if (strcmp(vmem->vm_name, "heap") != 0 &&
2368 2373 strcmp(vmem->vm_name, "heap32") != 0 &&
2369 2374 strcmp(vmem->vm_name, "heap_core") != 0 &&
2370 2375 strcmp(vmem->vm_name, "heap_lp") != 0)
2371 2376 return (WALK_NEXT);
2372 2377
2373 2378 if (strcmp(vmem->vm_name, "heap_lp") == 0)
2374 2379 walk_vseg = (mdb_walk_cb_t)kgrep_xwalk_vseg;
2375 2380
2376 2381 if (mdb_pwalk("vmem_alloc", walk_vseg, kg, addr) == -1) {
2377 2382 mdb_warn("couldn't walk vmem_alloc for vmem %p", addr);
2378 2383 return (WALK_ERR);
2379 2384 }
2380 2385
2381 2386 return (WALK_NEXT);
2382 2387 }
2383 2388
2384 2389 int
2385 2390 kgrep_subr(kgrep_cb_func *cb, void *cbdata)
2386 2391 {
2387 2392 GElf_Sym kas, kvseg, kvseg32, kvseg_core, segkpm;
2388 2393 kgrep_walk_data_t kg;
2389 2394
2390 2395 if (mdb_get_state() == MDB_STATE_RUNNING) {
2391 2396 mdb_warn("kgrep can only be run on a system "
2392 2397 "dump or under kmdb; see dumpadm(1M)\n");
2393 2398 return (DCMD_ERR);
2394 2399 }
2395 2400
2396 2401 if (mdb_lookup_by_name("kas", &kas) == -1) {
2397 2402 mdb_warn("failed to locate 'kas' symbol\n");
2398 2403 return (DCMD_ERR);
2399 2404 }
2400 2405
2401 2406 if (mdb_lookup_by_name("kvseg", &kvseg) == -1) {
2402 2407 mdb_warn("failed to locate 'kvseg' symbol\n");
2403 2408 return (DCMD_ERR);
2404 2409 }
2405 2410
2406 2411 if (mdb_lookup_by_name("kvseg32", &kvseg32) == -1) {
2407 2412 mdb_warn("failed to locate 'kvseg32' symbol\n");
2408 2413 return (DCMD_ERR);
2409 2414 }
2410 2415
2411 2416 if (mdb_lookup_by_name("kvseg_core", &kvseg_core) == -1) {
2412 2417 mdb_warn("failed to locate 'kvseg_core' symbol\n");
2413 2418 return (DCMD_ERR);
2414 2419 }
2415 2420
2416 2421 if (mdb_lookup_by_name("segkpm_ops", &segkpm) == -1) {
2417 2422 mdb_warn("failed to locate 'segkpm_ops' symbol\n");
2418 2423 return (DCMD_ERR);
2419 2424 }
2420 2425
2421 2426 if (mdb_readvar(&kg.kg_heap_lp_base, "heap_lp_base") == -1) {
2422 2427 mdb_warn("failed to read 'heap_lp_base'\n");
2423 2428 return (DCMD_ERR);
2424 2429 }
2425 2430
2426 2431 if (mdb_readvar(&kg.kg_heap_lp_end, "heap_lp_end") == -1) {
2427 2432 mdb_warn("failed to read 'heap_lp_end'\n");
2428 2433 return (DCMD_ERR);
2429 2434 }
2430 2435
2431 2436 kg.kg_cb = cb;
2432 2437 kg.kg_cbdata = cbdata;
2433 2438 kg.kg_kvseg = (uintptr_t)kvseg.st_value;
2434 2439 kg.kg_kvseg32 = (uintptr_t)kvseg32.st_value;
2435 2440 kg.kg_kvseg_core = (uintptr_t)kvseg_core.st_value;
2436 2441 kg.kg_segkpm = (uintptr_t)segkpm.st_value;
2437 2442
2438 2443 if (mdb_pwalk("seg", (mdb_walk_cb_t)kgrep_walk_seg,
2439 2444 &kg, kas.st_value) == -1) {
2440 2445 mdb_warn("failed to walk kas segments");
2441 2446 return (DCMD_ERR);
2442 2447 }
2443 2448
2444 2449 if (mdb_walk("vmem", (mdb_walk_cb_t)kgrep_walk_vmem, &kg) == -1) {
2445 2450 mdb_warn("failed to walk heap/heap32 vmem arenas");
2446 2451 return (DCMD_ERR);
2447 2452 }
2448 2453
2449 2454 return (DCMD_OK);
2450 2455 }
2451 2456
2452 2457 size_t
2453 2458 kgrep_subr_pagesize(void)
2454 2459 {
2455 2460 return (PAGESIZE);
2456 2461 }
2457 2462
2458 2463 typedef struct file_walk_data {
2459 2464 struct uf_entry *fw_flist;
2460 2465 int fw_flistsz;
2461 2466 int fw_ndx;
2462 2467 int fw_nofiles;
2463 2468 } file_walk_data_t;
2464 2469
2465 2470 typedef struct mdb_file_proc {
2466 2471 struct {
2467 2472 struct {
2468 2473 int fi_nfiles;
2469 2474 uf_entry_t *volatile fi_list;
2470 2475 } u_finfo;
2471 2476 } p_user;
2472 2477 } mdb_file_proc_t;
2473 2478
2474 2479 int
2475 2480 file_walk_init(mdb_walk_state_t *wsp)
2476 2481 {
2477 2482 file_walk_data_t *fw;
2478 2483 mdb_file_proc_t p;
2479 2484
2480 2485 if (wsp->walk_addr == NULL) {
2481 2486 mdb_warn("file walk doesn't support global walks\n");
2482 2487 return (WALK_ERR);
2483 2488 }
2484 2489
2485 2490 fw = mdb_alloc(sizeof (file_walk_data_t), UM_SLEEP);
2486 2491
2487 2492 if (mdb_ctf_vread(&p, "proc_t", "mdb_file_proc_t",
2488 2493 wsp->walk_addr, 0) == -1) {
2489 2494 mdb_free(fw, sizeof (file_walk_data_t));
2490 2495 mdb_warn("failed to read proc structure at %p", wsp->walk_addr);
2491 2496 return (WALK_ERR);
2492 2497 }
2493 2498
2494 2499 if (p.p_user.u_finfo.fi_nfiles == 0) {
2495 2500 mdb_free(fw, sizeof (file_walk_data_t));
2496 2501 return (WALK_DONE);
2497 2502 }
2498 2503
2499 2504 fw->fw_nofiles = p.p_user.u_finfo.fi_nfiles;
2500 2505 fw->fw_flistsz = sizeof (struct uf_entry) * fw->fw_nofiles;
2501 2506 fw->fw_flist = mdb_alloc(fw->fw_flistsz, UM_SLEEP);
2502 2507
2503 2508 if (mdb_vread(fw->fw_flist, fw->fw_flistsz,
2504 2509 (uintptr_t)p.p_user.u_finfo.fi_list) == -1) {
2505 2510 mdb_warn("failed to read file array at %p",
2506 2511 p.p_user.u_finfo.fi_list);
2507 2512 mdb_free(fw->fw_flist, fw->fw_flistsz);
2508 2513 mdb_free(fw, sizeof (file_walk_data_t));
2509 2514 return (WALK_ERR);
2510 2515 }
2511 2516
2512 2517 fw->fw_ndx = 0;
2513 2518 wsp->walk_data = fw;
2514 2519
2515 2520 return (WALK_NEXT);
2516 2521 }
2517 2522
2518 2523 int
2519 2524 file_walk_step(mdb_walk_state_t *wsp)
2520 2525 {
2521 2526 file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
2522 2527 struct file file;
2523 2528 uintptr_t fp;
2524 2529
2525 2530 again:
2526 2531 if (fw->fw_ndx == fw->fw_nofiles)
2527 2532 return (WALK_DONE);
2528 2533
2529 2534 if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) == NULL)
2530 2535 goto again;
2531 2536
2532 2537 (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
2533 2538 return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
2534 2539 }
2535 2540
2536 2541 int
2537 2542 allfile_walk_step(mdb_walk_state_t *wsp)
2538 2543 {
2539 2544 file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
2540 2545 struct file file;
2541 2546 uintptr_t fp;
2542 2547
2543 2548 if (fw->fw_ndx == fw->fw_nofiles)
2544 2549 return (WALK_DONE);
2545 2550
2546 2551 if ((fp = (uintptr_t)fw->fw_flist[fw->fw_ndx++].uf_file) != NULL)
2547 2552 (void) mdb_vread(&file, sizeof (file), (uintptr_t)fp);
2548 2553 else
2549 2554 bzero(&file, sizeof (file));
2550 2555
2551 2556 return (wsp->walk_callback(fp, &file, wsp->walk_cbdata));
2552 2557 }
2553 2558
2554 2559 void
2555 2560 file_walk_fini(mdb_walk_state_t *wsp)
2556 2561 {
2557 2562 file_walk_data_t *fw = (file_walk_data_t *)wsp->walk_data;
2558 2563
2559 2564 mdb_free(fw->fw_flist, fw->fw_flistsz);
2560 2565 mdb_free(fw, sizeof (file_walk_data_t));
2561 2566 }
2562 2567
2563 2568 int
2564 2569 port_walk_init(mdb_walk_state_t *wsp)
2565 2570 {
2566 2571 if (wsp->walk_addr == NULL) {
2567 2572 mdb_warn("port walk doesn't support global walks\n");
2568 2573 return (WALK_ERR);
2569 2574 }
2570 2575
2571 2576 if (mdb_layered_walk("file", wsp) == -1) {
2572 2577 mdb_warn("couldn't walk 'file'");
2573 2578 return (WALK_ERR);
2574 2579 }
2575 2580 return (WALK_NEXT);
2576 2581 }
2577 2582
2578 2583 int
2579 2584 port_walk_step(mdb_walk_state_t *wsp)
2580 2585 {
2581 2586 struct vnode vn;
2582 2587 uintptr_t vp;
2583 2588 uintptr_t pp;
2584 2589 struct port port;
2585 2590
2586 2591 vp = (uintptr_t)((struct file *)wsp->walk_layer)->f_vnode;
2587 2592 if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
2588 2593 mdb_warn("failed to read vnode_t at %p", vp);
2589 2594 return (WALK_ERR);
2590 2595 }
2591 2596 if (vn.v_type != VPORT)
2592 2597 return (WALK_NEXT);
2593 2598
2594 2599 pp = (uintptr_t)vn.v_data;
2595 2600 if (mdb_vread(&port, sizeof (port), pp) == -1) {
2596 2601 mdb_warn("failed to read port_t at %p", pp);
2597 2602 return (WALK_ERR);
2598 2603 }
2599 2604 return (wsp->walk_callback(pp, &port, wsp->walk_cbdata));
2600 2605 }
2601 2606
2602 2607 typedef struct portev_walk_data {
2603 2608 list_node_t *pev_node;
2604 2609 list_node_t *pev_last;
2605 2610 size_t pev_offset;
2606 2611 } portev_walk_data_t;
2607 2612
2608 2613 int
2609 2614 portev_walk_init(mdb_walk_state_t *wsp)
2610 2615 {
2611 2616 portev_walk_data_t *pevd;
2612 2617 struct port port;
2613 2618 struct vnode vn;
2614 2619 struct list *list;
2615 2620 uintptr_t vp;
2616 2621
2617 2622 if (wsp->walk_addr == NULL) {
2618 2623 mdb_warn("portev walk doesn't support global walks\n");
2619 2624 return (WALK_ERR);
2620 2625 }
2621 2626
2622 2627 pevd = mdb_alloc(sizeof (portev_walk_data_t), UM_SLEEP);
2623 2628
2624 2629 if (mdb_vread(&port, sizeof (port), wsp->walk_addr) == -1) {
2625 2630 mdb_free(pevd, sizeof (portev_walk_data_t));
2626 2631 mdb_warn("failed to read port structure at %p", wsp->walk_addr);
2627 2632 return (WALK_ERR);
2628 2633 }
2629 2634
2630 2635 vp = (uintptr_t)port.port_vnode;
2631 2636 if (mdb_vread(&vn, sizeof (vn), vp) == -1) {
2632 2637 mdb_free(pevd, sizeof (portev_walk_data_t));
2633 2638 mdb_warn("failed to read vnode_t at %p", vp);
2634 2639 return (WALK_ERR);
2635 2640 }
2636 2641
2637 2642 if (vn.v_type != VPORT) {
2638 2643 mdb_free(pevd, sizeof (portev_walk_data_t));
2639 2644 mdb_warn("input address (%p) does not point to an event port",
2640 2645 wsp->walk_addr);
2641 2646 return (WALK_ERR);
2642 2647 }
2643 2648
2644 2649 if (port.port_queue.portq_nent == 0) {
2645 2650 mdb_free(pevd, sizeof (portev_walk_data_t));
2646 2651 return (WALK_DONE);
2647 2652 }
2648 2653 list = &port.port_queue.portq_list;
2649 2654 pevd->pev_offset = list->list_offset;
2650 2655 pevd->pev_last = list->list_head.list_prev;
2651 2656 pevd->pev_node = list->list_head.list_next;
2652 2657 wsp->walk_data = pevd;
2653 2658 return (WALK_NEXT);
2654 2659 }
2655 2660
2656 2661 int
2657 2662 portev_walk_step(mdb_walk_state_t *wsp)
2658 2663 {
2659 2664 portev_walk_data_t *pevd;
2660 2665 struct port_kevent ev;
2661 2666 uintptr_t evp;
2662 2667
2663 2668 pevd = (portev_walk_data_t *)wsp->walk_data;
2664 2669
2665 2670 if (pevd->pev_last == NULL)
2666 2671 return (WALK_DONE);
2667 2672 if (pevd->pev_node == pevd->pev_last)
2668 2673 pevd->pev_last = NULL; /* last round */
2669 2674
2670 2675 evp = ((uintptr_t)(((char *)pevd->pev_node) - pevd->pev_offset));
2671 2676 if (mdb_vread(&ev, sizeof (ev), evp) == -1) {
2672 2677 mdb_warn("failed to read port_kevent at %p", evp);
2673 2678 return (WALK_DONE);
2674 2679 }
2675 2680 pevd->pev_node = ev.portkev_node.list_next;
2676 2681 return (wsp->walk_callback(evp, &ev, wsp->walk_cbdata));
2677 2682 }
2678 2683
2679 2684 void
2680 2685 portev_walk_fini(mdb_walk_state_t *wsp)
2681 2686 {
2682 2687 portev_walk_data_t *pevd = (portev_walk_data_t *)wsp->walk_data;
2683 2688
2684 2689 if (pevd != NULL)
2685 2690 mdb_free(pevd, sizeof (portev_walk_data_t));
2686 2691 }
2687 2692
2688 2693 typedef struct proc_walk_data {
2689 2694 uintptr_t *pw_stack;
2690 2695 int pw_depth;
2691 2696 int pw_max;
2692 2697 } proc_walk_data_t;
2693 2698
2694 2699 int
2695 2700 proc_walk_init(mdb_walk_state_t *wsp)
2696 2701 {
2697 2702 GElf_Sym sym;
2698 2703 proc_walk_data_t *pw;
2699 2704
2700 2705 if (wsp->walk_addr == NULL) {
2701 2706 if (mdb_lookup_by_name("p0", &sym) == -1) {
2702 2707 mdb_warn("failed to read 'practive'");
2703 2708 return (WALK_ERR);
2704 2709 }
2705 2710 wsp->walk_addr = (uintptr_t)sym.st_value;
2706 2711 }
2707 2712
2708 2713 pw = mdb_zalloc(sizeof (proc_walk_data_t), UM_SLEEP);
2709 2714
2710 2715 if (mdb_readvar(&pw->pw_max, "nproc") == -1) {
2711 2716 mdb_warn("failed to read 'nproc'");
2712 2717 mdb_free(pw, sizeof (pw));
2713 2718 return (WALK_ERR);
2714 2719 }
2715 2720
2716 2721 pw->pw_stack = mdb_alloc(pw->pw_max * sizeof (uintptr_t), UM_SLEEP);
2717 2722 wsp->walk_data = pw;
2718 2723
2719 2724 return (WALK_NEXT);
2720 2725 }
2721 2726
2722 2727 typedef struct mdb_walk_proc {
2723 2728 struct proc *p_child;
2724 2729 struct proc *p_sibling;
2725 2730 } mdb_walk_proc_t;
2726 2731
2727 2732 int
2728 2733 proc_walk_step(mdb_walk_state_t *wsp)
2729 2734 {
2730 2735 proc_walk_data_t *pw = wsp->walk_data;
2731 2736 uintptr_t addr = wsp->walk_addr;
2732 2737 uintptr_t cld, sib;
2733 2738 int status;
2734 2739 mdb_walk_proc_t pr;
2735 2740
2736 2741 if (mdb_ctf_vread(&pr, "proc_t", "mdb_walk_proc_t",
2737 2742 addr, 0) == -1) {
2738 2743 mdb_warn("failed to read proc at %p", addr);
2739 2744 return (WALK_DONE);
2740 2745 }
2741 2746
2742 2747 cld = (uintptr_t)pr.p_child;
2743 2748 sib = (uintptr_t)pr.p_sibling;
2744 2749
2745 2750 if (pw->pw_depth > 0 && addr == pw->pw_stack[pw->pw_depth - 1]) {
2746 2751 pw->pw_depth--;
2747 2752 goto sib;
2748 2753 }
2749 2754
2750 2755 /*
2751 2756 * Always pass NULL as the local copy pointer. Consumers
2752 2757 * should use mdb_ctf_vread() to read their own minimal
2753 2758 * version of proc_t. Thus minimizing the chance of breakage
2754 2759 * with older crash dumps.
2755 2760 */
2756 2761 status = wsp->walk_callback(addr, NULL, wsp->walk_cbdata);
2757 2762
2758 2763 if (status != WALK_NEXT)
2759 2764 return (status);
2760 2765
2761 2766 if ((wsp->walk_addr = cld) != NULL) {
2762 2767 if (mdb_ctf_vread(&pr, "proc_t", "mdb_walk_proc_t",
2763 2768 cld, 0) == -1) {
2764 2769 mdb_warn("proc %p has invalid p_child %p; skipping\n",
2765 2770 addr, cld);
2766 2771 goto sib;
2767 2772 }
2768 2773
2769 2774 pw->pw_stack[pw->pw_depth++] = addr;
2770 2775
2771 2776 if (pw->pw_depth == pw->pw_max) {
2772 2777 mdb_warn("depth %d exceeds max depth; try again\n",
2773 2778 pw->pw_depth);
2774 2779 return (WALK_DONE);
2775 2780 }
2776 2781 return (WALK_NEXT);
2777 2782 }
2778 2783
2779 2784 sib:
2780 2785 /*
2781 2786 * We know that p0 has no siblings, and if another starting proc
2782 2787 * was given, we don't want to walk its siblings anyway.
2783 2788 */
2784 2789 if (pw->pw_depth == 0)
2785 2790 return (WALK_DONE);
2786 2791
2787 2792 if (sib != NULL && mdb_ctf_vread(&pr, "proc_t", "mdb_walk_proc_t",
2788 2793 sib, 0) == -1) {
2789 2794 mdb_warn("proc %p has invalid p_sibling %p; skipping\n",
2790 2795 addr, sib);
2791 2796 sib = NULL;
2792 2797 }
2793 2798
2794 2799 if ((wsp->walk_addr = sib) == NULL) {
2795 2800 if (pw->pw_depth > 0) {
2796 2801 wsp->walk_addr = pw->pw_stack[pw->pw_depth - 1];
2797 2802 return (WALK_NEXT);
2798 2803 }
2799 2804 return (WALK_DONE);
2800 2805 }
2801 2806
2802 2807 return (WALK_NEXT);
2803 2808 }
2804 2809
2805 2810 void
2806 2811 proc_walk_fini(mdb_walk_state_t *wsp)
2807 2812 {
2808 2813 proc_walk_data_t *pw = wsp->walk_data;
2809 2814
2810 2815 mdb_free(pw->pw_stack, pw->pw_max * sizeof (uintptr_t));
2811 2816 mdb_free(pw, sizeof (proc_walk_data_t));
2812 2817 }
2813 2818
2814 2819 int
2815 2820 task_walk_init(mdb_walk_state_t *wsp)
2816 2821 {
2817 2822 task_t task;
2818 2823
2819 2824 if (mdb_vread(&task, sizeof (task_t), wsp->walk_addr) == -1) {
2820 2825 mdb_warn("failed to read task at %p", wsp->walk_addr);
2821 2826 return (WALK_ERR);
2822 2827 }
2823 2828 wsp->walk_addr = (uintptr_t)task.tk_memb_list;
2824 2829 wsp->walk_data = task.tk_memb_list;
2825 2830 return (WALK_NEXT);
2826 2831 }
2827 2832
2828 2833 typedef struct mdb_task_proc {
2829 2834 struct proc *p_tasknext;
2830 2835 } mdb_task_proc_t;
2831 2836
2832 2837 int
2833 2838 task_walk_step(mdb_walk_state_t *wsp)
2834 2839 {
2835 2840 mdb_task_proc_t proc;
2836 2841 int status;
2837 2842
2838 2843 if (mdb_ctf_vread(&proc, "proc_t", "mdb_task_proc_t",
2839 2844 wsp->walk_addr, 0) == -1) {
2840 2845 mdb_warn("failed to read proc at %p", wsp->walk_addr);
2841 2846 return (WALK_DONE);
2842 2847 }
2843 2848
2844 2849 status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
2845 2850
2846 2851 if (proc.p_tasknext == wsp->walk_data)
2847 2852 return (WALK_DONE);
2848 2853
2849 2854 wsp->walk_addr = (uintptr_t)proc.p_tasknext;
2850 2855 return (status);
2851 2856 }
2852 2857
2853 2858 int
2854 2859 project_walk_init(mdb_walk_state_t *wsp)
2855 2860 {
2856 2861 if (wsp->walk_addr == NULL) {
2857 2862 if (mdb_readvar(&wsp->walk_addr, "proj0p") == -1) {
2858 2863 mdb_warn("failed to read 'proj0p'");
2859 2864 return (WALK_ERR);
2860 2865 }
2861 2866 }
2862 2867 wsp->walk_data = (void *)wsp->walk_addr;
2863 2868 return (WALK_NEXT);
2864 2869 }
2865 2870
2866 2871 int
2867 2872 project_walk_step(mdb_walk_state_t *wsp)
2868 2873 {
2869 2874 uintptr_t addr = wsp->walk_addr;
2870 2875 kproject_t pj;
2871 2876 int status;
2872 2877
2873 2878 if (mdb_vread(&pj, sizeof (kproject_t), addr) == -1) {
2874 2879 mdb_warn("failed to read project at %p", addr);
2875 2880 return (WALK_DONE);
2876 2881 }
2877 2882 status = wsp->walk_callback(addr, &pj, wsp->walk_cbdata);
2878 2883 if (status != WALK_NEXT)
2879 2884 return (status);
2880 2885 wsp->walk_addr = (uintptr_t)pj.kpj_next;
2881 2886 if ((void *)wsp->walk_addr == wsp->walk_data)
2882 2887 return (WALK_DONE);
2883 2888 return (WALK_NEXT);
2884 2889 }
2885 2890
2886 2891 static int
2887 2892 generic_walk_step(mdb_walk_state_t *wsp)
2888 2893 {
2889 2894 return (wsp->walk_callback(wsp->walk_addr, wsp->walk_layer,
2890 2895 wsp->walk_cbdata));
2891 2896 }
2892 2897
2893 2898 static int
2894 2899 cpu_walk_cmp(const void *l, const void *r)
2895 2900 {
2896 2901 uintptr_t lhs = *((uintptr_t *)l);
2897 2902 uintptr_t rhs = *((uintptr_t *)r);
2898 2903 cpu_t lcpu, rcpu;
2899 2904
2900 2905 (void) mdb_vread(&lcpu, sizeof (lcpu), lhs);
2901 2906 (void) mdb_vread(&rcpu, sizeof (rcpu), rhs);
2902 2907
2903 2908 if (lcpu.cpu_id < rcpu.cpu_id)
2904 2909 return (-1);
2905 2910
2906 2911 if (lcpu.cpu_id > rcpu.cpu_id)
2907 2912 return (1);
2908 2913
2909 2914 return (0);
2910 2915 }
2911 2916
2912 2917 typedef struct cpu_walk {
2913 2918 uintptr_t *cw_array;
2914 2919 int cw_ndx;
2915 2920 } cpu_walk_t;
2916 2921
2917 2922 int
2918 2923 cpu_walk_init(mdb_walk_state_t *wsp)
2919 2924 {
2920 2925 cpu_walk_t *cw;
2921 2926 int max_ncpus, i = 0;
2922 2927 uintptr_t current, first;
2923 2928 cpu_t cpu, panic_cpu;
2924 2929 uintptr_t panicstr, addr;
2925 2930 GElf_Sym sym;
2926 2931
2927 2932 cw = mdb_zalloc(sizeof (cpu_walk_t), UM_SLEEP | UM_GC);
2928 2933
2929 2934 if (mdb_readvar(&max_ncpus, "max_ncpus") == -1) {
2930 2935 mdb_warn("failed to read 'max_ncpus'");
2931 2936 return (WALK_ERR);
2932 2937 }
2933 2938
2934 2939 if (mdb_readvar(&panicstr, "panicstr") == -1) {
2935 2940 mdb_warn("failed to read 'panicstr'");
2936 2941 return (WALK_ERR);
2937 2942 }
2938 2943
2939 2944 if (panicstr != NULL) {
2940 2945 if (mdb_lookup_by_name("panic_cpu", &sym) == -1) {
2941 2946 mdb_warn("failed to find 'panic_cpu'");
2942 2947 return (WALK_ERR);
2943 2948 }
2944 2949
2945 2950 addr = (uintptr_t)sym.st_value;
2946 2951
2947 2952 if (mdb_vread(&panic_cpu, sizeof (cpu_t), addr) == -1) {
2948 2953 mdb_warn("failed to read 'panic_cpu'");
2949 2954 return (WALK_ERR);
2950 2955 }
2951 2956 }
2952 2957
2953 2958 /*
2954 2959 * Unfortunately, there is no platform-independent way to walk
2955 2960 * CPUs in ID order. We therefore loop through in cpu_next order,
2956 2961 * building an array of CPU pointers which will subsequently be
2957 2962 * sorted.
2958 2963 */
2959 2964 cw->cw_array =
2960 2965 mdb_zalloc((max_ncpus + 1) * sizeof (uintptr_t), UM_SLEEP | UM_GC);
2961 2966
2962 2967 if (mdb_readvar(&first, "cpu_list") == -1) {
2963 2968 mdb_warn("failed to read 'cpu_list'");
2964 2969 return (WALK_ERR);
2965 2970 }
2966 2971
2967 2972 current = first;
2968 2973 do {
2969 2974 if (mdb_vread(&cpu, sizeof (cpu), current) == -1) {
2970 2975 mdb_warn("failed to read cpu at %p", current);
2971 2976 return (WALK_ERR);
2972 2977 }
2973 2978
2974 2979 if (panicstr != NULL && panic_cpu.cpu_id == cpu.cpu_id) {
2975 2980 cw->cw_array[i++] = addr;
2976 2981 } else {
2977 2982 cw->cw_array[i++] = current;
2978 2983 }
2979 2984 } while ((current = (uintptr_t)cpu.cpu_next) != first);
2980 2985
2981 2986 qsort(cw->cw_array, i, sizeof (uintptr_t), cpu_walk_cmp);
2982 2987 wsp->walk_data = cw;
2983 2988
2984 2989 return (WALK_NEXT);
2985 2990 }
2986 2991
2987 2992 int
2988 2993 cpu_walk_step(mdb_walk_state_t *wsp)
2989 2994 {
2990 2995 cpu_walk_t *cw = wsp->walk_data;
2991 2996 cpu_t cpu;
2992 2997 uintptr_t addr = cw->cw_array[cw->cw_ndx++];
2993 2998
2994 2999 if (addr == NULL)
2995 3000 return (WALK_DONE);
2996 3001
2997 3002 if (mdb_vread(&cpu, sizeof (cpu), addr) == -1) {
2998 3003 mdb_warn("failed to read cpu at %p", addr);
2999 3004 return (WALK_DONE);
3000 3005 }
3001 3006
3002 3007 return (wsp->walk_callback(addr, &cpu, wsp->walk_cbdata));
3003 3008 }
3004 3009
3005 3010 typedef struct cpuinfo_data {
3006 3011 intptr_t cid_cpu;
3007 3012 uintptr_t **cid_ithr;
3008 3013 char cid_print_head;
3009 3014 char cid_print_thr;
3010 3015 char cid_print_ithr;
3011 3016 char cid_print_flags;
3012 3017 } cpuinfo_data_t;
3013 3018
3014 3019 int
3015 3020 cpuinfo_walk_ithread(uintptr_t addr, const kthread_t *thr, cpuinfo_data_t *cid)
3016 3021 {
3017 3022 cpu_t c;
3018 3023 int id;
3019 3024 uint8_t pil;
3020 3025
3021 3026 if (!(thr->t_flag & T_INTR_THREAD) || thr->t_state == TS_FREE)
3022 3027 return (WALK_NEXT);
3023 3028
3024 3029 if (thr->t_bound_cpu == NULL) {
3025 3030 mdb_warn("thr %p is intr thread w/out a CPU\n", addr);
3026 3031 return (WALK_NEXT);
3027 3032 }
3028 3033
3029 3034 (void) mdb_vread(&c, sizeof (c), (uintptr_t)thr->t_bound_cpu);
3030 3035
3031 3036 if ((id = c.cpu_id) >= NCPU) {
3032 3037 mdb_warn("CPU %p has id (%d) greater than NCPU (%d)\n",
3033 3038 thr->t_bound_cpu, id, NCPU);
3034 3039 return (WALK_NEXT);
3035 3040 }
3036 3041
3037 3042 if ((pil = thr->t_pil) >= NINTR) {
3038 3043 mdb_warn("thread %p has pil (%d) greater than %d\n",
3039 3044 addr, pil, NINTR);
3040 3045 return (WALK_NEXT);
3041 3046 }
3042 3047
3043 3048 if (cid->cid_ithr[id][pil] != NULL) {
3044 3049 mdb_warn("CPU %d has multiple threads at pil %d (at least "
3045 3050 "%p and %p)\n", id, pil, addr, cid->cid_ithr[id][pil]);
3046 3051 return (WALK_NEXT);
3047 3052 }
3048 3053
3049 3054 cid->cid_ithr[id][pil] = addr;
3050 3055
3051 3056 return (WALK_NEXT);
3052 3057 }
3053 3058
3054 3059 #define CPUINFO_IDWIDTH 3
3055 3060 #define CPUINFO_FLAGWIDTH 9
3056 3061
3057 3062 #ifdef _LP64
3058 3063 #if defined(__amd64)
3059 3064 #define CPUINFO_TWIDTH 16
3060 3065 #define CPUINFO_CPUWIDTH 16
3061 3066 #else
3062 3067 #define CPUINFO_CPUWIDTH 11
3063 3068 #define CPUINFO_TWIDTH 11
3064 3069 #endif
3065 3070 #else
3066 3071 #define CPUINFO_CPUWIDTH 8
3067 3072 #define CPUINFO_TWIDTH 8
3068 3073 #endif
3069 3074
3070 3075 #define CPUINFO_THRDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 9)
3071 3076 #define CPUINFO_FLAGDELT (CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH + 4)
3072 3077 #define CPUINFO_ITHRDELT 4
3073 3078
3074 3079 #define CPUINFO_INDENT mdb_printf("%*s", CPUINFO_THRDELT, \
3075 3080 flagline < nflaglines ? flagbuf[flagline++] : "")
3076 3081
3077 3082 typedef struct mdb_cpuinfo_proc {
3078 3083 struct {
3079 3084 char u_comm[MAXCOMLEN + 1];
3080 3085 } p_user;
3081 3086 } mdb_cpuinfo_proc_t;
3082 3087
3083 3088 int
3084 3089 cpuinfo_walk_cpu(uintptr_t addr, const cpu_t *cpu, cpuinfo_data_t *cid)
3085 3090 {
3086 3091 kthread_t t;
3087 3092 disp_t disp;
3088 3093 mdb_cpuinfo_proc_t p;
3089 3094 uintptr_t pinned;
3090 3095 char **flagbuf;
3091 3096 int nflaglines = 0, flagline = 0, bspl, rval = WALK_NEXT;
3092 3097
3093 3098 const char *flags[] = {
3094 3099 "RUNNING", "READY", "QUIESCED", "EXISTS",
3095 3100 "ENABLE", "OFFLINE", "POWEROFF", "FROZEN",
3096 3101 "SPARE", "FAULTED", NULL
3097 3102 };
3098 3103
3099 3104 if (cid->cid_cpu != -1) {
3100 3105 if (addr != cid->cid_cpu && cpu->cpu_id != cid->cid_cpu)
3101 3106 return (WALK_NEXT);
3102 3107
3103 3108 /*
3104 3109 * Set cid_cpu to -1 to indicate that we found a matching CPU.
3105 3110 */
3106 3111 cid->cid_cpu = -1;
3107 3112 rval = WALK_DONE;
3108 3113 }
3109 3114
3110 3115 if (cid->cid_print_head) {
3111 3116 mdb_printf("%3s %-*s %3s %4s %4s %3s %4s %5s %-6s %-*s %s\n",
3112 3117 "ID", CPUINFO_CPUWIDTH, "ADDR", "FLG", "NRUN", "BSPL",
3113 3118 "PRI", "RNRN", "KRNRN", "SWITCH", CPUINFO_TWIDTH, "THREAD",
3114 3119 "PROC");
3115 3120 cid->cid_print_head = FALSE;
3116 3121 }
3117 3122
3118 3123 bspl = cpu->cpu_base_spl;
3119 3124
3120 3125 if (mdb_vread(&disp, sizeof (disp_t), (uintptr_t)cpu->cpu_disp) == -1) {
3121 3126 mdb_warn("failed to read disp_t at %p", cpu->cpu_disp);
3122 3127 return (WALK_ERR);
3123 3128 }
3124 3129
3125 3130 mdb_printf("%3d %0*p %3x %4d %4d ",
3126 3131 cpu->cpu_id, CPUINFO_CPUWIDTH, addr, cpu->cpu_flags,
3127 3132 disp.disp_nrunnable, bspl);
3128 3133
3129 3134 if (mdb_vread(&t, sizeof (t), (uintptr_t)cpu->cpu_thread) != -1) {
3130 3135 mdb_printf("%3d ", t.t_pri);
3131 3136 } else {
3132 3137 mdb_printf("%3s ", "-");
3133 3138 }
3134 3139
3135 3140 mdb_printf("%4s %5s ", cpu->cpu_runrun ? "yes" : "no",
3136 3141 cpu->cpu_kprunrun ? "yes" : "no");
3137 3142
3138 3143 if (cpu->cpu_last_swtch) {
3139 3144 mdb_printf("t-%-4d ",
3140 3145 (clock_t)mdb_get_lbolt() - cpu->cpu_last_swtch);
3141 3146 } else {
3142 3147 mdb_printf("%-6s ", "-");
3143 3148 }
3144 3149
3145 3150 mdb_printf("%0*p", CPUINFO_TWIDTH, cpu->cpu_thread);
3146 3151
3147 3152 if (cpu->cpu_thread == cpu->cpu_idle_thread)
3148 3153 mdb_printf(" (idle)\n");
3149 3154 else if (cpu->cpu_thread == NULL)
3150 3155 mdb_printf(" -\n");
3151 3156 else {
3152 3157 if (mdb_ctf_vread(&p, "proc_t", "mdb_cpuinfo_proc_t",
3153 3158 (uintptr_t)t.t_procp, 0) != -1) {
3154 3159 mdb_printf(" %s\n", p.p_user.u_comm);
3155 3160 } else {
3156 3161 mdb_printf(" ?\n");
3157 3162 }
3158 3163 }
3159 3164
3160 3165 flagbuf = mdb_zalloc(sizeof (flags), UM_SLEEP | UM_GC);
3161 3166
3162 3167 if (cid->cid_print_flags) {
3163 3168 int first = 1, i, j, k;
3164 3169 char *s;
3165 3170
3166 3171 cid->cid_print_head = TRUE;
3167 3172
3168 3173 for (i = 1, j = 0; flags[j] != NULL; i <<= 1, j++) {
3169 3174 if (!(cpu->cpu_flags & i))
3170 3175 continue;
3171 3176
3172 3177 if (first) {
3173 3178 s = mdb_alloc(CPUINFO_THRDELT + 1,
3174 3179 UM_GC | UM_SLEEP);
3175 3180
3176 3181 (void) mdb_snprintf(s, CPUINFO_THRDELT + 1,
3177 3182 "%*s|%*s", CPUINFO_FLAGDELT, "",
3178 3183 CPUINFO_THRDELT - 1 - CPUINFO_FLAGDELT, "");
3179 3184 flagbuf[nflaglines++] = s;
3180 3185 }
3181 3186
3182 3187 s = mdb_alloc(CPUINFO_THRDELT + 1, UM_GC | UM_SLEEP);
3183 3188 (void) mdb_snprintf(s, CPUINFO_THRDELT + 1, "%*s%*s %s",
3184 3189 CPUINFO_IDWIDTH + CPUINFO_CPUWIDTH -
3185 3190 CPUINFO_FLAGWIDTH, "", CPUINFO_FLAGWIDTH, flags[j],
3186 3191 first ? "<--+" : "");
3187 3192
3188 3193 for (k = strlen(s); k < CPUINFO_THRDELT; k++)
3189 3194 s[k] = ' ';
3190 3195 s[k] = '\0';
3191 3196
3192 3197 flagbuf[nflaglines++] = s;
3193 3198 first = 0;
3194 3199 }
3195 3200 }
3196 3201
3197 3202 if (cid->cid_print_ithr) {
3198 3203 int i, found_one = FALSE;
3199 3204 int print_thr = disp.disp_nrunnable && cid->cid_print_thr;
3200 3205
3201 3206 for (i = NINTR - 1; i >= 0; i--) {
3202 3207 uintptr_t iaddr = cid->cid_ithr[cpu->cpu_id][i];
3203 3208
3204 3209 if (iaddr == NULL)
3205 3210 continue;
3206 3211
3207 3212 if (!found_one) {
3208 3213 found_one = TRUE;
3209 3214
3210 3215 CPUINFO_INDENT;
3211 3216 mdb_printf("%c%*s|\n", print_thr ? '|' : ' ',
3212 3217 CPUINFO_ITHRDELT, "");
3213 3218
3214 3219 CPUINFO_INDENT;
3215 3220 mdb_printf("%c%*s+--> %3s %s\n",
3216 3221 print_thr ? '|' : ' ', CPUINFO_ITHRDELT,
3217 3222 "", "PIL", "THREAD");
3218 3223 }
3219 3224
3220 3225 if (mdb_vread(&t, sizeof (t), iaddr) == -1) {
3221 3226 mdb_warn("failed to read kthread_t at %p",
3222 3227 iaddr);
3223 3228 return (WALK_ERR);
3224 3229 }
3225 3230
3226 3231 CPUINFO_INDENT;
3227 3232 mdb_printf("%c%*s %3d %0*p\n",
3228 3233 print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "",
3229 3234 t.t_pil, CPUINFO_TWIDTH, iaddr);
3230 3235
3231 3236 pinned = (uintptr_t)t.t_intr;
3232 3237 }
3233 3238
3234 3239 if (found_one && pinned != NULL) {
3235 3240 cid->cid_print_head = TRUE;
3236 3241 (void) strcpy(p.p_user.u_comm, "?");
3237 3242
3238 3243 if (mdb_vread(&t, sizeof (t),
3239 3244 (uintptr_t)pinned) == -1) {
3240 3245 mdb_warn("failed to read kthread_t at %p",
3241 3246 pinned);
3242 3247 return (WALK_ERR);
3243 3248 }
3244 3249 if (mdb_ctf_vread(&p, "proc_t", "mdb_cpuinfo_proc_t",
3245 3250 (uintptr_t)t.t_procp, 0) == -1) {
3246 3251 mdb_warn("failed to read proc_t at %p",
3247 3252 t.t_procp);
3248 3253 return (WALK_ERR);
3249 3254 }
3250 3255
3251 3256 CPUINFO_INDENT;
3252 3257 mdb_printf("%c%*s %3s %0*p %s\n",
3253 3258 print_thr ? '|' : ' ', CPUINFO_ITHRDELT, "", "-",
3254 3259 CPUINFO_TWIDTH, pinned,
3255 3260 pinned == (uintptr_t)cpu->cpu_idle_thread ?
3256 3261 "(idle)" : p.p_user.u_comm);
3257 3262 }
3258 3263 }
3259 3264
3260 3265 if (disp.disp_nrunnable && cid->cid_print_thr) {
3261 3266 dispq_t *dq;
3262 3267
3263 3268 int i, npri = disp.disp_npri;
3264 3269
3265 3270 dq = mdb_alloc(sizeof (dispq_t) * npri, UM_SLEEP | UM_GC);
3266 3271
3267 3272 if (mdb_vread(dq, sizeof (dispq_t) * npri,
3268 3273 (uintptr_t)disp.disp_q) == -1) {
3269 3274 mdb_warn("failed to read dispq_t at %p", disp.disp_q);
3270 3275 return (WALK_ERR);
3271 3276 }
3272 3277
3273 3278 CPUINFO_INDENT;
3274 3279 mdb_printf("|\n");
3275 3280
3276 3281 CPUINFO_INDENT;
3277 3282 mdb_printf("+--> %3s %-*s %s\n", "PRI",
3278 3283 CPUINFO_TWIDTH, "THREAD", "PROC");
3279 3284
3280 3285 for (i = npri - 1; i >= 0; i--) {
3281 3286 uintptr_t taddr = (uintptr_t)dq[i].dq_first;
3282 3287
3283 3288 while (taddr != NULL) {
3284 3289 if (mdb_vread(&t, sizeof (t), taddr) == -1) {
3285 3290 mdb_warn("failed to read kthread_t "
3286 3291 "at %p", taddr);
3287 3292 return (WALK_ERR);
3288 3293 }
3289 3294 if (mdb_ctf_vread(&p, "proc_t",
3290 3295 "mdb_cpuinfo_proc_t",
3291 3296 (uintptr_t)t.t_procp, 0) == -1) {
3292 3297 mdb_warn("failed to read proc_t at %p",
3293 3298 t.t_procp);
3294 3299 return (WALK_ERR);
3295 3300 }
3296 3301
3297 3302 CPUINFO_INDENT;
3298 3303 mdb_printf(" %3d %0*p %s\n", t.t_pri,
3299 3304 CPUINFO_TWIDTH, taddr, p.p_user.u_comm);
3300 3305
3301 3306 taddr = (uintptr_t)t.t_link;
3302 3307 }
3303 3308 }
3304 3309 cid->cid_print_head = TRUE;
3305 3310 }
3306 3311
3307 3312 while (flagline < nflaglines)
3308 3313 mdb_printf("%s\n", flagbuf[flagline++]);
3309 3314
3310 3315 if (cid->cid_print_head)
3311 3316 mdb_printf("\n");
3312 3317
3313 3318 return (rval);
3314 3319 }
3315 3320
3316 3321 int
3317 3322 cpuinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3318 3323 {
3319 3324 uint_t verbose = FALSE;
3320 3325 cpuinfo_data_t cid;
3321 3326
3322 3327 cid.cid_print_ithr = FALSE;
3323 3328 cid.cid_print_thr = FALSE;
3324 3329 cid.cid_print_flags = FALSE;
3325 3330 cid.cid_print_head = DCMD_HDRSPEC(flags) ? TRUE : FALSE;
3326 3331 cid.cid_cpu = -1;
3327 3332
3328 3333 if (flags & DCMD_ADDRSPEC)
3329 3334 cid.cid_cpu = addr;
3330 3335
3331 3336 if (mdb_getopts(argc, argv,
3332 3337 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL) != argc)
3333 3338 return (DCMD_USAGE);
3334 3339
3335 3340 if (verbose) {
3336 3341 cid.cid_print_ithr = TRUE;
3337 3342 cid.cid_print_thr = TRUE;
3338 3343 cid.cid_print_flags = TRUE;
3339 3344 cid.cid_print_head = TRUE;
3340 3345 }
3341 3346
3342 3347 if (cid.cid_print_ithr) {
3343 3348 int i;
3344 3349
3345 3350 cid.cid_ithr = mdb_alloc(sizeof (uintptr_t **)
3346 3351 * NCPU, UM_SLEEP | UM_GC);
3347 3352
3348 3353 for (i = 0; i < NCPU; i++)
3349 3354 cid.cid_ithr[i] = mdb_zalloc(sizeof (uintptr_t *) *
3350 3355 NINTR, UM_SLEEP | UM_GC);
3351 3356
3352 3357 if (mdb_walk("thread", (mdb_walk_cb_t)cpuinfo_walk_ithread,
3353 3358 &cid) == -1) {
3354 3359 mdb_warn("couldn't walk thread");
3355 3360 return (DCMD_ERR);
3356 3361 }
3357 3362 }
3358 3363
3359 3364 if (mdb_walk("cpu", (mdb_walk_cb_t)cpuinfo_walk_cpu, &cid) == -1) {
3360 3365 mdb_warn("can't walk cpus");
3361 3366 return (DCMD_ERR);
3362 3367 }
3363 3368
3364 3369 if (cid.cid_cpu != -1) {
3365 3370 /*
3366 3371 * We didn't find this CPU when we walked through the CPUs
3367 3372 * (i.e. the address specified doesn't show up in the "cpu"
3368 3373 * walk). However, the specified address may still correspond
3369 3374 * to a valid cpu_t (for example, if the specified address is
3370 3375 * the actual panicking cpu_t and not the cached panic_cpu).
3371 3376 * Point is: even if we didn't find it, we still want to try
3372 3377 * to print the specified address as a cpu_t.
3373 3378 */
3374 3379 cpu_t cpu;
3375 3380
3376 3381 if (mdb_vread(&cpu, sizeof (cpu), cid.cid_cpu) == -1) {
3377 3382 mdb_warn("%p is neither a valid CPU ID nor a "
3378 3383 "valid cpu_t address\n", cid.cid_cpu);
3379 3384 return (DCMD_ERR);
3380 3385 }
3381 3386
3382 3387 (void) cpuinfo_walk_cpu(cid.cid_cpu, &cpu, &cid);
3383 3388 }
3384 3389
3385 3390 return (DCMD_OK);
3386 3391 }
3387 3392
3388 3393 /*ARGSUSED*/
3389 3394 int
3390 3395 flipone(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3391 3396 {
3392 3397 int i;
3393 3398
3394 3399 if (!(flags & DCMD_ADDRSPEC))
3395 3400 return (DCMD_USAGE);
3396 3401
3397 3402 for (i = 0; i < sizeof (addr) * NBBY; i++)
3398 3403 mdb_printf("%p\n", addr ^ (1UL << i));
3399 3404
3400 3405 return (DCMD_OK);
3401 3406 }
3402 3407
3403 3408 typedef struct mdb_as2proc_proc {
3404 3409 struct as *p_as;
3405 3410 } mdb_as2proc_proc_t;
3406 3411
3407 3412 /*ARGSUSED*/
3408 3413 int
3409 3414 as2proc_walk(uintptr_t addr, const void *ignored, struct as **asp)
3410 3415 {
3411 3416 mdb_as2proc_proc_t p;
3412 3417
3413 3418 mdb_ctf_vread(&p, "proc_t", "mdb_as2proc_proc_t", addr, 0);
3414 3419
3415 3420 if (p.p_as == *asp)
3416 3421 mdb_printf("%p\n", addr);
3417 3422 return (WALK_NEXT);
3418 3423 }
3419 3424
3420 3425 /*ARGSUSED*/
3421 3426 int
3422 3427 as2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3423 3428 {
3424 3429 if (!(flags & DCMD_ADDRSPEC) || argc != 0)
3425 3430 return (DCMD_USAGE);
3426 3431
3427 3432 if (mdb_walk("proc", (mdb_walk_cb_t)as2proc_walk, &addr) == -1) {
3428 3433 mdb_warn("failed to walk proc");
3429 3434 return (DCMD_ERR);
3430 3435 }
3431 3436
3432 3437 return (DCMD_OK);
3433 3438 }
3434 3439
3435 3440 typedef struct mdb_ptree_proc {
3436 3441 struct proc *p_parent;
3437 3442 struct {
3438 3443 char u_comm[MAXCOMLEN + 1];
3439 3444 } p_user;
3440 3445 } mdb_ptree_proc_t;
3441 3446
3442 3447 /*ARGSUSED*/
3443 3448 int
3444 3449 ptree_walk(uintptr_t addr, const void *ignored, void *data)
3445 3450 {
3446 3451 mdb_ptree_proc_t proc;
3447 3452 mdb_ptree_proc_t parent;
3448 3453 int ident = 0;
3449 3454 uintptr_t paddr;
3450 3455
3451 3456 mdb_ctf_vread(&proc, "proc_t", "mdb_ptree_proc_t", addr, 0);
3452 3457
3453 3458 for (paddr = (uintptr_t)proc.p_parent; paddr != NULL; ident += 5) {
3454 3459 mdb_ctf_vread(&parent, "proc_t", "mdb_ptree_proc_t", paddr, 0);
3455 3460 paddr = (uintptr_t)parent.p_parent;
3456 3461 }
3457 3462
3458 3463 mdb_inc_indent(ident);
3459 3464 mdb_printf("%0?p %s\n", addr, proc.p_user.u_comm);
3460 3465 mdb_dec_indent(ident);
3461 3466
3462 3467 return (WALK_NEXT);
3463 3468 }
3464 3469
3465 3470 void
3466 3471 ptree_ancestors(uintptr_t addr, uintptr_t start)
3467 3472 {
3468 3473 mdb_ptree_proc_t p;
3469 3474
3470 3475 if (mdb_ctf_vread(&p, "proc_t", "mdb_ptree_proc_t", addr, 0) == -1) {
3471 3476 mdb_warn("couldn't read ancestor at %p", addr);
3472 3477 return;
3473 3478 }
3474 3479
3475 3480 if (p.p_parent != NULL)
3476 3481 ptree_ancestors((uintptr_t)p.p_parent, start);
3477 3482
3478 3483 if (addr != start)
3479 3484 (void) ptree_walk(addr, &p, NULL);
3480 3485 }
3481 3486
3482 3487 /*ARGSUSED*/
3483 3488 int
3484 3489 ptree(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3485 3490 {
3486 3491 if (!(flags & DCMD_ADDRSPEC))
3487 3492 addr = NULL;
3488 3493 else
3489 3494 ptree_ancestors(addr, addr);
3490 3495
3491 3496 if (mdb_pwalk("proc", (mdb_walk_cb_t)ptree_walk, NULL, addr) == -1) {
3492 3497 mdb_warn("couldn't walk 'proc'");
3493 3498 return (DCMD_ERR);
3494 3499 }
3495 3500
3496 3501 return (DCMD_OK);
3497 3502 }
3498 3503
3499 3504 typedef struct mdb_fd_proc {
3500 3505 struct {
3501 3506 struct {
3502 3507 int fi_nfiles;
3503 3508 uf_entry_t *volatile fi_list;
3504 3509 } u_finfo;
3505 3510 } p_user;
3506 3511 } mdb_fd_proc_t;
3507 3512
3508 3513 /*ARGSUSED*/
3509 3514 static int
3510 3515 fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3511 3516 {
3512 3517 int fdnum;
3513 3518 const mdb_arg_t *argp = &argv[0];
3514 3519 mdb_fd_proc_t p;
3515 3520 uf_entry_t uf;
3516 3521
3517 3522 if ((flags & DCMD_ADDRSPEC) == 0) {
3518 3523 mdb_warn("fd doesn't give global information\n");
3519 3524 return (DCMD_ERR);
3520 3525 }
3521 3526 if (argc != 1)
3522 3527 return (DCMD_USAGE);
3523 3528
3524 3529 if (argp->a_type == MDB_TYPE_IMMEDIATE)
3525 3530 fdnum = argp->a_un.a_val;
3526 3531 else
3527 3532 fdnum = mdb_strtoull(argp->a_un.a_str);
3528 3533
3529 3534 if (mdb_ctf_vread(&p, "proc_t", "mdb_fd_proc_t", addr, 0) == -1) {
3530 3535 mdb_warn("couldn't read proc_t at %p", addr);
3531 3536 return (DCMD_ERR);
3532 3537 }
3533 3538 if (fdnum > p.p_user.u_finfo.fi_nfiles) {
3534 3539 mdb_warn("process %p only has %d files open.\n",
3535 3540 addr, p.p_user.u_finfo.fi_nfiles);
3536 3541 return (DCMD_ERR);
3537 3542 }
3538 3543 if (mdb_vread(&uf, sizeof (uf_entry_t),
3539 3544 (uintptr_t)&p.p_user.u_finfo.fi_list[fdnum]) == -1) {
3540 3545 mdb_warn("couldn't read uf_entry_t at %p",
3541 3546 &p.p_user.u_finfo.fi_list[fdnum]);
3542 3547 return (DCMD_ERR);
3543 3548 }
3544 3549
3545 3550 mdb_printf("%p\n", uf.uf_file);
3546 3551 return (DCMD_OK);
3547 3552 }
3548 3553
3549 3554 /*ARGSUSED*/
3550 3555 static int
3551 3556 pid2proc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3552 3557 {
3553 3558 pid_t pid = (pid_t)addr;
3554 3559
3555 3560 if (argc != 0)
3556 3561 return (DCMD_USAGE);
3557 3562
3558 3563 if ((addr = mdb_pid2proc(pid, NULL)) == 0) {
3559 3564 mdb_warn("PID 0t%d not found\n", pid);
3560 3565 return (DCMD_ERR);
3561 3566 }
3562 3567
3563 3568 mdb_printf("%p\n", addr);
3564 3569 return (DCMD_OK);
3565 3570 }
3566 3571
3567 3572 static char *sysfile_cmd[] = {
3568 3573 "exclude:",
3569 3574 "include:",
3570 3575 "forceload:",
3571 3576 "rootdev:",
3572 3577 "rootfs:",
3573 3578 "swapdev:",
3574 3579 "swapfs:",
3575 3580 "moddir:",
3576 3581 "set",
3577 3582 "unknown",
3578 3583 };
3579 3584
3580 3585 static char *sysfile_ops[] = { "", "=", "&", "|" };
3581 3586
3582 3587 /*ARGSUSED*/
3583 3588 static int
3584 3589 sysfile_vmem_seg(uintptr_t addr, const vmem_seg_t *vsp, void **target)
3585 3590 {
3586 3591 if (vsp->vs_type == VMEM_ALLOC && (void *)vsp->vs_start == *target) {
3587 3592 *target = NULL;
3588 3593 return (WALK_DONE);
3589 3594 }
3590 3595 return (WALK_NEXT);
3591 3596 }
3592 3597
3593 3598 /*ARGSUSED*/
3594 3599 static int
3595 3600 sysfile(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3596 3601 {
3597 3602 struct sysparam *sysp, sys;
3598 3603 char var[256];
3599 3604 char modname[256];
3600 3605 char val[256];
3601 3606 char strval[256];
3602 3607 vmem_t *mod_sysfile_arena;
3603 3608 void *straddr;
3604 3609
3605 3610 if (mdb_readvar(&sysp, "sysparam_hd") == -1) {
3606 3611 mdb_warn("failed to read sysparam_hd");
3607 3612 return (DCMD_ERR);
3608 3613 }
3609 3614
3610 3615 if (mdb_readvar(&mod_sysfile_arena, "mod_sysfile_arena") == -1) {
3611 3616 mdb_warn("failed to read mod_sysfile_arena");
3612 3617 return (DCMD_ERR);
3613 3618 }
3614 3619
3615 3620 while (sysp != NULL) {
3616 3621 var[0] = '\0';
3617 3622 val[0] = '\0';
3618 3623 modname[0] = '\0';
3619 3624 if (mdb_vread(&sys, sizeof (sys), (uintptr_t)sysp) == -1) {
3620 3625 mdb_warn("couldn't read sysparam %p", sysp);
3621 3626 return (DCMD_ERR);
3622 3627 }
3623 3628 if (sys.sys_modnam != NULL &&
3624 3629 mdb_readstr(modname, 256,
3625 3630 (uintptr_t)sys.sys_modnam) == -1) {
3626 3631 mdb_warn("couldn't read modname in %p", sysp);
3627 3632 return (DCMD_ERR);
3628 3633 }
3629 3634 if (sys.sys_ptr != NULL &&
3630 3635 mdb_readstr(var, 256, (uintptr_t)sys.sys_ptr) == -1) {
3631 3636 mdb_warn("couldn't read ptr in %p", sysp);
3632 3637 return (DCMD_ERR);
3633 3638 }
3634 3639 if (sys.sys_op != SETOP_NONE) {
3635 3640 /*
3636 3641 * Is this an int or a string? We determine this
3637 3642 * by checking whether straddr is contained in
3638 3643 * mod_sysfile_arena. If so, the walker will set
3639 3644 * straddr to NULL.
3640 3645 */
3641 3646 straddr = (void *)(uintptr_t)sys.sys_info;
3642 3647 if (sys.sys_op == SETOP_ASSIGN &&
3643 3648 sys.sys_info != 0 &&
3644 3649 mdb_pwalk("vmem_seg",
3645 3650 (mdb_walk_cb_t)sysfile_vmem_seg, &straddr,
3646 3651 (uintptr_t)mod_sysfile_arena) == 0 &&
3647 3652 straddr == NULL &&
3648 3653 mdb_readstr(strval, 256,
3649 3654 (uintptr_t)sys.sys_info) != -1) {
3650 3655 (void) mdb_snprintf(val, sizeof (val), "\"%s\"",
3651 3656 strval);
3652 3657 } else {
3653 3658 (void) mdb_snprintf(val, sizeof (val),
3654 3659 "0x%llx [0t%llu]", sys.sys_info,
3655 3660 sys.sys_info);
3656 3661 }
3657 3662 }
3658 3663 mdb_printf("%s %s%s%s%s%s\n", sysfile_cmd[sys.sys_type],
3659 3664 modname, modname[0] == '\0' ? "" : ":",
3660 3665 var, sysfile_ops[sys.sys_op], val);
3661 3666
3662 3667 sysp = sys.sys_next;
3663 3668 }
3664 3669
3665 3670 return (DCMD_OK);
3666 3671 }
3667 3672
3668 3673 int
3669 3674 didmatch(uintptr_t addr, const kthread_t *thr, kt_did_t *didp)
3670 3675 {
3671 3676
3672 3677 if (*didp == thr->t_did) {
3673 3678 mdb_printf("%p\n", addr);
3674 3679 return (WALK_DONE);
3675 3680 } else
3676 3681 return (WALK_NEXT);
3677 3682 }
3678 3683
3679 3684 /*ARGSUSED*/
3680 3685 int
3681 3686 did2thread(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3682 3687 {
3683 3688 const mdb_arg_t *argp = &argv[0];
3684 3689 kt_did_t did;
3685 3690
3686 3691 if (argc != 1)
3687 3692 return (DCMD_USAGE);
3688 3693
3689 3694 did = (kt_did_t)mdb_strtoull(argp->a_un.a_str);
3690 3695
3691 3696 if (mdb_walk("thread", (mdb_walk_cb_t)didmatch, (void *)&did) == -1) {
3692 3697 mdb_warn("failed to walk thread");
3693 3698 return (DCMD_ERR);
3694 3699
3695 3700 }
3696 3701 return (DCMD_OK);
3697 3702
3698 3703 }
3699 3704
3700 3705 static int
3701 3706 errorq_walk_init(mdb_walk_state_t *wsp)
3702 3707 {
3703 3708 if (wsp->walk_addr == NULL &&
3704 3709 mdb_readvar(&wsp->walk_addr, "errorq_list") == -1) {
3705 3710 mdb_warn("failed to read errorq_list");
3706 3711 return (WALK_ERR);
3707 3712 }
3708 3713
3709 3714 return (WALK_NEXT);
3710 3715 }
3711 3716
3712 3717 static int
3713 3718 errorq_walk_step(mdb_walk_state_t *wsp)
3714 3719 {
3715 3720 uintptr_t addr = wsp->walk_addr;
3716 3721 errorq_t eq;
3717 3722
3718 3723 if (addr == NULL)
3719 3724 return (WALK_DONE);
3720 3725
3721 3726 if (mdb_vread(&eq, sizeof (eq), addr) == -1) {
3722 3727 mdb_warn("failed to read errorq at %p", addr);
3723 3728 return (WALK_ERR);
3724 3729 }
3725 3730
3726 3731 wsp->walk_addr = (uintptr_t)eq.eq_next;
3727 3732 return (wsp->walk_callback(addr, &eq, wsp->walk_cbdata));
3728 3733 }
3729 3734
3730 3735 typedef struct eqd_walk_data {
3731 3736 uintptr_t *eqd_stack;
3732 3737 void *eqd_buf;
3733 3738 ulong_t eqd_qpos;
3734 3739 ulong_t eqd_qlen;
3735 3740 size_t eqd_size;
3736 3741 } eqd_walk_data_t;
3737 3742
3738 3743 /*
3739 3744 * In order to walk the list of pending error queue elements, we push the
3740 3745 * addresses of the corresponding data buffers in to the eqd_stack array.
3741 3746 * The error lists are in reverse chronological order when iterating using
3742 3747 * eqe_prev, so we then pop things off the top in eqd_walk_step so that the
3743 3748 * walker client gets addresses in order from oldest error to newest error.
3744 3749 */
3745 3750 static void
3746 3751 eqd_push_list(eqd_walk_data_t *eqdp, uintptr_t addr)
3747 3752 {
3748 3753 errorq_elem_t eqe;
3749 3754
3750 3755 while (addr != NULL) {
3751 3756 if (mdb_vread(&eqe, sizeof (eqe), addr) != sizeof (eqe)) {
3752 3757 mdb_warn("failed to read errorq element at %p", addr);
3753 3758 break;
3754 3759 }
3755 3760
3756 3761 if (eqdp->eqd_qpos == eqdp->eqd_qlen) {
3757 3762 mdb_warn("errorq is overfull -- more than %lu "
3758 3763 "elems found\n", eqdp->eqd_qlen);
3759 3764 break;
3760 3765 }
3761 3766
3762 3767 eqdp->eqd_stack[eqdp->eqd_qpos++] = (uintptr_t)eqe.eqe_data;
3763 3768 addr = (uintptr_t)eqe.eqe_prev;
3764 3769 }
3765 3770 }
3766 3771
3767 3772 static int
3768 3773 eqd_walk_init(mdb_walk_state_t *wsp)
3769 3774 {
3770 3775 eqd_walk_data_t *eqdp;
3771 3776 errorq_elem_t eqe, *addr;
3772 3777 errorq_t eq;
3773 3778 ulong_t i;
3774 3779
3775 3780 if (mdb_vread(&eq, sizeof (eq), wsp->walk_addr) == -1) {
3776 3781 mdb_warn("failed to read errorq at %p", wsp->walk_addr);
3777 3782 return (WALK_ERR);
3778 3783 }
3779 3784
3780 3785 if (eq.eq_ptail != NULL &&
3781 3786 mdb_vread(&eqe, sizeof (eqe), (uintptr_t)eq.eq_ptail) == -1) {
3782 3787 mdb_warn("failed to read errorq element at %p", eq.eq_ptail);
3783 3788 return (WALK_ERR);
3784 3789 }
3785 3790
3786 3791 eqdp = mdb_alloc(sizeof (eqd_walk_data_t), UM_SLEEP);
3787 3792 wsp->walk_data = eqdp;
3788 3793
3789 3794 eqdp->eqd_stack = mdb_zalloc(sizeof (uintptr_t) * eq.eq_qlen, UM_SLEEP);
3790 3795 eqdp->eqd_buf = mdb_alloc(eq.eq_size, UM_SLEEP);
3791 3796 eqdp->eqd_qlen = eq.eq_qlen;
3792 3797 eqdp->eqd_qpos = 0;
3793 3798 eqdp->eqd_size = eq.eq_size;
3794 3799
3795 3800 /*
3796 3801 * The newest elements in the queue are on the pending list, so we
3797 3802 * push those on to our stack first.
3798 3803 */
3799 3804 eqd_push_list(eqdp, (uintptr_t)eq.eq_pend);
3800 3805
3801 3806 /*
3802 3807 * If eq_ptail is set, it may point to a subset of the errors on the
3803 3808 * pending list in the event a atomic_cas_ptr() failed; if ptail's
3804 3809 * data is already in our stack, NULL out eq_ptail and ignore it.
3805 3810 */
3806 3811 if (eq.eq_ptail != NULL) {
3807 3812 for (i = 0; i < eqdp->eqd_qpos; i++) {
3808 3813 if (eqdp->eqd_stack[i] == (uintptr_t)eqe.eqe_data) {
3809 3814 eq.eq_ptail = NULL;
3810 3815 break;
3811 3816 }
3812 3817 }
3813 3818 }
3814 3819
3815 3820 /*
3816 3821 * If eq_phead is set, it has the processing list in order from oldest
3817 3822 * to newest. Use this to recompute eq_ptail as best we can and then
3818 3823 * we nicely fall into eqd_push_list() of eq_ptail below.
3819 3824 */
3820 3825 for (addr = eq.eq_phead; addr != NULL && mdb_vread(&eqe, sizeof (eqe),
3821 3826 (uintptr_t)addr) == sizeof (eqe); addr = eqe.eqe_next)
3822 3827 eq.eq_ptail = addr;
3823 3828
3824 3829 /*
3825 3830 * The oldest elements in the queue are on the processing list, subject
3826 3831 * to machinations in the if-clauses above. Push any such elements.
3827 3832 */
3828 3833 eqd_push_list(eqdp, (uintptr_t)eq.eq_ptail);
3829 3834 return (WALK_NEXT);
3830 3835 }
3831 3836
3832 3837 static int
3833 3838 eqd_walk_step(mdb_walk_state_t *wsp)
3834 3839 {
3835 3840 eqd_walk_data_t *eqdp = wsp->walk_data;
3836 3841 uintptr_t addr;
3837 3842
3838 3843 if (eqdp->eqd_qpos == 0)
3839 3844 return (WALK_DONE);
3840 3845
3841 3846 addr = eqdp->eqd_stack[--eqdp->eqd_qpos];
3842 3847
3843 3848 if (mdb_vread(eqdp->eqd_buf, eqdp->eqd_size, addr) != eqdp->eqd_size) {
3844 3849 mdb_warn("failed to read errorq data at %p", addr);
3845 3850 return (WALK_ERR);
3846 3851 }
3847 3852
3848 3853 return (wsp->walk_callback(addr, eqdp->eqd_buf, wsp->walk_cbdata));
3849 3854 }
3850 3855
3851 3856 static void
3852 3857 eqd_walk_fini(mdb_walk_state_t *wsp)
3853 3858 {
3854 3859 eqd_walk_data_t *eqdp = wsp->walk_data;
3855 3860
3856 3861 mdb_free(eqdp->eqd_stack, sizeof (uintptr_t) * eqdp->eqd_qlen);
3857 3862 mdb_free(eqdp->eqd_buf, eqdp->eqd_size);
3858 3863 mdb_free(eqdp, sizeof (eqd_walk_data_t));
3859 3864 }
3860 3865
3861 3866 #define EQKSVAL(eqv, what) (eqv.eq_kstat.what.value.ui64)
3862 3867
3863 3868 static int
3864 3869 errorq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3865 3870 {
3866 3871 int i;
3867 3872 errorq_t eq;
3868 3873 uint_t opt_v = FALSE;
3869 3874
3870 3875 if (!(flags & DCMD_ADDRSPEC)) {
3871 3876 if (mdb_walk_dcmd("errorq", "errorq", argc, argv) == -1) {
3872 3877 mdb_warn("can't walk 'errorq'");
3873 3878 return (DCMD_ERR);
3874 3879 }
3875 3880 return (DCMD_OK);
3876 3881 }
3877 3882
3878 3883 i = mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &opt_v, NULL);
3879 3884 argc -= i;
3880 3885 argv += i;
3881 3886
3882 3887 if (argc != 0)
3883 3888 return (DCMD_USAGE);
3884 3889
3885 3890 if (opt_v || DCMD_HDRSPEC(flags)) {
3886 3891 mdb_printf("%<u>%-11s %-16s %1s %1s %1s ",
3887 3892 "ADDR", "NAME", "S", "V", "N");
3888 3893 if (!opt_v) {
3889 3894 mdb_printf("%7s %7s %7s%</u>\n",
3890 3895 "ACCEPT", "DROP", "LOG");
3891 3896 } else {
3892 3897 mdb_printf("%5s %6s %6s %3s %16s%</u>\n",
3893 3898 "KSTAT", "QLEN", "SIZE", "IPL", "FUNC");
3894 3899 }
3895 3900 }
3896 3901
3897 3902 if (mdb_vread(&eq, sizeof (eq), addr) != sizeof (eq)) {
3898 3903 mdb_warn("failed to read errorq at %p", addr);
3899 3904 return (DCMD_ERR);
3900 3905 }
3901 3906
3902 3907 mdb_printf("%-11p %-16s %c %c %c ", addr, eq.eq_name,
3903 3908 (eq.eq_flags & ERRORQ_ACTIVE) ? '+' : '-',
3904 3909 (eq.eq_flags & ERRORQ_VITAL) ? '!' : ' ',
3905 3910 (eq.eq_flags & ERRORQ_NVLIST) ? '*' : ' ');
3906 3911
3907 3912 if (!opt_v) {
3908 3913 mdb_printf("%7llu %7llu %7llu\n",
3909 3914 EQKSVAL(eq, eqk_dispatched) + EQKSVAL(eq, eqk_committed),
3910 3915 EQKSVAL(eq, eqk_dropped) + EQKSVAL(eq, eqk_reserve_fail) +
3911 3916 EQKSVAL(eq, eqk_commit_fail), EQKSVAL(eq, eqk_logged));
3912 3917 } else {
3913 3918 mdb_printf("%5s %6lu %6lu %3u %a\n",
3914 3919 " | ", eq.eq_qlen, eq.eq_size, eq.eq_ipl, eq.eq_func);
3915 3920 mdb_printf("%38s\n%41s"
3916 3921 "%12s %llu\n"
3917 3922 "%53s %llu\n"
3918 3923 "%53s %llu\n"
3919 3924 "%53s %llu\n"
3920 3925 "%53s %llu\n"
3921 3926 "%53s %llu\n"
3922 3927 "%53s %llu\n"
3923 3928 "%53s %llu\n\n",
3924 3929 "|", "+-> ",
3925 3930 "DISPATCHED", EQKSVAL(eq, eqk_dispatched),
3926 3931 "DROPPED", EQKSVAL(eq, eqk_dropped),
3927 3932 "LOGGED", EQKSVAL(eq, eqk_logged),
3928 3933 "RESERVED", EQKSVAL(eq, eqk_reserved),
3929 3934 "RESERVE FAIL", EQKSVAL(eq, eqk_reserve_fail),
3930 3935 "COMMITTED", EQKSVAL(eq, eqk_committed),
3931 3936 "COMMIT FAIL", EQKSVAL(eq, eqk_commit_fail),
3932 3937 "CANCELLED", EQKSVAL(eq, eqk_cancelled));
3933 3938 }
3934 3939
3935 3940 return (DCMD_OK);
3936 3941 }
3937 3942
3938 3943 /*ARGSUSED*/
3939 3944 static int
3940 3945 panicinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3941 3946 {
3942 3947 cpu_t panic_cpu;
3943 3948 kthread_t *panic_thread;
3944 3949 void *buf;
3945 3950 panic_data_t *pd;
3946 3951 int i, n;
3947 3952
3948 3953 if (!mdb_prop_postmortem) {
3949 3954 mdb_warn("panicinfo can only be run on a system "
3950 3955 "dump; see dumpadm(1M)\n");
3951 3956 return (DCMD_ERR);
3952 3957 }
3953 3958
3954 3959 if (flags & DCMD_ADDRSPEC || argc != 0)
3955 3960 return (DCMD_USAGE);
3956 3961
3957 3962 if (mdb_readsym(&panic_cpu, sizeof (cpu_t), "panic_cpu") == -1)
3958 3963 mdb_warn("failed to read 'panic_cpu'");
3959 3964 else
3960 3965 mdb_printf("%16s %?d\n", "cpu", panic_cpu.cpu_id);
3961 3966
3962 3967 if (mdb_readvar(&panic_thread, "panic_thread") == -1)
3963 3968 mdb_warn("failed to read 'panic_thread'");
3964 3969 else
3965 3970 mdb_printf("%16s %?p\n", "thread", panic_thread);
3966 3971
3967 3972 buf = mdb_alloc(PANICBUFSIZE, UM_SLEEP);
3968 3973 pd = (panic_data_t *)buf;
3969 3974
3970 3975 if (mdb_readsym(buf, PANICBUFSIZE, "panicbuf") == -1 ||
3971 3976 pd->pd_version != PANICBUFVERS) {
3972 3977 mdb_warn("failed to read 'panicbuf'");
3973 3978 mdb_free(buf, PANICBUFSIZE);
3974 3979 return (DCMD_ERR);
3975 3980 }
3976 3981
3977 3982 mdb_printf("%16s %s\n", "message", (char *)buf + pd->pd_msgoff);
3978 3983
3979 3984 n = (pd->pd_msgoff - (sizeof (panic_data_t) -
3980 3985 sizeof (panic_nv_t))) / sizeof (panic_nv_t);
3981 3986
3982 3987 for (i = 0; i < n; i++)
3983 3988 mdb_printf("%16s %?llx\n",
3984 3989 pd->pd_nvdata[i].pnv_name, pd->pd_nvdata[i].pnv_value);
3985 3990
3986 3991 mdb_free(buf, PANICBUFSIZE);
3987 3992 return (DCMD_OK);
3988 3993 }
3989 3994
3990 3995 /*
3991 3996 * ::time dcmd, which will print a hires timestamp of when we entered the
3992 3997 * debugger, or the lbolt value if used with the -l option.
3993 3998 *
3994 3999 */
3995 4000 /*ARGSUSED*/
3996 4001 static int
3997 4002 time(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3998 4003 {
3999 4004 uint_t opt_dec = FALSE;
4000 4005 uint_t opt_lbolt = FALSE;
4001 4006 uint_t opt_hex = FALSE;
4002 4007 const char *fmt;
4003 4008 hrtime_t result;
4004 4009
4005 4010 if (mdb_getopts(argc, argv,
4006 4011 'd', MDB_OPT_SETBITS, TRUE, &opt_dec,
4007 4012 'l', MDB_OPT_SETBITS, TRUE, &opt_lbolt,
4008 4013 'x', MDB_OPT_SETBITS, TRUE, &opt_hex,
4009 4014 NULL) != argc)
4010 4015 return (DCMD_USAGE);
4011 4016
4012 4017 if (opt_dec && opt_hex)
4013 4018 return (DCMD_USAGE);
4014 4019
4015 4020 result = opt_lbolt ? mdb_get_lbolt() : mdb_gethrtime();
4016 4021 fmt =
4017 4022 opt_hex ? "0x%llx\n" :
4018 4023 opt_dec ? "0t%lld\n" : "%#llr\n";
4019 4024
4020 4025 mdb_printf(fmt, result);
4021 4026 return (DCMD_OK);
4022 4027 }
4023 4028
4024 4029 void
4025 4030 time_help(void)
4026 4031 {
4027 4032 mdb_printf("Prints the system time in nanoseconds.\n\n"
4028 4033 "::time will return the timestamp at which we dropped into, \n"
4029 4034 "if called from, kmdb(1); the core dump's high resolution \n"
4030 4035 "time if inspecting one; or the running hires time if we're \n"
4031 4036 "looking at a live system.\n\n"
4032 4037 "Switches:\n"
4033 4038 " -d report times in decimal\n"
4034 4039 " -l prints the number of clock ticks since system boot\n"
4035 4040 " -x report times in hexadecimal\n");
4036 4041 }
4037 4042
4038 4043 static const mdb_dcmd_t dcmds[] = {
4039 4044
4040 4045 /* from genunix.c */
4041 4046 { "as2proc", ":", "convert as to proc_t address", as2proc },
4042 4047 { "binding_hash_entry", ":", "print driver names hash table entry",
4043 4048 binding_hash_entry },
4044 4049 { "callout", "?[-r|n] [-s|l] [-xhB] [-t | -ab nsec [-dkD]]"
4045 4050 " [-C addr | -S seqid] [-f name|addr] [-p name| addr] [-T|L [-E]]"
4046 4051 " [-FivVA]",
4047 4052 "display callouts", callout, callout_help },
4048 4053 { "calloutid", "[-d|v] xid", "print callout by extended id",
4049 4054 calloutid, calloutid_help },
4050 4055 { "class", NULL, "print process scheduler classes", class },
4051 4056 { "cpuinfo", "?[-v]", "print CPUs and runnable threads", cpuinfo },
4052 4057 { "did2thread", "? kt_did", "find kernel thread for this id",
4053 4058 did2thread },
4054 4059 { "errorq", "?[-v]", "display kernel error queues", errorq },
4055 4060 { "fd", ":[fd num]", "get a file pointer from an fd", fd },
4056 4061 { "flipone", ":", "the vik_rev_level 2 special", flipone },
4057 4062 { "lminfo", NULL, "print lock manager information", lminfo },
4058 4063 { "ndi_event_hdl", "?", "print ndi_event_hdl", ndi_event_hdl },
4059 4064 { "panicinfo", NULL, "print panic information", panicinfo },
4060 4065 { "pid2proc", "?", "convert PID to proc_t address", pid2proc },
4061 4066 { "project", NULL, "display kernel project(s)", project },
4062 4067 { "ps", "[-fltzTP]", "list processes (and associated thr,lwp)", ps },
4063 4068 { "pflags", NULL, "display various proc_t flags", pflags },
4064 4069 { "pgrep", "[-x] [-n | -o] pattern",
4065 4070 "pattern match against all processes", pgrep },
4066 4071 { "ptree", NULL, "print process tree", ptree },
4067 4072 { "sysevent", "?[-sv]", "print sysevent pending or sent queue",
4068 4073 sysevent},
4069 4074 { "sysevent_channel", "?", "print sysevent channel database",
4070 4075 sysevent_channel},
4071 4076 { "sysevent_class_list", ":", "print sysevent class list",
4072 4077 sysevent_class_list},
4073 4078 { "sysevent_subclass_list", ":",
4074 4079 "print sysevent subclass list", sysevent_subclass_list},
4075 4080 { "system", NULL, "print contents of /etc/system file", sysfile },
4076 4081 { "task", NULL, "display kernel task(s)", task },
4077 4082 { "time", "[-dlx]", "display system time", time, time_help },
4078 4083 { "vnode2path", ":[-F]", "vnode address to pathname", vnode2path },
4079 4084 { "whereopen", ":", "given a vnode, dumps procs which have it open",
4080 4085 whereopen },
4081 4086
4082 4087 /* from bio.c */
4083 4088 { "bufpagefind", ":addr", "find page_t on buf_t list", bufpagefind },
4084 4089
4085 4090 /* from bitset.c */
4086 4091 { "bitset", ":", "display a bitset", bitset, bitset_help },
4087 4092
4088 4093 /* from contract.c */
4089 4094 { "contract", "?", "display a contract", cmd_contract },
4090 4095 { "ctevent", ":", "display a contract event", cmd_ctevent },
4091 4096 { "ctid", ":", "convert id to a contract pointer", cmd_ctid },
4092 4097
4093 4098 /* from cpupart.c */
4094 4099 { "cpupart", "?[-v]", "print cpu partition info", cpupart },
4095 4100
4096 4101 /* from cred.c */
4097 4102 { "cred", ":[-v]", "display a credential", cmd_cred },
4098 4103 { "credgrp", ":[-v]", "display cred_t groups", cmd_credgrp },
4099 4104 { "credsid", ":[-v]", "display a credsid_t", cmd_credsid },
4100 4105 { "ksidlist", ":[-v]", "display a ksidlist_t", cmd_ksidlist },
4101 4106
4102 4107 /* from cyclic.c */
4103 4108 { "cyccover", NULL, "dump cyclic coverage information", cyccover },
4104 4109 { "cycid", "?", "dump a cyclic id", cycid },
4105 4110 { "cycinfo", "?", "dump cyc_cpu info", cycinfo },
4106 4111 { "cyclic", ":", "developer information", cyclic },
4107 4112 { "cyctrace", "?", "dump cyclic trace buffer", cyctrace },
4108 4113
4109 4114 /* from damap.c */
4110 4115 { "damap", ":", "display a damap_t", damap, damap_help },
4111 4116
4112 4117 /* from ddi_periodic.c */
4113 4118 { "ddi_periodic", "?[-v]", "dump ddi_periodic_impl_t info", dprinfo },
4114 4119
4115 4120 /* from devinfo.c */
4116 4121 { "devbindings", "?[-qs] [device-name | major-num]",
4117 4122 "print devinfo nodes bound to device-name or major-num",
4118 4123 devbindings, devinfo_help },
4119 4124 { "devinfo", ":[-qs]", "detailed devinfo of one node", devinfo,
4120 4125 devinfo_help },
4121 4126 { "devinfo_audit", ":[-v]", "devinfo configuration audit record",
4122 4127 devinfo_audit },
4123 4128 { "devinfo_audit_log", "?[-v]", "system wide devinfo configuration log",
4124 4129 devinfo_audit_log },
4125 4130 { "devinfo_audit_node", ":[-v]", "devinfo node configuration history",
4126 4131 devinfo_audit_node },
4127 4132 { "devinfo2driver", ":", "find driver name for this devinfo node",
4128 4133 devinfo2driver },
4129 4134 { "devnames", "?[-vm] [num]", "print devnames array", devnames },
4130 4135 { "dev2major", "?<dev_t>", "convert dev_t to a major number",
4131 4136 dev2major },
4132 4137 { "dev2minor", "?<dev_t>", "convert dev_t to a minor number",
4133 4138 dev2minor },
4134 4139 { "devt", "?<dev_t>", "display a dev_t's major and minor numbers",
4135 4140 devt },
4136 4141 { "major2name", "?<major-num>", "convert major number to dev name",
4137 4142 major2name },
4138 4143 { "minornodes", ":", "given a devinfo node, print its minor nodes",
4139 4144 minornodes },
4140 4145 { "modctl2devinfo", ":", "given a modctl, list its devinfos",
4141 4146 modctl2devinfo },
4142 4147 { "name2major", "<dev-name>", "convert dev name to major number",
4143 4148 name2major },
4144 4149 { "prtconf", "?[-vpc] [-d driver]", "print devinfo tree", prtconf,
4145 4150 prtconf_help },
4146 4151 { "softstate", ":<instance>", "retrieve soft-state pointer",
4147 4152 softstate },
4148 4153 { "devinfo_fm", ":", "devinfo fault managment configuration",
4149 4154 devinfo_fm },
4150 4155 { "devinfo_fmce", ":", "devinfo fault managment cache entry",
4151 4156 devinfo_fmce},
4152 4157
4153 4158 /* from findstack.c */
4154 4159 { "findstack", ":[-v]", "find kernel thread stack", findstack },
4155 4160 { "findstack_debug", NULL, "toggle findstack debugging",
4156 4161 findstack_debug },
4157 4162 { "stacks", "?[-afiv] [-c func] [-C func] [-m module] [-M module] "
4158 4163 "[-s sobj | -S sobj] [-t tstate | -T tstate]",
4159 4164 "print unique kernel thread stacks",
4160 4165 stacks, stacks_help },
4161 4166
4162 4167 /* from fm.c */
4163 4168 { "ereport", "[-v]", "print ereports logged in dump",
4164 4169 ereport },
4165 4170
4166 4171 /* from group.c */
4167 4172 { "group", "?[-q]", "display a group", group},
4168 4173
4169 4174 /* from hotplug.c */
4170 4175 { "hotplug", "?[-p]", "display a registered hotplug attachment",
4171 4176 hotplug, hotplug_help },
4172 4177
4173 4178 /* from irm.c */
4174 4179 { "irmpools", NULL, "display interrupt pools", irmpools_dcmd },
4175 4180 { "irmreqs", NULL, "display interrupt requests in an interrupt pool",
4176 4181 irmreqs_dcmd },
4177 4182 { "irmreq", NULL, "display an interrupt request", irmreq_dcmd },
4178 4183
4179 4184 /* from kgrep.c + genunix.c */
4180 4185 { "kgrep", KGREP_USAGE, "search kernel as for a pointer", kgrep,
4181 4186 kgrep_help },
4182 4187
4183 4188 /* from kmem.c */
4184 4189 { "allocdby", ":", "given a thread, print its allocated buffers",
4185 4190 allocdby },
4186 4191 { "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] "
4187 4192 "[-t thd]", "print or filter a bufctl", bufctl, bufctl_help },
4188 4193 { "freedby", ":", "given a thread, print its freed buffers", freedby },
4189 4194 { "kmalog", "?[ fail | slab ]",
4190 4195 "display kmem transaction log and stack traces", kmalog },
4191 4196 { "kmastat", "[-kmg]", "kernel memory allocator stats",
4192 4197 kmastat },
4193 4198 { "kmausers", "?[-ef] [cache ...]", "current medium and large users "
4194 4199 "of the kmem allocator", kmausers, kmausers_help },
4195 4200 { "kmem_cache", "?[-n name]",
4196 4201 "print kernel memory caches", kmem_cache, kmem_cache_help},
4197 4202 { "kmem_slabs", "?[-v] [-n cache] [-N cache] [-b maxbins] "
4198 4203 "[-B minbinsize]", "display slab usage per kmem cache",
4199 4204 kmem_slabs, kmem_slabs_help },
4200 4205 { "kmem_debug", NULL, "toggle kmem dcmd/walk debugging", kmem_debug },
4201 4206 { "kmem_log", "?[-b]", "dump kmem transaction log", kmem_log },
4202 4207 { "kmem_verify", "?", "check integrity of kmem-managed memory",
4203 4208 kmem_verify },
4204 4209 { "vmem", "?", "print a vmem_t", vmem },
4205 4210 { "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] "
4206 4211 "[-m minsize] [-M maxsize] [-t thread] [-T type]",
4207 4212 "print or filter a vmem_seg", vmem_seg, vmem_seg_help },
4208 4213 { "whatthread", ":[-v]", "print threads whose stack contains the "
4209 4214 "given address", whatthread },
4210 4215
4211 4216 /* from ldi.c */
4212 4217 { "ldi_handle", "?[-i]", "display a layered driver handle",
4213 4218 ldi_handle, ldi_handle_help },
4214 4219 { "ldi_ident", NULL, "display a layered driver identifier",
4215 4220 ldi_ident, ldi_ident_help },
4216 4221
4217 4222 /* from leaky.c + leaky_subr.c */
4218 4223 { "findleaks", FINDLEAKS_USAGE,
4219 4224 "search for potential kernel memory leaks", findleaks,
4220 4225 findleaks_help },
4221 4226
4222 4227 /* from lgrp.c */
4223 4228 { "lgrp", "?[-q] [-p | -Pih]", "display an lgrp", lgrp},
4224 4229 { "lgrp_set", "", "display bitmask of lgroups as a list", lgrp_set},
4225 4230
4226 4231 /* from log.c */
4227 4232 { "msgbuf", "?[-v]", "print most recent console messages", msgbuf },
4228 4233
4229 4234 /* from mdi.c */
4230 4235 { "mdipi", NULL, "given a path, dump mdi_pathinfo "
4231 4236 "and detailed pi_prop list", mdipi },
4232 4237 { "mdiprops", NULL, "given a pi_prop, dump the pi_prop list",
4233 4238 mdiprops },
4234 4239 { "mdiphci", NULL, "given a phci, dump mdi_phci and "
4235 4240 "list all paths", mdiphci },
4236 4241 { "mdivhci", NULL, "given a vhci, dump mdi_vhci and list "
4237 4242 "all phcis", mdivhci },
4238 4243 { "mdiclient_paths", NULL, "given a path, walk mdi_pathinfo "
4239 4244 "client links", mdiclient_paths },
4240 4245 { "mdiphci_paths", NULL, "given a path, walk through mdi_pathinfo "
4241 4246 "phci links", mdiphci_paths },
4242 4247 { "mdiphcis", NULL, "given a phci, walk through mdi_phci ph_next links",
4243 4248 mdiphcis },
4244 4249
4245 4250 /* from memory.c */
4246 4251 { "addr2smap", ":[offset]", "translate address to smap", addr2smap },
4247 4252 { "memlist", "?[-iav]", "display a struct memlist", memlist },
4248 4253 { "memstat", NULL, "display memory usage summary", memstat },
4249 4254 { "page", "?", "display a summarized page_t", page },
4250 4255 { "pagelookup", "?[-v vp] [-o offset]",
4251 4256 "find the page_t with the name {vp, offset}",
4252 4257 pagelookup, pagelookup_help },
4253 4258 { "page_num2pp", ":", "find the page_t for a given page frame number",
4254 4259 page_num2pp },
4255 4260 { "pmap", ":[-q]", "print process memory map", pmap },
4256 4261 { "seg", ":", "print address space segment", seg },
4257 4262 { "swapinfo", "?", "display a struct swapinfo", swapinfof },
4258 4263 { "vnode2smap", ":[offset]", "translate vnode to smap", vnode2smap },
4259 4264
4260 4265 /* from mmd.c */
4261 4266 { "multidata", ":[-sv]", "display a summarized multidata_t",
4262 4267 multidata },
4263 4268 { "pattbl", ":", "display a summarized multidata attribute table",
4264 4269 pattbl },
4265 4270 { "pattr2multidata", ":", "print multidata pointer from pattr_t",
4266 4271 pattr2multidata },
4267 4272 { "pdesc2slab", ":", "print pdesc slab pointer from pdesc_t",
4268 4273 pdesc2slab },
4269 4274 { "pdesc_verify", ":", "verify integrity of a pdesc_t", pdesc_verify },
4270 4275 { "slab2multidata", ":", "print multidata pointer from pdesc_slab_t",
4271 4276 slab2multidata },
4272 4277
4273 4278 /* from modhash.c */
4274 4279 { "modhash", "?[-ceht] [-k key] [-v val] [-i index]",
4275 4280 "display information about one or all mod_hash structures",
4276 4281 modhash, modhash_help },
4277 4282 { "modent", ":[-k | -v | -t type]",
4278 4283 "display information about a mod_hash_entry", modent,
4279 4284 modent_help },
4280 4285
4281 4286 /* from net.c */
4282 4287 { "dladm", "?<sub-command> [flags]", "show data link information",
4283 4288 dladm, dladm_help },
4284 4289 { "mi", ":[-p] [-d | -m]", "filter and display MI object or payload",
4285 4290 mi },
4286 4291 { "netstat", "[-arv] [-f inet | inet6 | unix] [-P tcp | udp | icmp]",
4287 4292 "show network statistics", netstat },
4288 4293 { "sonode", "?[-f inet | inet6 | unix | #] "
4289 4294 "[-t stream | dgram | raw | #] [-p #]",
4290 4295 "filter and display sonode", sonode },
4291 4296
4292 4297 /* from netstack.c */
4293 4298 { "netstack", "", "show stack instances", netstack },
4294 4299 { "netstackid2netstack", ":",
4295 4300 "translate a netstack id to its netstack_t",
4296 4301 netstackid2netstack },
4297 4302
4298 4303 /* from nvpair.c */
4299 4304 { NVPAIR_DCMD_NAME, NVPAIR_DCMD_USAGE, NVPAIR_DCMD_DESCR,
4300 4305 nvpair_print },
4301 4306 { NVLIST_DCMD_NAME, NVLIST_DCMD_USAGE, NVLIST_DCMD_DESCR,
4302 4307 print_nvlist },
4303 4308
4304 4309 /* from pg.c */
4305 4310 { "pg", "?[-q]", "display a pg", pg},
4306 4311
4307 4312 /* from rctl.c */
4308 4313 { "rctl_dict", "?", "print systemwide default rctl definitions",
4309 4314 rctl_dict },
4310 4315 { "rctl_list", ":[handle]", "print rctls for the given proc",
4311 4316 rctl_list },
4312 4317 { "rctl", ":[handle]", "print a rctl_t, only if it matches the handle",
4313 4318 rctl },
4314 4319 { "rctl_validate", ":[-v] [-n #]", "test resource control value "
4315 4320 "sequence", rctl_validate },
4316 4321
4317 4322 /* from sobj.c */
4318 4323 { "rwlock", ":", "dump out a readers/writer lock", rwlock },
4319 4324 { "mutex", ":[-f]", "dump out an adaptive or spin mutex", mutex,
4320 4325 mutex_help },
4321 4326 { "sobj2ts", ":", "perform turnstile lookup on synch object", sobj2ts },
4322 4327 { "wchaninfo", "?[-v]", "dump condition variable", wchaninfo },
4323 4328 { "turnstile", "?", "display a turnstile", turnstile },
4324 4329
4325 4330 /* from stream.c */
4326 4331 { "mblk", ":[-q|v] [-f|F flag] [-t|T type] [-l|L|B len] [-d dbaddr]",
4327 4332 "print an mblk", mblk_prt, mblk_help },
4328 4333 { "mblk_verify", "?", "verify integrity of an mblk", mblk_verify },
4329 4334 { "mblk2dblk", ":", "convert mblk_t address to dblk_t address",
4330 4335 mblk2dblk },
4331 4336 { "q2otherq", ":", "print peer queue for a given queue", q2otherq },
4332 4337 { "q2rdq", ":", "print read queue for a given queue", q2rdq },
4333 4338 { "q2syncq", ":", "print syncq for a given queue", q2syncq },
4334 4339 { "q2stream", ":", "print stream pointer for a given queue", q2stream },
4335 4340 { "q2wrq", ":", "print write queue for a given queue", q2wrq },
4336 4341 { "queue", ":[-q|v] [-m mod] [-f flag] [-F flag] [-s syncq_addr]",
4337 4342 "filter and display STREAM queue", queue, queue_help },
4338 4343 { "stdata", ":[-q|v] [-f flag] [-F flag]",
4339 4344 "filter and display STREAM head", stdata, stdata_help },
4340 4345 { "str2mate", ":", "print mate of this stream", str2mate },
4341 4346 { "str2wrq", ":", "print write queue of this stream", str2wrq },
4342 4347 { "stream", ":", "display STREAM", stream },
4343 4348 { "strftevent", ":", "print STREAMS flow trace event", strftevent },
4344 4349 { "syncq", ":[-q|v] [-f flag] [-F flag] [-t type] [-T type]",
4345 4350 "filter and display STREAM sync queue", syncq, syncq_help },
4346 4351 { "syncq2q", ":", "print queue for a given syncq", syncq2q },
4347 4352
4348 4353 /* from taskq.c */
4349 4354 { "taskq", ":[-atT] [-m min_maxq] [-n name]",
4350 4355 "display a taskq", taskq, taskq_help },
4351 4356 { "taskq_entry", ":", "display a taskq_ent_t", taskq_ent },
4352 4357
4353 4358 /* from thread.c */
4354 4359 { "thread", "?[-bdfimps]", "display a summarized kthread_t", thread,
4355 4360 thread_help },
4356 4361 { "threadlist", "?[-t] [-v [count]]",
4357 4362 "display threads and associated C stack traces", threadlist,
4358 4363 threadlist_help },
4359 4364 { "stackinfo", "?[-h|-a]", "display kthread_t stack usage", stackinfo,
4360 4365 stackinfo_help },
4361 4366
4362 4367 /* from tsd.c */
4363 4368 { "tsd", ":-k key", "print tsd[key-1] for this thread", ttotsd },
4364 4369 { "tsdtot", ":", "find thread with this tsd", tsdtot },
4365 4370
4366 4371 /*
4367 4372 * typegraph does not work under kmdb, as it requires too much memory
4368 4373 * for its internal data structures.
4369 4374 */
4370 4375 #ifndef _KMDB
4371 4376 /* from typegraph.c */
4372 4377 { "findlocks", ":", "find locks held by specified thread", findlocks },
4373 4378 { "findfalse", "?[-v]", "find potentially falsely shared structures",
4374 4379 findfalse },
4375 4380 { "typegraph", NULL, "build type graph", typegraph },
4376 4381 { "istype", ":type", "manually set object type", istype },
4377 4382 { "notype", ":", "manually clear object type", notype },
4378 4383 { "whattype", ":", "determine object type", whattype },
4379 4384 #endif
4380 4385
4381 4386 /* from vfs.c */
4382 4387 { "fsinfo", "?[-v]", "print mounted filesystems", fsinfo },
4383 4388 { "pfiles", ":[-fp]", "print process file information", pfiles,
4384 4389 pfiles_help },
4385 4390
4386 4391 /* from zone.c */
4387 4392 { "zid2zone", ":", "find the zone_t with the given zone id",
4388 4393 zid2zone },
4389 4394 { "zone", "?[-r [-v]]", "display kernel zone(s)", zoneprt },
4390 4395 { "zsd", ":[-v] [zsd_key]", "display zone-specific-data entries for "
4391 4396 "selected zones", zsd },
4392 4397
4393 4398 #ifndef _KMDB
4394 4399 { "gcore", NULL, "generate a user core for the given process",
4395 4400 gcore_dcmd },
4396 4401 #endif
4397 4402
4398 4403 { NULL }
4399 4404 };
4400 4405
4401 4406 static const mdb_walker_t walkers[] = {
4402 4407
4403 4408 /* from genunix.c */
4404 4409 { "callouts_bytime", "walk callouts by list chain (expiration time)",
4405 4410 callout_walk_init, callout_walk_step, callout_walk_fini,
4406 4411 (void *)CALLOUT_WALK_BYLIST },
4407 4412 { "callouts_byid", "walk callouts by id hash chain",
4408 4413 callout_walk_init, callout_walk_step, callout_walk_fini,
4409 4414 (void *)CALLOUT_WALK_BYID },
4410 4415 { "callout_list", "walk a callout list", callout_list_walk_init,
4411 4416 callout_list_walk_step, callout_list_walk_fini },
4412 4417 { "callout_table", "walk callout table array", callout_table_walk_init,
4413 4418 callout_table_walk_step, callout_table_walk_fini },
4414 4419 { "cpu", "walk cpu structures", cpu_walk_init, cpu_walk_step },
4415 4420 { "dnlc", "walk dnlc entries",
4416 4421 dnlc_walk_init, dnlc_walk_step, dnlc_walk_fini },
4417 4422 { "ereportq_dump", "walk list of ereports in dump error queue",
4418 4423 ereportq_dump_walk_init, ereportq_dump_walk_step, NULL },
4419 4424 { "ereportq_pend", "walk list of ereports in pending error queue",
4420 4425 ereportq_pend_walk_init, ereportq_pend_walk_step, NULL },
4421 4426 { "errorq", "walk list of system error queues",
4422 4427 errorq_walk_init, errorq_walk_step, NULL },
4423 4428 { "errorq_data", "walk pending error queue data buffers",
4424 4429 eqd_walk_init, eqd_walk_step, eqd_walk_fini },
4425 4430 { "allfile", "given a proc pointer, list all file pointers",
4426 4431 file_walk_init, allfile_walk_step, file_walk_fini },
4427 4432 { "file", "given a proc pointer, list of open file pointers",
4428 4433 file_walk_init, file_walk_step, file_walk_fini },
4429 4434 { "lock_descriptor", "walk lock_descriptor_t structures",
4430 4435 ld_walk_init, ld_walk_step, NULL },
4431 4436 { "lock_graph", "walk lock graph",
4432 4437 lg_walk_init, lg_walk_step, NULL },
4433 4438 { "port", "given a proc pointer, list of created event ports",
4434 4439 port_walk_init, port_walk_step, NULL },
4435 4440 { "portev", "given a port pointer, list of events in the queue",
4436 4441 portev_walk_init, portev_walk_step, portev_walk_fini },
4437 4442 { "proc", "list of active proc_t structures",
4438 4443 proc_walk_init, proc_walk_step, proc_walk_fini },
4439 4444 { "projects", "walk a list of kernel projects",
4440 4445 project_walk_init, project_walk_step, NULL },
4441 4446 { "sysevent_pend", "walk sysevent pending queue",
4442 4447 sysevent_pend_walk_init, sysevent_walk_step,
4443 4448 sysevent_walk_fini},
4444 4449 { "sysevent_sent", "walk sysevent sent queue", sysevent_sent_walk_init,
4445 4450 sysevent_walk_step, sysevent_walk_fini},
4446 4451 { "sysevent_channel", "walk sysevent channel subscriptions",
4447 4452 sysevent_channel_walk_init, sysevent_channel_walk_step,
4448 4453 sysevent_channel_walk_fini},
4449 4454 { "sysevent_class_list", "walk sysevent subscription's class list",
4450 4455 sysevent_class_list_walk_init, sysevent_class_list_walk_step,
4451 4456 sysevent_class_list_walk_fini},
4452 4457 { "sysevent_subclass_list",
4453 4458 "walk sysevent subscription's subclass list",
4454 4459 sysevent_subclass_list_walk_init,
4455 4460 sysevent_subclass_list_walk_step,
4456 4461 sysevent_subclass_list_walk_fini},
4457 4462 { "task", "given a task pointer, walk its processes",
4458 4463 task_walk_init, task_walk_step, NULL },
4459 4464
4460 4465 /* from avl.c */
4461 4466 { AVL_WALK_NAME, AVL_WALK_DESC,
4462 4467 avl_walk_init, avl_walk_step, avl_walk_fini },
4463 4468
4464 4469 /* from bio.c */
4465 4470 { "buf", "walk the bio buf hash",
4466 4471 buf_walk_init, buf_walk_step, buf_walk_fini },
4467 4472
4468 4473 /* from contract.c */
4469 4474 { "contract", "walk all contracts, or those of the specified type",
4470 4475 ct_walk_init, generic_walk_step, NULL },
4471 4476 { "ct_event", "walk events on a contract event queue",
4472 4477 ct_event_walk_init, generic_walk_step, NULL },
4473 4478 { "ct_listener", "walk contract event queue listeners",
4474 4479 ct_listener_walk_init, generic_walk_step, NULL },
4475 4480
4476 4481 /* from cpupart.c */
4477 4482 { "cpupart_cpulist", "given an cpupart_t, walk cpus in partition",
4478 4483 cpupart_cpulist_walk_init, cpupart_cpulist_walk_step,
4479 4484 NULL },
4480 4485 { "cpupart_walk", "walk the set of cpu partitions",
4481 4486 cpupart_walk_init, cpupart_walk_step, NULL },
4482 4487
4483 4488 /* from ctxop.c */
4484 4489 { "ctxop", "walk list of context ops on a thread",
4485 4490 ctxop_walk_init, ctxop_walk_step, ctxop_walk_fini },
4486 4491
4487 4492 /* from cyclic.c */
4488 4493 { "cyccpu", "walk per-CPU cyc_cpu structures",
4489 4494 cyccpu_walk_init, cyccpu_walk_step, NULL },
4490 4495 { "cycomni", "for an omnipresent cyclic, walk cyc_omni_cpu list",
4491 4496 cycomni_walk_init, cycomni_walk_step, NULL },
4492 4497 { "cyctrace", "walk cyclic trace buffer",
4493 4498 cyctrace_walk_init, cyctrace_walk_step, cyctrace_walk_fini },
4494 4499
4495 4500 /* from devinfo.c */
4496 4501 { "binding_hash", "walk all entries in binding hash table",
4497 4502 binding_hash_walk_init, binding_hash_walk_step, NULL },
4498 4503 { "devinfo", "walk devinfo tree or subtree",
4499 4504 devinfo_walk_init, devinfo_walk_step, devinfo_walk_fini },
4500 4505 { "devinfo_audit_log", "walk devinfo audit system-wide log",
4501 4506 devinfo_audit_log_walk_init, devinfo_audit_log_walk_step,
4502 4507 devinfo_audit_log_walk_fini},
4503 4508 { "devinfo_audit_node", "walk per-devinfo audit history",
4504 4509 devinfo_audit_node_walk_init, devinfo_audit_node_walk_step,
4505 4510 devinfo_audit_node_walk_fini},
4506 4511 { "devinfo_children", "walk children of devinfo node",
4507 4512 devinfo_children_walk_init, devinfo_children_walk_step,
4508 4513 devinfo_children_walk_fini },
4509 4514 { "devinfo_parents", "walk ancestors of devinfo node",
4510 4515 devinfo_parents_walk_init, devinfo_parents_walk_step,
4511 4516 devinfo_parents_walk_fini },
4512 4517 { "devinfo_siblings", "walk siblings of devinfo node",
4513 4518 devinfo_siblings_walk_init, devinfo_siblings_walk_step, NULL },
4514 4519 { "devi_next", "walk devinfo list",
4515 4520 NULL, devi_next_walk_step, NULL },
4516 4521 { "devnames", "walk devnames array",
4517 4522 devnames_walk_init, devnames_walk_step, devnames_walk_fini },
4518 4523 { "minornode", "given a devinfo node, walk minor nodes",
4519 4524 minornode_walk_init, minornode_walk_step, NULL },
4520 4525 { "softstate",
4521 4526 "given an i_ddi_soft_state*, list all in-use driver stateps",
4522 4527 soft_state_walk_init, soft_state_walk_step,
4523 4528 NULL, NULL },
4524 4529 { "softstate_all",
4525 4530 "given an i_ddi_soft_state*, list all driver stateps",
4526 4531 soft_state_walk_init, soft_state_all_walk_step,
4527 4532 NULL, NULL },
4528 4533 { "devinfo_fmc",
4529 4534 "walk a fault management handle cache active list",
4530 4535 devinfo_fmc_walk_init, devinfo_fmc_walk_step, NULL },
4531 4536
4532 4537 /* from group.c */
4533 4538 { "group", "walk all elements of a group",
4534 4539 group_walk_init, group_walk_step, NULL },
4535 4540
4536 4541 /* from irm.c */
4537 4542 { "irmpools", "walk global list of interrupt pools",
4538 4543 irmpools_walk_init, list_walk_step, list_walk_fini },
4539 4544 { "irmreqs", "walk list of interrupt requests in an interrupt pool",
4540 4545 irmreqs_walk_init, list_walk_step, list_walk_fini },
4541 4546
4542 4547 /* from kmem.c */
4543 4548 { "allocdby", "given a thread, walk its allocated bufctls",
4544 4549 allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini },
4545 4550 { "bufctl", "walk a kmem cache's bufctls",
4546 4551 bufctl_walk_init, kmem_walk_step, kmem_walk_fini },
4547 4552 { "bufctl_history", "walk the available history of a bufctl",
4548 4553 bufctl_history_walk_init, bufctl_history_walk_step,
4549 4554 bufctl_history_walk_fini },
4550 4555 { "freedby", "given a thread, walk its freed bufctls",
4551 4556 freedby_walk_init, allocdby_walk_step, allocdby_walk_fini },
4552 4557 { "freectl", "walk a kmem cache's free bufctls",
4553 4558 freectl_walk_init, kmem_walk_step, kmem_walk_fini },
4554 4559 { "freectl_constructed", "walk a kmem cache's constructed free bufctls",
4555 4560 freectl_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
4556 4561 { "freemem", "walk a kmem cache's free memory",
4557 4562 freemem_walk_init, kmem_walk_step, kmem_walk_fini },
4558 4563 { "freemem_constructed", "walk a kmem cache's constructed free memory",
4559 4564 freemem_constructed_walk_init, kmem_walk_step, kmem_walk_fini },
4560 4565 { "kmem", "walk a kmem cache",
4561 4566 kmem_walk_init, kmem_walk_step, kmem_walk_fini },
4562 4567 { "kmem_cpu_cache", "given a kmem cache, walk its per-CPU caches",
4563 4568 kmem_cpu_cache_walk_init, kmem_cpu_cache_walk_step, NULL },
4564 4569 { "kmem_hash", "given a kmem cache, walk its allocated hash table",
4565 4570 kmem_hash_walk_init, kmem_hash_walk_step, kmem_hash_walk_fini },
4566 4571 { "kmem_log", "walk the kmem transaction log",
4567 4572 kmem_log_walk_init, kmem_log_walk_step, kmem_log_walk_fini },
4568 4573 { "kmem_slab", "given a kmem cache, walk its slabs",
4569 4574 kmem_slab_walk_init, combined_walk_step, combined_walk_fini },
4570 4575 { "kmem_slab_partial",
4571 4576 "given a kmem cache, walk its partially allocated slabs (min 1)",
4572 4577 kmem_slab_walk_partial_init, combined_walk_step,
4573 4578 combined_walk_fini },
4574 4579 { "vmem", "walk vmem structures in pre-fix, depth-first order",
4575 4580 vmem_walk_init, vmem_walk_step, vmem_walk_fini },
4576 4581 { "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs",
4577 4582 vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
4578 4583 { "vmem_free", "given a vmem_t, walk its free vmem_segs",
4579 4584 vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
4580 4585 { "vmem_postfix", "walk vmem structures in post-fix, depth-first order",
4581 4586 vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini },
4582 4587 { "vmem_seg", "given a vmem_t, walk all of its vmem_segs",
4583 4588 vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
4584 4589 { "vmem_span", "given a vmem_t, walk its spanning vmem_segs",
4585 4590 vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini },
4586 4591
4587 4592 /* from ldi.c */
4588 4593 { "ldi_handle", "walk the layered driver handle hash",
4589 4594 ldi_handle_walk_init, ldi_handle_walk_step, NULL },
4590 4595 { "ldi_ident", "walk the layered driver identifier hash",
4591 4596 ldi_ident_walk_init, ldi_ident_walk_step, NULL },
4592 4597
4593 4598 /* from leaky.c + leaky_subr.c */
4594 4599 { "leak", "given a leaked bufctl or vmem_seg, find leaks w/ same "
4595 4600 "stack trace",
4596 4601 leaky_walk_init, leaky_walk_step, leaky_walk_fini },
4597 4602 { "leakbuf", "given a leaked bufctl or vmem_seg, walk buffers for "
4598 4603 "leaks w/ same stack trace",
4599 4604 leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini },
4600 4605
4601 4606 /* from lgrp.c */
4602 4607 { "lgrp_cpulist", "walk CPUs in a given lgroup",
4603 4608 lgrp_cpulist_walk_init, lgrp_cpulist_walk_step, NULL },
4604 4609 { "lgrptbl", "walk lgroup table",
4605 4610 lgrp_walk_init, lgrp_walk_step, NULL },
4606 4611 { "lgrp_parents", "walk up lgroup lineage from given lgroup",
4607 4612 lgrp_parents_walk_init, lgrp_parents_walk_step, NULL },
4608 4613 { "lgrp_rsrc_mem", "walk lgroup memory resources of given lgroup",
4609 4614 lgrp_rsrc_mem_walk_init, lgrp_set_walk_step, NULL },
4610 4615 { "lgrp_rsrc_cpu", "walk lgroup CPU resources of given lgroup",
4611 4616 lgrp_rsrc_cpu_walk_init, lgrp_set_walk_step, NULL },
4612 4617
4613 4618 /* from list.c */
4614 4619 { LIST_WALK_NAME, LIST_WALK_DESC,
4615 4620 list_walk_init, list_walk_step, list_walk_fini },
4616 4621
4617 4622 /* from mdi.c */
4618 4623 { "mdipi_client_list", "Walker for mdi_pathinfo pi_client_link",
4619 4624 mdi_pi_client_link_walk_init,
4620 4625 mdi_pi_client_link_walk_step,
4621 4626 mdi_pi_client_link_walk_fini },
4622 4627 { "mdipi_phci_list", "Walker for mdi_pathinfo pi_phci_link",
4623 4628 mdi_pi_phci_link_walk_init,
4624 4629 mdi_pi_phci_link_walk_step,
4625 4630 mdi_pi_phci_link_walk_fini },
4626 4631 { "mdiphci_list", "Walker for mdi_phci ph_next link",
4627 4632 mdi_phci_ph_next_walk_init,
4628 4633 mdi_phci_ph_next_walk_step,
4629 4634 mdi_phci_ph_next_walk_fini },
4630 4635
4631 4636 /* from memory.c */
4632 4637 { "allpages", "walk all pages, including free pages",
4633 4638 allpages_walk_init, allpages_walk_step, allpages_walk_fini },
4634 4639 { "anon", "given an amp, list allocated anon structures",
4635 4640 anon_walk_init, anon_walk_step, anon_walk_fini,
4636 4641 ANON_WALK_ALLOC },
4637 4642 { "anon_all", "given an amp, list contents of all anon slots",
4638 4643 anon_walk_init, anon_walk_step, anon_walk_fini,
4639 4644 ANON_WALK_ALL },
4640 4645 { "memlist", "walk specified memlist",
4641 4646 NULL, memlist_walk_step, NULL },
4642 4647 { "page", "walk all pages, or those from the specified vnode",
4643 4648 page_walk_init, page_walk_step, page_walk_fini },
4644 4649 { "seg", "given an as, list of segments",
4645 4650 seg_walk_init, avl_walk_step, avl_walk_fini },
4646 4651 { "segvn_anon",
4647 4652 "given a struct segvn_data, list allocated anon structures",
4648 4653 segvn_anon_walk_init, anon_walk_step, anon_walk_fini,
4649 4654 ANON_WALK_ALLOC },
4650 4655 { "segvn_anon_all",
4651 4656 "given a struct segvn_data, list contents of all anon slots",
4652 4657 segvn_anon_walk_init, anon_walk_step, anon_walk_fini,
4653 4658 ANON_WALK_ALL },
4654 4659 { "segvn_pages",
4655 4660 "given a struct segvn_data, list resident pages in "
4656 4661 "offset order",
4657 4662 segvn_pages_walk_init, segvn_pages_walk_step,
4658 4663 segvn_pages_walk_fini, SEGVN_PAGES_RESIDENT },
4659 4664 { "segvn_pages_all",
4660 4665 "for each offset in a struct segvn_data, give page_t pointer "
4661 4666 "(if resident), or NULL.",
4662 4667 segvn_pages_walk_init, segvn_pages_walk_step,
4663 4668 segvn_pages_walk_fini, SEGVN_PAGES_ALL },
4664 4669 { "swapinfo", "walk swapinfo structures",
4665 4670 swap_walk_init, swap_walk_step, NULL },
4666 4671
4667 4672 /* from mmd.c */
4668 4673 { "pattr", "walk pattr_t structures", pattr_walk_init,
4669 4674 mmdq_walk_step, mmdq_walk_fini },
4670 4675 { "pdesc", "walk pdesc_t structures",
4671 4676 pdesc_walk_init, mmdq_walk_step, mmdq_walk_fini },
4672 4677 { "pdesc_slab", "walk pdesc_slab_t structures",
4673 4678 pdesc_slab_walk_init, mmdq_walk_step, mmdq_walk_fini },
4674 4679
4675 4680 /* from modhash.c */
4676 4681 { "modhash", "walk list of mod_hash structures", modhash_walk_init,
4677 4682 modhash_walk_step, NULL },
4678 4683 { "modent", "walk list of entries in a given mod_hash",
4679 4684 modent_walk_init, modent_walk_step, modent_walk_fini },
4680 4685 { "modchain", "walk list of entries in a given mod_hash_entry",
4681 4686 NULL, modchain_walk_step, NULL },
4682 4687
4683 4688 /* from net.c */
4684 4689 { "icmp", "walk ICMP control structures using MI for all stacks",
4685 4690 mi_payload_walk_init, mi_payload_walk_step, NULL,
4686 4691 &mi_icmp_arg },
4687 4692 { "mi", "given a MI_O, walk the MI",
4688 4693 mi_walk_init, mi_walk_step, mi_walk_fini, NULL },
4689 4694 { "sonode", "given a sonode, walk its children",
4690 4695 sonode_walk_init, sonode_walk_step, sonode_walk_fini, NULL },
4691 4696 { "icmp_stacks", "walk all the icmp_stack_t",
4692 4697 icmp_stacks_walk_init, icmp_stacks_walk_step, NULL },
4693 4698 { "tcp_stacks", "walk all the tcp_stack_t",
4694 4699 tcp_stacks_walk_init, tcp_stacks_walk_step, NULL },
4695 4700 { "udp_stacks", "walk all the udp_stack_t",
4696 4701 udp_stacks_walk_init, udp_stacks_walk_step, NULL },
4697 4702
4698 4703 /* from netstack.c */
4699 4704 { "netstack", "walk a list of kernel netstacks",
4700 4705 netstack_walk_init, netstack_walk_step, NULL },
4701 4706
4702 4707 /* from nvpair.c */
4703 4708 { NVPAIR_WALKER_NAME, NVPAIR_WALKER_DESCR,
4704 4709 nvpair_walk_init, nvpair_walk_step, NULL },
4705 4710
4706 4711 /* from rctl.c */
4707 4712 { "rctl_dict_list", "walk all rctl_dict_entry_t's from rctl_lists",
4708 4713 rctl_dict_walk_init, rctl_dict_walk_step, NULL },
4709 4714 { "rctl_set", "given a rctl_set, walk all rctls", rctl_set_walk_init,
4710 4715 rctl_set_walk_step, NULL },
4711 4716 { "rctl_val", "given a rctl_t, walk all rctl_val entries associated",
4712 4717 rctl_val_walk_init, rctl_val_walk_step },
4713 4718
4714 4719 /* from sobj.c */
4715 4720 { "blocked", "walk threads blocked on a given sobj",
4716 4721 blocked_walk_init, blocked_walk_step, NULL },
4717 4722 { "wchan", "given a wchan, list of blocked threads",
4718 4723 wchan_walk_init, wchan_walk_step, wchan_walk_fini },
4719 4724
4720 4725 /* from stream.c */
4721 4726 { "b_cont", "walk mblk_t list using b_cont",
4722 4727 mblk_walk_init, b_cont_step, mblk_walk_fini },
4723 4728 { "b_next", "walk mblk_t list using b_next",
4724 4729 mblk_walk_init, b_next_step, mblk_walk_fini },
4725 4730 { "qlink", "walk queue_t list using q_link",
4726 4731 queue_walk_init, queue_link_step, queue_walk_fini },
4727 4732 { "qnext", "walk queue_t list using q_next",
4728 4733 queue_walk_init, queue_next_step, queue_walk_fini },
4729 4734 { "strftblk", "given a dblk_t, walk STREAMS flow trace event list",
4730 4735 strftblk_walk_init, strftblk_step, strftblk_walk_fini },
4731 4736 { "readq", "walk read queue side of stdata",
4732 4737 str_walk_init, strr_walk_step, str_walk_fini },
4733 4738 { "writeq", "walk write queue side of stdata",
4734 4739 str_walk_init, strw_walk_step, str_walk_fini },
4735 4740
4736 4741 /* from taskq.c */
4737 4742 { "taskq_thread", "given a taskq_t, list all of its threads",
4738 4743 taskq_thread_walk_init,
4739 4744 taskq_thread_walk_step,
4740 4745 taskq_thread_walk_fini },
4741 4746 { "taskq_entry", "given a taskq_t*, list all taskq_ent_t in the list",
4742 4747 taskq_ent_walk_init, taskq_ent_walk_step, NULL },
4743 4748
4744 4749 /* from thread.c */
4745 4750 { "deathrow", "walk threads on both lwp_ and thread_deathrow",
4746 4751 deathrow_walk_init, deathrow_walk_step, NULL },
4747 4752 { "cpu_dispq", "given a cpu_t, walk threads in dispatcher queues",
4748 4753 cpu_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
4749 4754 { "cpupart_dispq",
4750 4755 "given a cpupart_t, walk threads in dispatcher queues",
4751 4756 cpupart_dispq_walk_init, dispq_walk_step, dispq_walk_fini },
4752 4757 { "lwp_deathrow", "walk lwp_deathrow",
4753 4758 lwp_deathrow_walk_init, deathrow_walk_step, NULL },
4754 4759 { "thread", "global or per-process kthread_t structures",
4755 4760 thread_walk_init, thread_walk_step, thread_walk_fini },
4756 4761 { "thread_deathrow", "walk threads on thread_deathrow",
4757 4762 thread_deathrow_walk_init, deathrow_walk_step, NULL },
4758 4763
4759 4764 /* from tsd.c */
4760 4765 { "tsd", "walk list of thread-specific data",
4761 4766 tsd_walk_init, tsd_walk_step, tsd_walk_fini },
4762 4767
4763 4768 /* from tsol.c */
4764 4769 { "tnrh", "walk remote host cache structures",
4765 4770 tnrh_walk_init, tnrh_walk_step, tnrh_walk_fini },
4766 4771 { "tnrhtp", "walk remote host template structures",
4767 4772 tnrhtp_walk_init, tnrhtp_walk_step, tnrhtp_walk_fini },
4768 4773
4769 4774 /*
4770 4775 * typegraph does not work under kmdb, as it requires too much memory
4771 4776 * for its internal data structures.
4772 4777 */
4773 4778 #ifndef _KMDB
4774 4779 /* from typegraph.c */
4775 4780 { "typeconflict", "walk buffers with conflicting type inferences",
4776 4781 typegraph_walk_init, typeconflict_walk_step },
4777 4782 { "typeunknown", "walk buffers with unknown types",
4778 4783 typegraph_walk_init, typeunknown_walk_step },
4779 4784 #endif
4780 4785
4781 4786 /* from vfs.c */
4782 4787 { "vfs", "walk file system list",
4783 4788 vfs_walk_init, vfs_walk_step },
4784 4789
4785 4790 /* from zone.c */
4786 4791 { "zone", "walk a list of kernel zones",
4787 4792 zone_walk_init, zone_walk_step, NULL },
4788 4793 { "zsd", "walk list of zsd entries for a zone",
4789 4794 zsd_walk_init, zsd_walk_step, NULL },
4790 4795
4791 4796 { NULL }
4792 4797 };
4793 4798
4794 4799 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
4795 4800
4796 4801 /*ARGSUSED*/
4797 4802 static void
4798 4803 genunix_statechange_cb(void *ignored)
4799 4804 {
4800 4805 /*
4801 4806 * Force ::findleaks and ::stacks to let go any cached state.
4802 4807 */
4803 4808 leaky_cleanup(1);
4804 4809 stacks_cleanup(1);
4805 4810
4806 4811 kmem_statechange(); /* notify kmem */
4807 4812 }
4808 4813
4809 4814 const mdb_modinfo_t *
4810 4815 _mdb_init(void)
4811 4816 {
4812 4817 kmem_init();
4813 4818
4814 4819 (void) mdb_callback_add(MDB_CALLBACK_STCHG,
4815 4820 genunix_statechange_cb, NULL);
4816 4821
4817 4822 #ifndef _KMDB
4818 4823 gcore_init();
4819 4824 #endif
4820 4825
4821 4826 return (&modinfo);
4822 4827 }
4823 4828
4824 4829 void
4825 4830 _mdb_fini(void)
4826 4831 {
4827 4832 leaky_cleanup(1);
4828 4833 stacks_cleanup(1);
4829 4834 }
↓ open down ↓ |
4554 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX