xref: /titanic_44/usr/src/uts/sun4u/os/cmp.c (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/types.h>
29 #include <sys/machsystm.h>
30 #include <sys/x_call.h>
31 #include <sys/cmp.h>
32 #include <sys/cmt.h>
33 #include <sys/debug.h>
34 #include <sys/disp.h>
35 #include <sys/cheetahregs.h>
36 
37 /*
38  * Note: We assume that chipid == portid.  This is not necessarily true.
39  * We buried it down here in the implementation, and not in the
40  * interfaces, so that we can change it later.
41  */
42 
43 /*
44  * pre-alloc'ed because this is used early in boot (before the memory
45  * allocator is available).
46  */
47 static cpuset_t chips[MAX_CPU_CHIPID];
48 
49 /*
50  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
51  */
52 int
53 cmp_cpu_is_cmp(processorid_t cpuid)
54 {
55 	chipid_t chipid;
56 
57 	/* N.B. We're assuming that the cpunode[].portid is still intact */
58 	chipid = cpunodes[cpuid].portid;
59 	return (!CPUSET_ISNULL(chips[chipid]));
60 }
61 
62 /*
63  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
64  * Called during boot and DR add.
65  */
66 void
67 cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
68 {
69 	CPUSET_ADD(chips[chipid], cpuid);
70 }
71 
72 /*
73  * Indicate that this core (cpuid) is being DR removed.
74  */
75 void
76 cmp_delete_cpu(processorid_t cpuid)
77 {
78 	chipid_t chipid;
79 
80 	/* N.B. We're assuming that the cpunode[].portid is still intact */
81 	chipid = cpunodes[cpuid].portid;
82 	CPUSET_DEL(chips[chipid], cpuid);
83 }
84 
85 /*
86  * Called when cpuid is being onlined or offlined.  If the offlined
87  * processor is CMP-capable then current target of the CMP Error Steering
88  * Register is set to either the lowest numbered on-line sibling core, if
89  * one exists, or else to this core.
90  */
91 /* ARGSUSED */
92 void
93 cmp_error_resteer(processorid_t cpuid)
94 {
95 #ifndef	_CMP_NO_ERROR_STEERING
96 	cpuset_t mycores;
97 	cpu_t *cpu;
98 	chipid_t chipid;
99 	int i;
100 
101 	if (!cmp_cpu_is_cmp(cpuid))
102 		return;
103 
104 	ASSERT(MUTEX_HELD(&cpu_lock));
105 	chipid = cpunodes[cpuid].portid;
106 	mycores = chips[chipid];
107 
108 	/* Look for an online sibling core */
109 	for (i = 0; i < NCPU; i++) {
110 		if (i == cpuid)
111 			continue;
112 
113 		if (CPU_IN_SET(mycores, i) &&
114 		    (cpu = cpu_get(i)) != NULL && cpu_is_active(cpu)) {
115 			/* Found one, reset error steering  */
116 			xc_one(i, (xcfunc_t *)set_cmp_error_steering, 0, 0);
117 			break;
118 		}
119 	}
120 
121 	/* No online sibling cores, point to this core.  */
122 	if (i == NCPU) {
123 		xc_one(cpuid, (xcfunc_t *)set_cmp_error_steering, 0, 0);
124 	}
125 #else
126 	/* Not all CMP's support (e.g. Olympus-C by Fujitsu) error steering */
127 	return;
128 #endif /* _CMP_NO_ERROR_STEERING */
129 }
130 
131 chipid_t
132 cmp_cpu_to_chip(processorid_t cpuid)
133 {
134 	if (!cmp_cpu_is_cmp(cpuid)) {
135 		/* This CPU is not a CMP, so by definition chipid==cpuid */
136 		ASSERT(cpuid < MAX_CPU_CHIPID && CPUSET_ISNULL(chips[cpuid]));
137 		return (cpuid);
138 	}
139 
140 	/* N.B. We're assuming that the cpunode[].portid is still intact */
141 	return (cpunodes[cpuid].portid);
142 }
143 
144 /* ARGSUSED */
145 int
146 pg_plat_hw_shared(cpu_t *cp, pghw_type_t hw)
147 {
148 	int impl;
149 
150 	impl = cpunodes[cp->cpu_id].implementation;
151 
152 	switch (hw) {
153 	case PGHW_IPIPE:
154 		if ((IS_OLYMPUS_C(impl)) || (IS_JUPITER(impl)))
155 			return (1);
156 		break;
157 	case PGHW_CHIP:
158 		if (IS_JAGUAR(impl) || IS_PANTHER(impl) ||
159 		    IS_OLYMPUS_C(impl) || IS_JUPITER(impl))
160 			return (1);
161 		break;
162 	case PGHW_CACHE:
163 		if (IS_PANTHER(impl) || IS_OLYMPUS_C(impl) || IS_JUPITER(impl))
164 			return (1);
165 		break;
166 	}
167 	return (0);
168 }
169 
170 int
171 pg_plat_cpus_share(cpu_t *cpu_a, cpu_t *cpu_b, pghw_type_t hw)
172 {
173 	int impl;
174 
175 	impl = cpunodes[cpu_a->cpu_id].implementation;
176 
177 	switch (hw) {
178 	case PGHW_IPIPE:
179 	case PGHW_CHIP:
180 		return (pg_plat_hw_instance_id(cpu_a, hw) ==
181 		    pg_plat_hw_instance_id(cpu_b, hw));
182 	case PGHW_CACHE:
183 		if ((IS_PANTHER(impl) || IS_OLYMPUS_C(impl) ||
184 		    IS_JUPITER(impl)) && pg_plat_cpus_share(cpu_a,
185 		    cpu_b, PGHW_CHIP)) {
186 			return (1);
187 		} else {
188 			return (0);
189 		}
190 	}
191 	return (0);
192 }
193 
194 id_t
195 pg_plat_hw_instance_id(cpu_t *cpu, pghw_type_t hw)
196 {
197 	int impl;
198 
199 	impl = cpunodes[cpu->cpu_id].implementation;
200 
201 	switch (hw) {
202 	case PGHW_IPIPE:
203 		if (IS_OLYMPUS_C(impl) || IS_JUPITER(impl)) {
204 			/*
205 			 * Currently only Fujitsu Olympus-C (SPARC64-VI) and
206 			 * Jupiter (SPARC64-VII) processors support
207 			 * multi-stranded cores. Return the cpu_id with the
208 			 * strand bit masked out.
209 			 */
210 			return ((id_t)((uint_t)cpu->cpu_id & ~(0x1)));
211 		} else {
212 			return (cpu->cpu_id);
213 		}
214 	case PGHW_CHIP:
215 		return (cmp_cpu_to_chip(cpu->cpu_id));
216 	case PGHW_CACHE:
217 		if (IS_PANTHER(impl) ||
218 		    IS_OLYMPUS_C(impl) || IS_JUPITER(impl))
219 			return (pg_plat_hw_instance_id(cpu, PGHW_CHIP));
220 		else
221 			return (cpu->cpu_id);
222 	default:
223 		return (-1);
224 	}
225 }
226 
227 int
228 pg_plat_hw_level(pghw_type_t hw)
229 {
230 	int i;
231 	static pghw_type_t hw_hier[] = {
232 		PGHW_IPIPE,
233 		PGHW_CHIP,
234 		PGHW_CACHE,
235 		PGHW_NUM_COMPONENTS
236 	};
237 
238 	for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) {
239 		if (hw_hier[i] == hw)
240 			return (i);
241 	}
242 	return (-1);
243 }
244 
245 /*
246  * Return 1 if CMT load balancing policies should be
247  * implemented across instances of the specified hardware
248  * sharing relationship.
249  */
250 int
251 pg_plat_cmt_load_bal_hw(pghw_type_t hw)
252 {
253 	if (hw == PGHW_IPIPE ||
254 	    hw == PGHW_FPU ||
255 	    hw == PGHW_CHIP)
256 		return (1);
257 	else
258 		return (0);
259 }
260 
261 
262 /*
263  * Return 1 if thread affinity polices should be implemented
264  * for instances of the specifed hardware sharing relationship.
265  */
266 int
267 pg_plat_cmt_affinity_hw(pghw_type_t hw)
268 {
269 	if (hw == PGHW_CACHE)
270 		return (1);
271 	else
272 		return (0);
273 }
274 
275 id_t
276 pg_plat_get_core_id(cpu_t *cp)
277 {
278 	return (pg_plat_hw_instance_id(cp, PGHW_IPIPE));
279 }
280 
281 void
282 cmp_set_nosteal_interval(void)
283 {
284 	/* Set the nosteal interval (used by disp_getbest()) to 100us */
285 	nosteal_nsec = 100000UL;
286 }
287 /*
288  * Return 1 if CMT load balancing policies should be
289  * implemented across instances of the specified hardware
290  * sharing relationship.
291  */
292 int
293 pg_cmt_load_bal_hw(pghw_type_t hw)
294 {
295 	if (hw == PGHW_IPIPE ||
296 	    hw == PGHW_FPU ||
297 	    hw == PGHW_CHIP)
298 		return (1);
299 	else
300 		return (0);
301 }
302 /*
303  * Return 1 if thread affinity polices should be implemented
304  * for instances of the specifed hardware sharing relationship.
305  */
306 int
307 pg_cmt_affinity_hw(pghw_type_t hw)
308 {
309 	if (hw == PGHW_CACHE)
310 		return (1);
311 	else
312 		return (0);
313 }
314