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