Skip to content

Commit 58aa34a

Browse files
committed
x86/cpu/topology: Confine topology information
Now that all external fiddling with num_processors and disabled_cpus is gone, move the last user prefill_possible_map() into the topology code too and remove the global visibility of these variables. Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Sohil Mehta <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e753070 commit 58aa34a

File tree

4 files changed

+74
-78
lines changed

4 files changed

+74
-78
lines changed

arch/x86/include/asm/smp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <asm/thread_info.h>
1010

1111
extern int smp_num_siblings;
12-
extern unsigned int num_processors;
1312

1413
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
1514
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
@@ -174,8 +173,6 @@ static inline struct cpumask *cpu_llc_shared_mask(int cpu)
174173
}
175174
#endif /* CONFIG_SMP */
176175

177-
extern unsigned disabled_cpus;
178-
179176
#ifdef CONFIG_DEBUG_NMI_SELFTEST
180177
extern void nmi_selftest(void);
181178
#else

arch/x86/kernel/apic/apic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,6 @@ void __init init_apic_mappings(void)
20542054
pr_info("APIC: disable apic facility\n");
20552055
apic_disable();
20562056
}
2057-
num_processors = 1;
20582057
}
20592058
}
20602059

arch/x86/kernel/cpu/topology.c

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ u32 cpuid_to_apicid[] __read_mostly = { [0 ... NR_CPUS - 1] = BAD_APICID, };
2929
*/
3030
static u32 disabled_cpu_apicid __ro_after_init = BAD_APICID;
3131

32-
unsigned int num_processors;
33-
unsigned disabled_cpus;
32+
static unsigned int num_processors;
33+
static unsigned int disabled_cpus;
3434

3535
/*
3636
* The number of allocated logical CPU IDs. Since logical CPU IDs are allocated
@@ -174,6 +174,71 @@ static int generic_processor_info(int apicid)
174174
return cpu;
175175
}
176176

177+
static int __initdata setup_possible_cpus = -1;
178+
179+
/*
180+
* cpu_possible_mask should be static, it cannot change as cpu's
181+
* are onlined, or offlined. The reason is per-cpu data-structures
182+
* are allocated by some modules at init time, and don't expect to
183+
* do this dynamically on cpu arrival/departure.
184+
* cpu_present_mask on the other hand can change dynamically.
185+
* In case when cpu_hotplug is not compiled, then we resort to current
186+
* behaviour, which is cpu_possible == cpu_present.
187+
* - Ashok Raj
188+
*
189+
* Three ways to find out the number of additional hotplug CPUs:
190+
* - If the BIOS specified disabled CPUs in ACPI/mptables use that.
191+
* - The user can overwrite it with possible_cpus=NUM
192+
* - Otherwise don't reserve additional CPUs.
193+
* We do this because additional CPUs waste a lot of memory.
194+
* -AK
195+
*/
196+
__init void prefill_possible_map(void)
197+
{
198+
int i, possible;
199+
200+
i = setup_max_cpus ?: 1;
201+
if (setup_possible_cpus == -1) {
202+
possible = num_processors;
203+
#ifdef CONFIG_HOTPLUG_CPU
204+
if (setup_max_cpus)
205+
possible += disabled_cpus;
206+
#else
207+
if (possible > i)
208+
possible = i;
209+
#endif
210+
} else
211+
possible = setup_possible_cpus;
212+
213+
total_cpus = max_t(int, possible, num_processors + disabled_cpus);
214+
215+
/* nr_cpu_ids could be reduced via nr_cpus= */
216+
if (possible > nr_cpu_ids) {
217+
pr_warn("%d Processors exceeds NR_CPUS limit of %u\n",
218+
possible, nr_cpu_ids);
219+
possible = nr_cpu_ids;
220+
}
221+
222+
#ifdef CONFIG_HOTPLUG_CPU
223+
if (!setup_max_cpus)
224+
#endif
225+
if (possible > i) {
226+
pr_warn("%d Processors exceeds max_cpus limit of %u\n",
227+
possible, setup_max_cpus);
228+
possible = i;
229+
}
230+
231+
set_nr_cpu_ids(possible);
232+
233+
pr_info("Allowing %d CPUs, %d hotplug CPUs\n",
234+
possible, max_t(int, possible - num_processors, 0));
235+
236+
reset_cpu_possible_mask();
237+
238+
for (i = 0; i < possible; i++)
239+
set_cpu_possible(i, true);
240+
}
241+
177242
/**
178243
* topology_register_apic - Register an APIC in early topology maps
179244
* @apic_id: The APIC ID to set up
@@ -251,6 +316,13 @@ void topology_hotunplug_apic(unsigned int cpu)
251316
}
252317
#endif
253318

319+
static int __init _setup_possible_cpus(char *str)
320+
{
321+
get_option(&str, &setup_possible_cpus);
322+
return 0;
323+
}
324+
early_param("possible_cpus", _setup_possible_cpus);
325+
254326
static int __init apic_set_disabled_cpu_apicid(char *arg)
255327
{
256328
if (!arg || !get_option(&arg, &disabled_cpu_apicid))

arch/x86/kernel/smpboot.c

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,78 +1291,6 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
12911291
cache_aps_init();
12921292
}
12931293

1294-
static int __initdata setup_possible_cpus = -1;
1295-
static int __init _setup_possible_cpus(char *str)
1296-
{
1297-
get_option(&str, &setup_possible_cpus);
1298-
return 0;
1299-
}
1300-
early_param("possible_cpus", _setup_possible_cpus);
1301-
1302-
1303-
/*
1304-
* cpu_possible_mask should be static, it cannot change as cpu's
1305-
* are onlined, or offlined. The reason is per-cpu data-structures
1306-
* are allocated by some modules at init time, and don't expect to
1307-
* do this dynamically on cpu arrival/departure.
1308-
* cpu_present_mask on the other hand can change dynamically.
1309-
* In case when cpu_hotplug is not compiled, then we resort to current
1310-
* behaviour, which is cpu_possible == cpu_present.
1311-
* - Ashok Raj
1312-
*
1313-
* Three ways to find out the number of additional hotplug CPUs:
1314-
* - If the BIOS specified disabled CPUs in ACPI/mptables use that.
1315-
* - The user can overwrite it with possible_cpus=NUM
1316-
* - Otherwise don't reserve additional CPUs.
1317-
* We do this because additional CPUs waste a lot of memory.
1318-
* -AK
1319-
*/
1320-
__init void prefill_possible_map(void)
1321-
{
1322-
int i, possible;
1323-
1324-
i = setup_max_cpus ?: 1;
1325-
if (setup_possible_cpus == -1) {
1326-
possible = num_processors;
1327-
#ifdef CONFIG_HOTPLUG_CPU
1328-
if (setup_max_cpus)
1329-
possible += disabled_cpus;
1330-
#else
1331-
if (possible > i)
1332-
possible = i;
1333-
#endif
1334-
} else
1335-
possible = setup_possible_cpus;
1336-
1337-
total_cpus = max_t(int, possible, num_processors + disabled_cpus);
1338-
1339-
/* nr_cpu_ids could be reduced via nr_cpus= */
1340-
if (possible > nr_cpu_ids) {
1341-
pr_warn("%d Processors exceeds NR_CPUS limit of %u\n",
1342-
possible, nr_cpu_ids);
1343-
possible = nr_cpu_ids;
1344-
}
1345-
1346-
#ifdef CONFIG_HOTPLUG_CPU
1347-
if (!setup_max_cpus)
1348-
#endif
1349-
if (possible > i) {
1350-
pr_warn("%d Processors exceeds max_cpus limit of %u\n",
1351-
possible, setup_max_cpus);
1352-
possible = i;
1353-
}
1354-
1355-
set_nr_cpu_ids(possible);
1356-
1357-
pr_info("Allowing %d CPUs, %d hotplug CPUs\n",
1358-
possible, max_t(int, possible - num_processors, 0));
1359-
1360-
reset_cpu_possible_mask();
1361-
1362-
for (i = 0; i < possible; i++)
1363-
set_cpu_possible(i, true);
1364-
}
1365-
13661294
/* correctly size the local cpu masks */
13671295
void __init setup_cpu_local_masks(void)
13681296
{

0 commit comments

Comments
 (0)