Re:[PATCH V4] MIPS: Support CPU topology files in sysfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, Ralf,

Please update this patch since the V3 has failed the kbuild test in linux-next tree.

Huacai


---原始邮件---
发件人:"陈华才"<chenhc@xxxxxxxxxx>
发送时间:2014年8月1日(星期五) 下午5:21
收件人:"Ralf Baechle"<ralf@xxxxxxxxxxxxxx>;
主题:[PATCH V4] MIPS: Support CPU topology files in sysfs
This patch is prepared for Loongson's NUMA support, it offer meaningful
sysfs files such as physical_package_id, core_id, core_siblings and
thread_siblings in /sys/devices/system/cpu/cpu?/topology.

V4: Fix macros redefinition problems for Netlogic.

Signed-off-by: Huacai Chen <chenhc@xxxxxxxxxx>
Reviewed-by: Andreas Herrmann <andreas.herrmann@xxxxxxxxxxxxxxxxxx>
Cc: Jayachandran C. <jchandra@xxxxxxxxxxxx>
---
arch/mips/include/asm/cpu-info.h |    1 +
arch/mips/include/asm/smp.h      |    1 +
arch/mips/include/asm/topology.h |   13 +++++++++++++
arch/mips/kernel/proc.c          |    1 +
arch/mips/kernel/smp.c           |   26 +++++++++++++++++++++++++-
5 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/arch/mips/include/asm/cpu-info.h b/arch/mips/include/asm/cpu-info.h
index 780cff9..d5f42c1 100644
--- a/arch/mips/include/asm/cpu-info.h
+++ b/arch/mips/include/asm/cpu-info.h
@@ -61,6 +61,7 @@ struct cpuinfo_mips {
 struct cache_desc scache; /* Secondary cache */
 struct cache_desc tcache; /* Tertiary/split secondary cache */
 int srsets; /* Shadow register sets */
+ int package;/* physical package number */
 int core; /* physical core number */
#ifdef CONFIG_64BIT
 int vmbits; /* Virtual memory size in bits */
diff --git a/arch/mips/include/asm/smp.h b/arch/mips/include/asm/smp.h
index b037334..eacf865 100644
--- a/arch/mips/include/asm/smp.h
+++ b/arch/mips/include/asm/smp.h
@@ -22,6 +22,7 @@

extern int smp_num_siblings;
extern cpumask_t cpu_sibling_map[];
+extern cpumask_t cpu_core_map[];

#define raw_smp_processor_id() (current_thread_info()->cpu)

diff --git a/arch/mips/include/asm/topology.h b/arch/mips/include/asm/topology.h
index 20ea485..2a0f04b 100644
--- a/arch/mips/include/asm/topology.h
+++ b/arch/mips/include/asm/topology.h
@@ -10,4 +10,17 @@

#include <topology.h>

+#ifndef topology_physical_package_id
+#define topology_physical_package_id(cpu) (cpu_data[cpu].package)
+#endif
+#ifndef topology_core_id
+#define topology_core_id(cpu) (cpu_data[cpu].core)
+#endif
+#ifndef topology_core_cpumask
+#define topology_core_cpumask(cpu)(&cpu_core_map[cpu])
+#endif
+#ifndef topology_thread_cpumask
+#define topology_thread_cpumask(cpu)(&cpu_sibling_map[cpu])
+#endif
+
#endif /* __ASM_TOPOLOGY_H */
diff --git a/arch/mips/kernel/proc.c b/arch/mips/kernel/proc.c
index 1ed1b5a..097fc8d 100644
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -124,6 +124,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
      cpu_data[n].srsets);
 seq_printf(m, "kscratch registers\t: %d\n",
      hweight8(cpu_data[n].kscratch_mask));
+ seq_printf(m, "package\t\t\t: %d\n", cpu_data[n].package);
 seq_printf(m, "core\t\t\t: %d\n", cpu_data[n].core);

 sprintf(fmt, "VCE%%c exceptions\t\t: %s\n",
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index 9bad52e..c94c4e9 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -59,9 +59,16 @@ EXPORT_SYMBOL(smp_num_siblings);
cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
EXPORT_SYMBOL(cpu_sibling_map);

+/* representing the core map of multi-core chips of each logical CPU */
+cpumask_t cpu_core_map[NR_CPUS] __read_mostly;
+EXPORT_SYMBOL(cpu_core_map);
+
/* representing cpus for which sibling maps can be computed */
static cpumask_t cpu_sibling_setup_map;

+/* representing cpus for which core maps can be computed */
+static cpumask_t cpu_core_setup_map;
+
cpumask_t cpu_coherent_mask;

static inline void set_cpu_sibling_map(int cpu)
@@ -72,7 +79,8 @@ static inline void set_cpu_sibling_map(int cpu)

 if (smp_num_siblings > 1) {
for_each_cpu_mask(i, cpu_sibling_setup_map) {
- if (cpu_data[cpu].core == cpu_data[i].core) {
+ if (cpu_data[cpu].package == cpu_data[i].package &&
+    cpu_data[cpu].core == cpu_data[i].core) {
cpu_set(i, cpu_sibling_map[cpu]);
cpu_set(cpu, cpu_sibling_map[i]);
 }
@@ -81,6 +89,20 @@ static inline void set_cpu_sibling_map(int cpu)
cpu_set(cpu, cpu_sibling_map[cpu]);
}

+static inline void set_cpu_core_map(int cpu)
+{
+ int i;
+
+ cpu_set(cpu, cpu_core_setup_map);
+
+ for_each_cpu_mask(i, cpu_core_setup_map) {
+if (cpu_data[cpu].package == cpu_data[i].package) {
+ cpu_set(i, cpu_core_map[cpu]);
+ cpu_set(cpu, cpu_core_map[i]);
+}
+ }
+}
+
struct plat_smp_ops *mp_ops;
EXPORT_SYMBOL(mp_ops);

@@ -122,6 +144,7 @@ asmlinkage void start_secondary(void)
 set_cpu_online(cpu, true);

 set_cpu_sibling_map(cpu);
+ set_cpu_core_map(cpu);

 cpu_set(cpu, cpu_callin_map);

@@ -175,6 +198,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
 current_thread_info()->cpu = 0;
 mp_ops->prepare_cpus(max_cpus);
 set_cpu_sibling_map(0);
+ set_cpu_core_map(0);
#ifndef CONFIG_HOTPLUG_CPU
 init_cpu_present(cpu_possible_mask);
#endif
-- 
1.7.7.3


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux