xref: /illumos-gate/usr/src/uts/sun4v/os/cmp.c (revision b885580b)
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 /*
220e751525SEric Saxe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
287c478bd9Sstevel@tonic-gate #include <sys/cmp.h>
29d129bde2Sesaxe #include <sys/cmt.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Note: For now assume the chip ID as 0 for all the cpus until additional
337c478bd9Sstevel@tonic-gate  * information is available via machine description table
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Returns 1 if cpuid is CMP-capable, 0 otherwise.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate /*ARGSUSED*/
407c478bd9Sstevel@tonic-gate int
cmp_cpu_is_cmp(processorid_t cpuid)417c478bd9Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid)
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate 	return (0);
447c478bd9Sstevel@tonic-gate }
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Indicate that this core (cpuid) resides on the chip indicated by chipid.
487c478bd9Sstevel@tonic-gate  * Called during boot and DR add.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate /*ARGSUSED*/
517c478bd9Sstevel@tonic-gate void
cmp_add_cpu(chipid_t chipid,processorid_t cpuid)527c478bd9Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate }
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * Indicate that this core (cpuid) is being DR removed.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate /*ARGSUSED*/
607c478bd9Sstevel@tonic-gate void
cmp_delete_cpu(processorid_t cpuid)617c478bd9Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid)
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate }
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Called when cpuid is being onlined or offlined.  If the offlined
677c478bd9Sstevel@tonic-gate  * processor is CMP-capable then current target of the CMP Error Steering
687c478bd9Sstevel@tonic-gate  * Register is set to either the lowest numbered on-line sibling core, if
697c478bd9Sstevel@tonic-gate  * one exists, or else to this core.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate /*ARGSUSED*/
727c478bd9Sstevel@tonic-gate void
cmp_error_resteer(processorid_t cpuid)737c478bd9Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid)
747c478bd9Sstevel@tonic-gate {
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Return 0, shortterm workaround until MD table is updated
797c478bd9Sstevel@tonic-gate  * to provide cpu-chip mapping
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
837c478bd9Sstevel@tonic-gate chipid_t
cmp_cpu_to_chip(processorid_t cpuid)847c478bd9Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid)
857c478bd9Sstevel@tonic-gate {
8659ac0c16Sdavemq 	return (cpu[cpuid]->cpu_m.cpu_chip);
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate 
89fb2f18f8Sesaxe /*ARGSUSED*/
90fb2f18f8Sesaxe int
pg_plat_hw_shared(cpu_t * cp,pghw_type_t hw)91fb2f18f8Sesaxe pg_plat_hw_shared(cpu_t *cp, pghw_type_t hw)
927c478bd9Sstevel@tonic-gate {
93fb2f18f8Sesaxe 	switch (hw) {
94fb2f18f8Sesaxe 	case PGHW_IPIPE:
95fb2f18f8Sesaxe 		return (1);
96fb2f18f8Sesaxe 	case PGHW_FPU:
97fb2f18f8Sesaxe 		return (1);
98ce8eb11aSdp 	case PGHW_MPIPE:
99fb2f18f8Sesaxe 		return (1);
100fb2f18f8Sesaxe 	}
101fb2f18f8Sesaxe 	return (0);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
104fb2f18f8Sesaxe int
pg_plat_cpus_share(cpu_t * cpu_a,cpu_t * cpu_b,pghw_type_t hw)105fb2f18f8Sesaxe pg_plat_cpus_share(cpu_t *cpu_a, cpu_t *cpu_b, pghw_type_t hw)
1067c478bd9Sstevel@tonic-gate {
107fb2f18f8Sesaxe 	if (pg_plat_hw_shared(cpu_a, hw) == 0 ||
108fb2f18f8Sesaxe 	    pg_plat_hw_shared(cpu_b, hw) == 0)
109fb2f18f8Sesaxe 		return (0);
110fb2f18f8Sesaxe 
111fb2f18f8Sesaxe 	return (pg_plat_hw_instance_id(cpu_a, hw) ==
112fb2f18f8Sesaxe 	    pg_plat_hw_instance_id(cpu_b, hw));
113fb2f18f8Sesaxe }
114fb2f18f8Sesaxe 
115fb2f18f8Sesaxe id_t
pg_plat_hw_instance_id(cpu_t * cpu,pghw_type_t hw)116fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu_t *cpu, pghw_type_t hw)
117fb2f18f8Sesaxe {
118fb2f18f8Sesaxe 	switch (hw) {
119fb2f18f8Sesaxe 	case PGHW_IPIPE:
120fb2f18f8Sesaxe 		return (cpu->cpu_m.cpu_ipipe);
121e853d8c3Sjc 	case PGHW_CHIP:
122e853d8c3Sjc 		return (cpu->cpu_m.cpu_chip);
123ce8eb11aSdp 	case PGHW_MPIPE:
124ce8eb11aSdp 		return (cpu->cpu_m.cpu_mpipe);
125fb2f18f8Sesaxe 	case PGHW_FPU:
126fb2f18f8Sesaxe 		return (cpu->cpu_m.cpu_fpu);
127fb2f18f8Sesaxe 	default:
128fb2f18f8Sesaxe 		return (-1);
129fb2f18f8Sesaxe 	}
1307c478bd9Sstevel@tonic-gate }
13170f54eadSesaxe 
13270f54eadSesaxe /*
1330e751525SEric Saxe  * Rank the relative importance of optimizing for hw1 or hw2
13470f54eadSesaxe  */
1350e751525SEric Saxe pghw_type_t
pg_plat_hw_rank(pghw_type_t hw1,pghw_type_t hw2)1360e751525SEric Saxe pg_plat_hw_rank(pghw_type_t hw1, pghw_type_t hw2)
137fb2f18f8Sesaxe {
138fb2f18f8Sesaxe 	int i;
1390e751525SEric Saxe 	int rank1 = 0;
1400e751525SEric Saxe 	int rank2 = 0;
1410e751525SEric Saxe 
142fb2f18f8Sesaxe 	static pghw_type_t hw_hier[] = {
143fb2f18f8Sesaxe 		PGHW_IPIPE,
144fb2f18f8Sesaxe 		PGHW_FPU,
145ce8eb11aSdp 		PGHW_MPIPE,
146fb2f18f8Sesaxe 		PGHW_NUM_COMPONENTS
147fb2f18f8Sesaxe 	};
148fb2f18f8Sesaxe 
149fb2f18f8Sesaxe 	for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) {
1500e751525SEric Saxe 		if (hw_hier[i] == hw1)
1510e751525SEric Saxe 			rank1 = i;
1520e751525SEric Saxe 		if (hw_hier[i] == hw2)
1530e751525SEric Saxe 			rank2 = i;
154fb2f18f8Sesaxe 	}
1550e751525SEric Saxe 	if (rank1 > rank2)
1560e751525SEric Saxe 		return (hw1);
157d129bde2Sesaxe 	else
1580e751525SEric Saxe 		return (hw2);
159d129bde2Sesaxe }
160d129bde2Sesaxe 
161d129bde2Sesaxe /*
1620e751525SEric Saxe  * Override the default CMT dispatcher policy for the specified
1630e751525SEric Saxe  * hardware sharing relationship
164d129bde2Sesaxe  */
1650e751525SEric Saxe /* ARGSUSED */
1660e751525SEric Saxe pg_cmt_policy_t
pg_plat_cmt_policy(pghw_type_t hw)1670e751525SEric Saxe pg_plat_cmt_policy(pghw_type_t hw)
168d129bde2Sesaxe {
1690e751525SEric Saxe 	/* Accept the default policies */
1700e751525SEric Saxe 	return (CMT_NO_POLICY);
171d129bde2Sesaxe }
172d129bde2Sesaxe 
17370f54eadSesaxe id_t
pg_plat_get_core_id(cpu_t * cpu)174fb2f18f8Sesaxe pg_plat_get_core_id(cpu_t *cpu)
175fb2f18f8Sesaxe {
176fb2f18f8Sesaxe 	return (cpu->cpu_m.cpu_core);
177fb2f18f8Sesaxe }
178fb2f18f8Sesaxe 
179fb2f18f8Sesaxe void
cmp_set_nosteal_interval(void)180fb2f18f8Sesaxe cmp_set_nosteal_interval(void)
18170f54eadSesaxe {
182fb2f18f8Sesaxe 	nosteal_nsec = 0;
18370f54eadSesaxe }
184ce8eb11aSdp /*
185ce8eb11aSdp  * Return 1 if CMT load balancing policies should be
186ce8eb11aSdp  * implemented across instances of the specified hardware
187ce8eb11aSdp  * sharing relationship.
188ce8eb11aSdp  */
189ce8eb11aSdp int
pg_cmt_load_bal_hw(pghw_type_t hw)190ce8eb11aSdp pg_cmt_load_bal_hw(pghw_type_t hw)
191ce8eb11aSdp {
192ce8eb11aSdp 	if (hw == PGHW_IPIPE ||
193ce8eb11aSdp 	    hw == PGHW_FPU ||
194ce8eb11aSdp 	    hw == PGHW_MPIPE)
195ce8eb11aSdp 		return (1);
196ce8eb11aSdp 	else
197ce8eb11aSdp 		return (0);
198ce8eb11aSdp }
199ce8eb11aSdp /*
2000e751525SEric Saxe  * Return 1 if thread affinity policies should be implemented
201ce8eb11aSdp  * for instances of the specifed hardware sharing relationship.
202ce8eb11aSdp  */
203ce8eb11aSdp int
pg_cmt_affinity_hw(pghw_type_t hw)204ce8eb11aSdp pg_cmt_affinity_hw(pghw_type_t hw)
205ce8eb11aSdp {
206ce8eb11aSdp 	if (hw == PGHW_CACHE)
207ce8eb11aSdp 		return (1);
208ce8eb11aSdp 	else
209ce8eb11aSdp 		return (0);
210ce8eb11aSdp }
211*b885580bSAlexander Kolbasov 
212*b885580bSAlexander Kolbasov /*
213*b885580bSAlexander Kolbasov  * Return number of counter events requested to measure hardware capacity and
214*b885580bSAlexander Kolbasov  * utilization and setup CPC requests for specified CPU if list where to add
215*b885580bSAlexander Kolbasov  * CPC requests is given
216*b885580bSAlexander Kolbasov  */
217*b885580bSAlexander Kolbasov int
218*b885580bSAlexander Kolbasov /* LINTED E_FUNC_ARG_UNUSED */
cu_plat_cpc_init(cpu_t * cp,kcpc_request_list_t * reqs,int nreqs)219*b885580bSAlexander Kolbasov cu_plat_cpc_init(cpu_t *cp, kcpc_request_list_t *reqs, int nreqs)
220*b885580bSAlexander Kolbasov {
221*b885580bSAlexander Kolbasov 	/*
222*b885580bSAlexander Kolbasov 	 * Return error to tell common code to decide what counter events to
223*b885580bSAlexander Kolbasov 	 * program on this CPU for measuring hardware capacity and utilization
224*b885580bSAlexander Kolbasov 	 */
225*b885580bSAlexander Kolbasov 	return (-1);
226*b885580bSAlexander Kolbasov }
227