xref: /titanic_50/usr/src/uts/common/sys/pghw.h (revision b885580b43755ee4ea1e280b85428893d2ba9291)
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  */
218031591dSSrihari Venkatesan 
22fb2f18f8Sesaxe /*
230e751525SEric Saxe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24fb2f18f8Sesaxe  * Use is subject to license terms.
25fb2f18f8Sesaxe  */
26fb2f18f8Sesaxe 
27fb2f18f8Sesaxe #ifndef	_PGHW_H
28fb2f18f8Sesaxe #define	_PGHW_H
29fb2f18f8Sesaxe 
30fb2f18f8Sesaxe #ifdef	__cplusplus
31fb2f18f8Sesaxe extern "C" {
32fb2f18f8Sesaxe #endif
33fb2f18f8Sesaxe 
34fb2f18f8Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER))
35fb2f18f8Sesaxe #include <sys/cpuvar.h>
36fb2f18f8Sesaxe #include <sys/group.h>
37fb2f18f8Sesaxe #include <sys/processor.h>
38fb2f18f8Sesaxe #include <sys/bitmap.h>
39fb2f18f8Sesaxe #include <sys/atomic.h>
40fb2f18f8Sesaxe #include <sys/types.h>
41fb2f18f8Sesaxe #include <sys/kstat.h>
42fb2f18f8Sesaxe #include <sys/pg.h>
43fb2f18f8Sesaxe 
44fb2f18f8Sesaxe /*
45fb2f18f8Sesaxe  * Hardware that may be shared by a group of processors
46fb2f18f8Sesaxe  */
47fb2f18f8Sesaxe typedef enum pghw_type {
48fb2f18f8Sesaxe 	PGHW_START,
490e751525SEric Saxe 	PGHW_IPIPE,	/* Instruction Pipeline */
500e751525SEric Saxe 	PGHW_CACHE,	/* Cache (generally last level) */
510e751525SEric Saxe 	PGHW_FPU,	/* Floating Point Unit / Pipeline */
520e751525SEric Saxe 	PGHW_MPIPE,	/* Pipe to Memory */
530e751525SEric Saxe 	PGHW_CHIP,	/* Socket */
54fb2f18f8Sesaxe 	PGHW_MEMORY,
550e751525SEric Saxe 	PGHW_POW_ACTIVE,	/* Active Power Management Domain */
560e751525SEric Saxe 	PGHW_POW_IDLE,		/* Idle Power Management Domain */
57fb2f18f8Sesaxe 	PGHW_NUM_COMPONENTS
58fb2f18f8Sesaxe } pghw_type_t;
59fb2f18f8Sesaxe 
60fb2f18f8Sesaxe /*
618031591dSSrihari Venkatesan  * See comments in usr/src/uts/i86pc/os/cpuid.c
628031591dSSrihari Venkatesan  * for description of processor nodes
638031591dSSrihari Venkatesan  *
648031591dSSrihari Venkatesan  * From sharing point of view processor nodes are
658031591dSSrihari Venkatesan  * very similar to memory pipes, hence the #define below.
668031591dSSrihari Venkatesan  */
678031591dSSrihari Venkatesan #define	PGHW_PROCNODE	PGHW_MPIPE
688031591dSSrihari Venkatesan 
698031591dSSrihari Venkatesan /*
700e751525SEric Saxe  * Returns true if the hardware is a type of power management domain
710e751525SEric Saxe  */
720e751525SEric Saxe #define	PGHW_IS_PM_DOMAIN(hw)	\
730e751525SEric Saxe 	(hw == PGHW_POW_ACTIVE || hw == PGHW_POW_IDLE)
740e751525SEric Saxe 
750e751525SEric Saxe /*
76fb2f18f8Sesaxe  * Anonymous instance id
77fb2f18f8Sesaxe  */
78fb2f18f8Sesaxe #define	PGHW_INSTANCE_ANON ((id_t)0xdecafbad)
79fb2f18f8Sesaxe 
80fb2f18f8Sesaxe /*
810e751525SEric Saxe  * Max length of PGHW kstat strings
820e751525SEric Saxe  */
830e751525SEric Saxe #define	PGHW_KSTAT_STR_LEN_MAX	32
840e751525SEric Saxe 
850e751525SEric Saxe 
860e751525SEric Saxe /*
870e751525SEric Saxe  * Platform specific handle
880e751525SEric Saxe  */
890e751525SEric Saxe typedef uintptr_t pghw_handle_t;
900e751525SEric Saxe 
910e751525SEric Saxe /*
92*b885580bSAlexander Kolbasov  * Representation of PG hardware utilization NOTE: All the sums listed below are
93*b885580bSAlexander Kolbasov  * the sums of running total of each item for each CPU in the PG (eg.
94*b885580bSAlexander Kolbasov  * sum(utilization) is sum of running total utilization of each CPU in PG)
95*b885580bSAlexander Kolbasov  */
96*b885580bSAlexander Kolbasov typedef struct pghw_util {
97*b885580bSAlexander Kolbasov 	uint64_t	pghw_util;	/* sum(utilization) */
98*b885580bSAlexander Kolbasov 	uint64_t	pghw_rate;	/* Last observed utilization rate */
99*b885580bSAlexander Kolbasov 	uint64_t	pghw_rate_max;	/* Max observed rate (in units/sec) */
100*b885580bSAlexander Kolbasov 	hrtime_t	pghw_time_stamp; /* Timestamp of last snapshot */
101*b885580bSAlexander Kolbasov 	/*
102*b885580bSAlexander Kolbasov 	 * sum(time utilization counters on)
103*b885580bSAlexander Kolbasov 	 */
104*b885580bSAlexander Kolbasov 	hrtime_t	pghw_time_running;
105*b885580bSAlexander Kolbasov 	/*
106*b885580bSAlexander Kolbasov 	 * sum(time utilization counters off)
107*b885580bSAlexander Kolbasov 	 */
108*b885580bSAlexander Kolbasov 	hrtime_t	pghw_time_stopped;
109*b885580bSAlexander Kolbasov } pghw_util_t;
110*b885580bSAlexander Kolbasov 
111*b885580bSAlexander Kolbasov 
112*b885580bSAlexander Kolbasov /*
113fb2f18f8Sesaxe  * Processor Group (physical sharing relationship)
114fb2f18f8Sesaxe  */
115fb2f18f8Sesaxe typedef struct pghw {
116fb2f18f8Sesaxe 	pg_t		pghw_pg;	/* processor group */
117fb2f18f8Sesaxe 	pghw_type_t	pghw_hw;	/* HW sharing relationship */
118fb2f18f8Sesaxe 	id_t		pghw_instance;	/* sharing instance identifier */
1190e751525SEric Saxe 	pghw_handle_t	pghw_handle;	/* hw specific opaque handle */
120fb2f18f8Sesaxe 	kstat_t		*pghw_kstat;	/* physical kstats exported */
121*b885580bSAlexander Kolbasov 	kstat_t		*pghw_cu_kstat;  /* for capacity and utilization */
122*b885580bSAlexander Kolbasov 	/*
123*b885580bSAlexander Kolbasov 	 * pghw_generation should be updated by superclasses whenever PG changes
124*b885580bSAlexander Kolbasov 	 * significanly (e.g.  new CPUs join or leave PG).
125*b885580bSAlexander Kolbasov 	 */
126*b885580bSAlexander Kolbasov 	uint_t		pghw_generation; /* generation number */
127*b885580bSAlexander Kolbasov 
128*b885580bSAlexander Kolbasov 	/*
129*b885580bSAlexander Kolbasov 	 * The following fields are used by PGHW cu kstats
130*b885580bSAlexander Kolbasov 	 */
131*b885580bSAlexander Kolbasov 	char		*pghw_cpulist;	/* list of CPUs */
132*b885580bSAlexander Kolbasov 	size_t		pghw_cpulist_len;	/* length of the list */
133*b885580bSAlexander Kolbasov 	/*
134*b885580bSAlexander Kolbasov 	 * Generation number at kstat update time
135*b885580bSAlexander Kolbasov 	 */
136*b885580bSAlexander Kolbasov 	uint_t		pghw_kstat_gen;
137*b885580bSAlexander Kolbasov 	pghw_util_t	pghw_stats;	/* Utilization data */
138fb2f18f8Sesaxe } pghw_t;
139fb2f18f8Sesaxe 
140fb2f18f8Sesaxe /*
141fb2f18f8Sesaxe  * IDs associating a CPU with various physical hardware
142fb2f18f8Sesaxe  */
143fb2f18f8Sesaxe typedef struct cpu_physid {
144fb2f18f8Sesaxe 	id_t		cpu_chipid;	/* CPU's physical processor */
145fb2f18f8Sesaxe 	id_t		cpu_coreid;	/* CPU's physical core */
146fb2f18f8Sesaxe 	id_t		cpu_cacheid;	/* CPU's cache id */
147fb2f18f8Sesaxe } cpu_physid_t;
148fb2f18f8Sesaxe 
149fb2f18f8Sesaxe /*
150fb2f18f8Sesaxe  * Physical PG initialization / CPU service hooks
151fb2f18f8Sesaxe  */
152*b885580bSAlexander Kolbasov extern void		pghw_init(pghw_t *, cpu_t *, pghw_type_t);
153*b885580bSAlexander Kolbasov extern void		pghw_fini(pghw_t *);
154*b885580bSAlexander Kolbasov extern void		pghw_cpu_add(pghw_t *, cpu_t *);
155*b885580bSAlexander Kolbasov extern pghw_t		*pghw_place_cpu(cpu_t *, pghw_type_t);
156fb2f18f8Sesaxe 
157fb2f18f8Sesaxe /*
158fb2f18f8Sesaxe  * Physical ID cache creation / destruction
159fb2f18f8Sesaxe  */
160*b885580bSAlexander Kolbasov extern void		pghw_physid_create(cpu_t *);
161*b885580bSAlexander Kolbasov extern void		pghw_physid_destroy(cpu_t *);
162fb2f18f8Sesaxe 
163fb2f18f8Sesaxe /*
164fb2f18f8Sesaxe  * CPU / PG hardware related seach operations
165fb2f18f8Sesaxe  */
166*b885580bSAlexander Kolbasov extern pghw_t		*pghw_find_pg(cpu_t *, pghw_type_t);
167*b885580bSAlexander Kolbasov extern pghw_t		*pghw_find_by_instance(id_t, pghw_type_t);
168*b885580bSAlexander Kolbasov extern group_t		*pghw_set_lookup(pghw_type_t);
169fb2f18f8Sesaxe 
170fb2f18f8Sesaxe /* Hardware sharing relationship platform interfaces */
171*b885580bSAlexander Kolbasov extern int		pg_plat_hw_shared(cpu_t *, pghw_type_t);
172*b885580bSAlexander Kolbasov extern int		pg_plat_cpus_share(cpu_t *, cpu_t *, pghw_type_t);
173*b885580bSAlexander Kolbasov extern id_t		pg_plat_hw_instance_id(cpu_t *, pghw_type_t);
174*b885580bSAlexander Kolbasov extern pghw_type_t	pg_plat_hw_rank(pghw_type_t, pghw_type_t);
175*b885580bSAlexander Kolbasov 
176*b885580bSAlexander Kolbasov /*
177*b885580bSAlexander Kolbasov  * String representation of the hardware type
178*b885580bSAlexander Kolbasov  */
179*b885580bSAlexander Kolbasov extern char		*pghw_type_string(pghw_type_t);
180*b885580bSAlexander Kolbasov extern char		*pghw_type_shortstring(pghw_type_t);
181fb2f18f8Sesaxe 
182fb2f18f8Sesaxe /*
183fb2f18f8Sesaxe  * What comprises a "core" may vary across processor implementations,
184fb2f18f8Sesaxe  * and so the term itself is somewhat unstable. For this reason, there
185fb2f18f8Sesaxe  * is no PGHW_CORE type, but we provide an interface here to allow platforms
186fb2f18f8Sesaxe  * to express cpu <=> core mappings.
187fb2f18f8Sesaxe  */
188*b885580bSAlexander Kolbasov extern id_t		pg_plat_get_core_id(cpu_t *);
189fb2f18f8Sesaxe 
190fb2f18f8Sesaxe #endif	/* !_KERNEL && !_KMEMUSER */
191fb2f18f8Sesaxe 
192fb2f18f8Sesaxe #ifdef	__cplusplus
193fb2f18f8Sesaxe }
194fb2f18f8Sesaxe #endif
195fb2f18f8Sesaxe 
196fb2f18f8Sesaxe #endif /* _PGHW_H */
197