xref: /titanic_54/usr/src/uts/common/sys/pg.h (revision fb2f18f820d90b001aea4fb27dd654bc1263c440)
1*fb2f18f8Sesaxe /*
2*fb2f18f8Sesaxe  * CDDL HEADER START
3*fb2f18f8Sesaxe  *
4*fb2f18f8Sesaxe  * The contents of this file are subject to the terms of the
5*fb2f18f8Sesaxe  * Common Development and Distribution License (the "License").
6*fb2f18f8Sesaxe  * You may not use this file except in compliance with the License.
7*fb2f18f8Sesaxe  *
8*fb2f18f8Sesaxe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fb2f18f8Sesaxe  * or http://www.opensolaris.org/os/licensing.
10*fb2f18f8Sesaxe  * See the License for the specific language governing permissions
11*fb2f18f8Sesaxe  * and limitations under the License.
12*fb2f18f8Sesaxe  *
13*fb2f18f8Sesaxe  * When distributing Covered Code, include this CDDL HEADER in each
14*fb2f18f8Sesaxe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fb2f18f8Sesaxe  * If applicable, add the following below this CDDL HEADER, with the
16*fb2f18f8Sesaxe  * fields enclosed by brackets "[]" replaced with your own identifying
17*fb2f18f8Sesaxe  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fb2f18f8Sesaxe  *
19*fb2f18f8Sesaxe  * CDDL HEADER END
20*fb2f18f8Sesaxe  */
21*fb2f18f8Sesaxe /*
22*fb2f18f8Sesaxe  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*fb2f18f8Sesaxe  * Use is subject to license terms.
24*fb2f18f8Sesaxe  */
25*fb2f18f8Sesaxe 
26*fb2f18f8Sesaxe #ifndef	_PG_H
27*fb2f18f8Sesaxe #define	_PG_H
28*fb2f18f8Sesaxe 
29*fb2f18f8Sesaxe #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*fb2f18f8Sesaxe 
31*fb2f18f8Sesaxe /*
32*fb2f18f8Sesaxe  * Processor Groups
33*fb2f18f8Sesaxe  */
34*fb2f18f8Sesaxe 
35*fb2f18f8Sesaxe #ifdef	__cplusplus
36*fb2f18f8Sesaxe extern "C" {
37*fb2f18f8Sesaxe #endif
38*fb2f18f8Sesaxe 
39*fb2f18f8Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER))
40*fb2f18f8Sesaxe #include <sys/cpuvar.h>
41*fb2f18f8Sesaxe #include <sys/group.h>
42*fb2f18f8Sesaxe #include <sys/processor.h>
43*fb2f18f8Sesaxe #include <sys/bitset.h>
44*fb2f18f8Sesaxe #include <sys/atomic.h>
45*fb2f18f8Sesaxe #include <sys/types.h>
46*fb2f18f8Sesaxe #include <sys/kstat.h>
47*fb2f18f8Sesaxe 
48*fb2f18f8Sesaxe typedef uint_t		pgid_t;		/* processor group id */
49*fb2f18f8Sesaxe typedef uint_t		pg_cid_t;	/* processor group class id */
50*fb2f18f8Sesaxe 
51*fb2f18f8Sesaxe /*
52*fb2f18f8Sesaxe  * Nature of CPU relationships
53*fb2f18f8Sesaxe  */
54*fb2f18f8Sesaxe typedef enum pg_relation {
55*fb2f18f8Sesaxe 	PGR_LOGICAL,
56*fb2f18f8Sesaxe 	PGR_PHYSICAL
57*fb2f18f8Sesaxe } pg_relation_t;
58*fb2f18f8Sesaxe 
59*fb2f18f8Sesaxe /*
60*fb2f18f8Sesaxe  * Processor group structure
61*fb2f18f8Sesaxe  */
62*fb2f18f8Sesaxe typedef struct pg {
63*fb2f18f8Sesaxe 	pgid_t		pg_id;		/* seq id */
64*fb2f18f8Sesaxe 	pg_relation_t	pg_relation;	/* grouping relationship */
65*fb2f18f8Sesaxe 	struct pg_class	*pg_class;	/* pg class */
66*fb2f18f8Sesaxe 	struct group	pg_cpus;	/* group of CPUs */
67*fb2f18f8Sesaxe } pg_t;
68*fb2f18f8Sesaxe 
69*fb2f18f8Sesaxe /*
70*fb2f18f8Sesaxe  * PG class callbacks
71*fb2f18f8Sesaxe  */
72*fb2f18f8Sesaxe struct pg_ops {
73*fb2f18f8Sesaxe 	struct pg	*(*alloc)();
74*fb2f18f8Sesaxe 	void		(*free)(struct pg *);
75*fb2f18f8Sesaxe 	void		(*cpu_init)(struct cpu *);
76*fb2f18f8Sesaxe 	void		(*cpu_fini)(struct cpu *);
77*fb2f18f8Sesaxe 	void		(*cpu_active)(struct cpu *);
78*fb2f18f8Sesaxe 	void		(*cpu_inactive)(struct cpu *);
79*fb2f18f8Sesaxe 	void		(*cpupart_in)(struct cpu *, struct cpupart *);
80*fb2f18f8Sesaxe 	void		(*cpupart_out)(struct cpu *, struct cpupart *);
81*fb2f18f8Sesaxe 	void		(*cpupart_move)(struct cpu *, struct cpupart *,
82*fb2f18f8Sesaxe 			    struct cpupart *);
83*fb2f18f8Sesaxe 	int		(*cpu_belongs)(struct pg *, struct cpu *);
84*fb2f18f8Sesaxe };
85*fb2f18f8Sesaxe 
86*fb2f18f8Sesaxe #define	PG_CLASS_NAME_MAX 32
87*fb2f18f8Sesaxe 
88*fb2f18f8Sesaxe /*
89*fb2f18f8Sesaxe  * PG class structure
90*fb2f18f8Sesaxe  */
91*fb2f18f8Sesaxe typedef struct pg_class {
92*fb2f18f8Sesaxe 	pg_cid_t	pgc_id;
93*fb2f18f8Sesaxe 	char		pgc_name[PG_CLASS_NAME_MAX];
94*fb2f18f8Sesaxe 	struct pg_ops	*pgc_ops;
95*fb2f18f8Sesaxe 	pg_relation_t	pgc_relation;
96*fb2f18f8Sesaxe } pg_class_t;
97*fb2f18f8Sesaxe 
98*fb2f18f8Sesaxe /*
99*fb2f18f8Sesaxe  * Per CPU processor group data
100*fb2f18f8Sesaxe  */
101*fb2f18f8Sesaxe typedef struct cpu_pg {
102*fb2f18f8Sesaxe 	struct group	pgs;		/* All the CPU's PGs */
103*fb2f18f8Sesaxe 	struct group	cmt_pgs;	/* CMT load balancing lineage */
104*fb2f18f8Sesaxe 					/* (Group hierarchy ordered) */
105*fb2f18f8Sesaxe 	struct pg	*cmt_lineage;	/* Ascending lineage chain */
106*fb2f18f8Sesaxe } cpu_pg_t;
107*fb2f18f8Sesaxe 
108*fb2f18f8Sesaxe /*
109*fb2f18f8Sesaxe  * PG cpu iterator cookie
110*fb2f18f8Sesaxe  */
111*fb2f18f8Sesaxe typedef struct	pg_cpu_itr {
112*fb2f18f8Sesaxe 	pg_t		*pg;
113*fb2f18f8Sesaxe 	group_iter_t	position;
114*fb2f18f8Sesaxe } pg_cpu_itr_t;
115*fb2f18f8Sesaxe 
116*fb2f18f8Sesaxe /*
117*fb2f18f8Sesaxe  * Initialize a PG CPU iterator cookie
118*fb2f18f8Sesaxe  */
119*fb2f18f8Sesaxe #define	PG_CPU_ITR_INIT(pgrp, itr)		\
120*fb2f18f8Sesaxe {						\
121*fb2f18f8Sesaxe 	group_iter_init(&(itr).position);	\
122*fb2f18f8Sesaxe 	(itr).pg = ((pg_t *)pgrp);		\
123*fb2f18f8Sesaxe }
124*fb2f18f8Sesaxe 
125*fb2f18f8Sesaxe /*
126*fb2f18f8Sesaxe  * Return the first CPU in a PG
127*fb2f18f8Sesaxe  */
128*fb2f18f8Sesaxe #define	PG_CPU_GET_FIRST(pgrp)			\
129*fb2f18f8Sesaxe 	(GROUP_SIZE(&((pg_t *)pgrp)->pg_cpus) > 0 ?	\
130*fb2f18f8Sesaxe 	    GROUP_ACCESS(&((pg_t *)pgrp)->pg_cpus, 0) : NULL)
131*fb2f18f8Sesaxe 
132*fb2f18f8Sesaxe /*
133*fb2f18f8Sesaxe  * Framework routines
134*fb2f18f8Sesaxe  */
135*fb2f18f8Sesaxe void		pg_init(void);
136*fb2f18f8Sesaxe pg_cid_t	pg_class_register(char *, struct pg_ops *, pg_relation_t);
137*fb2f18f8Sesaxe 
138*fb2f18f8Sesaxe /*
139*fb2f18f8Sesaxe  * PG CPU reconfiguration hooks
140*fb2f18f8Sesaxe  */
141*fb2f18f8Sesaxe void		pg_cpu0_init(void);
142*fb2f18f8Sesaxe void		pg_cpu_init(cpu_t *);
143*fb2f18f8Sesaxe void		pg_cpu_fini(cpu_t *);
144*fb2f18f8Sesaxe void		pg_cpu_active(cpu_t *);
145*fb2f18f8Sesaxe void		pg_cpu_inactive(cpu_t *);
146*fb2f18f8Sesaxe void		pg_cpu_startup(cpu_t *);
147*fb2f18f8Sesaxe void		pg_cpu_bootstrap(cpu_t *);
148*fb2f18f8Sesaxe 
149*fb2f18f8Sesaxe /*
150*fb2f18f8Sesaxe  * PG cpupart service hooks
151*fb2f18f8Sesaxe  */
152*fb2f18f8Sesaxe void		pg_cpupart_in(cpu_t *, struct cpupart *);
153*fb2f18f8Sesaxe void		pg_cpupart_out(cpu_t *, struct cpupart *);
154*fb2f18f8Sesaxe void		pg_cpupart_move(cpu_t *, struct cpupart *, struct cpupart *);
155*fb2f18f8Sesaxe 
156*fb2f18f8Sesaxe /*
157*fb2f18f8Sesaxe  * PG CPU utility routines
158*fb2f18f8Sesaxe  */
159*fb2f18f8Sesaxe pg_t		*pg_create(pg_cid_t);
160*fb2f18f8Sesaxe void		pg_destroy(pg_t *);
161*fb2f18f8Sesaxe void		pg_cpu_add(pg_t *, cpu_t *);
162*fb2f18f8Sesaxe void		pg_cpu_delete(pg_t *, cpu_t *);
163*fb2f18f8Sesaxe pg_t		*pg_cpu_find_pg(cpu_t *, group_t *);
164*fb2f18f8Sesaxe cpu_t		*pg_cpu_next(pg_cpu_itr_t *);
165*fb2f18f8Sesaxe 
166*fb2f18f8Sesaxe 
167*fb2f18f8Sesaxe #endif	/* !_KERNEL && !_KMEMUSER */
168*fb2f18f8Sesaxe 
169*fb2f18f8Sesaxe #ifdef	__cplusplus
170*fb2f18f8Sesaxe }
171*fb2f18f8Sesaxe #endif
172*fb2f18f8Sesaxe 
173*fb2f18f8Sesaxe #endif /* _PG_H */
174