Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Unify checks for sibling CPUs

Up until now we have open-coded checks for whether CPUs are siblings,
with slight variations on whether we consider the package ID or not.

This will only get more complex when we introduce cluster support, so in
preparation for that this patch introduces a cpus_are_siblings()
function which can be used to check whether or not 2 CPUs are siblings
in a consistent manner.

By checking globalnumber with the VP ID masked out this also has the
neat side effect of being ready for multi-cluster systems already.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Acked-by: Rafael J. Wysocki <rjw@rjwysocki.net>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/17011/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Paul Burton and committed by
Ralf Baechle
fe7a38c6 856fbcee

+28 -13
+17
arch/mips/include/asm/cpu-info.h
··· 158 158 extern void cpu_set_core(struct cpuinfo_mips *cpuinfo, unsigned int core); 159 159 extern void cpu_set_vpe_id(struct cpuinfo_mips *cpuinfo, unsigned int vpe); 160 160 161 + static inline bool cpus_are_siblings(int cpua, int cpub) 162 + { 163 + struct cpuinfo_mips *infoa = &cpu_data[cpua]; 164 + struct cpuinfo_mips *infob = &cpu_data[cpub]; 165 + unsigned int gnuma, gnumb; 166 + 167 + if (infoa->package != infob->package) 168 + return false; 169 + 170 + gnuma = infoa->globalnumber & ~MIPS_GLOBALNUMBER_VP; 171 + gnumb = infob->globalnumber & ~MIPS_GLOBALNUMBER_VP; 172 + if (gnuma != gnumb) 173 + return false; 174 + 175 + return true; 176 + } 177 + 161 178 static inline unsigned long cpu_asid_inc(void) 162 179 { 163 180 return 1 << CONFIG_MIPS_ASID_SHIFT;
+4 -4
arch/mips/kernel/smp-cps.c
··· 147 147 cpu_has_dc_aliases ? "dcache aliasing" : ""); 148 148 149 149 for_each_present_cpu(c) { 150 - if (cpu_core(&cpu_data[c])) 150 + if (!cpus_are_siblings(smp_processor_id(), c)) 151 151 set_cpu_present(c, false); 152 152 } 153 153 } ··· 319 319 mips_cm_unlock_other(); 320 320 } 321 321 322 - if (core != cpu_core(&current_cpu_data)) { 322 + if (!cpus_are_siblings(cpu, smp_processor_id())) { 323 323 /* Boot a VPE on another powered up core */ 324 324 for (remote = 0; remote < NR_CPUS; remote++) { 325 - if (cpu_core(&cpu_data[remote]) != core) 325 + if (!cpus_are_siblings(cpu, remote)) 326 326 continue; 327 327 if (cpu_online(remote)) 328 328 break; ··· 431 431 432 432 /* Look for another online VPE within the core */ 433 433 for_each_online_cpu(cpu_death_sibling) { 434 - if (cpu_core(&cpu_data[cpu_death_sibling]) != core) 434 + if (!cpus_are_siblings(cpu, cpu_death_sibling)) 435 435 continue; 436 436 437 437 /*
+5 -7
arch/mips/kernel/smp.c
··· 96 96 97 97 if (smp_num_siblings > 1) { 98 98 for_each_cpu(i, &cpu_sibling_setup_map) { 99 - if (cpu_data[cpu].package == cpu_data[i].package && 100 - cpu_core(&cpu_data[cpu]) == cpu_core(&cpu_data[i])) { 99 + if (cpus_are_siblings(cpu, i)) { 101 100 cpumask_set_cpu(i, &cpu_sibling_map[cpu]); 102 101 cpumask_set_cpu(cpu, &cpu_sibling_map[i]); 103 102 } ··· 133 134 for_each_online_cpu(i) { 134 135 core_present = 0; 135 136 for_each_cpu(k, &temp_foreign_map) 136 - if (cpu_data[i].package == cpu_data[k].package && 137 - cpu_core(&cpu_data[i]) == cpu_core(&cpu_data[k])) 137 + if (cpus_are_siblings(i, k)) 138 138 core_present = 1; 139 139 if (!core_present) 140 140 cpumask_set_cpu(i, &temp_foreign_map); ··· 184 186 185 187 if (mips_cpc_present()) { 186 188 for_each_cpu(cpu, mask) { 187 - core = cpu_core(&cpu_data[cpu]); 188 - 189 - if (core == cpu_core(&current_cpu_data)) 189 + if (cpus_are_siblings(cpu, smp_processor_id())) 190 190 continue; 191 + 192 + core = cpu_core(&cpu_data[cpu]); 191 193 192 194 while (!cpumask_test_cpu(cpu, &cpu_coherent_mask)) { 193 195 mips_cm_lock_other(core, 0);
+1 -1
drivers/cpuidle/cpuidle-cps.c
··· 37 37 * TODO: don't treat core 0 specially, just prevent the final core 38 38 * TODO: remap interrupt affinity temporarily 39 39 */ 40 - if (!cpu_core(&cpu_data[dev->cpu]) && (index > STATE_NC_WAIT)) 40 + if (cpus_are_siblings(0, dev->cpu) && (index > STATE_NC_WAIT)) 41 41 index = STATE_NC_WAIT; 42 42 43 43 /* Select the appropriate cps_pm_state */
+1 -1
drivers/irqchip/irq-mips-cpu.c
··· 101 101 local_irq_save(flags); 102 102 103 103 /* We can only send IPIs to VPEs within the local core */ 104 - WARN_ON(cpu_data[cpu].core != current_cpu_data.core); 104 + WARN_ON(!cpus_are_siblings(smp_processor_id(), cpu)); 105 105 106 106 vpflags = dvpe(); 107 107 settc(cpu_vpe_id(&cpu_data[cpu]));