xref: /titanic_44/usr/src/uts/sun4v/os/cmp.c (revision 59ac0c1669407488b67ae9e273667a340dccc611)
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 {
88*59ac0c16Sdavemq 	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);
100fb2f18f8Sesaxe 	case PGHW_CHIP:
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);
123fb2f18f8Sesaxe 	case PGHW_CHIP:
124*59ac0c16Sdavemq 		return (cpu->cpu_m.cpu_chip);
125fb2f18f8Sesaxe 	case PGHW_FPU:
126fb2f18f8Sesaxe 		return (cpu->cpu_m.cpu_fpu);
127fb2f18f8Sesaxe 	default:
128fb2f18f8Sesaxe 		return (-1);
129fb2f18f8Sesaxe 	}
130fb2f18f8Sesaxe }
131fb2f18f8Sesaxe 
132fb2f18f8Sesaxe /*
133fb2f18f8Sesaxe  * Order the relevant hw sharing relationships
134fb2f18f8Sesaxe  * from least, to greatest physical scope.
135fb2f18f8Sesaxe  *
136fb2f18f8Sesaxe  * The hierarchy *must* be defined for all hw that
137fb2f18f8Sesaxe  * pg_plat_hw_shared() returns non-zero.
138fb2f18f8Sesaxe  */
139fb2f18f8Sesaxe int
140fb2f18f8Sesaxe pg_plat_hw_level(pghw_type_t hw)
141fb2f18f8Sesaxe {
142fb2f18f8Sesaxe 	int i;
143fb2f18f8Sesaxe 	static pghw_type_t hw_hier[] = {
144fb2f18f8Sesaxe 		PGHW_IPIPE,
145fb2f18f8Sesaxe 		PGHW_FPU,
146fb2f18f8Sesaxe 		PGHW_CHIP,
147fb2f18f8Sesaxe 		PGHW_NUM_COMPONENTS
148fb2f18f8Sesaxe 	};
149fb2f18f8Sesaxe 
150fb2f18f8Sesaxe 	for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) {
151fb2f18f8Sesaxe 		if (hw_hier[i] == hw)
152fb2f18f8Sesaxe 			return (i);
153fb2f18f8Sesaxe 	}
154fb2f18f8Sesaxe 	return (-1);
155fb2f18f8Sesaxe }
156fb2f18f8Sesaxe 
157d129bde2Sesaxe /*
158d129bde2Sesaxe  * Return 1 if CMT load balancing policies should be
159d129bde2Sesaxe  * implemented across instances of the specified hardware
160d129bde2Sesaxe  * sharing relationship.
161d129bde2Sesaxe  */
162d129bde2Sesaxe int
163d129bde2Sesaxe pg_plat_cmt_load_bal_hw(pghw_type_t hw)
164d129bde2Sesaxe {
165d129bde2Sesaxe 	if (hw == PGHW_IPIPE ||
166d129bde2Sesaxe 	    hw == PGHW_FPU ||
167d129bde2Sesaxe 	    hw == PGHW_CHIP)
168d129bde2Sesaxe 		return (1);
169d129bde2Sesaxe 	else
170d129bde2Sesaxe 		return (0);
171d129bde2Sesaxe }
172d129bde2Sesaxe 
173d129bde2Sesaxe 
174d129bde2Sesaxe /*
175d129bde2Sesaxe  * Return 1 if thread affinity polices should be implemented
176d129bde2Sesaxe  * for instances of the specifed hardware sharing relationship.
177d129bde2Sesaxe  */
178d129bde2Sesaxe int
179d129bde2Sesaxe pg_plat_cmt_affinity_hw(pghw_type_t hw)
180d129bde2Sesaxe {
181d129bde2Sesaxe 	if (hw == PGHW_CACHE)
182d129bde2Sesaxe 		return (1);
183d129bde2Sesaxe 	else
184d129bde2Sesaxe 		return (0);
185d129bde2Sesaxe }
186d129bde2Sesaxe 
187fb2f18f8Sesaxe id_t
188fb2f18f8Sesaxe pg_plat_get_core_id(cpu_t *cpu)
189fb2f18f8Sesaxe {
190fb2f18f8Sesaxe 	return (cpu->cpu_m.cpu_core);
191fb2f18f8Sesaxe }
192fb2f18f8Sesaxe 
193fb2f18f8Sesaxe void
194fb2f18f8Sesaxe cmp_set_nosteal_interval(void)
195fb2f18f8Sesaxe {
196fb2f18f8Sesaxe 	nosteal_nsec = 0;
19770f54eadSesaxe }
198