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

MIPS: CPS: Add a couple of multi-cluster utility functions

This patch introduces a couple of utility functions which help later
patches with introducing support for multi-cluster systems.

- mips_cps_multicluster_cpus() allows its caller to determine whether
the system includes CPUs spread across multiple clusters. This is
useful because in some cases behaviour can be more optimal taking
this knowledge into account. The means by which we check this is
dependent upon the way we probe CPUs & assign their numbers, so
keeping this knowledge confined here in arch/mips/ seems appropriate.

- mips_cps_first_online_in_cluster() allows its caller to determine
whether it is running upon the first CPU online within its cluster.
This information is useful in cases where some cluster-wide
configuration may need to occur, but should not be repeated if
another CPU in the cluster is already online. Similarly to the above
this is determined based upon knowledge of CPU numbering so it makes
sense to keep that knowledge in arch/mips/. The function is defined
in mips-cm.c rather than in asm/mips-cps.h in order to allow us to
use asm/cpu-info.h & linux/smp.h without encountering an include
nightmare.

Signed-off-by: Paul Burton <paulburton@kernel.org>
Signed-off-by: Chao-ying Fu <cfu@wavecomp.com>
Signed-off-by: Dragan Mladjenovic <dragan.mladjenovic@syrmia.com>
Signed-off-by: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Paul Burton and committed by
Thomas Bogendoerfer
36675ac2 89c7f507

+76
+39
arch/mips/include/asm/mips-cps.h
··· 8 8 #define __MIPS_ASM_MIPS_CPS_H__ 9 9 10 10 #include <linux/bitfield.h> 11 + #include <linux/cpumask.h> 11 12 #include <linux/io.h> 12 13 #include <linux/types.h> 13 14 ··· 228 227 229 228 return FIELD_GET(CM_GCR_Cx_CONFIG_PVPE, cfg + 1); 230 229 } 230 + 231 + /** 232 + * mips_cps_multicluster_cpus() - Detect whether CPUs are in multiple clusters 233 + * 234 + * Determine whether the system includes CPUs in multiple clusters - ie. 235 + * whether we can treat the system as single or multi-cluster as far as CPUs 236 + * are concerned. Note that this is slightly different to simply checking 237 + * whether multiple clusters are present - it is possible for there to be 238 + * clusters which contain no CPUs, which this function will effectively ignore. 239 + * 240 + * Returns true if CPUs are spread across multiple clusters, else false. 241 + */ 242 + static inline bool mips_cps_multicluster_cpus(void) 243 + { 244 + unsigned int first_cl, last_cl; 245 + 246 + /* 247 + * CPUs are numbered sequentially by cluster - ie. CPUs 0..X will be in 248 + * cluster 0, CPUs X+1..Y in cluster 1, CPUs Y+1..Z in cluster 2 etc. 249 + * 250 + * Thus we can detect multiple clusters trivially by checking whether 251 + * the first & last CPUs belong to the same cluster. 252 + */ 253 + first_cl = cpu_cluster(&boot_cpu_data); 254 + last_cl = cpu_cluster(&cpu_data[nr_cpu_ids - 1]); 255 + return first_cl != last_cl; 256 + } 257 + 258 + /** 259 + * mips_cps_first_online_in_cluster() - Detect if CPU is first online in cluster 260 + * 261 + * Determine whether the local CPU is the first to be brought online in its 262 + * cluster - that is, whether there are any other online CPUs in the local 263 + * cluster. 264 + * 265 + * Returns true if this CPU is first online, else false. 266 + */ 267 + extern unsigned int mips_cps_first_online_in_cluster(void); 231 268 232 269 #endif /* __MIPS_ASM_MIPS_CPS_H__ */
+37
arch/mips/kernel/mips-cm.c
··· 512 512 /* reprime cause register */ 513 513 write_gcr_error_cause(cm_error); 514 514 } 515 + 516 + unsigned int mips_cps_first_online_in_cluster(void) 517 + { 518 + unsigned int local_cl; 519 + int i; 520 + 521 + local_cl = cpu_cluster(&current_cpu_data); 522 + 523 + /* 524 + * We rely upon knowledge that CPUs are numbered sequentially by 525 + * cluster - ie. CPUs 0..X will be in cluster 0, CPUs X+1..Y in cluster 526 + * 1, CPUs Y+1..Z in cluster 2 etc. This means that CPUs in the same 527 + * cluster will immediately precede or follow one another. 528 + * 529 + * First we scan backwards, until we find an online CPU in the cluster 530 + * or we move on to another cluster. 531 + */ 532 + for (i = smp_processor_id() - 1; i >= 0; i--) { 533 + if (cpu_cluster(&cpu_data[i]) != local_cl) 534 + break; 535 + if (!cpu_online(i)) 536 + continue; 537 + return false; 538 + } 539 + 540 + /* Then do the same for higher numbered CPUs */ 541 + for (i = smp_processor_id() + 1; i < nr_cpu_ids; i++) { 542 + if (cpu_cluster(&cpu_data[i]) != local_cl) 543 + break; 544 + if (!cpu_online(i)) 545 + continue; 546 + return false; 547 + } 548 + 549 + /* We found no online CPUs in the local cluster */ 550 + return true; 551 + }