xref: /titanic_54/usr/src/uts/common/os/pghw.c (revision e853d8c363bb48f997502f6e034877de20256ab0)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23fb2f18f8Sesaxe  * Use is subject to license terms.
24fb2f18f8Sesaxe  */
25fb2f18f8Sesaxe 
26fb2f18f8Sesaxe #pragma ident	"%Z%%M%	%I%	%E% SMI"
27fb2f18f8Sesaxe 
28fb2f18f8Sesaxe #include <sys/systm.h>
29fb2f18f8Sesaxe #include <sys/types.h>
30fb2f18f8Sesaxe #include <sys/param.h>
31fb2f18f8Sesaxe #include <sys/thread.h>
32fb2f18f8Sesaxe #include <sys/cpuvar.h>
33fb2f18f8Sesaxe #include <sys/kmem.h>
34fb2f18f8Sesaxe #include <sys/cmn_err.h>
35fb2f18f8Sesaxe #include <sys/group.h>
36fb2f18f8Sesaxe #include <sys/pg.h>
37fb2f18f8Sesaxe #include <sys/pghw.h>
38fb2f18f8Sesaxe 
39fb2f18f8Sesaxe /*
40fb2f18f8Sesaxe  * Processor Groups: Hardware sharing relationship layer
41fb2f18f8Sesaxe  *
42fb2f18f8Sesaxe  * This file implements an extension to Processor Groups to capture
43fb2f18f8Sesaxe  * hardware sharing relationships existing between logical CPUs. Examples of
44fb2f18f8Sesaxe  * hardware sharing relationships include shared caches on some CMT
45fb2f18f8Sesaxe  * procesoor architectures, or shared local memory controllers on NUMA
46fb2f18f8Sesaxe  * based system architectures.
47fb2f18f8Sesaxe  *
48fb2f18f8Sesaxe  * The pghw_t structure represents the extended PG. The first member
49fb2f18f8Sesaxe  * of the structure is the generic pg_t with the pghw specific members
50fb2f18f8Sesaxe  * following. The generic pg_t *must* remain the first member of the
51fb2f18f8Sesaxe  * structure as the code uses casting of structure references to access
52fb2f18f8Sesaxe  * the generic pg_t structure elements.
53fb2f18f8Sesaxe  *
54fb2f18f8Sesaxe  * In addition to the generic CPU grouping, physical PGs have a hardware
55fb2f18f8Sesaxe  * sharing relationship enumerated "type", and an instance id. The enumerated
56fb2f18f8Sesaxe  * type is defined by the pghw_type_t enumeration, while the instance id
57fb2f18f8Sesaxe  * uniquely identifies the sharing instance from among others of the same
58fb2f18f8Sesaxe  * hardware sharing type.
59fb2f18f8Sesaxe  *
60fb2f18f8Sesaxe  * The physical PGs are organized into an overall hierarchy, and are tracked
61fb2f18f8Sesaxe  * in a number of different per CPU, and per pghw_type_t type groups.
62fb2f18f8Sesaxe  * As an example:
63fb2f18f8Sesaxe  *
64fb2f18f8Sesaxe  * -------------
65fb2f18f8Sesaxe  * | pg_hw     |
66fb2f18f8Sesaxe  * | (group_t) |
67fb2f18f8Sesaxe  * -------------
68fb2f18f8Sesaxe  *  ||                          ============================
69fb2f18f8Sesaxe  *  ||\\-----------------------//       \\                 \\
70fb2f18f8Sesaxe  *  ||  | hwset (PGC_HW_CHIP) |        -------------      -------------
71fb2f18f8Sesaxe  *  ||  | (group_t)           |        | pghw_t    |      | pghw_t    |
72fb2f18f8Sesaxe  *  ||  -----------------------        | chip 0    |      | chip 1    |
73fb2f18f8Sesaxe  *  ||                                 -------------      -------------
74fb2f18f8Sesaxe  *  ||                                 \\  \\  \\  \\     \\  \\  \\  \\
75fb2f18f8Sesaxe  *  ||                                  cpu cpu cpu cpu    cpu cpu cpu cpu
76fb2f18f8Sesaxe  *  ||
77fb2f18f8Sesaxe  *  ||                          ============================
78fb2f18f8Sesaxe  *  ||\\-----------------------//       \\                 \\
79fb2f18f8Sesaxe  *  ||  | hwset (PGC_HW_IPIPE)|        -------------      -------------
80fb2f18f8Sesaxe  *  ||  | (group_t)           |        | pghw_t    |      | pghw_t    |
81fb2f18f8Sesaxe  *  ||  -----------------------        | ipipe 0   |      | ipipe 1   |
82fb2f18f8Sesaxe  *  ||                                 -------------      -------------
83fb2f18f8Sesaxe  *  ||                                 \\  \\             \\  \\
84fb2f18f8Sesaxe  *  ||                                  cpu cpu            cpu cpu
85fb2f18f8Sesaxe  *  ...
86fb2f18f8Sesaxe  *
87fb2f18f8Sesaxe  *
88fb2f18f8Sesaxe  * The top level pg_hw is a group of "hwset" groups. Each hwset holds of group
89fb2f18f8Sesaxe  * of physical PGs of the same hardware sharing type. Within each hwset, the
90fb2f18f8Sesaxe  * PG's instance id uniquely identifies the grouping relationshsip among other
91fb2f18f8Sesaxe  * groupings of the same sharing type. The instance id for a grouping is
92fb2f18f8Sesaxe  * platform defined, and in some cases may be used by platform code as a handle
93fb2f18f8Sesaxe  * to search for a particular relationship instance.
94fb2f18f8Sesaxe  *
95fb2f18f8Sesaxe  * Each physical PG (by virtue of the embedded pg_t) contains a group of CPUs
96fb2f18f8Sesaxe  * that participate in the sharing relationship. Each CPU also has associated
97fb2f18f8Sesaxe  * with it a grouping tracking the PGs in which the CPU belongs. This can be
98fb2f18f8Sesaxe  * used to iterate over the various relationships in which the CPU participates
99fb2f18f8Sesaxe  * (the CPU's chip, cache, lgroup, etc.).
100fb2f18f8Sesaxe  *
101fb2f18f8Sesaxe  * The hwsets are created dynamically as new hardware sharing relationship types
102fb2f18f8Sesaxe  * are instantiated. They are never destroyed, as once a given relathionship
103fb2f18f8Sesaxe  * type appears in the system, it is quite likely that at least one instance of
104fb2f18f8Sesaxe  * that relationship will always persist as long as the system is running.
105fb2f18f8Sesaxe  */
106fb2f18f8Sesaxe 
107fb2f18f8Sesaxe static group_t		*pg_hw;		/* top level pg hw group */
108fb2f18f8Sesaxe 
109fb2f18f8Sesaxe /*
110fb2f18f8Sesaxe  * Lookup table mapping hardware sharing relationships with hierarchy levels
111fb2f18f8Sesaxe  */
112fb2f18f8Sesaxe static int		pghw_level_table[PGHW_NUM_COMPONENTS];
113fb2f18f8Sesaxe 
114fb2f18f8Sesaxe /*
115fb2f18f8Sesaxe  * Physical PG kstats
116fb2f18f8Sesaxe  */
117fb2f18f8Sesaxe struct pghw_kstat {
118fb2f18f8Sesaxe 	kstat_named_t	pg_id;
119fb2f18f8Sesaxe 	kstat_named_t	pg_class;
120fb2f18f8Sesaxe 	kstat_named_t	pg_ncpus;
121fb2f18f8Sesaxe 	kstat_named_t	pg_instance_id;
122fb2f18f8Sesaxe 	kstat_named_t	pg_hw;
123fb2f18f8Sesaxe } pghw_kstat = {
124fb2f18f8Sesaxe 	{ "id",			KSTAT_DATA_UINT64 },
125fb2f18f8Sesaxe 	{ "pg_class",		KSTAT_DATA_STRING },
126fb2f18f8Sesaxe 	{ "ncpus",		KSTAT_DATA_UINT64 },
127fb2f18f8Sesaxe 	{ "instance_id",	KSTAT_DATA_UINT64 },
128fb2f18f8Sesaxe 	{ "hardware",		KSTAT_DATA_STRING },
129fb2f18f8Sesaxe };
130fb2f18f8Sesaxe 
131fb2f18f8Sesaxe kmutex_t		pghw_kstat_lock;
132fb2f18f8Sesaxe 
133fb2f18f8Sesaxe /*
134fb2f18f8Sesaxe  * hwset operations
135fb2f18f8Sesaxe  */
136fb2f18f8Sesaxe static group_t		*pghw_set_create(pghw_type_t);
137fb2f18f8Sesaxe static void		pghw_set_add(group_t *, pghw_t *);
138fb2f18f8Sesaxe static void		pghw_set_remove(group_t *, pghw_t *);
139fb2f18f8Sesaxe 
140fb2f18f8Sesaxe /*
141fb2f18f8Sesaxe  * Initialize the physical portion of a physical PG
142fb2f18f8Sesaxe  */
143fb2f18f8Sesaxe void
144fb2f18f8Sesaxe pghw_init(pghw_t *pg, cpu_t *cp, pghw_type_t hw)
145fb2f18f8Sesaxe {
146fb2f18f8Sesaxe 	group_t		*hwset;
147fb2f18f8Sesaxe 
148fb2f18f8Sesaxe 	if ((hwset = pghw_set_lookup(hw)) == NULL) {
149fb2f18f8Sesaxe 		/*
150fb2f18f8Sesaxe 		 * Haven't seen this hardware type yet
151fb2f18f8Sesaxe 		 */
152fb2f18f8Sesaxe 		hwset = pghw_set_create(hw);
153fb2f18f8Sesaxe 	}
154fb2f18f8Sesaxe 
155fb2f18f8Sesaxe 	pghw_set_add(hwset, pg);
156fb2f18f8Sesaxe 	pg->pghw_hw = hw;
157fb2f18f8Sesaxe 	pg->pghw_instance =
158fb2f18f8Sesaxe 	    pg_plat_hw_instance_id(cp, hw);
159fb2f18f8Sesaxe 	pghw_kstat_create(pg);
160fb2f18f8Sesaxe }
161fb2f18f8Sesaxe 
162fb2f18f8Sesaxe /*
163fb2f18f8Sesaxe  * Teardown the physical portion of a physical PG
164fb2f18f8Sesaxe  */
165fb2f18f8Sesaxe void
166fb2f18f8Sesaxe pghw_fini(pghw_t *pg)
167fb2f18f8Sesaxe {
168fb2f18f8Sesaxe 	group_t		*hwset;
169fb2f18f8Sesaxe 
170fb2f18f8Sesaxe 	hwset = pghw_set_lookup(pg->pghw_hw);
171fb2f18f8Sesaxe 	ASSERT(hwset != NULL);
172fb2f18f8Sesaxe 
173fb2f18f8Sesaxe 	pghw_set_remove(hwset, pg);
174fb2f18f8Sesaxe 	pg->pghw_instance = (id_t)PGHW_INSTANCE_ANON;
175fb2f18f8Sesaxe 	pg->pghw_hw = (pghw_type_t)-1;
176fb2f18f8Sesaxe 
177fb2f18f8Sesaxe 	if (pg->pghw_kstat)
178fb2f18f8Sesaxe 		kstat_delete(pg->pghw_kstat);
179fb2f18f8Sesaxe }
180fb2f18f8Sesaxe 
181fb2f18f8Sesaxe /*
182fb2f18f8Sesaxe  * Find an existing physical PG in which to place
183fb2f18f8Sesaxe  * the given CPU for the specified hardware sharing
184fb2f18f8Sesaxe  * relationship
185fb2f18f8Sesaxe  */
186fb2f18f8Sesaxe pghw_t *
187fb2f18f8Sesaxe pghw_place_cpu(cpu_t *cp, pghw_type_t hw)
188fb2f18f8Sesaxe {
189fb2f18f8Sesaxe 	group_t		*hwset;
190fb2f18f8Sesaxe 
191fb2f18f8Sesaxe 	if ((hwset = pghw_set_lookup(hw)) == NULL) {
192fb2f18f8Sesaxe 		return (NULL);
193fb2f18f8Sesaxe 	}
194fb2f18f8Sesaxe 
195fb2f18f8Sesaxe 	return ((pghw_t *)pg_cpu_find_pg(cp, hwset));
196fb2f18f8Sesaxe }
197fb2f18f8Sesaxe 
198fb2f18f8Sesaxe /*
199fb2f18f8Sesaxe  * Find the pg representing the hw sharing relationship in which
200fb2f18f8Sesaxe  * cp belongs
201fb2f18f8Sesaxe  */
202fb2f18f8Sesaxe pghw_t *
203fb2f18f8Sesaxe pghw_find_pg(cpu_t *cp, pghw_type_t hw)
204fb2f18f8Sesaxe {
205fb2f18f8Sesaxe 	group_iter_t	i;
206fb2f18f8Sesaxe 	pghw_t	*pg;
207fb2f18f8Sesaxe 
208fb2f18f8Sesaxe 	group_iter_init(&i);
209fb2f18f8Sesaxe 	while ((pg = group_iterate(&cp->cpu_pg->pgs, &i)) != NULL) {
210fb2f18f8Sesaxe 		if (pg->pghw_hw == hw)
211fb2f18f8Sesaxe 			return (pg);
212fb2f18f8Sesaxe 	}
213fb2f18f8Sesaxe 	return (NULL);
214fb2f18f8Sesaxe }
215fb2f18f8Sesaxe 
216fb2f18f8Sesaxe /*
217fb2f18f8Sesaxe  * Find the PG of the given hardware sharing relationship
218fb2f18f8Sesaxe  * type with the given instance id
219fb2f18f8Sesaxe  */
220fb2f18f8Sesaxe pghw_t *
221fb2f18f8Sesaxe pghw_find_by_instance(id_t id, pghw_type_t hw)
222fb2f18f8Sesaxe {
223fb2f18f8Sesaxe 	group_iter_t	i;
224fb2f18f8Sesaxe 	group_t		*set;
225fb2f18f8Sesaxe 	pghw_t		*pg;
226fb2f18f8Sesaxe 
227fb2f18f8Sesaxe 	set = pghw_set_lookup(hw);
228fb2f18f8Sesaxe 	if (!set)
229fb2f18f8Sesaxe 		return (NULL);
230fb2f18f8Sesaxe 
231fb2f18f8Sesaxe 	group_iter_init(&i);
232fb2f18f8Sesaxe 	while ((pg = group_iterate(set, &i)) != NULL) {
233fb2f18f8Sesaxe 		if (pg->pghw_instance == id)
234fb2f18f8Sesaxe 			return (pg);
235fb2f18f8Sesaxe 	}
236fb2f18f8Sesaxe 	return (NULL);
237fb2f18f8Sesaxe }
238fb2f18f8Sesaxe 
239fb2f18f8Sesaxe /*
240fb2f18f8Sesaxe  * CPUs physical ID cache creation / destruction
241fb2f18f8Sesaxe  * The cache's elements are initialized to the CPU's id
242fb2f18f8Sesaxe  */
243fb2f18f8Sesaxe void
244fb2f18f8Sesaxe pghw_physid_create(cpu_t *cp)
245fb2f18f8Sesaxe {
246fb2f18f8Sesaxe 	int	i;
247fb2f18f8Sesaxe 
248fb2f18f8Sesaxe 	cp->cpu_physid = kmem_alloc(sizeof (cpu_physid_t), KM_SLEEP);
249fb2f18f8Sesaxe 
250fb2f18f8Sesaxe 	for (i = 0; i < (sizeof (cpu_physid_t) / sizeof (id_t)); i++) {
251fb2f18f8Sesaxe 		((id_t *)cp->cpu_physid)[i] = cp->cpu_id;
252fb2f18f8Sesaxe 	}
253fb2f18f8Sesaxe }
254fb2f18f8Sesaxe 
255fb2f18f8Sesaxe void
256fb2f18f8Sesaxe pghw_physid_destroy(cpu_t *cp)
257fb2f18f8Sesaxe {
258fb2f18f8Sesaxe 	if (cp->cpu_physid) {
259fb2f18f8Sesaxe 		kmem_free(cp->cpu_physid, sizeof (cpu_physid_t));
260fb2f18f8Sesaxe 		cp->cpu_physid = NULL;
261fb2f18f8Sesaxe 	}
262fb2f18f8Sesaxe }
263fb2f18f8Sesaxe 
264fb2f18f8Sesaxe /*
265fb2f18f8Sesaxe  * Return a sequential level identifier for the specified
266fb2f18f8Sesaxe  * hardware sharing relationship
267fb2f18f8Sesaxe  */
268fb2f18f8Sesaxe int
269fb2f18f8Sesaxe pghw_level(pghw_type_t hw)
270fb2f18f8Sesaxe {
271fb2f18f8Sesaxe 	return (pg_plat_hw_level(hw));
272fb2f18f8Sesaxe }
273fb2f18f8Sesaxe 
274fb2f18f8Sesaxe /*
275fb2f18f8Sesaxe  * Create a new, empty hwset.
276fb2f18f8Sesaxe  * This routine may block, and must not be called from any
277fb2f18f8Sesaxe  * paused CPU context.
278fb2f18f8Sesaxe  */
279fb2f18f8Sesaxe static group_t	*
280fb2f18f8Sesaxe pghw_set_create(pghw_type_t hw)
281fb2f18f8Sesaxe {
282fb2f18f8Sesaxe 	group_t	*g;
283fb2f18f8Sesaxe 	int	ret;
284fb2f18f8Sesaxe 
285fb2f18f8Sesaxe 	/*
286fb2f18f8Sesaxe 	 * Create the top level PG hw group if it doesn't already exist
287fb2f18f8Sesaxe 	 * This is a "set" of hardware sets, that is ordered (and indexed)
288fb2f18f8Sesaxe 	 * by the pghw_type_t enum.
289fb2f18f8Sesaxe 	 */
290fb2f18f8Sesaxe 	if (pg_hw == NULL) {
291fb2f18f8Sesaxe 		pg_hw = kmem_alloc(sizeof (group_t), KM_SLEEP);
292fb2f18f8Sesaxe 		group_create(pg_hw);
293fb2f18f8Sesaxe 		group_expand(pg_hw, (uint_t)PGHW_NUM_COMPONENTS);
294fb2f18f8Sesaxe 	}
295fb2f18f8Sesaxe 
296fb2f18f8Sesaxe 	/*
297fb2f18f8Sesaxe 	 * Create the new hwset
298fb2f18f8Sesaxe 	 * Add it to the top level pg_hw group.
299fb2f18f8Sesaxe 	 */
300fb2f18f8Sesaxe 	g = kmem_alloc(sizeof (group_t), KM_SLEEP);
301fb2f18f8Sesaxe 	group_create(g);
302fb2f18f8Sesaxe 
303fb2f18f8Sesaxe 	ret = group_add_at(pg_hw, g, (uint_t)hw);
304fb2f18f8Sesaxe 	ASSERT(ret == 0);
305fb2f18f8Sesaxe 
306fb2f18f8Sesaxe 	/*
307fb2f18f8Sesaxe 	 * Update the table that maps hardware sharing relationships
308fb2f18f8Sesaxe 	 * to hierarchy levels
309fb2f18f8Sesaxe 	 */
310fb2f18f8Sesaxe 	ASSERT(pghw_level_table[hw] == NULL);
311fb2f18f8Sesaxe 	pghw_level_table[hw] = pg_plat_hw_level(hw);
312fb2f18f8Sesaxe 
313fb2f18f8Sesaxe 	return (g);
314fb2f18f8Sesaxe }
315fb2f18f8Sesaxe 
316fb2f18f8Sesaxe /*
317fb2f18f8Sesaxe  * Find the hwset associated with the given hardware sharing type
318fb2f18f8Sesaxe  */
319fb2f18f8Sesaxe group_t *
320fb2f18f8Sesaxe pghw_set_lookup(pghw_type_t hw)
321fb2f18f8Sesaxe {
322fb2f18f8Sesaxe 	group_t	*hwset;
323fb2f18f8Sesaxe 
324fb2f18f8Sesaxe 	if (pg_hw == NULL)
325fb2f18f8Sesaxe 		return (NULL);
326fb2f18f8Sesaxe 
327fb2f18f8Sesaxe 	hwset = GROUP_ACCESS(pg_hw, (uint_t)hw);
328fb2f18f8Sesaxe 	return (hwset);
329fb2f18f8Sesaxe }
330fb2f18f8Sesaxe 
331fb2f18f8Sesaxe /*
332fb2f18f8Sesaxe  * Add a PG to a hwset
333fb2f18f8Sesaxe  */
334fb2f18f8Sesaxe static void
335fb2f18f8Sesaxe pghw_set_add(group_t *hwset, pghw_t *pg)
336fb2f18f8Sesaxe {
337fb2f18f8Sesaxe 	(void) group_add(hwset, pg, GRP_RESIZE);
338fb2f18f8Sesaxe }
339fb2f18f8Sesaxe 
340fb2f18f8Sesaxe /*
341fb2f18f8Sesaxe  * Remove a PG from a hwset
342fb2f18f8Sesaxe  */
343fb2f18f8Sesaxe static void
344fb2f18f8Sesaxe pghw_set_remove(group_t *hwset, pghw_t *pg)
345fb2f18f8Sesaxe {
346fb2f18f8Sesaxe 	int result;
347fb2f18f8Sesaxe 
348fb2f18f8Sesaxe 	result = group_remove(hwset, pg, GRP_RESIZE);
349fb2f18f8Sesaxe 	ASSERT(result == 0);
350fb2f18f8Sesaxe }
351fb2f18f8Sesaxe 
352fb2f18f8Sesaxe 
353fb2f18f8Sesaxe /*
354fb2f18f8Sesaxe  * Return a string name given a pg_hw sharing type
355fb2f18f8Sesaxe  */
356fb2f18f8Sesaxe #define	PGHW_TYPE_NAME_MAX	8
357fb2f18f8Sesaxe 
358fb2f18f8Sesaxe static char *
359fb2f18f8Sesaxe pghw_type_string(pghw_type_t hw)
360fb2f18f8Sesaxe {
361fb2f18f8Sesaxe 	switch (hw) {
362fb2f18f8Sesaxe 	case PGHW_IPIPE:
363fb2f18f8Sesaxe 		return ("ipipe");
364fb2f18f8Sesaxe 	case PGHW_CACHE:
365fb2f18f8Sesaxe 		return ("cache");
366fb2f18f8Sesaxe 	case PGHW_FPU:
367fb2f18f8Sesaxe 		return ("fpu");
368*e853d8c3Sjc25722 	case PGHW_MPIPE:
369*e853d8c3Sjc25722 		return ("mpipe");
370fb2f18f8Sesaxe 	case PGHW_CHIP:
371fb2f18f8Sesaxe 		return ("chip");
372fb2f18f8Sesaxe 	case PGHW_MEMORY:
373fb2f18f8Sesaxe 		return ("memory");
374fb2f18f8Sesaxe 	default:
375fb2f18f8Sesaxe 		return ("unknown");
376fb2f18f8Sesaxe 	}
377fb2f18f8Sesaxe }
378fb2f18f8Sesaxe 
379fb2f18f8Sesaxe /*
380fb2f18f8Sesaxe  * Create / Update routines for PG hw kstats
381fb2f18f8Sesaxe  *
382fb2f18f8Sesaxe  * It is the intention of these kstats to provide some level
383fb2f18f8Sesaxe  * of informational / debugging observability into the types
384fb2f18f8Sesaxe  * and nature of the system's detected hardware sharing relationships
385fb2f18f8Sesaxe  */
386fb2f18f8Sesaxe void
387fb2f18f8Sesaxe pghw_kstat_create(pghw_t *pg)
388fb2f18f8Sesaxe {
389fb2f18f8Sesaxe 	/*
390fb2f18f8Sesaxe 	 * Create a physical pg kstat
391fb2f18f8Sesaxe 	 */
392fb2f18f8Sesaxe 	if ((pg->pghw_kstat = kstat_create("pg", ((pg_t *)pg)->pg_id,
393fb2f18f8Sesaxe 	    "pg", "pg", KSTAT_TYPE_NAMED,
394fb2f18f8Sesaxe 	    sizeof (pghw_kstat) / sizeof (kstat_named_t),
395fb2f18f8Sesaxe 	    KSTAT_FLAG_VIRTUAL)) != NULL) {
396fb2f18f8Sesaxe 		pg->pghw_kstat->ks_data_size += PG_CLASS_NAME_MAX;
397fb2f18f8Sesaxe 		pg->pghw_kstat->ks_data_size += PGHW_TYPE_NAME_MAX;
398fb2f18f8Sesaxe 		pg->pghw_kstat->ks_lock = &pghw_kstat_lock;
399fb2f18f8Sesaxe 		pg->pghw_kstat->ks_data = &pghw_kstat;
400fb2f18f8Sesaxe 		pg->pghw_kstat->ks_update = pghw_kstat_update;
401fb2f18f8Sesaxe 		pg->pghw_kstat->ks_private = pg;
402fb2f18f8Sesaxe 		kstat_install(pg->pghw_kstat);
403fb2f18f8Sesaxe 	}
404fb2f18f8Sesaxe }
405fb2f18f8Sesaxe 
406fb2f18f8Sesaxe int
407fb2f18f8Sesaxe pghw_kstat_update(kstat_t *ksp, int rw)
408fb2f18f8Sesaxe {
409fb2f18f8Sesaxe 	struct pghw_kstat	*pgsp = &pghw_kstat;
410fb2f18f8Sesaxe 	pghw_t			*pg = ksp->ks_private;
411fb2f18f8Sesaxe 
412fb2f18f8Sesaxe 	if (rw == KSTAT_WRITE)
413fb2f18f8Sesaxe 		return (EACCES);
414fb2f18f8Sesaxe 
415fb2f18f8Sesaxe 	pgsp->pg_id.value.ui64 = ((pg_t *)pg)->pg_id;
416fb2f18f8Sesaxe 	pgsp->pg_ncpus.value.ui64 = GROUP_SIZE(&((pg_t *)pg)->pg_cpus);
417fb2f18f8Sesaxe 	pgsp->pg_instance_id.value.ui64 = (uint64_t)pg->pghw_instance;
418fb2f18f8Sesaxe 	kstat_named_setstr(&pgsp->pg_class, ((pg_t *)pg)->pg_class->pgc_name);
419fb2f18f8Sesaxe 	kstat_named_setstr(&pgsp->pg_hw, pghw_type_string(pg->pghw_hw));
420fb2f18f8Sesaxe 
421fb2f18f8Sesaxe 	return (0);
422fb2f18f8Sesaxe }
423