xref: /titanic_50/usr/src/uts/sun4v/os/cmp.c (revision e853d8c363bb48f997502f6e034877de20256ab0)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * 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.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22fb2f18f8Sesaxe  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
307c478bd9Sstevel@tonic-gate #include <sys/cmp.h>
31d129bde2Sesaxe #include <sys/cmt.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Note: For now assume the chip ID as 0 for all the cpus until additional
357c478bd9Sstevel@tonic-gate  * information is available via machine description table
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
427c478bd9Sstevel@tonic-gate int
437c478bd9Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid)
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate 	return (0);
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
507c478bd9Sstevel@tonic-gate  * Called during boot and DR add.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate /*ARGSUSED*/
537c478bd9Sstevel@tonic-gate void
547c478bd9Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * Indicate that this core (cpuid) is being DR removed.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate /*ARGSUSED*/
627c478bd9Sstevel@tonic-gate void
637c478bd9Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid)
647c478bd9Sstevel@tonic-gate {
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * Called when cpuid is being onlined or offlined.  If the offlined
697c478bd9Sstevel@tonic-gate  * processor is CMP-capable then current target of the CMP Error Steering
707c478bd9Sstevel@tonic-gate  * Register is set to either the lowest numbered on-line sibling core, if
717c478bd9Sstevel@tonic-gate  * one exists, or else to this core.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate /*ARGSUSED*/
747c478bd9Sstevel@tonic-gate void
757c478bd9Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid)
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * Return 0, shortterm workaround until MD table is updated
817c478bd9Sstevel@tonic-gate  * to provide cpu-chip mapping
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*ARGSUSED*/
857c478bd9Sstevel@tonic-gate chipid_t
867c478bd9Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid)
877c478bd9Sstevel@tonic-gate {
8859ac0c16Sdavemq 	return (cpu[cpuid]->cpu_m.cpu_chip);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*ARGSUSED*/
92fb2f18f8Sesaxe int
93fb2f18f8Sesaxe pg_plat_hw_shared(cpu_t *cp, pghw_type_t hw)
947c478bd9Sstevel@tonic-gate {
95fb2f18f8Sesaxe 	switch (hw) {
96fb2f18f8Sesaxe 	case PGHW_IPIPE:
97fb2f18f8Sesaxe 		return (1);
98fb2f18f8Sesaxe 	case PGHW_FPU:
99fb2f18f8Sesaxe 		return (1);
100ce8eb11aSdp78419 	case PGHW_MPIPE:
101fb2f18f8Sesaxe 		return (1);
102fb2f18f8Sesaxe 	}
103fb2f18f8Sesaxe 	return (0);
1047c478bd9Sstevel@tonic-gate }
10570f54eadSesaxe 
106fb2f18f8Sesaxe int
107fb2f18f8Sesaxe pg_plat_cpus_share(cpu_t *cpu_a, cpu_t *cpu_b, pghw_type_t hw)
108fb2f18f8Sesaxe {
109fb2f18f8Sesaxe 	if (pg_plat_hw_shared(cpu_a, hw) == 0 ||
110fb2f18f8Sesaxe 	    pg_plat_hw_shared(cpu_b, hw) == 0)
111fb2f18f8Sesaxe 		return (0);
112fb2f18f8Sesaxe 
113fb2f18f8Sesaxe 	return (pg_plat_hw_instance_id(cpu_a, hw) ==
114fb2f18f8Sesaxe 	    pg_plat_hw_instance_id(cpu_b, hw));
115fb2f18f8Sesaxe }
11670f54eadSesaxe 
11770f54eadSesaxe id_t
118fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu_t *cpu, pghw_type_t hw)
11970f54eadSesaxe {
120fb2f18f8Sesaxe 	switch (hw) {
121fb2f18f8Sesaxe 	case PGHW_IPIPE:
122fb2f18f8Sesaxe 		return (cpu->cpu_m.cpu_ipipe);
123*e853d8c3Sjc25722 	case PGHW_CHIP:
124*e853d8c3Sjc25722 		return (cpu->cpu_m.cpu_chip);
125ce8eb11aSdp78419 	case PGHW_MPIPE:
126ce8eb11aSdp78419 		return (cpu->cpu_m.cpu_mpipe);
127fb2f18f8Sesaxe 	case PGHW_FPU:
128fb2f18f8Sesaxe 		return (cpu->cpu_m.cpu_fpu);
129fb2f18f8Sesaxe 	default:
130fb2f18f8Sesaxe 		return (-1);
131fb2f18f8Sesaxe 	}
132fb2f18f8Sesaxe }
133fb2f18f8Sesaxe 
134fb2f18f8Sesaxe /*
135fb2f18f8Sesaxe  * Order the relevant hw sharing relationships
136fb2f18f8Sesaxe  * from least, to greatest physical scope.
137fb2f18f8Sesaxe  *
138fb2f18f8Sesaxe  * The hierarchy *must* be defined for all hw that
139fb2f18f8Sesaxe  * pg_plat_hw_shared() returns non-zero.
140fb2f18f8Sesaxe  */
141fb2f18f8Sesaxe int
142fb2f18f8Sesaxe pg_plat_hw_level(pghw_type_t hw)
143fb2f18f8Sesaxe {
144fb2f18f8Sesaxe 	int i;
145fb2f18f8Sesaxe 	static pghw_type_t hw_hier[] = {
146fb2f18f8Sesaxe 		PGHW_IPIPE,
147fb2f18f8Sesaxe 		PGHW_FPU,
148ce8eb11aSdp78419 		PGHW_MPIPE,
149fb2f18f8Sesaxe 		PGHW_NUM_COMPONENTS
150fb2f18f8Sesaxe 	};
151fb2f18f8Sesaxe 
152fb2f18f8Sesaxe 	for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) {
153fb2f18f8Sesaxe 		if (hw_hier[i] == hw)
154fb2f18f8Sesaxe 			return (i);
155fb2f18f8Sesaxe 	}
156fb2f18f8Sesaxe 	return (-1);
157fb2f18f8Sesaxe }
158fb2f18f8Sesaxe 
159d129bde2Sesaxe /*
160d129bde2Sesaxe  * Return 1 if CMT load balancing policies should be
161d129bde2Sesaxe  * implemented across instances of the specified hardware
162d129bde2Sesaxe  * sharing relationship.
163d129bde2Sesaxe  */
164d129bde2Sesaxe int
165d129bde2Sesaxe pg_plat_cmt_load_bal_hw(pghw_type_t hw)
166d129bde2Sesaxe {
167d129bde2Sesaxe 	if (hw == PGHW_IPIPE ||
168d129bde2Sesaxe 	    hw == PGHW_FPU ||
169ce8eb11aSdp78419 	    hw == PGHW_MPIPE)
170d129bde2Sesaxe 		return (1);
171d129bde2Sesaxe 	else
172d129bde2Sesaxe 		return (0);
173d129bde2Sesaxe }
174d129bde2Sesaxe 
175d129bde2Sesaxe 
176d129bde2Sesaxe /*
177d129bde2Sesaxe  * Return 1 if thread affinity polices should be implemented
178d129bde2Sesaxe  * for instances of the specifed hardware sharing relationship.
179d129bde2Sesaxe  */
180d129bde2Sesaxe int
181d129bde2Sesaxe pg_plat_cmt_affinity_hw(pghw_type_t hw)
182d129bde2Sesaxe {
183d129bde2Sesaxe 	if (hw == PGHW_CACHE)
184d129bde2Sesaxe 		return (1);
185d129bde2Sesaxe 	else
186d129bde2Sesaxe 		return (0);
187d129bde2Sesaxe }
188d129bde2Sesaxe 
189fb2f18f8Sesaxe id_t
190fb2f18f8Sesaxe pg_plat_get_core_id(cpu_t *cpu)
191fb2f18f8Sesaxe {
192fb2f18f8Sesaxe 	return (cpu->cpu_m.cpu_core);
193fb2f18f8Sesaxe }
194fb2f18f8Sesaxe 
195fb2f18f8Sesaxe void
196fb2f18f8Sesaxe cmp_set_nosteal_interval(void)
197fb2f18f8Sesaxe {
198fb2f18f8Sesaxe 	nosteal_nsec = 0;
19970f54eadSesaxe }
200ce8eb11aSdp78419 /*
201ce8eb11aSdp78419  * Return 1 if CMT load balancing policies should be
202ce8eb11aSdp78419  * implemented across instances of the specified hardware
203ce8eb11aSdp78419  * sharing relationship.
204ce8eb11aSdp78419  */
205ce8eb11aSdp78419 int
206ce8eb11aSdp78419 pg_cmt_load_bal_hw(pghw_type_t hw)
207ce8eb11aSdp78419 {
208ce8eb11aSdp78419 	if (hw == PGHW_IPIPE ||
209ce8eb11aSdp78419 	    hw == PGHW_FPU ||
210ce8eb11aSdp78419 	    hw == PGHW_MPIPE)
211ce8eb11aSdp78419 		return (1);
212ce8eb11aSdp78419 	else
213ce8eb11aSdp78419 		return (0);
214ce8eb11aSdp78419 }
215ce8eb11aSdp78419 /*
216ce8eb11aSdp78419  * Return 1 if thread affinity polices should be implemented
217ce8eb11aSdp78419  * for instances of the specifed hardware sharing relationship.
218ce8eb11aSdp78419  */
219ce8eb11aSdp78419 int
220ce8eb11aSdp78419 pg_cmt_affinity_hw(pghw_type_t hw)
221ce8eb11aSdp78419 {
222ce8eb11aSdp78419 	if (hw == PGHW_CACHE)
223ce8eb11aSdp78419 		return (1);
224ce8eb11aSdp78419 	else
225ce8eb11aSdp78419 		return (0);
226ce8eb11aSdp78419 }
227