[8/9] cpu: Make cpu_get_core_index() return the fused core number

Message ID 20180927044849.28322-9-benh@kernel.crashing.org
State Under Review
Headers show
Series
  • Initial "big cores" support for POWER9
Related show

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied

Commit Message

Benjamin Herrenschmidt Sept. 27, 2018, 4:48 a.m.
cpu_get_core_index() currently uses pir_to_core_id() which returns
an EC number always (ie, a small core number) even in fused core
mode. This is inconsistent with cpu_get_thread_index() which returns
a thread within a fused core (0...7) on P9.

So let's make things consistent and document it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 core/chip.c    | 13 +++++++++++++
 core/cpu.c     |  2 +-
 include/chip.h |  5 +++++
 include/cpu.h  |  6 ++++++
 4 files changed, 25 insertions(+), 1 deletion(-)

Patch

diff --git a/core/chip.c b/core/chip.c
index 902327e1..60c7a6e7 100644
--- a/core/chip.c
+++ b/core/chip.c
@@ -48,6 +48,19 @@  uint32_t pir_to_core_id(uint32_t pir)
 		return P7_PIR2COREID(pir);
 }
 
+uint32_t pir_to_fused_core_id(uint32_t pir)
+{
+	if (proc_gen == proc_gen_p9) {
+		if (this_cpu()->is_fused_core)
+			return P9_PIR2FUSEDCOREID(pir);
+		else
+			return P9_PIR2COREID(pir);
+	} else if (proc_gen == proc_gen_p8)
+		return P8_PIR2COREID(pir);
+	else
+		return P7_PIR2COREID(pir);
+}
+
 uint32_t pir_to_thread_id(uint32_t pir)
 {
 	if (proc_gen == proc_gen_p9) {
diff --git a/core/cpu.c b/core/cpu.c
index 0a0c5d7e..53dae741 100644
--- a/core/cpu.c
+++ b/core/cpu.c
@@ -846,7 +846,7 @@  struct cpu_thread *first_available_core_in_chip(u32 chip_id)
 
 uint32_t cpu_get_core_index(struct cpu_thread *cpu)
 {
-	return pir_to_core_id(cpu->pir);
+	return pir_to_fused_core_id(cpu->pir);
 }
 
 void cpu_remove_node(const struct cpu_thread *t)
diff --git a/include/chip.h b/include/chip.h
index a9ab5560..322f84e9 100644
--- a/include/chip.h
+++ b/include/chip.h
@@ -268,6 +268,11 @@  extern uint32_t pir_to_chip_id(uint32_t pir);
 extern uint32_t pir_to_core_id(uint32_t pir);
 extern uint32_t pir_to_thread_id(uint32_t pir);
 
+/* In P9 fused core mode, this is the "fused" core ID, in
+ * normal core mode or P8, this is the same as pir_to_core_id
+ */
+extern uint32_t pir_to_fused_core_id(uint32_t pir);
+
 extern struct proc_chip *next_chip(struct proc_chip *chip);
 
 #define for_each_chip(__c) for (__c=next_chip(NULL); __c; __c=next_chip(__c))
diff --git a/include/cpu.h b/include/cpu.h
index a8ac5678..3a266535 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -242,6 +242,12 @@  static inline __nomcount struct cpu_thread *this_cpu(void)
 	return __this_cpu;
 }
 
+/*
+ * Note: On POWER9 fused core, cpu_get_thread_index() and cpu_get_core_index()
+ * return respectively the thread number within a fused core (0..7) and
+ * the fused core number. If you want the EC (small core) number, you have
+ * to use the low level pir_to_core_id() and pir_to_thread_id().
+ */
 /* Get the thread # of a cpu within the core */
 static inline uint32_t cpu_get_thread_index(struct cpu_thread *cpu)
 {