Skip to content

Commit de2d944

Browse files
htejunIngo Molnar
authored andcommitted
x86: Unify node_to_cpumask_map handling between 32 and 64bit
x86_32 has been managing node_to_cpumask_map explicitly from map_cpu_to_node() and friends in a rather ugly way. With previous changes, it's now possible to share the code with 64bit. * When CONFIG_NUMA_EMU is disabled, numa_add/remove_cpu() are implemented in numa.c and shared by 32 and 64bit. CONFIG_NUMA_EMU versions still live in numa_64.c. NUMA_EMU's dependency on 64bit is planned to be removed and the above should go away together. * identify_cpu() now calls numa_add_cpu() for 32bit too. This makes the explicit mask management from map_cpu_to_node() unnecessary. * The whole x86_32 specific map_cpu_to_node() chunk is no longer necessary. Dropped. Signed-off-by: Tejun Heo <[email protected]> Reviewed-by: Pekka Enberg <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: David Rientjes <[email protected]> Cc: Shaohui Zheng <[email protected]>
1 parent 645a791 commit de2d944

File tree

7 files changed

+87
-115
lines changed

7 files changed

+87
-115
lines changed

arch/x86/include/asm/numa.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _ASM_X86_NUMA_H
22
#define _ASM_X86_NUMA_H
33

4+
#include <asm/topology.h>
45
#include <asm/apicdef.h>
56

67
#ifdef CONFIG_NUMA
@@ -33,9 +34,17 @@ static inline void set_apicid_to_node(int apicid, s16 node)
3334
#ifdef CONFIG_NUMA
3435
extern void __cpuinit numa_set_node(int cpu, int node);
3536
extern void __cpuinit numa_clear_node(int cpu);
37+
extern void __cpuinit numa_add_cpu(int cpu);
38+
extern void __cpuinit numa_remove_cpu(int cpu);
3639
#else /* CONFIG_NUMA */
3740
static inline void numa_set_node(int cpu, int node) { }
3841
static inline void numa_clear_node(int cpu) { }
42+
static inline void numa_add_cpu(int cpu) { }
43+
static inline void numa_remove_cpu(int cpu) { }
3944
#endif /* CONFIG_NUMA */
4045

46+
#ifdef CONFIG_DEBUG_PER_CPU_MAPS
47+
struct cpumask __cpuinit *debug_cpumask_set_cpu(int cpu, int enable);
48+
#endif
49+
4150
#endif /* _ASM_X86_NUMA_H */

arch/x86/include/asm/numa_32.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
extern int numa_off;
55

66
extern int pxm_to_nid(int pxm);
7-
extern void numa_remove_cpu(int cpu);
87

98
#ifdef CONFIG_NUMA
109
extern int __cpuinit numa_cpu_node(int apicid);

arch/x86/include/asm/numa_64.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ extern void setup_node_bootmem(int nodeid, unsigned long start,
3030

3131
extern void __init init_cpu_to_node(void);
3232
extern int __cpuinit numa_cpu_node(int cpu);
33-
extern void __cpuinit numa_add_cpu(int cpu);
34-
extern void __cpuinit numa_remove_cpu(int cpu);
3533

3634
#ifdef CONFIG_NUMA_EMU
3735
#define FAKE_NODE_MIN_SIZE ((u64)32 << 20)
@@ -41,8 +39,6 @@ void numa_emu_cmdline(char *);
4139
#else
4240
static inline void init_cpu_to_node(void) { }
4341
static inline int numa_cpu_node(int cpu) { return NUMA_NO_NODE; }
44-
static inline void numa_add_cpu(int cpu, int node) { }
45-
static inline void numa_remove_cpu(int cpu) { }
4642
#endif
4743

4844
#endif /* _ASM_X86_NUMA_64_H */

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
869869

870870
select_idle_routine(c);
871871

872-
#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
872+
#ifdef CONFIG_NUMA
873873
numa_add_cpu(smp_processor_id());
874874
#endif
875875
}

arch/x86/kernel/smpboot.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -132,49 +132,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
132132

133133
atomic_t init_deasserted;
134134

135-
#if defined(CONFIG_NUMA) && defined(CONFIG_X86_32)
136-
/* set up a mapping between cpu and node. */
137-
static void map_cpu_to_node(int cpu, int node)
138-
{
139-
printk(KERN_INFO "Mapping cpu %d to node %d\n", cpu, node);
140-
cpumask_set_cpu(cpu, node_to_cpumask_map[node]);
141-
}
142-
143-
/* undo a mapping between cpu and node. */
144-
static void unmap_cpu_to_node(int cpu)
145-
{
146-
int node;
147-
148-
printk(KERN_INFO "Unmapping cpu %d from all nodes\n", cpu);
149-
for (node = 0; node < MAX_NUMNODES; node++)
150-
cpumask_clear_cpu(cpu, node_to_cpumask_map[node]);
151-
}
152-
#else /* !(CONFIG_NUMA && CONFIG_X86_32) */
153-
#define map_cpu_to_node(cpu, node) ({})
154-
#define unmap_cpu_to_node(cpu) ({})
155-
#endif
156-
157-
#ifdef CONFIG_X86_32
158-
static void map_cpu_to_logical_apicid(void)
159-
{
160-
int cpu = smp_processor_id();
161-
int node;
162-
163-
node = numa_cpu_node(cpu);
164-
if (!node_online(node))
165-
node = first_online_node;
166-
167-
map_cpu_to_node(cpu, node);
168-
}
169-
170-
void numa_remove_cpu(int cpu)
171-
{
172-
unmap_cpu_to_node(cpu);
173-
}
174-
#else
175-
#define map_cpu_to_logical_apicid() do {} while (0)
176-
#endif
177-
178135
/*
179136
* Report back to the Boot Processor.
180137
* Running on AP.
@@ -242,7 +199,6 @@ static void __cpuinit smp_callin(void)
242199
apic->smp_callin_clear_local_apic();
243200
setup_local_APIC();
244201
end_local_APIC_setup();
245-
map_cpu_to_logical_apicid();
246202

247203
/*
248204
* Need to setup vector mappings before we enable interrupts.
@@ -943,7 +899,6 @@ static __init void disable_smp(void)
943899
physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
944900
else
945901
physid_set_mask_of_physid(0, &phys_cpu_present_map);
946-
map_cpu_to_logical_apicid();
947902
cpumask_set_cpu(0, cpu_sibling_mask(0));
948903
cpumask_set_cpu(0, cpu_core_mask(0));
949904
}
@@ -1120,8 +1075,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
11201075

11211076
end_local_APIC_setup();
11221077

1123-
map_cpu_to_logical_apicid();
1124-
11251078
if (apic->setup_portio_remap)
11261079
apic->setup_portio_remap();
11271080

arch/x86/mm/numa.c

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,21 @@ void __init setup_node_to_cpumask_map(void)
9999
pr_debug("Node to cpumask map for %d nodes\n", nr_node_ids);
100100
}
101101

102-
#ifdef CONFIG_DEBUG_PER_CPU_MAPS
102+
#ifndef CONFIG_DEBUG_PER_CPU_MAPS
103+
104+
# ifndef CONFIG_NUMA_EMU
105+
void __cpuinit numa_add_cpu(int cpu)
106+
{
107+
cpumask_set_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
108+
}
109+
110+
void __cpuinit numa_remove_cpu(int cpu)
111+
{
112+
cpumask_clear_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
113+
}
114+
# endif /* !CONFIG_NUMA_EMU */
115+
116+
#else /* !CONFIG_DEBUG_PER_CPU_MAPS */
103117

104118
int __cpu_to_node(int cpu)
105119
{
@@ -131,6 +145,52 @@ int early_cpu_to_node(int cpu)
131145
return per_cpu(x86_cpu_to_node_map, cpu);
132146
}
133147

148+
struct cpumask __cpuinit *debug_cpumask_set_cpu(int cpu, int enable)
149+
{
150+
int node = early_cpu_to_node(cpu);
151+
struct cpumask *mask;
152+
char buf[64];
153+
154+
mask = node_to_cpumask_map[node];
155+
if (!mask) {
156+
pr_err("node_to_cpumask_map[%i] NULL\n", node);
157+
dump_stack();
158+
return NULL;
159+
}
160+
161+
cpulist_scnprintf(buf, sizeof(buf), mask);
162+
printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
163+
enable ? "numa_add_cpu" : "numa_remove_cpu",
164+
cpu, node, buf);
165+
return mask;
166+
}
167+
168+
# ifndef CONFIG_NUMA_EMU
169+
static void __cpuinit numa_set_cpumask(int cpu, int enable)
170+
{
171+
struct cpumask *mask;
172+
173+
mask = debug_cpumask_set_cpu(cpu, enable);
174+
if (!mask)
175+
return;
176+
177+
if (enable)
178+
cpumask_set_cpu(cpu, mask);
179+
else
180+
cpumask_clear_cpu(cpu, mask);
181+
}
182+
183+
void __cpuinit numa_add_cpu(int cpu)
184+
{
185+
numa_set_cpumask(cpu, 1);
186+
}
187+
188+
void __cpuinit numa_remove_cpu(int cpu)
189+
{
190+
numa_set_cpumask(cpu, 0);
191+
}
192+
# endif /* !CONFIG_NUMA_EMU */
193+
134194
/*
135195
* Returns a pointer to the bitmask of CPUs on Node 'node'.
136196
*/
@@ -154,4 +214,4 @@ const struct cpumask *cpumask_of_node(int node)
154214
}
155215
EXPORT_SYMBOL(cpumask_of_node);
156216

157-
#endif /* CONFIG_DEBUG_PER_CPU_MAPS */
217+
#endif /* !CONFIG_DEBUG_PER_CPU_MAPS */

arch/x86/mm/numa_64.c

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -726,19 +726,18 @@ int __cpuinit numa_cpu_node(int cpu)
726726
return NUMA_NO_NODE;
727727
}
728728

729-
#ifndef CONFIG_DEBUG_PER_CPU_MAPS
730-
731-
#ifndef CONFIG_NUMA_EMU
732-
void __cpuinit numa_add_cpu(int cpu)
733-
{
734-
cpumask_set_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
735-
}
736-
737-
void __cpuinit numa_remove_cpu(int cpu)
738-
{
739-
cpumask_clear_cpu(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
740-
}
741-
#else
729+
/*
730+
* UGLINESS AHEAD: Currently, CONFIG_NUMA_EMU is 64bit only and makes use
731+
* of 64bit specific data structures. The distinction is artificial and
732+
* should be removed. numa_{add|remove}_cpu() are implemented in numa.c
733+
* for both 32 and 64bit when CONFIG_NUMA_EMU is disabled but here when
734+
* enabled.
735+
*
736+
* NUMA emulation is planned to be made generic and the following and other
737+
* related code should be moved to numa.c.
738+
*/
739+
#ifdef CONFIG_NUMA_EMU
740+
# ifndef CONFIG_DEBUG_PER_CPU_MAPS
742741
void __cpuinit numa_add_cpu(int cpu)
743742
{
744743
unsigned long addr;
@@ -778,47 +777,7 @@ void __cpuinit numa_remove_cpu(int cpu)
778777
for_each_online_node(i)
779778
cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
780779
}
781-
#endif /* !CONFIG_NUMA_EMU */
782-
783-
#else /* CONFIG_DEBUG_PER_CPU_MAPS */
784-
static struct cpumask __cpuinit *debug_cpumask_set_cpu(int cpu, int enable)
785-
{
786-
int node = early_cpu_to_node(cpu);
787-
struct cpumask *mask;
788-
char buf[64];
789-
790-
mask = node_to_cpumask_map[node];
791-
if (!mask) {
792-
pr_err("node_to_cpumask_map[%i] NULL\n", node);
793-
dump_stack();
794-
return NULL;
795-
}
796-
797-
cpulist_scnprintf(buf, sizeof(buf), mask);
798-
printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
799-
enable ? "numa_add_cpu" : "numa_remove_cpu",
800-
cpu, node, buf);
801-
return mask;
802-
}
803-
804-
/*
805-
* --------- debug versions of the numa functions ---------
806-
*/
807-
#ifndef CONFIG_NUMA_EMU
808-
static void __cpuinit numa_set_cpumask(int cpu, int enable)
809-
{
810-
struct cpumask *mask;
811-
812-
mask = debug_cpumask_set_cpu(cpu, enable);
813-
if (!mask)
814-
return;
815-
816-
if (enable)
817-
cpumask_set_cpu(cpu, mask);
818-
else
819-
cpumask_clear_cpu(cpu, mask);
820-
}
821-
#else
780+
# else /* !CONFIG_DEBUG_PER_CPU_MAPS */
822781
static void __cpuinit numa_set_cpumask(int cpu, int enable)
823782
{
824783
int node = early_cpu_to_node(cpu);
@@ -842,7 +801,6 @@ static void __cpuinit numa_set_cpumask(int cpu, int enable)
842801
cpumask_clear_cpu(cpu, mask);
843802
}
844803
}
845-
#endif /* CONFIG_NUMA_EMU */
846804

847805
void __cpuinit numa_add_cpu(int cpu)
848806
{
@@ -853,8 +811,5 @@ void __cpuinit numa_remove_cpu(int cpu)
853811
{
854812
numa_set_cpumask(cpu, 0);
855813
}
856-
/*
857-
* --------- end of debug versions of the numa functions ---------
858-
*/
859-
860-
#endif /* CONFIG_DEBUG_PER_CPU_MAPS */
814+
# endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
815+
#endif /* CONFIG_NUMA_EMU */

0 commit comments

Comments
 (0)