Skip to content

Commit bda4584

Browse files
chenhuacairalfbaechle
authored andcommitted
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. Signed-off-by: Huacai Chen <[email protected]> Reviewed-by: Andreas Herrmann <[email protected]> Cc: John Crispin <[email protected]> Cc: Steven J. Hill <[email protected]> Cc: Aurelien Jarno <[email protected]> Cc: [email protected] Cc: Fuxin Zhang <[email protected]> Cc: Zhangjin Wu <[email protected]> Patchwork: https://patchwork.linux-mips.org/patch/7184/ Signed-off-by: Ralf Baechle <[email protected]>
1 parent 0f3f506 commit bda4584

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

arch/mips/include/asm/cpu-info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct cpuinfo_mips {
6161
struct cache_desc scache; /* Secondary cache */
6262
struct cache_desc tcache; /* Tertiary/split secondary cache */
6363
int srsets; /* Shadow register sets */
64+
int package;/* physical package number */
6465
int core; /* physical core number */
6566
#ifdef CONFIG_64BIT
6667
int vmbits; /* Virtual memory size in bits */

arch/mips/include/asm/smp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
extern int smp_num_siblings;
2424
extern cpumask_t cpu_sibling_map[];
25+
extern cpumask_t cpu_core_map[];
2526

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

@@ -36,6 +37,11 @@ extern int __cpu_logical_map[NR_CPUS];
3637

3738
#define NO_PROC_ID (-1)
3839

40+
#define topology_physical_package_id(cpu) (cpu_data[cpu].package)
41+
#define topology_core_id(cpu) (cpu_data[cpu].core)
42+
#define topology_core_cpumask(cpu) (&cpu_core_map[cpu])
43+
#define topology_thread_cpumask(cpu) (&cpu_sibling_map[cpu])
44+
3945
#define SMP_RESCHEDULE_YOURSELF 0x1 /* XXX braindead */
4046
#define SMP_CALL_FUNCTION 0x2
4147
/* Octeon - Tell another core to flush its icache */

arch/mips/kernel/proc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
123123
cpu_data[n].srsets);
124124
seq_printf(m, "kscratch registers\t: %d\n",
125125
hweight8(cpu_data[n].kscratch_mask));
126+
seq_printf(m, "package\t\t\t: %d\n", cpu_data[n].package);
126127
seq_printf(m, "core\t\t\t: %d\n", cpu_data[n].core);
127128

128129
sprintf(fmt, "VCE%%c exceptions\t\t: %s\n",

arch/mips/kernel/smp.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ EXPORT_SYMBOL(smp_num_siblings);
5959
cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
6060
EXPORT_SYMBOL(cpu_sibling_map);
6161

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

69+
/* representing cpus for which core maps can be computed */
70+
static cpumask_t cpu_core_setup_map;
71+
6572
cpumask_t cpu_coherent_mask;
6673

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

7380
if (smp_num_siblings > 1) {
7481
for_each_cpu_mask(i, cpu_sibling_setup_map) {
75-
if (cpu_data[cpu].core == cpu_data[i].core) {
82+
if (cpu_data[cpu].package == cpu_data[i].package &&
83+
cpu_data[cpu].core == cpu_data[i].core) {
7684
cpu_set(i, cpu_sibling_map[cpu]);
7785
cpu_set(cpu, cpu_sibling_map[i]);
7886
}
@@ -81,6 +89,20 @@ static inline void set_cpu_sibling_map(int cpu)
8189
cpu_set(cpu, cpu_sibling_map[cpu]);
8290
}
8391

92+
static inline void set_cpu_core_map(int cpu)
93+
{
94+
int i;
95+
96+
cpu_set(cpu, cpu_core_setup_map);
97+
98+
for_each_cpu_mask(i, cpu_core_setup_map) {
99+
if (cpu_data[cpu].package == cpu_data[i].package) {
100+
cpu_set(i, cpu_core_map[cpu]);
101+
cpu_set(cpu, cpu_core_map[i]);
102+
}
103+
}
104+
}
105+
84106
struct plat_smp_ops *mp_ops;
85107
EXPORT_SYMBOL(mp_ops);
86108

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

124146
set_cpu_sibling_map(cpu);
147+
set_cpu_core_map(cpu);
125148

126149
cpu_set(cpu, cpu_callin_map);
127150

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

0 commit comments

Comments
 (0)