xref: /onnv-gate/usr/src/uts/sun4v/os/cmp.c (revision 11389:dd00b884e84f)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53434Sesaxe  * Common Development and Distribution License (the "License").
63434Sesaxe  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
228906SEric.Saxe@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/machsystm.h>
280Sstevel@tonic-gate #include <sys/cmp.h>
294606Sesaxe #include <sys/cmt.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * Note: For now assume the chip ID as 0 for all the cpus until additional
330Sstevel@tonic-gate  * information is available via machine description table
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate /*ARGSUSED*/
400Sstevel@tonic-gate int
cmp_cpu_is_cmp(processorid_t cpuid)410Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	return (0);
440Sstevel@tonic-gate }
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
480Sstevel@tonic-gate  * Called during boot and DR add.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate /*ARGSUSED*/
510Sstevel@tonic-gate void
cmp_add_cpu(chipid_t chipid,processorid_t cpuid)520Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate }
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * Indicate that this core (cpuid) is being DR removed.
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate /*ARGSUSED*/
600Sstevel@tonic-gate void
cmp_delete_cpu(processorid_t cpuid)610Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate }
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * Called when cpuid is being onlined or offlined.  If the offlined
670Sstevel@tonic-gate  * processor is CMP-capable then current target of the CMP Error Steering
680Sstevel@tonic-gate  * Register is set to either the lowest numbered on-line sibling core, if
690Sstevel@tonic-gate  * one exists, or else to this core.
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate /*ARGSUSED*/
720Sstevel@tonic-gate void
cmp_error_resteer(processorid_t cpuid)730Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate }
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * Return 0, shortterm workaround until MD table is updated
790Sstevel@tonic-gate  * to provide cpu-chip mapping
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*ARGSUSED*/
830Sstevel@tonic-gate chipid_t
cmp_cpu_to_chip(processorid_t cpuid)840Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid)
850Sstevel@tonic-gate {
864732Sdavemq 	return (cpu[cpuid]->cpu_m.cpu_chip);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate 
893434Sesaxe /*ARGSUSED*/
903434Sesaxe int
pg_plat_hw_shared(cpu_t * cp,pghw_type_t hw)913434Sesaxe pg_plat_hw_shared(cpu_t *cp, pghw_type_t hw)
920Sstevel@tonic-gate {
933434Sesaxe 	switch (hw) {
943434Sesaxe 	case PGHW_IPIPE:
953434Sesaxe 		return (1);
963434Sesaxe 	case PGHW_FPU:
973434Sesaxe 		return (1);
984769Sdp78419 	case PGHW_MPIPE:
993434Sesaxe 		return (1);
1003434Sesaxe 	}
1013434Sesaxe 	return (0);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate 
1043434Sesaxe int
pg_plat_cpus_share(cpu_t * cpu_a,cpu_t * cpu_b,pghw_type_t hw)1053434Sesaxe pg_plat_cpus_share(cpu_t *cpu_a, cpu_t *cpu_b, pghw_type_t hw)
1060Sstevel@tonic-gate {
1073434Sesaxe 	if (pg_plat_hw_shared(cpu_a, hw) == 0 ||
1083434Sesaxe 	    pg_plat_hw_shared(cpu_b, hw) == 0)
1093434Sesaxe 		return (0);
1103434Sesaxe 
1113434Sesaxe 	return (pg_plat_hw_instance_id(cpu_a, hw) ==
1123434Sesaxe 	    pg_plat_hw_instance_id(cpu_b, hw));
1133434Sesaxe }
1140Sstevel@tonic-gate 
1153434Sesaxe id_t
pg_plat_hw_instance_id(cpu_t * cpu,pghw_type_t hw)1163434Sesaxe pg_plat_hw_instance_id(cpu_t *cpu, pghw_type_t hw)
1173434Sesaxe {
1183434Sesaxe 	switch (hw) {
1193434Sesaxe 	case PGHW_IPIPE:
1203434Sesaxe 		return (cpu->cpu_m.cpu_ipipe);
1215079Sjc25722 	case PGHW_CHIP:
1225079Sjc25722 		return (cpu->cpu_m.cpu_chip);
1234769Sdp78419 	case PGHW_MPIPE:
1244769Sdp78419 		return (cpu->cpu_m.cpu_mpipe);
1253434Sesaxe 	case PGHW_FPU:
1263434Sesaxe 		return (cpu->cpu_m.cpu_fpu);
1273434Sesaxe 	default:
1283434Sesaxe 		return (-1);
1293434Sesaxe 	}
1300Sstevel@tonic-gate }
131220Sesaxe 
132220Sesaxe /*
1338906SEric.Saxe@Sun.COM  * Rank the relative importance of optimizing for hw1 or hw2
134220Sesaxe  */
1358906SEric.Saxe@Sun.COM pghw_type_t
pg_plat_hw_rank(pghw_type_t hw1,pghw_type_t hw2)1368906SEric.Saxe@Sun.COM pg_plat_hw_rank(pghw_type_t hw1, pghw_type_t hw2)
1373434Sesaxe {
1383434Sesaxe 	int i;
1398906SEric.Saxe@Sun.COM 	int rank1 = 0;
1408906SEric.Saxe@Sun.COM 	int rank2 = 0;
1418906SEric.Saxe@Sun.COM 
1423434Sesaxe 	static pghw_type_t hw_hier[] = {
1433434Sesaxe 		PGHW_IPIPE,
1443434Sesaxe 		PGHW_FPU,
1454769Sdp78419 		PGHW_MPIPE,
1463434Sesaxe 		PGHW_NUM_COMPONENTS
1473434Sesaxe 	};
1483434Sesaxe 
1493434Sesaxe 	for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) {
1508906SEric.Saxe@Sun.COM 		if (hw_hier[i] == hw1)
1518906SEric.Saxe@Sun.COM 			rank1 = i;
1528906SEric.Saxe@Sun.COM 		if (hw_hier[i] == hw2)
1538906SEric.Saxe@Sun.COM 			rank2 = i;
1543434Sesaxe 	}
1558906SEric.Saxe@Sun.COM 	if (rank1 > rank2)
1568906SEric.Saxe@Sun.COM 		return (hw1);
1578906SEric.Saxe@Sun.COM 	else
1588906SEric.Saxe@Sun.COM 		return (hw2);
1593434Sesaxe }
160220Sesaxe 
1614606Sesaxe /*
1628906SEric.Saxe@Sun.COM  * Override the default CMT dispatcher policy for the specified
1638906SEric.Saxe@Sun.COM  * hardware sharing relationship
1644606Sesaxe  */
1658906SEric.Saxe@Sun.COM /* ARGSUSED */
1668906SEric.Saxe@Sun.COM pg_cmt_policy_t
pg_plat_cmt_policy(pghw_type_t hw)1678906SEric.Saxe@Sun.COM pg_plat_cmt_policy(pghw_type_t hw)
1684606Sesaxe {
1698906SEric.Saxe@Sun.COM 	/* Accept the default policies */
1708906SEric.Saxe@Sun.COM 	return (CMT_NO_POLICY);
1714606Sesaxe }
1724606Sesaxe 
173220Sesaxe id_t
pg_plat_get_core_id(cpu_t * cpu)1743434Sesaxe pg_plat_get_core_id(cpu_t *cpu)
175220Sesaxe {
1763434Sesaxe 	return (cpu->cpu_m.cpu_core);
177220Sesaxe }
1783434Sesaxe 
1793434Sesaxe void
cmp_set_nosteal_interval(void)1803434Sesaxe cmp_set_nosteal_interval(void)
1813434Sesaxe {
1823434Sesaxe 	nosteal_nsec = 0;
1833434Sesaxe }
1844769Sdp78419 /*
1854769Sdp78419  * Return 1 if CMT load balancing policies should be
1864769Sdp78419  * implemented across instances of the specified hardware
1874769Sdp78419  * sharing relationship.
1884769Sdp78419  */
1894769Sdp78419 int
pg_cmt_load_bal_hw(pghw_type_t hw)1904769Sdp78419 pg_cmt_load_bal_hw(pghw_type_t hw)
1914769Sdp78419 {
1924769Sdp78419 	if (hw == PGHW_IPIPE ||
1934769Sdp78419 	    hw == PGHW_FPU ||
1944769Sdp78419 	    hw == PGHW_MPIPE)
1954769Sdp78419 		return (1);
1964769Sdp78419 	else
1974769Sdp78419 		return (0);
1984769Sdp78419 }
1994769Sdp78419 /*
2008906SEric.Saxe@Sun.COM  * Return 1 if thread affinity policies should be implemented
2014769Sdp78419  * for instances of the specifed hardware sharing relationship.
2024769Sdp78419  */
2034769Sdp78419 int
pg_cmt_affinity_hw(pghw_type_t hw)2044769Sdp78419 pg_cmt_affinity_hw(pghw_type_t hw)
2054769Sdp78419 {
2064769Sdp78419 	if (hw == PGHW_CACHE)
2074769Sdp78419 		return (1);
2084769Sdp78419 	else
2094769Sdp78419 		return (0);
2104769Sdp78419 }
211*11389SAlexander.Kolbasov@Sun.COM 
212*11389SAlexander.Kolbasov@Sun.COM /*
213*11389SAlexander.Kolbasov@Sun.COM  * Return number of counter events requested to measure hardware capacity and
214*11389SAlexander.Kolbasov@Sun.COM  * utilization and setup CPC requests for specified CPU if list where to add
215*11389SAlexander.Kolbasov@Sun.COM  * CPC requests is given
216*11389SAlexander.Kolbasov@Sun.COM  */
217*11389SAlexander.Kolbasov@Sun.COM int
218*11389SAlexander.Kolbasov@Sun.COM /* LINTED E_FUNC_ARG_UNUSED */
cu_plat_cpc_init(cpu_t * cp,kcpc_request_list_t * reqs,int nreqs)219*11389SAlexander.Kolbasov@Sun.COM cu_plat_cpc_init(cpu_t *cp, kcpc_request_list_t *reqs, int nreqs)
220*11389SAlexander.Kolbasov@Sun.COM {
221*11389SAlexander.Kolbasov@Sun.COM 	/*
222*11389SAlexander.Kolbasov@Sun.COM 	 * Return error to tell common code to decide what counter events to
223*11389SAlexander.Kolbasov@Sun.COM 	 * program on this CPU for measuring hardware capacity and utilization
224*11389SAlexander.Kolbasov@Sun.COM 	 */
225*11389SAlexander.Kolbasov@Sun.COM 	return (-1);
226*11389SAlexander.Kolbasov@Sun.COM }
227