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 525cf1a30Sjl139090 * Common Development and Distribution License (the "License"). 625cf1a30Sjl139090 * 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/x_call.h> 317c478bd9Sstevel@tonic-gate #include <sys/cmp.h> 32d129bde2Sesaxe #include <sys/cmt.h> 337c478bd9Sstevel@tonic-gate #include <sys/debug.h> 34685679f7Sakolb #include <sys/disp.h> 357c478bd9Sstevel@tonic-gate #include <sys/cheetahregs.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * Note: We assume that chipid == portid. This is not necessarily true. 397c478bd9Sstevel@tonic-gate * We buried it down here in the implementation, and not in the 407c478bd9Sstevel@tonic-gate * interfaces, so that we can change it later. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * pre-alloc'ed because this is used early in boot (before the memory 457c478bd9Sstevel@tonic-gate * allocator is available). 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate static cpuset_t chips[MAX_CPU_CHIPID]; 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * Returns 1 if cpuid is CMP-capable, 0 otherwise. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate int 537c478bd9Sstevel@tonic-gate cmp_cpu_is_cmp(processorid_t cpuid) 547c478bd9Sstevel@tonic-gate { 557c478bd9Sstevel@tonic-gate chipid_t chipid; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* N.B. We're assuming that the cpunode[].portid is still intact */ 587c478bd9Sstevel@tonic-gate chipid = cpunodes[cpuid].portid; 597c478bd9Sstevel@tonic-gate return (!CPUSET_ISNULL(chips[chipid])); 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Indicate that this core (cpuid) resides on the chip indicated by chipid. 647c478bd9Sstevel@tonic-gate * Called during boot and DR add. 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate void 677c478bd9Sstevel@tonic-gate cmp_add_cpu(chipid_t chipid, processorid_t cpuid) 687c478bd9Sstevel@tonic-gate { 697c478bd9Sstevel@tonic-gate CPUSET_ADD(chips[chipid], cpuid); 707c478bd9Sstevel@tonic-gate } 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * Indicate that this core (cpuid) is being DR removed. 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate void 767c478bd9Sstevel@tonic-gate cmp_delete_cpu(processorid_t cpuid) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate chipid_t chipid; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* N.B. We're assuming that the cpunode[].portid is still intact */ 817c478bd9Sstevel@tonic-gate chipid = cpunodes[cpuid].portid; 827c478bd9Sstevel@tonic-gate CPUSET_DEL(chips[chipid], cpuid); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * Called when cpuid is being onlined or offlined. If the offlined 877c478bd9Sstevel@tonic-gate * processor is CMP-capable then current target of the CMP Error Steering 887c478bd9Sstevel@tonic-gate * Register is set to either the lowest numbered on-line sibling core, if 897c478bd9Sstevel@tonic-gate * one exists, or else to this core. 907c478bd9Sstevel@tonic-gate */ 9125cf1a30Sjl139090 /* ARGSUSED */ 927c478bd9Sstevel@tonic-gate void 937c478bd9Sstevel@tonic-gate cmp_error_resteer(processorid_t cpuid) 947c478bd9Sstevel@tonic-gate { 9525cf1a30Sjl139090 #ifndef _CMP_NO_ERROR_STEERING 967c478bd9Sstevel@tonic-gate cpuset_t mycores; 977c478bd9Sstevel@tonic-gate cpu_t *cpu; 987c478bd9Sstevel@tonic-gate chipid_t chipid; 997c478bd9Sstevel@tonic-gate int i; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate if (!cmp_cpu_is_cmp(cpuid)) 1027c478bd9Sstevel@tonic-gate return; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 1057c478bd9Sstevel@tonic-gate chipid = cpunodes[cpuid].portid; 1067c478bd9Sstevel@tonic-gate mycores = chips[chipid]; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* Look for an online sibling core */ 1097c478bd9Sstevel@tonic-gate for (i = 0; i < NCPU; i++) { 1107c478bd9Sstevel@tonic-gate if (i == cpuid) 1117c478bd9Sstevel@tonic-gate continue; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate if (CPU_IN_SET(mycores, i) && 1147c478bd9Sstevel@tonic-gate (cpu = cpu_get(i)) != NULL && cpu_is_active(cpu)) { 1157c478bd9Sstevel@tonic-gate /* Found one, reset error steering */ 1167c478bd9Sstevel@tonic-gate xc_one(i, (xcfunc_t *)set_cmp_error_steering, 0, 0); 1177c478bd9Sstevel@tonic-gate break; 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* No online sibling cores, point to this core. */ 1227c478bd9Sstevel@tonic-gate if (i == NCPU) { 1237c478bd9Sstevel@tonic-gate xc_one(cpuid, (xcfunc_t *)set_cmp_error_steering, 0, 0); 1247c478bd9Sstevel@tonic-gate } 12525cf1a30Sjl139090 #else 12625cf1a30Sjl139090 /* Not all CMP's support (e.g. Olympus-C by Fujitsu) error steering */ 12725cf1a30Sjl139090 return; 12825cf1a30Sjl139090 #endif /* _CMP_NO_ERROR_STEERING */ 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate chipid_t 1327c478bd9Sstevel@tonic-gate cmp_cpu_to_chip(processorid_t cpuid) 1337c478bd9Sstevel@tonic-gate { 1347c478bd9Sstevel@tonic-gate if (!cmp_cpu_is_cmp(cpuid)) { 1357c478bd9Sstevel@tonic-gate /* This CPU is not a CMP, so by definition chipid==cpuid */ 1367c478bd9Sstevel@tonic-gate ASSERT(cpuid < MAX_CPU_CHIPID && CPUSET_ISNULL(chips[cpuid])); 1377c478bd9Sstevel@tonic-gate return (cpuid); 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate /* N.B. We're assuming that the cpunode[].portid is still intact */ 1417c478bd9Sstevel@tonic-gate return (cpunodes[cpuid].portid); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 144fb2f18f8Sesaxe /* ARGSUSED */ 145fb2f18f8Sesaxe int 146fb2f18f8Sesaxe pg_plat_hw_shared(cpu_t *cp, pghw_type_t hw) 1478949bcd6Sandrei { 14825cf1a30Sjl139090 int impl; 14925cf1a30Sjl139090 15025cf1a30Sjl139090 impl = cpunodes[cp->cpu_id].implementation; 15125cf1a30Sjl139090 152fb2f18f8Sesaxe switch (hw) { 153fb2f18f8Sesaxe case PGHW_IPIPE: 154*e98fafb9Sjl139090 if ((IS_OLYMPUS_C(impl)) || (IS_JUPITER(impl))) 155fb2f18f8Sesaxe return (1); 156fb2f18f8Sesaxe break; 157fb2f18f8Sesaxe case PGHW_CHIP: 158*e98fafb9Sjl139090 if (IS_JAGUAR(impl) || IS_PANTHER(impl) || 159*e98fafb9Sjl139090 IS_OLYMPUS_C(impl) || IS_JUPITER(impl)) 160fb2f18f8Sesaxe return (1); 161fb2f18f8Sesaxe break; 162fb2f18f8Sesaxe case PGHW_CACHE: 163*e98fafb9Sjl139090 if (IS_PANTHER(impl) || IS_OLYMPUS_C(impl) || IS_JUPITER(impl)) 164fb2f18f8Sesaxe return (1); 165fb2f18f8Sesaxe break; 166fb2f18f8Sesaxe } 167fb2f18f8Sesaxe return (0); 168fb2f18f8Sesaxe } 169fb2f18f8Sesaxe 170fb2f18f8Sesaxe int 171fb2f18f8Sesaxe pg_plat_cpus_share(cpu_t *cpu_a, cpu_t *cpu_b, pghw_type_t hw) 172fb2f18f8Sesaxe { 173a6604450Sesaxe int impl; 174fb2f18f8Sesaxe 175a6604450Sesaxe impl = cpunodes[cpu_a->cpu_id].implementation; 176fb2f18f8Sesaxe 177fb2f18f8Sesaxe switch (hw) { 178fb2f18f8Sesaxe case PGHW_IPIPE: 179fb2f18f8Sesaxe case PGHW_CHIP: 180fb2f18f8Sesaxe return (pg_plat_hw_instance_id(cpu_a, hw) == 181fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu_b, hw)); 182fb2f18f8Sesaxe case PGHW_CACHE: 183*e98fafb9Sjl139090 if ((IS_PANTHER(impl) || IS_OLYMPUS_C(impl) || 184*e98fafb9Sjl139090 IS_JUPITER(impl)) && pg_plat_cpus_share(cpu_a, 185*e98fafb9Sjl139090 cpu_b, PGHW_CHIP)) { 186a6604450Sesaxe return (1); 187a6604450Sesaxe } else { 188a6604450Sesaxe return (0); 189a6604450Sesaxe } 190fb2f18f8Sesaxe } 191fb2f18f8Sesaxe return (0); 192fb2f18f8Sesaxe } 193fb2f18f8Sesaxe 194fb2f18f8Sesaxe id_t 195fb2f18f8Sesaxe pg_plat_hw_instance_id(cpu_t *cpu, pghw_type_t hw) 196fb2f18f8Sesaxe { 197fb2f18f8Sesaxe int impl; 198fb2f18f8Sesaxe 199fb2f18f8Sesaxe impl = cpunodes[cpu->cpu_id].implementation; 200fb2f18f8Sesaxe 201a6604450Sesaxe switch (hw) { 202a6604450Sesaxe case PGHW_IPIPE: 203*e98fafb9Sjl139090 if (IS_OLYMPUS_C(impl) || IS_JUPITER(impl)) { 20425cf1a30Sjl139090 /* 205*e98fafb9Sjl139090 * Currently only Fujitsu Olympus-C (SPARC64-VI) and 206*e98fafb9Sjl139090 * Jupiter (SPARC64-VII) processors support 207*e98fafb9Sjl139090 * multi-stranded cores. Return the cpu_id with the 208*e98fafb9Sjl139090 * strand bit masked out. 20925cf1a30Sjl139090 */ 210fb2f18f8Sesaxe return ((id_t)((uint_t)cpu->cpu_id & ~(0x1))); 21125cf1a30Sjl139090 } else { 212fb2f18f8Sesaxe return (cpu->cpu_id); 2138949bcd6Sandrei } 214fb2f18f8Sesaxe case PGHW_CHIP: 215fb2f18f8Sesaxe return (cmp_cpu_to_chip(cpu->cpu_id)); 216fb2f18f8Sesaxe case PGHW_CACHE: 217*e98fafb9Sjl139090 if (IS_PANTHER(impl) || 218*e98fafb9Sjl139090 IS_OLYMPUS_C(impl) || IS_JUPITER(impl)) 219a6604450Sesaxe return (pg_plat_hw_instance_id(cpu, PGHW_CHIP)); 220a6604450Sesaxe else 221a6604450Sesaxe return (cpu->cpu_id); 222fb2f18f8Sesaxe default: 223fb2f18f8Sesaxe return (-1); 224fb2f18f8Sesaxe } 225fb2f18f8Sesaxe } 226fb2f18f8Sesaxe 227fb2f18f8Sesaxe int 228fb2f18f8Sesaxe pg_plat_hw_level(pghw_type_t hw) 229fb2f18f8Sesaxe { 230fb2f18f8Sesaxe int i; 231fb2f18f8Sesaxe static pghw_type_t hw_hier[] = { 232fb2f18f8Sesaxe PGHW_IPIPE, 233fb2f18f8Sesaxe PGHW_CHIP, 234fb2f18f8Sesaxe PGHW_CACHE, 235fb2f18f8Sesaxe PGHW_NUM_COMPONENTS 236fb2f18f8Sesaxe }; 237fb2f18f8Sesaxe 238fb2f18f8Sesaxe for (i = 0; hw_hier[i] != PGHW_NUM_COMPONENTS; i++) { 239fb2f18f8Sesaxe if (hw_hier[i] == hw) 240fb2f18f8Sesaxe return (i); 241fb2f18f8Sesaxe } 242fb2f18f8Sesaxe return (-1); 243fb2f18f8Sesaxe } 244fb2f18f8Sesaxe 245d129bde2Sesaxe /* 246d129bde2Sesaxe * Return 1 if CMT load balancing policies should be 247d129bde2Sesaxe * implemented across instances of the specified hardware 248d129bde2Sesaxe * sharing relationship. 249d129bde2Sesaxe */ 250d129bde2Sesaxe int 251d129bde2Sesaxe pg_plat_cmt_load_bal_hw(pghw_type_t hw) 252d129bde2Sesaxe { 253d129bde2Sesaxe if (hw == PGHW_IPIPE || 254d129bde2Sesaxe hw == PGHW_FPU || 255d129bde2Sesaxe hw == PGHW_CHIP) 256d129bde2Sesaxe return (1); 257d129bde2Sesaxe else 258d129bde2Sesaxe return (0); 259d129bde2Sesaxe } 260d129bde2Sesaxe 261d129bde2Sesaxe 262d129bde2Sesaxe /* 263d129bde2Sesaxe * Return 1 if thread affinity polices should be implemented 264d129bde2Sesaxe * for instances of the specifed hardware sharing relationship. 265d129bde2Sesaxe */ 266d129bde2Sesaxe int 267d129bde2Sesaxe pg_plat_cmt_affinity_hw(pghw_type_t hw) 268d129bde2Sesaxe { 269d129bde2Sesaxe if (hw == PGHW_CACHE) 270d129bde2Sesaxe return (1); 271d129bde2Sesaxe else 272d129bde2Sesaxe return (0); 273d129bde2Sesaxe } 274d129bde2Sesaxe 275fb2f18f8Sesaxe id_t 276fb2f18f8Sesaxe pg_plat_get_core_id(cpu_t *cp) 277fb2f18f8Sesaxe { 278fb2f18f8Sesaxe return (pg_plat_hw_instance_id(cp, PGHW_IPIPE)); 27925cf1a30Sjl139090 } 2808949bcd6Sandrei 2817c478bd9Sstevel@tonic-gate void 282fb2f18f8Sesaxe cmp_set_nosteal_interval(void) 2837c478bd9Sstevel@tonic-gate { 284fb2f18f8Sesaxe /* Set the nosteal interval (used by disp_getbest()) to 100us */ 285fb2f18f8Sesaxe nosteal_nsec = 100000UL; 2867c478bd9Sstevel@tonic-gate } 287ce8eb11aSdp78419 /* 288ce8eb11aSdp78419 * Return 1 if CMT load balancing policies should be 289ce8eb11aSdp78419 * implemented across instances of the specified hardware 290ce8eb11aSdp78419 * sharing relationship. 291ce8eb11aSdp78419 */ 292ce8eb11aSdp78419 int 293ce8eb11aSdp78419 pg_cmt_load_bal_hw(pghw_type_t hw) 294ce8eb11aSdp78419 { 295ce8eb11aSdp78419 if (hw == PGHW_IPIPE || 296ce8eb11aSdp78419 hw == PGHW_FPU || 297ce8eb11aSdp78419 hw == PGHW_CHIP) 298ce8eb11aSdp78419 return (1); 299ce8eb11aSdp78419 else 300ce8eb11aSdp78419 return (0); 301ce8eb11aSdp78419 } 302ce8eb11aSdp78419 /* 303ce8eb11aSdp78419 * Return 1 if thread affinity polices should be implemented 304ce8eb11aSdp78419 * for instances of the specifed hardware sharing relationship. 305ce8eb11aSdp78419 */ 306ce8eb11aSdp78419 int 307ce8eb11aSdp78419 pg_cmt_affinity_hw(pghw_type_t hw) 308ce8eb11aSdp78419 { 309ce8eb11aSdp78419 if (hw == PGHW_CACHE) 310ce8eb11aSdp78419 return (1); 311ce8eb11aSdp78419 else 312ce8eb11aSdp78419 return (0); 313ce8eb11aSdp78419 } 314