@@ -22,26 +22,25 @@ DECLARE_BITMAP(phys_cpu_present_map, MAX_LOCAL_APIC) __read_mostly;
22
22
/* Used for CPU number allocation and parallel CPU bringup */
23
23
u32 cpuid_to_apicid [] __read_mostly = { [0 ... NR_CPUS - 1 ] = BAD_APICID , };
24
24
25
+ /*
26
+ * Keep track of assigned, disabled and rejected CPUs. Present assigned
27
+ * with 1 as CPU #0 is reserved for the boot CPU.
28
+ */
29
+ static struct {
30
+ unsigned int nr_assigned_cpus ;
31
+ unsigned int nr_disabled_cpus ;
32
+ unsigned int nr_rejected_cpus ;
33
+ } topo_info __read_mostly = {
34
+ .nr_assigned_cpus = 1 ,
35
+ };
36
+
25
37
/*
26
38
* Processor to be disabled specified by kernel parameter
27
39
* disable_cpu_apicid=<int>, mostly used for the kdump 2nd kernel to
28
40
* avoid undefined behaviour caused by sending INIT from AP to BSP.
29
41
*/
30
42
static u32 disabled_cpu_apicid __ro_after_init = BAD_APICID ;
31
43
32
- static unsigned int num_processors ;
33
- static unsigned int disabled_cpus ;
34
-
35
- /*
36
- * The number of allocated logical CPU IDs. Since logical CPU IDs are allocated
37
- * contiguously, it equals to current allocated max logical CPU ID plus 1.
38
- * All allocated CPU IDs should be in the [0, nr_logical_cpuids) range,
39
- * so the maximum of nr_logical_cpuids is nr_cpu_ids.
40
- *
41
- * NOTE: Reserve 0 for BSP.
42
- */
43
- static int nr_logical_cpuids = 1 ;
44
-
45
44
bool arch_match_cpu_phys_id (int cpu , u64 phys_id )
46
45
{
47
46
return phys_id == (u64 )cpuid_to_apicid [cpu ];
@@ -75,7 +74,7 @@ static int __init smp_init_primary_thread_mask(void)
75
74
return 0 ;
76
75
}
77
76
78
- for (cpu = 0 ; cpu < nr_logical_cpuids ; cpu ++ )
77
+ for (cpu = 0 ; cpu < topo_info . nr_assigned_cpus ; cpu ++ )
79
78
cpu_mark_primary_thread (cpu , cpuid_to_apicid [cpu ]);
80
79
return 0 ;
81
80
}
@@ -89,7 +88,7 @@ static int topo_lookup_cpuid(u32 apic_id)
89
88
int i ;
90
89
91
90
/* CPU# to APICID mapping is persistent once it is established */
92
- for (i = 0 ; i < nr_logical_cpuids ; i ++ ) {
91
+ for (i = 0 ; i < topo_info . nr_assigned_cpus ; i ++ ) {
93
92
if (cpuid_to_apicid [i ] == apic_id )
94
93
return i ;
95
94
}
@@ -107,22 +106,21 @@ static int allocate_logical_cpuid(u32 apic_id)
107
106
if (cpu >= 0 )
108
107
return cpu ;
109
108
110
- cpuid_to_apicid [nr_logical_cpuids ] = apic_id ;
111
- return nr_logical_cpuids ++ ;
109
+ return topo_info .nr_assigned_cpus ++ ;
112
110
}
113
111
114
- static void cpu_update_apic (int cpu , u32 apicid )
112
+ static void cpu_update_apic (unsigned int cpu , u32 apic_id )
115
113
{
116
114
#if defined(CONFIG_SMP ) || defined(CONFIG_X86_64 )
117
- early_per_cpu (x86_cpu_to_apicid , cpu ) = apicid ;
115
+ early_per_cpu (x86_cpu_to_apicid , cpu ) = apic_id ;
118
116
#endif
117
+ cpuid_to_apicid [cpu ] = apic_id ;
119
118
set_cpu_possible (cpu , true);
120
- set_bit (apicid , phys_cpu_present_map );
119
+ set_bit (apic_id , phys_cpu_present_map );
121
120
set_cpu_present (cpu , true);
122
- num_processors ++ ;
123
121
124
122
if (system_state != SYSTEM_BOOTING )
125
- cpu_mark_primary_thread (cpu , apicid );
123
+ cpu_mark_primary_thread (cpu , apic_id );
126
124
}
127
125
128
126
static int generic_processor_info (int apicid )
@@ -137,18 +135,18 @@ static int generic_processor_info(int apicid)
137
135
return 0 ;
138
136
139
137
if (disabled_cpu_apicid == apicid ) {
140
- int thiscpu = num_processors + disabled_cpus ;
138
+ int thiscpu = topo_info . nr_assigned_cpus + topo_info . nr_disabled_cpus ;
141
139
142
140
pr_warn ("APIC: Disabling requested cpu. Processor %d/0x%x ignored.\n" ,
143
141
thiscpu , apicid );
144
142
145
- disabled_cpus ++ ;
143
+ topo_info . nr_rejected_cpus ++ ;
146
144
return - ENODEV ;
147
145
}
148
146
149
- if (num_processors >= nr_cpu_ids ) {
147
+ if (topo_info . nr_assigned_cpus >= nr_cpu_ids ) {
150
148
pr_warn_once ("APIC: CPU limit of %d reached. Ignoring further CPUs\n" , nr_cpu_ids );
151
- disabled_cpus ++ ;
149
+ topo_info . nr_rejected_cpus ++ ;
152
150
return - ENOSPC ;
153
151
}
154
152
@@ -178,14 +176,16 @@ static int __initdata setup_possible_cpus = -1;
178
176
*/
179
177
__init void prefill_possible_map (void )
180
178
{
179
+ unsigned int num_processors = topo_info .nr_assigned_cpus ;
180
+ unsigned int disabled_cpus = topo_info .nr_disabled_cpus ;
181
181
int i , possible ;
182
182
183
183
i = setup_max_cpus ?: 1 ;
184
184
if (setup_possible_cpus == -1 ) {
185
- possible = num_processors ;
185
+ possible = topo_info . nr_assigned_cpus ;
186
186
#ifdef CONFIG_HOTPLUG_CPU
187
187
if (setup_max_cpus )
188
- possible += disabled_cpus ;
188
+ possible += num_processors ;
189
189
#else
190
190
if (possible > i )
191
191
possible = i ;
@@ -238,7 +238,7 @@ void __init topology_register_apic(u32 apic_id, u32 acpi_id, bool present)
238
238
}
239
239
240
240
if (!present ) {
241
- disabled_cpus ++ ;
241
+ topo_info . nr_disabled_cpus ++ ;
242
242
return ;
243
243
}
244
244
@@ -295,7 +295,6 @@ void topology_hotunplug_apic(unsigned int cpu)
295
295
per_cpu (x86_cpu_to_apicid , cpu ) = BAD_APICID ;
296
296
clear_bit (apic_id , phys_cpu_present_map );
297
297
set_cpu_present (cpu , false);
298
- num_processors -- ;
299
298
}
300
299
#endif
301
300
0 commit comments