Skip to content

Commit 0aa002f

Browse files
htejunKAGA-KOKO
authored andcommitted
x86: apic: Cleanup and simplify setup_local_APIC()
setup_local_APIC() is used to setup local APIC early during CPU initialization and already assumes that preemption is disabled on entry. However, The function unnecessarily disables and enables preemption and uses smp_processor_id() multiple times in and out of the nested preemption disabled section. This gives the wrong impression that the function might be able to handle being called with preemption enabled and/or migrated to another processor in the middle. Make it clear that the function is always called with preemption disabled, drop the confusing preemption disable block and call smp_processor_id() once at the beginning of the function. Signed-off-by: Tejun Heo <[email protected]> Acked-by: Cyrill Gorcunov <[email protected]> Reviewed-by: Pekka Enberg <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: [email protected] LKML-Reference: <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 0e3fa13 commit 0aa002f

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

arch/x86/kernel/apic/apic.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,12 +1195,15 @@ static void __cpuinit lapic_setup_esr(void)
11951195
oldvalue, value);
11961196
}
11971197

1198-
11991198
/**
12001199
* setup_local_APIC - setup the local APIC
1200+
*
1201+
* Used to setup local APIC while initializing BSP or bringin up APs.
1202+
* Always called with preemption disabled.
12011203
*/
12021204
void __cpuinit setup_local_APIC(void)
12031205
{
1206+
int cpu = smp_processor_id();
12041207
unsigned int value, queued;
12051208
int i, j, acked = 0;
12061209
unsigned long long tsc = 0, ntsc;
@@ -1225,8 +1228,6 @@ void __cpuinit setup_local_APIC(void)
12251228
#endif
12261229
perf_events_lapic_init();
12271230

1228-
preempt_disable();
1229-
12301231
/*
12311232
* Double-check whether this APIC is really registered.
12321233
* This is meaningless in clustered apic mode, so we skip it.
@@ -1342,33 +1343,29 @@ void __cpuinit setup_local_APIC(void)
13421343
* TODO: set up through-local-APIC from through-I/O-APIC? --macro
13431344
*/
13441345
value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
1345-
if (!smp_processor_id() && (pic_mode || !value)) {
1346+
if (!cpu && (pic_mode || !value)) {
13461347
value = APIC_DM_EXTINT;
1347-
apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
1348-
smp_processor_id());
1348+
apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", cpu);
13491349
} else {
13501350
value = APIC_DM_EXTINT | APIC_LVT_MASKED;
1351-
apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
1352-
smp_processor_id());
1351+
apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", cpu);
13531352
}
13541353
apic_write(APIC_LVT0, value);
13551354

13561355
/*
13571356
* only the BP should see the LINT1 NMI signal, obviously.
13581357
*/
1359-
if (!smp_processor_id())
1358+
if (!cpu)
13601359
value = APIC_DM_NMI;
13611360
else
13621361
value = APIC_DM_NMI | APIC_LVT_MASKED;
13631362
if (!lapic_is_integrated()) /* 82489DX */
13641363
value |= APIC_LVT_LEVEL_TRIGGER;
13651364
apic_write(APIC_LVT1, value);
13661365

1367-
preempt_enable();
1368-
13691366
#ifdef CONFIG_X86_MCE_INTEL
13701367
/* Recheck CMCI information after local APIC is up on CPU #0 */
1371-
if (smp_processor_id() == 0)
1368+
if (!cpu)
13721369
cmci_recheck();
13731370
#endif
13741371
}

0 commit comments

Comments
 (0)