xref: /titanic_41/usr/src/cmd/mdb/common/modules/genunix/pg.c (revision f52e84dfce89ba2ea0ebb6a191b4466da3012efd)
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",
47 	"chip",
48 	"memory",
49 };
50 
51 #define	A_CNT(arr)	(sizeof (arr) / sizeof (arr[0]))
52 
53 #define	NHW	 A_CNT(pg_hw_names)
54 
55 /*
56  * Convert HW id to symbolic name
57  */
58 static char *
59 pg_hw_name(int hw)
60 {
61 	return ((hw < 0 || hw > NHW) ? "UNKNOWN" : pg_hw_names[hw]);
62 }
63 
64 /*
65  * Display processor group.
66  */
67 /* ARGSUSED */
68 int
69 pg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
70 {
71 	pg_t		pg;
72 	pghw_t		pghw;
73 	pg_class_t	pg_class;
74 	int		opt_q = 0; /* display only address. */
75 
76 	/* Should provide an address */
77 	if (! (flags & DCMD_ADDRSPEC))
78 		return (DCMD_USAGE);
79 
80 	if (mdb_getopts(argc, argv,
81 	    'q', MDB_OPT_SETBITS, TRUE, &opt_q,
82 	    NULL) != argc)
83 		return (DCMD_USAGE);
84 
85 	if (flags & DCMD_PIPE_OUT)
86 		opt_q = B_TRUE;
87 
88 	if (DCMD_HDRSPEC(flags) && !opt_q) {
89 		mdb_printf("%6s %?s %6s %7s %9s %5s\n",
90 		    "PGID",
91 		    "ADDR",
92 		    "PHYSID",
93 		    "CLASS",
94 		    "HARDWARE",
95 		    "#CPUs");
96 	}
97 
98 	/*
99 	 * Read pg at specified address
100 	 */
101 	if (mdb_vread(&pg, sizeof (struct pg), addr) == -1) {
102 		mdb_warn("unable to read 'pg' at %p", addr);
103 		return (DCMD_ERR);
104 	}
105 
106 	/*
107 	 * In quiet mode just print pg address
108 	 */
109 	if (opt_q) {
110 		mdb_printf("%0?p\n", addr);
111 		return (DCMD_OK);
112 	}
113 
114 	if (mdb_vread(&pg_class, sizeof (struct pg_class),
115 	    (uintptr_t)pg.pg_class) == -1) {
116 		mdb_warn("unable to read 'pg_class' at %p", pg.pg_class);
117 		return (DCMD_ERR);
118 	}
119 
120 	if (pg.pg_relation == PGR_PHYSICAL) {
121 		if (mdb_vread(&pghw, sizeof (struct pghw), addr) == -1) {
122 			mdb_warn("unable to read 'pghw' at %p", addr);
123 			return (DCMD_ERR);
124 		}
125 		/*
126 		 * Display the physical PG info.
127 		 */
128 		mdb_printf("%6d %?p %6d %7s %9s %5d\n",
129 		    pg.pg_id, addr, pghw.pghw_instance,
130 		    pg_class.pgc_name, pg_hw_name(pghw.pghw_hw),
131 		    pg.pg_cpus.grp_size);
132 	} else {
133 		/*
134 		 * Display the basic PG info.
135 		 */
136 		mdb_printf("%6d %?p %7s %5d\n",
137 		    pg.pg_id, addr, pg_class.pgc_name,
138 		    pg.pg_cpus.grp_size);
139 	}
140 
141 	return (DCMD_OK);
142 }
143