4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
27 #include <sys/ksynch.h>
29 #include <sys/errno.h>
32 #include <sys/mdb_modapi.h>
35 #include <sys/nsc_thread.h>
36 #include <sys/nsctl/nsc_dev.h>
37 #include <sys/nsctl/nsc_gen.h>
38 #include <sys/nsctl/nsc_mem.h>
39 #include <sys/nsctl/nsctl.h>
40 #include <sys/nsctl/nsc_disk.h>
44 * Data struct for the complex walks.
58 { "NSC_READ", NSC_READ, NSC_READ }, \
59 { "NSC_WRITE", NSC_WRITE, NSC_WRITE }
62 static const mdb_bitmask_t nsc_bhflag_bits
[] = {
64 { "NSC_PINNABLE", NSC_PINNABLE
, NSC_PINNABLE
},
65 { "NSC_NOBLOCK", NSC_NOBLOCK
, NSC_NOBLOCK
},
66 { "NSC_HALLOCATED", NSC_HALLOCATED
, NSC_HALLOCATED
},
67 { "NSC_HACTIVE", NSC_HACTIVE
, NSC_HACTIVE
},
68 { "NSC_BCOPY", NSC_BCOPY
, NSC_BCOPY
},
69 { "NSC_PAGEIO", NSC_PAGEIO
, NSC_PAGEIO
},
70 { "NSC_ABUF", NSC_ABUF
, NSC_ABUF
},
71 { "NSC_MIXED", NSC_MIXED
, NSC_MIXED
},
72 { "NSC_WRTHRU", NSC_WRTHRU
, NSC_WRTHRU
},
73 { "NSC_FORCED_WRTHRU", NSC_FORCED_WRTHRU
, NSC_FORCED_WRTHRU
},
74 { "NSC_NOCACHE", NSC_NOCACHE
, NSC_NOCACHE
},
75 { "NSC_QUEUE", NSC_QUEUE
, NSC_QUEUE
},
76 { "NSC_RDAHEAD", NSC_RDAHEAD
, NSC_RDAHEAD
},
77 { "NSC_NO_FORCED_WRTHRU", NSC_NO_FORCED_WRTHRU
, NSC_NO_FORCED_WRTHRU
},
78 { "NSC_METADATA", NSC_METADATA
, NSC_METADATA
},
79 { "NSC_SEQ_IO", NSC_SEQ_IO
, NSC_SEQ_IO
},
84 static const mdb_bitmask_t nsc_fdflag_bits
[] = {
90 static const mdb_bitmask_t nsc_fdmode_bits
[] = {
91 { "NSC_MULTI", NSC_MULTI
, NSC_MULTI
},
96 static const mdb_bitmask_t nsc_type_bits
[] = {
98 { "NSC_NULL", NSC_NULL
, NSC_NULL
},
99 { "NSC_DEVICE", NSC_DEVICE
, NSC_DEVICE
},
100 { "NSC_FILE", NSC_FILE
, NSC_FILE
},
101 { "NSC_CACHE", NSC_CACHE
, NSC_CACHE
},
102 { "NSC_VCHR", NSC_VCHR
, NSC_VCHR
},
103 { "NSC_NCALL", NSC_NCALL
, NSC_NCALL
},
106 { "NSC_ANON", NSC_ANON
, NSC_ANON
},
109 { "NSC_RAW_ID", NSC_RAW_ID
, NSC_RAW_ID
},
110 { "NSC_FILE_ID", NSC_FILE_ID
, NSC_FILE_ID
},
111 { "NSC_FREEZE_ID", NSC_FREEZE_ID
, NSC_FREEZE_ID
},
112 { "NSC_VCHR_ID", NSC_VCHR_ID
, NSC_VCHR_ID
},
113 { "NSC_NCALL_ID", NSC_NCALL_ID
, NSC_NCALL_ID
},
114 { "NSC_SDBC_ID", NSC_SDBC_ID
, NSC_SDBC_ID
},
115 { "NSC_RDCLR_ID", NSC_RDCLR_ID
, NSC_RDCLR_ID
},
116 { "NSC_RDCL_ID", NSC_RDCL_ID
, NSC_RDCL_ID
},
117 { "NSC_IIR_ID", NSC_IIR_ID
, NSC_IIR_ID
},
118 { "NSC_II_ID", NSC_II_ID
, NSC_II_ID
},
119 { "NSC_RDCHR_ID", NSC_RDCHR_ID
, NSC_RDCHR_ID
},
120 { "NSC_RDCH_ID", NSC_RDCH_ID
, NSC_RDCH_ID
},
125 static const mdb_bitmask_t nsc_availpend_bits
[] = {
127 { "_NSC_OPEN", _NSC_OPEN
, _NSC_OPEN
},
128 { "_NSC_CLOSE", _NSC_CLOSE
, _NSC_CLOSE
},
129 { "_NSC_PINNED", _NSC_PINNED
, _NSC_PINNED
},
130 { "_NSC_ATTACH", _NSC_ATTACH
, _NSC_ATTACH
},
131 { "_NSC_DETACH", _NSC_DETACH
, _NSC_DETACH
},
132 { "_NSC_OWNER", _NSC_OWNER
, _NSC_OWNER
},
137 static const mdb_bitmask_t nsc_ioflag_bits
[] = {
138 { "NSC_REFCNT", NSC_REFCNT
, NSC_REFCNT
},
139 { "NSC_FILTER", NSC_FILTER
, NSC_FILTER
},
144 static const mdb_bitmask_t nstset_flag_bits
[] = {
145 { "NST_SF_KILL", NST_SF_KILL
, NST_SF_KILL
},
150 static const mdb_bitmask_t nst_flag_bits
[] = {
151 { "NST_TF_INUSE", NST_TF_INUSE
, NST_TF_INUSE
},
152 { "NST_TF_ACTIVE", NST_TF_ACTIVE
, NST_TF_ACTIVE
},
153 { "NST_TF_PENDING", NST_TF_PENDING
, NST_TF_PENDING
},
154 { "NST_TF_DESTROY", NST_TF_DESTROY
, NST_TF_DESTROY
},
155 { "NST_TF_KILL", NST_TF_KILL
, NST_TF_KILL
},
164 static nsc_mem_t type_mem
[20];
165 static int complex_walk
;
166 static int complex_hdr
;
169 /* ---------------------------------------------------------------------- */
172 * Walker for an nsc_io chain.
173 * A global walk is assumed to start at _nsc_io_top.
177 nsc_io_winit(mdb_walk_state_t
*wsp
)
179 if (wsp
->walk_addr
== NULL
&&
180 mdb_readvar(&wsp
->walk_addr
, "_nsc_io_top") == -1) {
181 mdb_warn("unable to read '_nsc_io_top'");
190 nsc_io_wstep(mdb_walk_state_t
*wsp
)
195 if (wsp
->walk_addr
== NULL
)
198 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
201 next
= wsp
->walk_addr
+ OFFSETOF(nsc_io_t
, next
);
203 if (mdb_vread(&wsp
->walk_addr
, sizeof (uintptr_t), next
) == -1) {
204 mdb_warn("failed to read nsc_io_t.next at %p", next
);
212 /* ---------------------------------------------------------------------- */
215 * Walker for an nsc_dev chain.
216 * A global walk is assumed to start at _nsc_dev_top.
220 nsc_dev_winit(mdb_walk_state_t
*wsp
)
222 if (wsp
->walk_addr
== NULL
&&
223 mdb_readvar(&wsp
->walk_addr
, "_nsc_dev_top") == -1) {
224 mdb_warn("unable to read '_nsc_dev_top'");
233 nsc_dev_wstep(mdb_walk_state_t
*wsp
)
238 if (wsp
->walk_addr
== NULL
)
241 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
244 next
= wsp
->walk_addr
+ OFFSETOF(nsc_dev_t
, nsc_next
);
246 if (mdb_vread(&wsp
->walk_addr
, sizeof (uintptr_t), next
) == -1) {
247 mdb_warn("failed to read nsc_dev_t.nsc_next at %p", next
);
258 nsc_dev_wfini(mdb_walk_state_t
*wsp
)
264 /* ---------------------------------------------------------------------- */
267 * Walker for a chain of nsc_devval_t structures.
268 * Global walks start from _nsc_devval_top;
272 nsc_devval_winit(mdb_walk_state_t
*wsp
)
274 if (wsp
->walk_addr
== NULL
&&
275 mdb_readvar(&wsp
->walk_addr
, "_nsc_devval_top") == -1) {
276 mdb_warn("unable to read '_nsc_devval_top'");
285 nsc_devval_wstep(mdb_walk_state_t
*wsp
)
287 uintptr_t devval
= wsp
->walk_addr
;
293 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
296 /* move on to next devval */
298 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
299 devval
+ OFFSETOF(nsc_devval_t
, dv_next
)) == -1) {
300 mdb_warn("failed to read nsc_devval_t.dv_next");
308 /* ---------------------------------------------------------------------- */
311 * Walker for a chain of nsc_fd_t structures.
316 nsc_fd_winit(mdb_walk_state_t
*wsp
)
318 if (wsp
->walk_addr
== NULL
) {
319 mdb_warn("nsc_fd doesn't support global walks");
328 nsc_fd_wstep(mdb_walk_state_t
*wsp
)
330 uintptr_t fd
= wsp
->walk_addr
;
336 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
339 /* move on to next fd */
341 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
342 fd
+ OFFSETOF(nsc_fd_t
, sf_next
)) == -1) {
343 mdb_warn("failed to read nsc_fd_t.sf_next");
351 /* ---------------------------------------------------------------------- */
354 * Walker for a chain of nsc_iodev_t structures.
359 nsc_iodev_winit(mdb_walk_state_t
*wsp
)
361 if (wsp
->walk_addr
== NULL
) {
362 mdb_warn("nsc_iodev doesn't support global walks");
371 nsc_iodev_wstep(mdb_walk_state_t
*wsp
)
373 uintptr_t iodev
= wsp
->walk_addr
;
379 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
382 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
383 iodev
+ OFFSETOF(nsc_iodev_t
, si_next
)) == -1) {
384 mdb_warn("failed to read nsc_iodev_t.si_next");
392 /* ---------------------------------------------------------------------- */
395 * Walker for a chain of nsc_service_t structures.
396 * Global walks start at _nsc_services.
400 nsc_service_winit(mdb_walk_state_t
*wsp
)
402 if (wsp
->walk_addr
== NULL
&&
403 mdb_readvar(&wsp
->walk_addr
, "_nsc_services") == -1) {
404 mdb_warn("unable to read '_nsc_services'");
413 nsc_service_wstep(mdb_walk_state_t
*wsp
)
415 uintptr_t service
= wsp
->walk_addr
;
421 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
424 /* move on to next service */
426 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
427 service
+ OFFSETOF(nsc_service_t
, s_next
)) == -1) {
428 mdb_warn("failed to read nsc_service_t.s_next");
436 /* ---------------------------------------------------------------------- */
439 * Walker for a chain of nsc_svc_t structures.
444 nsc_svc_winit(mdb_walk_state_t
*wsp
)
446 if (wsp
->walk_addr
== NULL
) {
447 mdb_warn("nsc_svc does not support global walks");
456 nsc_svc_wstep(mdb_walk_state_t
*wsp
)
458 uintptr_t svc
= wsp
->walk_addr
;
464 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
467 /* move on to next svc */
469 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
470 svc
+ OFFSETOF(nsc_svc_t
, svc_next
)) == -1) {
471 mdb_warn("failed to read nsc_svc_t.svc_next");
479 /* ---------------------------------------------------------------------- */
482 * Walker for a chain of nsc_val_t structures.
487 nsc_val_winit(mdb_walk_state_t
*wsp
)
489 if (wsp
->walk_addr
== NULL
) {
490 mdb_warn("nsc_val doesn't support global walks");
499 nsc_val_wstep(mdb_walk_state_t
*wsp
)
501 uintptr_t val
= wsp
->walk_addr
;
507 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
510 /* move on to next val */
512 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
513 val
+ OFFSETOF(nsc_val_t
, sv_next
)) == -1) {
514 mdb_warn("failed to read nsc_val_t.sv_next");
522 /* ---------------------------------------------------------------------- */
525 * Walker for a chain of nstset_t structures.
526 * Global walks start at _nst_sets.
530 nstset_winit(mdb_walk_state_t
*wsp
)
532 if (wsp
->walk_addr
== NULL
&&
533 mdb_readvar(&wsp
->walk_addr
, "nst_sets") == -1) {
534 mdb_warn("unable to read 'nst_sets'");
543 nstset_wstep(mdb_walk_state_t
*wsp
)
545 uintptr_t set
= wsp
->walk_addr
;
551 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
554 /* move on to next set */
556 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
557 set
+ OFFSETOF(nstset_t
, set_next
)) == -1) {
558 mdb_warn("failed to read nstset_t.set_next");
566 /* ---------------------------------------------------------------------- */
569 * Walker for a chain of nsthread_t structures.
574 nsthread_winit(mdb_walk_state_t
*wsp
)
576 if (wsp
->walk_addr
== NULL
) {
577 mdb_warn("nsthread does not support global walks");
586 nsthread_wstep(mdb_walk_state_t
*wsp
)
588 uintptr_t thread
= wsp
->walk_addr
;
594 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
597 /* move on to next iodev */
599 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
600 thread
+ OFFSETOF(nsthread_t
, tp_chain
)) == -1) {
601 mdb_warn("failed to read nsthread_t.tp_chain");
609 /* ---------------------------------------------------------------------- */
612 * Walker for nsthread_t free/reuse chain.
617 nst_free_winit(mdb_walk_state_t
*wsp
)
619 if (wsp
->walk_addr
== NULL
) {
620 mdb_warn("nst_free does not support global walks");
624 /* store starting address */
626 wsp
->walk_data
= (void *)wsp
->walk_addr
;
628 /* move on to next thread */
630 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
631 wsp
->walk_addr
+ OFFSETOF(nsthread_t
, tp_link
.q_forw
)) == -1) {
632 mdb_warn("failed to read nsthread_t.tp_link.q_forw");
641 nst_free_wstep(mdb_walk_state_t
*wsp
)
643 uintptr_t thread
= wsp
->walk_addr
;
649 if (thread
== (uintptr_t)wsp
->walk_data
)
652 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
655 /* move on to next thread */
657 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
658 thread
+ OFFSETOF(nsthread_t
, tp_link
.q_forw
)) == -1) {
659 mdb_warn("failed to read nsthread_t.tp_link.q_forw");
667 /* ---------------------------------------------------------------------- */
670 * Walker for a chain of nsc_mem_t structures.
671 * Global walks start at _nsc_mem_top.
675 nsc_mem_winit(mdb_walk_state_t
*wsp
)
677 if (wsp
->walk_addr
== NULL
&&
678 mdb_readvar(&wsp
->walk_addr
, "_nsc_mem_top") == -1) {
679 mdb_warn("unable to read '_nsc_mem_top'");
688 nsc_mem_wstep(mdb_walk_state_t
*wsp
)
690 uintptr_t mem
= wsp
->walk_addr
;
696 status
= wsp
->walk_callback(wsp
->walk_addr
, wsp
->walk_data
,
699 /* move on to next mem */
701 if (mdb_vread(&wsp
->walk_addr
, sizeof (wsp
->walk_addr
),
702 mem
+ OFFSETOF(nsc_mem_t
, next
)) == -1) {
703 mdb_warn("failed to read nsc_mem_t.next");
711 /* ---------------------------------------------------------------------- */
717 { "NSC_RAW_ID", NSC_RAW_ID
},
718 { "NSC_FILE_ID", NSC_FILE_ID
},
719 { "NSC_FREEZE_ID", NSC_FREEZE_ID
},
720 { "NSC_SDBC_ID", NSC_SDBC_ID
},
721 { "NSC_RDCLR_ID", NSC_RDCLR_ID
},
722 { "NSC_RDCL_ID", NSC_RDCL_ID
},
723 { "NSC_IIR_ID", NSC_IIR_ID
},
724 { "NSC_II_ID", NSC_II_ID
},
725 { "NSC_RDCHR_ID", NSC_RDCHR_ID
},
726 { "NSC_RDCH_ID", NSC_RDCH_ID
},
732 nsc_io_id(const int id
)
736 for (i
= 0; io_ids
[i
].name
!= NULL
; i
++) {
737 if (io_ids
[i
].id
== id
) {
738 return (io_ids
[i
].name
);
747 * Display a single nsc_io_t structure.
748 * If called with no address, performs a global walk of all nsc_ios.
751 nsc_io(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
759 if (mdb_getopts(argc
, argv
,
760 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
763 if (!(flags
& DCMD_ADDRSPEC
)) {
764 if (mdb_walk_dcmd("nsctl`nsc_io",
765 "nsctl`nsc_io", argc
, argv
) == -1) {
766 mdb_warn("failed to walk 'nsc_io'");
773 io
= mdb_zalloc(sizeof (*io
), UM_SLEEP
| UM_GC
);
774 memset(io_name
, 0, sizeof (io_name
));
776 if (mdb_vread(io
, sizeof (*io
), addr
) != sizeof (*io
)) {
777 mdb_warn("failed to read nsc_io at %p", addr
);
782 if (mdb_readstr(io_name
, sizeof (io_name
),
783 (uintptr_t)io
->name
) == -1) {
784 mdb_warn("failed to read nsc_io_t.name");
789 if (DCMD_HDRSPEC(flags
)) {
790 mdb_printf("%-?s %8Tid fl ref abuf name\n", "io");
793 mdb_printf("%0?p %8T%08x %2x %4d %4d %s\n",
794 addr
, io
->id
, io
->flag
, io
->refcnt
, io
->abufcnt
, io_name
);
801 mdb_printf("id: %08x <%s>\n", io
->id
, nsc_io_id(io
->id
));
803 mdb_printf("provide: %08x <%b>\n", io
->provide
,
804 io
->provide
, nsc_type_bits
);
806 mdb_printf("flag: %08x <%b>\n", io
->flag
, io
->flag
, nsc_ioflag_bits
);
808 mdb_printf("pend: %d\n", io
->pend
);
816 /* ---------------------------------------------------------------------- */
819 * Display a single nsc_dev_t structure.
820 * If called with no address, performs a global walk of all nsc_devs.
823 nsc_dev(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
825 char path
[NSC_MAXPATH
+1];
833 if (mdb_getopts(argc
, argv
,
834 'a', MDB_OPT_SETBITS
, TRUE
, &a_opt
,
835 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
838 if (!(flags
& DCMD_ADDRSPEC
)) {
839 mdb_printf("Active device structures:\n");
841 if (mdb_walk_dcmd("nsctl`nsc_dev",
842 "nsctl`nsc_dev", argc
, argv
) == -1) {
843 mdb_warn("failed to walk 'nsc_dev'");
848 if (mdb_readvar(&dev_pend
, "_nsc_dev_pend") == -1) {
849 mdb_warn("failed to read _nsc_dev_pend");
853 mdb_printf("\nPending device structures:");
858 if (mdb_pwalk_dcmd("nsctl`nsc_dev",
859 "nsctl`nsc_dev", argc
, argv
,
861 mdb_warn("failed to walk "
862 "pending dev structs");
866 mdb_printf(" none\n");
873 memset(path
, 0, sizeof (path
));
874 dev
= mdb_zalloc(sizeof (*dev
), UM_SLEEP
| UM_GC
);
876 if (mdb_vread(dev
, sizeof (*dev
), addr
) != sizeof (*dev
)) {
877 mdb_warn("failed to read nsc_dev at %p", addr
);
881 if (mdb_readstr(path
, sizeof (path
), (uintptr_t)dev
->nsc_path
) == -1) {
882 mdb_warn("failed to read nsc_path at %p", dev
->nsc_path
);
886 if (DCMD_HDRSPEC(flags
)) {
887 mdb_printf("%-?s %8Tref pend rpnd wait path\n", "dev");
890 mdb_printf("%0?p %8T%3d %4d %4d %4d %s\n",
891 addr
, dev
->nsc_refcnt
, dev
->nsc_pend
, dev
->nsc_rpend
,
892 dev
->nsc_wait
, path
);
899 mdb_printf("next: %0?p %8Tclose: %0?p\n",
900 dev
->nsc_next
, dev
->nsc_close
);
902 mdb_printf("list: %0?p %8Tlock: %0?p\n",
903 dev
->nsc_list
, addr
+ OFFSETOF(nsc_dev_t
, nsc_lock
));
905 mdb_printf("cv: %0?p %8Tpath: %0?p %8Tphash: %016llx\n",
906 addr
+ OFFSETOF(nsc_dev_t
, nsc_cv
),
907 dev
->nsc_path
, dev
->nsc_phash
);
909 mdb_printf("drop: %d %8Treopen: %d\n",
910 dev
->nsc_drop
, dev
->nsc_reopen
);
912 if (dev
->nsc_values
) {
913 dv
= mdb_zalloc(sizeof (*dv
), UM_SLEEP
| UM_GC
);
914 if (mdb_vread(dv
, sizeof (*dv
), (uintptr_t)dev
->nsc_values
) !=
916 mdb_warn("unable to read nsc_dev_t.nsc_values");
922 mdb_printf("device/values: (nsc_devval: %0?p)\n",
927 if (mdb_pwalk_dcmd("nsctl`nsc_val", "nsctl`nsc_val",
928 0, NULL
, (uintptr_t)dv
->dv_values
) == -1) {
943 /* ---------------------------------------------------------------------- */
946 * Display a single nsc_devval_t structure.
947 * If called with no address, performs a global walk of all nsc_devs.
950 nsc_devval(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
957 if (mdb_getopts(argc
, argv
,
958 'a', MDB_OPT_SETBITS
, TRUE
, &a_opt
) != argc
)
961 if (!(flags
& DCMD_ADDRSPEC
)) {
962 if (mdb_walk_dcmd("nsctl`nsc_devval",
963 "nsctl`nsc_devval", argc
, argv
) == -1) {
964 mdb_warn("failed to walk 'nsc_devval'");
971 dv
= mdb_zalloc(sizeof (*dv
), UM_SLEEP
| UM_GC
);
973 if (mdb_vread(dv
, sizeof (*dv
), addr
) != sizeof (*dv
)) {
974 mdb_warn("failed to read nsc_devval at %p", addr
);
978 if (!a_opt
&& !dv
->dv_values
) {
982 if (DCMD_HDRSPEC(flags
)) {
983 mdb_printf("%-?s %8T%?-s %8Tpath\n", "devval", "phash");
986 mdb_printf("%0?p %8T%016llx %8T%s\n", addr
,
987 dv
->dv_phash
, dv
->dv_path
);
992 if (mdb_pwalk_dcmd("nsctl`nsc_val", "nsctl`nsc_val",
993 0, NULL
, (uintptr_t)dv
->dv_values
) == -1) {
997 mdb_printf("No values\n");
1006 /* ---------------------------------------------------------------------- */
1009 * Part 2 callback for the all devices and fds walk. Called per iodev.
1013 nsc_fd_iodev(uintptr_t addr
, const void *data
, void *cbdata
)
1015 struct complex_args
*fdall
= cbdata
;
1016 struct nsc_fd_t
*fd
;
1018 if (mdb_vread(&fd
, sizeof (fd
),
1019 addr
+ OFFSETOF(nsc_iodev_t
, si_open
)) == -1) {
1020 mdb_warn("unable to read nsc_iodev_t.si_open");
1025 if (mdb_pwalk_dcmd("nsctl`nsc_fd", "nsctl`nsc_fd",
1026 fdall
->argc
, fdall
->argv
, (uintptr_t)fd
) == -1)
1035 * Part 1 callback for the all devices and fds walk. Called per device.
1039 nsc_fd_dev(uintptr_t addr
, const void *data
, void *cbdata
)
1041 struct complex_args
*fdall
= cbdata
;
1045 if (mdb_vread(&iodev
, sizeof (iodev
),
1046 addr
+ OFFSETOF(nsc_dev_t
, nsc_list
)) == -1) {
1047 mdb_warn("unable to read nsc_dev_t.nsc_list at %p", addr
);
1051 /* walk iodev chains */
1053 if (iodev
!= NULL
) {
1054 if (mdb_pwalk("nsctl`nsc_iodev",
1055 nsc_fd_iodev
, fdall
, (uintptr_t)iodev
) == -1)
1059 /* walk nsc_close (closing fds) chains */
1061 if (mdb_vread(&fd
, sizeof (fd
),
1062 addr
+ OFFSETOF(nsc_dev_t
, nsc_close
)) == -1) {
1063 mdb_warn("unable to read nsc_dev_t.nsc_close at %p", addr
);
1068 if (mdb_pwalk_dcmd("nsctl`nsc_fd", "nsctl`nsc_fd",
1069 fdall
->argc
, fdall
->argv
, (uintptr_t)fd
) == -1)
1078 * Walk all devices and fds in the system.
1081 nsc_fd_all(int argc
, const mdb_arg_t
*argv
)
1083 struct complex_args fdall
;
1086 fdall
.argv
= (mdb_arg_t
*)argv
;
1091 if (mdb_walk("nsctl`nsc_dev", nsc_fd_dev
, &fdall
) == -1) {
1101 * Display an nsd_fd_t structure, or walk all devices and fds in the system.
1104 nsc_fd(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1106 char io_name
[128], *io_namep
;
1107 char path
[NSC_MAXPATH
+1];
1116 if (mdb_getopts(argc
, argv
,
1117 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
1118 return (DCMD_USAGE
);
1120 if (!(flags
& DCMD_ADDRSPEC
)) {
1121 return (nsc_fd_all(argc
, argv
));
1124 memset(path
, 0, sizeof (path
));
1125 fd
= mdb_zalloc(sizeof (*fd
), UM_SLEEP
| UM_GC
);
1126 memset(io_name
, 0, sizeof (io_name
));
1128 if (mdb_vread(fd
, sizeof (*fd
), addr
) != sizeof (*fd
)) {
1129 mdb_warn("failed to read nsc_fd at %p", addr
);
1133 if (mdb_vread(&pathp
, sizeof (pathp
),
1134 (uintptr_t)fd
->sf_dev
+ OFFSETOF(nsc_dev_t
, nsc_path
)) !=
1136 mdb_warn("failed to read nsc_dev.nsc_path");
1140 if (mdb_readstr(path
, sizeof (path
), pathp
) == -1) {
1141 mdb_warn("failed to read nsc_path");
1146 if (mdb_vread(&io
, sizeof (io
),
1147 (uintptr_t)fd
->sf_iodev
+ OFFSETOF(nsc_iodev_t
, si_io
)) !=
1149 mdb_warn("failed to read nsc_iodev.si_io");
1153 if (mdb_vread(&io_namep
, sizeof (io_namep
),
1154 (uintptr_t)io
+ OFFSETOF(nsc_io_t
, name
)) !=
1155 sizeof (io_namep
)) {
1156 mdb_warn("failed to read nsc_io_t.name");
1160 if (mdb_readstr(io_name
, sizeof (io_name
),
1161 (uintptr_t)io_namep
) == -1) {
1162 mdb_warn("failed to read nsc_io_t.name string");
1173 } else if (DCMD_HDRSPEC(flags
)) {
1178 mdb_printf("%-?s %8T%-?s %8T%-8s %-?s\n",
1179 "fd", "dev", "io", "cd");
1180 mdb_printf(" %-?s %8Trv pend av path\n", "arg");
1183 mdb_printf("%0?p %8T%0?p %8T%-8s %p\n",
1184 addr
, fd
->sf_dev
, io_name
, fd
->sf_cd
);
1185 mdb_printf(" %0?p %8T%2d %4x %2x %s\n",
1186 fd
->sf_arg
, fd
->sf_reserve
, fd
->sf_pend
,
1187 fd
->sf_avail
, path
);
1194 mdb_printf("open type: %08x <%b>\n", fd
->sf_type
,
1195 fd
->sf_type
, nsc_type_bits
);
1197 mdb_printf("avail: %08x <%b>\n", fd
->sf_avail
,
1198 fd
->sf_avail
, nsc_availpend_bits
);
1200 mdb_printf("flag: %08x <%b>\n", fd
->sf_flag
,
1201 fd
->sf_flag
, nsc_fdflag_bits
);
1203 mdb_printf("rsrv mode: %08x <%b>\n", fd
->sf_mode
,
1204 fd
->sf_mode
, nsc_fdmode_bits
);
1206 mdb_printf("open lbolt: %?x %8Treopen: %d\n", fd
->sf_lbolt
,
1215 /* ---------------------------------------------------------------------- */
1218 * Callback for the all devices and iodevs walk. Called per device.
1222 nsc_iodev_dev(uintptr_t addr
, const void *data
, void *cbdata
)
1224 struct complex_args
*iodevall
= cbdata
;
1227 if (mdb_vread(&iodev
, sizeof (iodev
),
1228 addr
+ OFFSETOF(nsc_dev_t
, nsc_list
)) == -1) {
1229 mdb_warn("unable to read nsc_dev_t.nsc_list at %p", addr
);
1233 /* walk iodev chains */
1235 if (iodev
!= NULL
) {
1236 if (mdb_pwalk_dcmd("nsctl`nsc_iodev", "nsctl`nsc_iodev",
1237 iodevall
->argc
, iodevall
->argv
, iodev
) == -1)
1246 * Walk all devices and iodevs in the system.
1249 nsc_iodev_all(int argc
, const mdb_arg_t
*argv
)
1251 struct complex_args iodevall
;
1253 iodevall
.argc
= argc
;
1254 iodevall
.argv
= (mdb_arg_t
*)argv
;
1259 if (mdb_walk("nsctl`nsc_dev", nsc_iodev_dev
, &iodevall
) == -1) {
1268 * Display an nsc_iodev_t structure, or walk all devices and
1269 * iodevs in the system.
1272 nsc_iodev(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1274 char io_name
[128], *io_namep
;
1275 char path
[NSC_MAXPATH
+1];
1283 if (mdb_getopts(argc
, argv
,
1284 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
1285 return (DCMD_USAGE
);
1287 if (!(flags
& DCMD_ADDRSPEC
)) {
1288 return (nsc_iodev_all(argc
, argv
));
1291 memset(path
, 0, sizeof (path
));
1292 iodev
= mdb_zalloc(sizeof (*iodev
), UM_SLEEP
| UM_GC
);
1293 memset(io_name
, 0, sizeof (io_name
));
1295 if (mdb_vread(iodev
, sizeof (*iodev
), addr
) != sizeof (*iodev
)) {
1296 mdb_warn("failed to read nsc_iodev at %p", addr
);
1300 if (mdb_vread(&pathp
, sizeof (pathp
),
1301 (uintptr_t)iodev
->si_dev
+ OFFSETOF(nsc_dev_t
, nsc_path
)) !=
1303 mdb_warn("failed to read nsc_dev.nsc_path");
1307 if (mdb_readstr(path
, sizeof (path
), pathp
) == -1) {
1308 mdb_warn("failed to read nsc_path");
1312 if (mdb_vread(&io_namep
, sizeof (io_namep
),
1313 (uintptr_t)iodev
->si_io
+ OFFSETOF(nsc_io_t
, name
)) !=
1314 sizeof (io_namep
)) {
1315 mdb_warn("failed to read nsc_io_t.name");
1319 if (mdb_readstr(io_name
, sizeof (io_name
),
1320 (uintptr_t)io_namep
) == -1) {
1321 mdb_warn("failed to read nsc_io_t.name string");
1331 } else if (DCMD_HDRSPEC(flags
)) {
1336 mdb_printf("%-?s %8T%-?s ref %-8s path\n",
1337 "iodev", "dev", "io");
1340 mdb_printf("%0?p %8T%0?p %3d %-8s %s\n",
1341 addr
, iodev
->si_dev
, iodev
->si_refcnt
, io_name
, path
);
1348 mdb_printf("open fds: %?p %8Tactive ios: %?p\n",
1349 iodev
->si_open
, iodev
->si_active
);
1351 mdb_printf("busy: %d %8Trsrv pend: %d\n",
1352 iodev
->si_busy
, iodev
->si_rpend
);
1354 mdb_printf("pend: %08x <%b>\n", iodev
->si_pend
,
1355 iodev
->si_pend
, nsc_availpend_bits
);
1357 mdb_printf("avail: %08x <%b>\n", iodev
->si_avail
,
1358 iodev
->si_avail
, nsc_availpend_bits
);
1366 /* ---------------------------------------------------------------------- */
1369 * Display an nsc_service_t structure, or walk all services.
1372 nsc_service(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1374 nsc_service_t
*service
;
1380 if (mdb_getopts(argc
, argv
,
1381 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
1382 return (DCMD_USAGE
);
1384 if (!(flags
& DCMD_ADDRSPEC
)) {
1385 if (mdb_walk_dcmd("nsctl`nsc_service",
1386 "nsctl`nsc_service", argc
, argv
) == -1) {
1387 mdb_warn("failed to walk 'nsc_service'");
1394 service
= mdb_zalloc(sizeof (*service
), UM_SLEEP
| UM_GC
);
1396 if (mdb_vread(service
, sizeof (*service
), addr
) != sizeof (*service
)) {
1397 mdb_warn("failed to read nsc_service at %p", addr
);
1401 if (DCMD_HDRSPEC(flags
)) {
1402 mdb_printf("%-?s %8Tname\n", "service");
1405 memset(s_name
, 0, sizeof (s_name
));
1406 if (service
->s_name
) {
1407 if (mdb_readstr(s_name
, sizeof (s_name
),
1408 (uintptr_t)service
->s_name
) == -1) {
1409 mdb_warn("failed to read nsc_io_t.name");
1414 mdb_printf("%0?p %8T%s\n", addr
, s_name
);
1421 mdb_printf("servers:\n");
1422 if (service
->s_servers
== NULL
) {
1423 mdb_printf("<none>\n");
1426 if (mdb_pwalk_dcmd("nsctl`nsc_svc", "nsctl`nsc_svc",
1427 argc
, argv
, (uintptr_t)service
->s_servers
) == -1) {
1434 mdb_printf("clients:\n");
1435 if (service
->s_clients
== NULL
) {
1436 mdb_printf("<none>\n");
1439 if (mdb_pwalk_dcmd("nsctl`nsc_svc", "nsctl`nsc_svc",
1440 argc
, argv
, (uintptr_t)service
->s_clients
) == -1) {
1453 /* ---------------------------------------------------------------------- */
1456 * Display an nsc_svc_t structure.
1460 nsc_svc(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1464 if (!(flags
& DCMD_ADDRSPEC
))
1465 return (DCMD_USAGE
);
1467 svc
= mdb_zalloc(sizeof (*svc
), UM_SLEEP
| UM_GC
);
1469 if (mdb_vread(svc
, sizeof (*svc
), addr
) != sizeof (*svc
)) {
1470 mdb_warn("failed to read nsc_svc at %p", addr
);
1474 if (DCMD_HDRSPEC(flags
)) {
1475 mdb_printf("%-?s %8T%-?s %8Tfunc\n", "svc", "service");
1478 mdb_printf("%0?p %8T%0?p %8T%a\n", addr
, svc
->svc_svc
, svc
->svc_fn
);
1483 /* ---------------------------------------------------------------------- */
1486 * Display a single nsc_val_t structure.
1487 * If called with no address, performs a global walk of all nsc_devs.
1491 nsc_val(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1496 return (DCMD_USAGE
);
1498 if (!(flags
& DCMD_ADDRSPEC
)) {
1499 mdb_warn("nsc_val requires an address");
1503 vp
= mdb_zalloc(sizeof (*vp
), UM_SLEEP
| UM_GC
);
1505 if (mdb_vread(vp
, sizeof (*vp
), addr
) != sizeof (*vp
)) {
1506 mdb_warn("failed to read nsc_val at %p", addr
);
1510 if (DCMD_HDRSPEC(flags
)) {
1511 mdb_printf("%-?s %8T%8-s %8Tname\n", "val", "value");
1514 mdb_printf("%0?p %8T%08x %8T%s\n", addr
, vp
->sv_value
, vp
->sv_name
);
1520 /* ---------------------------------------------------------------------- */
1523 * Display an nstset_t structure, or walk all sets.
1527 nstset(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1530 int f_opt
, r_opt
, t_opt
, v_opt
;
1532 f_opt
= r_opt
= t_opt
= v_opt
= 0;
1534 if (mdb_getopts(argc
, argv
,
1535 'f', MDB_OPT_SETBITS
, TRUE
, &f_opt
, /* free list */
1536 'r', MDB_OPT_SETBITS
, TRUE
, &r_opt
, /* reuse list */
1537 't', MDB_OPT_SETBITS
, TRUE
, &t_opt
, /* all threads */
1538 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
1539 return (DCMD_USAGE
);
1541 /* displaying threads implies verbose */
1542 if (f_opt
|| r_opt
|| t_opt
)
1545 if (!(flags
& DCMD_ADDRSPEC
)) {
1546 if (mdb_walk_dcmd("nsctl`nstset",
1547 "nsctl`nstset", argc
, argv
) == -1) {
1548 mdb_warn("failed to walk 'nstset'");
1555 set
= mdb_zalloc(sizeof (*set
), UM_SLEEP
| UM_GC
);
1557 if (mdb_vread(set
, sizeof (*set
), addr
) != sizeof (*set
)) {
1558 mdb_warn("failed to read nstset at %p", addr
);
1562 if (DCMD_HDRSPEC(flags
)) {
1563 mdb_printf("%-?s %8T live nthr flag name\n", "set");
1566 mdb_printf("%0?p %8T%6d %6d %4x %s\n", addr
,
1567 set
->set_nlive
, set
->set_nthread
, set
->set_flag
, set
->set_name
);
1574 mdb_printf("chain: %0?p %8Tpending: %4d res_cnt: %4d\n",
1575 set
->set_chain
, set
->set_pending
, set
->set_res_cnt
);
1577 if (set
->set_reuse
.q_forw
== set
->set_reuse
.q_back
&&
1578 (uintptr_t)set
->set_reuse
.q_forw
==
1579 (addr
+ OFFSETOF(nstset_t
, set_reuse
))) {
1580 mdb_printf("reuse.forw: %-?s %8Treuse.back: %s\n",
1583 mdb_printf("reuse.forw: %0?p %8Treuse.back: %0?p\n",
1584 set
->set_reuse
.q_forw
, set
->set_reuse
.q_back
);
1586 /* display all threads in reuse list */
1588 mdb_pwalk_dcmd("nsctl`nst_free", "nsctl`nsthread",
1589 0, (const mdb_arg_t
*)NULL
,
1590 (addr
+ OFFSETOF(nstset_t
, set_reuse
))) == -1) {
1596 if (set
->set_free
.q_forw
== set
->set_free
.q_back
&&
1597 (uintptr_t)set
->set_free
.q_forw
==
1598 (addr
+ OFFSETOF(nstset_t
, set_free
))) {
1599 mdb_printf("free.forw: %-?s %8Tfree.back: %s\n",
1602 mdb_printf("free.forw: %0?p %8Tfree.back: %0?p\n",
1603 set
->set_free
.q_forw
, set
->set_free
.q_back
);
1605 /* display all threads in free list */
1607 mdb_pwalk_dcmd("nsctl`nst_free", "nsctl`nsthread",
1608 0, (const mdb_arg_t
*)NULL
,
1609 (addr
+ OFFSETOF(nstset_t
, set_free
))) == -1) {
1615 mdb_printf("flag: %08x <%b>\n",
1616 set
->set_flag
, set
->set_flag
, nstset_flag_bits
);
1618 /* display all threads in set */
1620 mdb_printf("all threads in set:\n");
1621 if (mdb_pwalk_dcmd("nsctl`nsthread", "nsctl`nsthread",
1622 0, (const mdb_arg_t
*)NULL
,
1623 (uintptr_t)set
->set_chain
) == -1) {
1635 /* ---------------------------------------------------------------------- */
1638 * Callback for the all nstsets and threads walk. Called per set.
1642 nst_thr_set(uintptr_t addr
, const void *data
, void *cbdata
)
1644 struct complex_args
*thrall
= cbdata
;
1648 if (mdb_vread(&tp
, sizeof (tp
),
1649 addr
+ OFFSETOF(nstset_t
, set_chain
)) == -1) {
1650 mdb_warn("unable to read nstset_t.set_chain at %p", addr
);
1654 memset(set_name
, 0, sizeof (set_name
));
1656 if (mdb_readstr(set_name
, sizeof (set_name
),
1657 addr
+ OFFSETOF(nstset_t
, set_name
)) == -1) {
1658 mdb_warn("unable to read nstset_t.set_name at %p", addr
);
1661 mdb_printf("nstset: %0?p (%s)\n", addr
, set_name
);
1663 /* walk thread chains */
1666 if (mdb_pwalk_dcmd("nsctl`nsthread", "nsctl`nsthread",
1667 thrall
->argc
, thrall
->argv
, tp
) == -1)
1670 mdb_printf(" no threads\n");
1679 * Walk all nstsets and threads in the system.
1682 nst_thr_all(int argc
, const mdb_arg_t
*argv
)
1684 struct complex_args thrall
;
1687 thrall
.argv
= (mdb_arg_t
*)argv
;
1689 if (mdb_walk("nsctl`nstset", nst_thr_set
, &thrall
) == -1)
1697 * Display an nsthread_t structure, or walk all threads.
1701 nsthread(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1710 if (mdb_getopts(argc
, argv
,
1711 'a', MDB_OPT_SETBITS
, TRUE
, &a_opt
,
1712 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
1713 return (DCMD_USAGE
);
1715 if (!(flags
& DCMD_ADDRSPEC
)) {
1716 if ((rc
= nst_thr_all(argc
, argv
)) != DCMD_OK
)
1720 if (mdb_readvar(&thrpend
, "nst_pending") == -1) {
1721 mdb_warn("unable to read 'nst_pending'");
1726 mdb_printf("\nPending threads:\n");
1728 if (mdb_pwalk_dcmd("nsctl`nsthread",
1729 "nsctl`nsthread", argc
, argv
,
1731 mdb_warn("failed to walk 'nsthread'");
1740 tp
= mdb_zalloc(sizeof (*tp
), UM_SLEEP
| UM_GC
);
1742 if (mdb_vread(tp
, sizeof (*tp
), addr
) != sizeof (*tp
)) {
1743 mdb_warn("failed to read nsthread at %p", addr
);
1747 if (DCMD_HDRSPEC(flags
)) {
1748 mdb_printf("%-?s %8Tflag %-?s %8Tfunc\n", "thread", "arg");
1751 mdb_printf("%0?p %8T%4x %0?p %8T%a\n",
1752 addr
, tp
->tp_flag
, tp
->tp_arg
, tp
->tp_func
);
1759 mdb_printf("set: %0?p %8Tchain: %0?p\n",
1760 tp
->tp_set
, tp
->tp_chain
);
1762 mdb_printf("link.forw: %0?p %8Tlink.back: %0?p\n",
1763 tp
->tp_link
.q_forw
, tp
->tp_link
.q_back
);
1765 mdb_printf("flag: %08x <%b>\n",
1766 tp
->tp_flag
, tp
->tp_flag
, nst_flag_bits
);
1774 /* ---------------------------------------------------------------------- */
1777 nsc_rmap(char *name
)
1784 if (mdb_readvar(&addr
, name
) == -1) {
1785 mdb_warn("unable to read rmap '%s'", name
);
1789 if (mdb_vread(&slot
, sizeof (slot
), addr
) != sizeof (slot
)) {
1790 mdb_warn("unable to read rmap '%s' slot 0", name
);
1794 mdb_printf("\nmap name offset size nslot\n");
1795 mdb_printf("%16s %9d %9d %5d\n",
1796 slot
.name
, slot
.offset
, slot
.size
, slot
.inuse
);
1799 mdb_printf("\nslot name offset size inuse\n");
1802 addr
+= sizeof (slot
);
1804 if (mdb_vread(&slot
, sizeof (slot
), addr
) != sizeof (slot
)) {
1805 mdb_warn("unable to read rmap '%s' slot @ %p",
1810 if (!slot
.inuse
|| !slot
.size
)
1813 for (cp
= slot
.name
; *cp
; cp
++)
1817 mdb_printf("%16s %9d %9d %08x\n",
1818 slot
.name
, slot
.offset
, slot
.size
, slot
.inuse
);
1826 nsc_rmhdr_t
*rmhdr
= mdb_zalloc(sizeof (*rmhdr
), UM_SLEEP
| UM_GC
);
1829 if (mdb_readvar(&addr
, "_nsc_rmhdr_ptr") == -1) {
1830 mdb_warn("unable to read _nsc_rmhdr_ptr");
1835 mdb_printf("\n\nGlobal header not initialised\n");
1839 if (mdb_vread(rmhdr
, sizeof (*rmhdr
), addr
) != sizeof (*rmhdr
)) {
1840 mdb_warn("unable to read global header at %p", addr
);
1844 mdb_printf("\n\nglobal header (magic %08x, version %d, size %d)\n",
1845 rmhdr
->magic
, rmhdr
->ver
, rmhdr
->size
);
1847 nsc_rmap("_nsc_global_map");
1852 memptr(int type
, int flag
)
1856 type
&= NSC_MEM_GLOBAL
;
1862 return (&type_mem
[0]);
1864 for (i
= 1; i
< (sizeof (type_mem
) / sizeof (nsc_mem_t
)); i
++) {
1865 if (!type_mem
[i
].flag
&& !type_mem
[i
].type
) {
1866 type_mem
[i
].flag
= flag
;
1867 type_mem
[i
].type
= type
;
1868 return (&type_mem
[i
]);
1871 if (type_mem
[i
].flag
== flag
&& type_mem
[i
].type
== type
)
1872 return (&type_mem
[i
]);
1875 return (&type_mem
[i
]);
1879 #define typename(t) \
1880 (((t) & NSC_MEM_GLOBAL) ? "gbl" : " - ")
1882 #define memname(t) \
1883 (((t) & NSC_MEM_GLOBAL) ? "nsc_global" : "system kmem")
1886 nsc_mem_type(const int first
, nsc_mem_t
*mp
)
1891 mdb_printf("\nregion typ f ");
1892 mdb_printf("used hwm pgs alloc free\n");
1895 type
= typename(mp
->type
);
1896 name
= memname(mp
->type
);
1898 mdb_printf("%16s %s %2x %9d %9d %6d %5d %5d\n",
1899 name
, type
, mp
->flag
, mp
->used
, mp
->hwm
, mp
->pagehwm
,
1900 mp
->nalloc
, mp
->nfree
);
1905 nsc_mem_all(int argc
, const mdb_arg_t
*argv
, int v_opt
)
1910 memset(type_mem
, 0, sizeof (type_mem
));
1912 if (mdb_walk_dcmd("nsctl`nsc_mem",
1913 "nsctl`nsc_mem", argc
, argv
) == -1) {
1914 mdb_warn("unable to walk 'nsc_mem'");
1918 for (first
= 1, i
= 0;
1919 i
< (sizeof (type_mem
) / sizeof (nsc_mem_t
)); first
= 0, i
++) {
1920 if (type_mem
[i
].nalloc
|| type_mem
[i
].hwm
) {
1921 nsc_mem_type(first
, &type_mem
[i
]);
1933 nsc_mem(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1935 char name
[16], *type
, *cp
;
1941 if (mdb_getopts(argc
, argv
,
1942 'v', MDB_OPT_SETBITS
, TRUE
, &v_opt
) != argc
)
1943 return (DCMD_USAGE
);
1945 if (!(flags
& DCMD_ADDRSPEC
)) {
1946 return (nsc_mem_all(argc
, argv
, v_opt
));
1949 if (mdb_vread(&mem
, sizeof (mem
), addr
) != sizeof (mem
)) {
1950 mdb_warn("failed to read nsc_mem_t at %p", addr
);
1954 if (mdb_readstr(name
, sizeof (name
), (uintptr_t)mem
.name
) == -1) {
1955 mdb_warn("failed to read nsc_mem_t.name at %p", addr
);
1959 if (!mem
.nalloc
&& !mem
.hwm
&& !v_opt
)
1962 if (DCMD_HDRSPEC(flags
)) {
1963 mdb_printf("name typ f ");
1964 mdb_printf("used hwm pgs alloc free base\n");
1967 type
= typename(mem
.type
);
1968 mp
= memptr(mem
.type
, mem
.flag
);
1970 for (cp
= name
; *cp
; cp
++)
1974 mdb_printf("%-16s %s %2x %9d %9d %5d %5d %5d %0?p\n",
1975 name
, type
, mem
.flag
, mem
.used
, mem
.hwm
, mem
.pagehwm
,
1976 mem
.nalloc
, mem
.nfree
, mem
.base
);
1978 mp
->used
+= mem
.used
;
1980 mp
->pagehwm
+= mem
.pagehwm
;
1981 mp
->nalloc
+= mem
.nalloc
;
1982 mp
->nfree
+= mem
.nfree
;
1989 nsc_vec(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1993 vec
= mdb_zalloc(sizeof (*vec
), UM_SLEEP
| UM_GC
);
1994 if (mdb_vread(vec
, sizeof (*vec
), addr
) != sizeof (*vec
)) {
1995 mdb_warn("failed to read nsc_vec at %p", addr
);
1998 mdb_printf("nsc_vec_t @ 0x%p = {\n", addr
);
2000 mdb_printf("sv_addr: %p\n", vec
->sv_addr
);
2001 mdb_printf("sv_vme: %lu\n", vec
->sv_vme
);
2002 mdb_printf("sv_len: %d\n", vec
->sv_len
);
2011 /* ---------------------------------------------------------------------- */
2013 * Display an nsc_buf_t structure.
2016 #ifdef NSC_MULTI_TERABYTE
2017 #define STRCONV "ll"
2024 nsc_buf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2029 if (!(flags
& DCMD_ADDRSPEC
))
2030 return (DCMD_USAGE
);
2032 bh
= mdb_zalloc(sizeof (*bh
), UM_SLEEP
| UM_GC
);
2034 if (mdb_vread(bh
, sizeof (*bh
), addr
) != sizeof (*bh
)) {
2035 mdb_warn("failed to read nsc_buf at %p", addr
);
2039 mdb_printf("nsc_buf_t @ 0x%p = {\n", addr
);
2041 mdb_printf("sb_fd: 0x%p\n", bh
->sb_fd
);
2042 mdb_printf("sb_pos: 0x%" STRCONV
"x\n", bh
->sb_pos
);
2043 mdb_printf("sb_len: 0x%" STRCONV
"x\n", bh
->sb_len
);
2044 mdb_printf("sb_flag: 0x%08x <%b>\n", bh
->sb_flag
,
2045 bh
->sb_flag
, nsc_bhflag_bits
);
2046 mdb_printf("sb_error: %d\n", bh
->sb_error
);
2047 #ifdef NSC_MULTI_TERABYTE
2048 mdb_printf("sb_user: 0x%p\n", bh
->sb_user
);
2050 mdb_printf("sb_user: 0x%x\n", bh
->sb_user
);
2052 mdb_printf("sb_vec: 0x%p\n", bh
->sb_vec
);
2054 while (nsc_vec((uintptr_t)v
, flags
, argc
, argv
) == DCMD_OK
)
2063 /* ---------------------------------------------------------------------- */
2067 nsc_dbuf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2071 if (!(flags
& DCMD_ADDRSPEC
))
2072 return (DCMD_USAGE
);
2074 bh
= mdb_zalloc(sizeof (*bh
), UM_SLEEP
| UM_GC
);
2076 if (mdb_vread(bh
, sizeof (*bh
), addr
) != sizeof (*bh
)) {
2077 mdb_warn("failed to read nsc_dbuf at %p", addr
);
2081 mdb_printf("nsc_dbuf_t @ 0x%p = {\n", addr
);
2083 mdb_printf("db_disc: 0x%p\n", bh
->db_disc
);
2084 mdb_printf("db_addr: 0x%p\n", bh
->db_addr
);
2085 mdb_printf("db_next: 0x%p\n", bh
->db_next
);
2086 mdb_printf("db_maxfbas: 0x%d\n", bh
->db_maxfbas
);
2094 /* ---------------------------------------------------------------------- */
2097 * MDB module linkage information:
2100 static const mdb_dcmd_t dcmds
[] = {
2102 { "nsctl", NULL
, "display nsctl module info", nsctl
},
2104 { "nsc_buf", ":", "list nsc_buf structure", nsc_buf
},
2105 { "nsc_dbuf", ":", "list nsc_dbuf structure", nsc_dbuf
},
2106 { "nsc_dev", "?[-av]", "list nsc_dev structure", nsc_dev
},
2107 { "nsc_devval", "?[-a]", "list nsc_devval structure", nsc_devval
},
2108 { "nsc_fd", "?[-v]", "list nsc_fd structure", nsc_fd
},
2109 { "nsc_iodev", "?[-v]", "list nsc_iodev structure", nsc_iodev
},
2110 { "nsc_io", "?[-v]", "list nsc_io structure", nsc_io
},
2111 { "nsc_mem", "?[-v]", "list nsc_mem structure", nsc_mem
},
2112 { "nsc_svc", ":", "list nsc_svc structure", nsc_svc
},
2113 { "nsc_service", "?[-v]", "list nsc_service structure", nsc_service
},
2114 { "nsc_val", ":", "list nsc_val structure", nsc_val
},
2115 { "nstset", "?[-frtv]", "list nstset structure", nstset
},
2116 { "nsthread", "?[-av]", "list nsthread structure", nsthread
},
2121 static const mdb_walker_t walkers
[] = {
2122 { "nsc_dev", "walk nsc_dev chain",
2123 nsc_dev_winit
, nsc_dev_wstep
, nsc_dev_wfini
, NULL
},
2124 { "nsc_devval", "walk nsc_devval chain",
2125 nsc_devval_winit
, nsc_devval_wstep
, NULL
, NULL
},
2126 { "nsc_fd", "walk nsc_fd chain",
2127 nsc_fd_winit
, nsc_fd_wstep
, NULL
, NULL
},
2128 { "nsc_io", "walk nsc_io chain",
2129 nsc_io_winit
, nsc_io_wstep
, NULL
, NULL
},
2130 { "nsc_iodev", "walk nsc_iodev chain",
2131 nsc_iodev_winit
, nsc_iodev_wstep
, NULL
, NULL
},
2132 { "nsc_mem", "walk nsc_mem chain",
2133 nsc_mem_winit
, nsc_mem_wstep
, NULL
, NULL
},
2134 { "nsc_service", "walk nsc_service chain",
2135 nsc_service_winit
, nsc_service_wstep
, NULL
, NULL
},
2136 { "nsc_svc", "walk nsc_svc chain",
2137 nsc_svc_winit
, nsc_svc_wstep
, NULL
, NULL
},
2138 { "nsc_val", "walk nsc_val chain",
2139 nsc_val_winit
, nsc_val_wstep
, NULL
, NULL
},
2140 { "nstset", "walk nstset chain",
2141 nstset_winit
, nstset_wstep
, NULL
, NULL
},
2142 { "nsthread", "walk nsthread chain",
2143 nsthread_winit
, nsthread_wstep
, NULL
, NULL
},
2144 { "nst_free", "walk nsthread free/reuse list",
2145 nst_free_winit
, nst_free_wstep
, NULL
, NULL
},
2150 static const mdb_modinfo_t modinfo
= {
2151 MDB_API_VERSION
, dcmds
, walkers
2155 const mdb_modinfo_t
*