xref: /titanic_51/usr/src/cmd/mdb/common/modules/genunix/pg.c (revision c81d47afd05baeb768e2f032636019b717899efd)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Display processor group information
31  */
32 
33 #include "pg.h"
34 
35 #include <mdb/mdb_modapi.h>
36 #include <sys/pghw.h>
37 
38 /*
39  * PG hardware types indexed by hardware ID
40  */
41 char *pg_hw_names[] = {
42 	"hw",
43 	"ipipe",
44 	"cache",
45 	"fpu",
46 	"mpipe/chip",
47 	"memory",
48 };
49 
50 #define	A_CNT(arr)	(sizeof (arr) / sizeof (arr[0]))
51 
52 #define	NHW	 A_CNT(pg_hw_names)
53 
54 /*
55  * Convert HW id to symbolic name
56  */
57 static char *
58 pg_hw_name(int hw)
59 {
60 	return ((hw < 0 || hw > NHW) ? "UNKNOWN" : pg_hw_names[hw]);
61 }
62 
63 /*
64  * Display processor group.
65  */
66 /* ARGSUSED */
67 int
68 pg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
69 {
70 	pg_t		pg;
71 	pghw_t		pghw;
72 	pg_class_t	pg_class;
73 	int		opt_q = 0; /* display only address. */
74 
75 	/* Should provide an address */
76 	if (! (flags & DCMD_ADDRSPEC))
77 		return (DCMD_USAGE);
78 
79 	if (mdb_getopts(argc, argv,
80 	    'q', MDB_OPT_SETBITS, TRUE, &opt_q,
81 		NULL) != argc)
82 		return (DCMD_USAGE);
83 
84 	if (flags & DCMD_PIPE_OUT)
85 		opt_q = B_TRUE;
86 
87 	if (DCMD_HDRSPEC(flags) && !opt_q) {
88 		mdb_printf("%6s %?s %6s %7s %9s %5s\n",
89 		    "PGID",
90 		    "ADDR",
91 		    "PHYSID",
92 		    "CLASS",
93 		    "HARDWARE",
94 		    "#CPUs");
95 	}
96 
97 	/*
98 	 * Read pg at specified address
99 	 */
100 	if (mdb_vread(&pg, sizeof (struct pg), addr) == -1) {
101 		mdb_warn("unable to read 'pg' at %p", addr);
102 		return (DCMD_ERR);
103 	}
104 
105 	/*
106 	 * In quiet mode just print pg address
107 	 */
108 	if (opt_q) {
109 		mdb_printf("%0?p\n", addr);
110 		return (DCMD_OK);
111 	}
112 
113 	if (mdb_vread(&pg_class, sizeof (struct pg_class),
114 		(uintptr_t)pg.pg_class) == -1) {
115 		mdb_warn("unable to read 'pg_class' at %p", pg.pg_class);
116 		return (DCMD_ERR);
117 	}
118 
119 	if (pg.pg_relation == PGR_PHYSICAL) {
120 		if (mdb_vread(&pghw, sizeof (struct pghw), addr) == -1) {
121 			mdb_warn("unable to read 'pghw' at %p", addr);
122 			return (DCMD_ERR);
123 		}
124 		/*
125 		 * Display the physical PG info.
126 		 */
127 		mdb_printf("%6d %?p %6d %7s %9s %5d\n",
128 		    pg.pg_id, addr, pghw.pghw_instance,
129 		    pg_class.pgc_name, pg_hw_name(pghw.pghw_hw),
130 		    pg.pg_cpus.grp_size);
131 	} else {
132 		/*
133 		 * Display the basic PG info.
134 		 */
135 		mdb_printf("%6d %?p %7s %5d\n",
136 		    pg.pg_id, addr, pg_class.pgc_name,
137 		    pg.pg_cpus.grp_size);
138 	}
139 
140 	return (DCMD_OK);
141 }
142