Skip to content

Commit 9d1c8f2

Browse files
ubizjakIngo Molnar
authored andcommitted
x86/smp: Move the call to smp_processor_id() after the early exit in native_stop_other_cpus()
Improve code generation in native_stop_other_cpus() a tiny bit: smp_processor_id() accesses a per-CPU variable, so the compiler is not able to move the call after the early exit on its own. Also rename the "cpu" variable to a more descriptive "this_cpu", and use 'cpu' as a separate iterator variable later in the function. No functional change intended. Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4604c05 commit 9d1c8f2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/kernel/smp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ static int register_stop_handler(void)
148148

149149
static void native_stop_other_cpus(int wait)
150150
{
151-
unsigned int cpu = smp_processor_id();
151+
unsigned int this_cpu;
152152
unsigned long flags, timeout;
153153

154154
if (reboot_force)
155155
return;
156156

157157
/* Only proceed if this is the first CPU to reach this code */
158-
if (atomic_cmpxchg(&stopping_cpu, -1, cpu) != -1)
158+
this_cpu = smp_processor_id();
159+
if (atomic_cmpxchg(&stopping_cpu, -1, this_cpu) != -1)
159160
return;
160161

161162
/* For kexec, ensure that offline CPUs are out of MWAIT and in HLT */
@@ -190,7 +191,7 @@ static void native_stop_other_cpus(int wait)
190191
* NMIs.
191192
*/
192193
cpumask_copy(&cpus_stop_mask, cpu_online_mask);
193-
cpumask_clear_cpu(cpu, &cpus_stop_mask);
194+
cpumask_clear_cpu(this_cpu, &cpus_stop_mask);
194195

195196
if (!cpumask_empty(&cpus_stop_mask)) {
196197
apic_send_IPI_allbutself(REBOOT_VECTOR);
@@ -234,6 +235,8 @@ static void native_stop_other_cpus(int wait)
234235
* CPUs to stop.
235236
*/
236237
if (!smp_no_nmi_ipi && !register_stop_handler()) {
238+
unsigned int cpu;
239+
237240
pr_emerg("Shutting down cpus with NMI\n");
238241

239242
for_each_cpu(cpu, &cpus_stop_mask)

0 commit comments

Comments
 (0)