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