xref: /titanic_44/usr/src/uts/common/sys/pg.h (revision 4e942d8cd27c7f8bb80549d7c2564445f19ba4a3)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_PG_H
27 #define	_PG_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * Processor Groups
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #if (defined(_KERNEL) || defined(_KMEMUSER))
40 #include <sys/cpuvar.h>
41 #include <sys/group.h>
42 #include <sys/processor.h>
43 #include <sys/bitset.h>
44 #include <sys/atomic.h>
45 #include <sys/types.h>
46 #include <sys/kstat.h>
47 
48 typedef uint_t		pgid_t;		/* processor group id */
49 typedef uint_t		pg_cid_t;	/* processor group class id */
50 
51 /*
52  * Nature of CPU relationships
53  */
54 typedef enum pg_relation {
55 	PGR_LOGICAL,
56 	PGR_PHYSICAL
57 } pg_relation_t;
58 
59 /*
60  * Processor group structure
61  */
62 typedef struct pg {
63 	pgid_t		pg_id;		/* seq id */
64 	pg_relation_t	pg_relation;	/* grouping relationship */
65 	struct pg_class	*pg_class;	/* pg class */
66 	struct group	pg_cpus;	/* group of CPUs */
67 } pg_t;
68 
69 /*
70  * PG class callbacks
71  */
72 struct pg_ops {
73 	struct pg	*(*alloc)();
74 	void		(*free)(struct pg *);
75 	void		(*cpu_init)(struct cpu *);
76 	void		(*cpu_fini)(struct cpu *);
77 	void		(*cpu_active)(struct cpu *);
78 	void		(*cpu_inactive)(struct cpu *);
79 	void		(*cpupart_in)(struct cpu *, struct cpupart *);
80 	void		(*cpupart_out)(struct cpu *, struct cpupart *);
81 	void		(*cpupart_move)(struct cpu *, struct cpupart *,
82 			    struct cpupart *);
83 	int		(*cpu_belongs)(struct pg *, struct cpu *);
84 };
85 
86 #define	PG_CLASS_NAME_MAX 32
87 
88 /*
89  * PG class structure
90  */
91 typedef struct pg_class {
92 	pg_cid_t	pgc_id;
93 	char		pgc_name[PG_CLASS_NAME_MAX];
94 	struct pg_ops	*pgc_ops;
95 	pg_relation_t	pgc_relation;
96 } pg_class_t;
97 
98 /*
99  * Per CPU processor group data
100  */
101 typedef struct cpu_pg {
102 	struct group	pgs;		/* All the CPU's PGs */
103 	struct group	cmt_pgs;	/* CMT load balancing lineage */
104 					/* (Group hierarchy ordered) */
105 	struct pg	*cmt_lineage;	/* Ascending lineage chain */
106 } cpu_pg_t;
107 
108 /*
109  * PG cpu iterator cookie
110  */
111 typedef struct	pg_cpu_itr {
112 	pg_t		*pg;
113 	group_iter_t	position;
114 } pg_cpu_itr_t;
115 
116 /*
117  * Initialize a PG CPU iterator cookie
118  */
119 #define	PG_CPU_ITR_INIT(pgrp, itr)		\
120 {						\
121 	group_iter_init(&(itr).position);	\
122 	(itr).pg = ((pg_t *)pgrp);		\
123 }
124 
125 /*
126  * Return the first CPU in a PG
127  */
128 #define	PG_CPU_GET_FIRST(pgrp)			\
129 	(GROUP_SIZE(&((pg_t *)pgrp)->pg_cpus) > 0 ?	\
130 	    GROUP_ACCESS(&((pg_t *)pgrp)->pg_cpus, 0) : NULL)
131 
132 /*
133  * Framework routines
134  */
135 void		pg_init(void);
136 pg_cid_t	pg_class_register(char *, struct pg_ops *, pg_relation_t);
137 
138 /*
139  * PG CPU reconfiguration hooks
140  */
141 void		pg_cpu0_init(void);
142 void		pg_cpu_init(cpu_t *);
143 void		pg_cpu_fini(cpu_t *);
144 void		pg_cpu_active(cpu_t *);
145 void		pg_cpu_inactive(cpu_t *);
146 void		pg_cpu_startup(cpu_t *);
147 void		pg_cpu_bootstrap(cpu_t *);
148 
149 /*
150  * PG cpupart service hooks
151  */
152 void		pg_cpupart_in(cpu_t *, struct cpupart *);
153 void		pg_cpupart_out(cpu_t *, struct cpupart *);
154 void		pg_cpupart_move(cpu_t *, struct cpupart *, struct cpupart *);
155 
156 /*
157  * PG CPU utility routines
158  */
159 pg_t		*pg_create(pg_cid_t);
160 void		pg_destroy(pg_t *);
161 void		pg_cpu_add(pg_t *, cpu_t *);
162 void		pg_cpu_delete(pg_t *, cpu_t *);
163 pg_t		*pg_cpu_find_pg(cpu_t *, group_t *);
164 cpu_t		*pg_cpu_next(pg_cpu_itr_t *);
165 
166 
167 #endif	/* !_KERNEL && !_KMEMUSER */
168 
169 #ifdef	__cplusplus
170 }
171 #endif
172 
173 #endif /* _PG_H */
174