1fb2f18f8Sesaxe /*
2fb2f18f8Sesaxe * CDDL HEADER START
3fb2f18f8Sesaxe *
4fb2f18f8Sesaxe * The contents of this file are subject to the terms of the
5fb2f18f8Sesaxe * Common Development and Distribution License (the "License").
6fb2f18f8Sesaxe * You may not use this file except in compliance with the License.
7fb2f18f8Sesaxe *
8fb2f18f8Sesaxe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fb2f18f8Sesaxe * or http://www.opensolaris.org/os/licensing.
10fb2f18f8Sesaxe * See the License for the specific language governing permissions
11fb2f18f8Sesaxe * and limitations under the License.
12fb2f18f8Sesaxe *
13fb2f18f8Sesaxe * When distributing Covered Code, include this CDDL HEADER in each
14fb2f18f8Sesaxe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fb2f18f8Sesaxe * If applicable, add the following below this CDDL HEADER, with the
16fb2f18f8Sesaxe * fields enclosed by brackets "[]" replaced with your own identifying
17fb2f18f8Sesaxe * information: Portions Copyright [yyyy] [name of copyright owner]
18fb2f18f8Sesaxe *
19fb2f18f8Sesaxe * CDDL HEADER END
20fb2f18f8Sesaxe */
21fb2f18f8Sesaxe
22fb2f18f8Sesaxe /*
230e751525SEric Saxe * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24fb2f18f8Sesaxe * Use is subject to license terms.
25fb2f18f8Sesaxe */
26fb2f18f8Sesaxe
27fb2f18f8Sesaxe /*
28fb2f18f8Sesaxe * Display processor group information
29fb2f18f8Sesaxe */
30fb2f18f8Sesaxe
31fb2f18f8Sesaxe #include "pg.h"
32fb2f18f8Sesaxe
33fb2f18f8Sesaxe #include <mdb/mdb_modapi.h>
34fb2f18f8Sesaxe #include <sys/pghw.h>
350e751525SEric Saxe #include <sys/cmt.h>
36fb2f18f8Sesaxe
37fb2f18f8Sesaxe /*
38fb2f18f8Sesaxe * PG hardware types indexed by hardware ID
39fb2f18f8Sesaxe */
40fb2f18f8Sesaxe char *pg_hw_names[] = {
41fb2f18f8Sesaxe "hw",
42fb2f18f8Sesaxe "ipipe",
43fb2f18f8Sesaxe "cache",
44fb2f18f8Sesaxe "fpu",
45e853d8c3Sjc25722 "mpipe",
46e853d8c3Sjc25722 "chip",
47fb2f18f8Sesaxe "memory",
480e751525SEric Saxe "active_pwr",
490e751525SEric Saxe "idle_pwr",
50fb2f18f8Sesaxe };
51fb2f18f8Sesaxe
52fb2f18f8Sesaxe #define A_CNT(arr) (sizeof (arr) / sizeof (arr[0]))
53fb2f18f8Sesaxe
54fb2f18f8Sesaxe #define NHW A_CNT(pg_hw_names)
55fb2f18f8Sesaxe
56fb2f18f8Sesaxe /*
57fb2f18f8Sesaxe * Convert HW id to symbolic name
58fb2f18f8Sesaxe */
59fb2f18f8Sesaxe static char *
pg_hw_name(int hw)60fb2f18f8Sesaxe pg_hw_name(int hw)
61fb2f18f8Sesaxe {
62fb2f18f8Sesaxe return ((hw < 0 || hw > NHW) ? "UNKNOWN" : pg_hw_names[hw]);
63fb2f18f8Sesaxe }
64fb2f18f8Sesaxe
65fb2f18f8Sesaxe /*
66fb2f18f8Sesaxe * Display processor group.
67fb2f18f8Sesaxe */
68fb2f18f8Sesaxe /* ARGSUSED */
69fb2f18f8Sesaxe int
pg(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)70fb2f18f8Sesaxe pg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
71fb2f18f8Sesaxe {
72fb2f18f8Sesaxe pg_t pg;
73fb2f18f8Sesaxe pghw_t pghw;
740e751525SEric Saxe pg_cmt_t pg_cmt;
75fb2f18f8Sesaxe pg_class_t pg_class;
76fb2f18f8Sesaxe int opt_q = 0; /* display only address. */
770e751525SEric Saxe int is_cmt = 0; /* This is CMT pg */
78fb2f18f8Sesaxe
79fb2f18f8Sesaxe /* Should provide an address */
80fb2f18f8Sesaxe if (! (flags & DCMD_ADDRSPEC))
81fb2f18f8Sesaxe return (DCMD_USAGE);
82fb2f18f8Sesaxe
83fb2f18f8Sesaxe if (mdb_getopts(argc, argv,
84fb2f18f8Sesaxe 'q', MDB_OPT_SETBITS, TRUE, &opt_q,
85fb2f18f8Sesaxe NULL) != argc)
86fb2f18f8Sesaxe return (DCMD_USAGE);
87fb2f18f8Sesaxe
88fb2f18f8Sesaxe if (flags & DCMD_PIPE_OUT)
89fb2f18f8Sesaxe opt_q = B_TRUE;
90fb2f18f8Sesaxe
91fb2f18f8Sesaxe if (DCMD_HDRSPEC(flags) && !opt_q) {
920e751525SEric Saxe mdb_printf("%6s %?s %6s %7s %11s %5s %5s\n",
93fb2f18f8Sesaxe "PGID",
94fb2f18f8Sesaxe "ADDR",
95fb2f18f8Sesaxe "PHYSID",
96fb2f18f8Sesaxe "CLASS",
97fb2f18f8Sesaxe "HARDWARE",
980e751525SEric Saxe "#CPUs",
990e751525SEric Saxe "LOAD");
100fb2f18f8Sesaxe }
101fb2f18f8Sesaxe
102fb2f18f8Sesaxe /*
103fb2f18f8Sesaxe * Read pg at specified address
104fb2f18f8Sesaxe */
105fb2f18f8Sesaxe if (mdb_vread(&pg, sizeof (struct pg), addr) == -1) {
106fb2f18f8Sesaxe mdb_warn("unable to read 'pg' at %p", addr);
107fb2f18f8Sesaxe return (DCMD_ERR);
108fb2f18f8Sesaxe }
109fb2f18f8Sesaxe
110fb2f18f8Sesaxe /*
111fb2f18f8Sesaxe * In quiet mode just print pg address
112fb2f18f8Sesaxe */
113fb2f18f8Sesaxe if (opt_q) {
114fb2f18f8Sesaxe mdb_printf("%0?p\n", addr);
115fb2f18f8Sesaxe return (DCMD_OK);
116fb2f18f8Sesaxe }
117fb2f18f8Sesaxe
118*c0a3d87bSRafael Vanoni if (mdb_vread(&pg_class, sizeof (struct pg_class),
119*c0a3d87bSRafael Vanoni (uintptr_t)pg.pg_class) == -1) {
120*c0a3d87bSRafael Vanoni mdb_warn("unable to read 'pg_class' at %p", pg.pg_class);
121*c0a3d87bSRafael Vanoni return (DCMD_ERR);
122*c0a3d87bSRafael Vanoni }
123*c0a3d87bSRafael Vanoni
1240e751525SEric Saxe if (strcmp(pg_class.pgc_name, "cmt") == 0) {
1250e751525SEric Saxe if (mdb_vread(&pg_cmt, sizeof (pg_cmt_t), addr) == -1) {
1260e751525SEric Saxe mdb_warn("unable to read 'cmt pg' at %p", addr);
1270e751525SEric Saxe return (DCMD_ERR);
1280e751525SEric Saxe }
1290e751525SEric Saxe is_cmt = 1;
1300e751525SEric Saxe }
1310e751525SEric Saxe
132fb2f18f8Sesaxe if (pg.pg_relation == PGR_PHYSICAL) {
133fb2f18f8Sesaxe if (mdb_vread(&pghw, sizeof (struct pghw), addr) == -1) {
134fb2f18f8Sesaxe mdb_warn("unable to read 'pghw' at %p", addr);
135fb2f18f8Sesaxe return (DCMD_ERR);
136fb2f18f8Sesaxe }
137fb2f18f8Sesaxe /*
138fb2f18f8Sesaxe * Display the physical PG info.
139fb2f18f8Sesaxe */
1400e751525SEric Saxe mdb_printf("%6d %?p %6d %7s %11s %5d %5d\n",
141fb2f18f8Sesaxe pg.pg_id, addr, pghw.pghw_instance,
142fb2f18f8Sesaxe pg_class.pgc_name, pg_hw_name(pghw.pghw_hw),
1430e751525SEric Saxe pg.pg_cpus.grp_size,
1440e751525SEric Saxe is_cmt ? pg_cmt.cmt_utilization : 0);
145fb2f18f8Sesaxe } else {
146fb2f18f8Sesaxe /*
147fb2f18f8Sesaxe * Display the basic PG info.
148fb2f18f8Sesaxe */
149fb2f18f8Sesaxe mdb_printf("%6d %?p %7s %5d\n",
150fb2f18f8Sesaxe pg.pg_id, addr, pg_class.pgc_name,
151fb2f18f8Sesaxe pg.pg_cpus.grp_size);
152fb2f18f8Sesaxe }
153fb2f18f8Sesaxe
154fb2f18f8Sesaxe return (DCMD_OK);
155fb2f18f8Sesaxe }
156