Skip to content

Commit a71c8bc

Browse files
Fenghua YuH. Peter Anvin
authored andcommitted
x86, topology: Debug CPU0 hotplug
CONFIG_DEBUG_HOTPLUG_CPU0 is for debugging the CPU0 hotplug feature. The switch offlines CPU0 as soon as possible and boots userspace up with CPU0 offlined. User can online CPU0 back after boot time. The default value of the switch is off. To debug CPU0 hotplug, you need to enable CPU0 offline/online feature by either turning on CONFIG_BOOTPARAM_HOTPLUG_CPU0 during compilation or giving cpu0_hotplug kernel parameter at boot. It's safe and early place to take down CPU0 after all hotplug notifiers are installed and SMP is booted. Please note that some applications or drivers, e.g. some versions of udevd, during boot time may put CPU0 online again in this CPU0 hotplug debug mode. In this debug mode, setup_local_APIC() may report a warning on max_loops<=0 when CPU0 is onlined back after boot time. This is because pending interrupt in IRR can not move to ISR. The warning is not CPU0 specfic and it can happen on other CPUs as well. It is harmless except the first CPU0 online takes a bit longer time. And so this debug mode is useful to expose this issue. I'll send a seperate patch to fix this generic warning issue. Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Link: http://lkml.kernel.org/r/1352835171-3958-15-git-send-email-fenghua.yu@intel.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent 6f5298c commit a71c8bc

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

‎arch/x86/Kconfig‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,21 @@ config BOOTPARAM_HOTPLUG_CPU0
17271727
You still can enable the CPU0 hotplug feature at boot by kernel
17281728
parameter cpu0_hotplug.
17291729

1730+
config DEBUG_HOTPLUG_CPU0
1731+
def_bool n
1732+
prompt "Debug CPU0 hotplug"
1733+
depends on HOTPLUG_CPU && EXPERIMENTAL
1734+
---help---
1735+
Enabling this option offlines CPU0 (if CPU0 can be offlined) as
1736+
soon as possible and boots up userspace with CPU0 offlined. User
1737+
can online CPU0 back after boot time.
1738+
1739+
To debug CPU0 hotplug, you need to enable CPU0 offline/online
1740+
feature by either turning on CONFIG_BOOTPARAM_HOTPLUG_CPU0 during
1741+
compilation or giving cpu0_hotplug kernel parameter at boot.
1742+
1743+
If unsure, say N.
1744+
17301745
config COMPAT_VDSO
17311746
def_bool y
17321747
prompt "Compat VDSO support"

‎arch/x86/include/asm/cpu.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ struct x86_cpu {
2929
extern int arch_register_cpu(int num);
3030
extern void arch_unregister_cpu(int);
3131
extern void __cpuinit start_cpu0(void);
32+
#ifdef CONFIG_DEBUG_HOTPLUG_CPU0
33+
extern int _debug_hotplug_cpu(int cpu, int action);
34+
#endif
3235
#endif
3336

3437
DECLARE_PER_CPU(int, cpu_state);

‎arch/x86/kernel/topology.c‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,57 @@ static int __init enable_cpu0_hotplug(char *str)
5050
__setup("cpu0_hotplug", enable_cpu0_hotplug);
5151
#endif
5252

53+
#ifdef CONFIG_DEBUG_HOTPLUG_CPU0
54+
/*
55+
* This function offlines a CPU as early as possible and allows userspace to
56+
* boot up without the CPU. The CPU can be onlined back by user after boot.
57+
*
58+
* This is only called for debugging CPU offline/online feature.
59+
*/
60+
int __ref _debug_hotplug_cpu(int cpu, int action)
61+
{
62+
struct device *dev = get_cpu_device(cpu);
63+
int ret;
64+
65+
if (!cpu_is_hotpluggable(cpu))
66+
return -EINVAL;
67+
68+
cpu_hotplug_driver_lock();
69+
70+
switch (action) {
71+
case 0:
72+
ret = cpu_down(cpu);
73+
if (!ret) {
74+
pr_info("CPU %u is now offline\n", cpu);
75+
kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
76+
} else
77+
pr_debug("Can't offline CPU%d.\n", cpu);
78+
break;
79+
case 1:
80+
ret = cpu_up(cpu);
81+
if (!ret)
82+
kobject_uevent(&dev->kobj, KOBJ_ONLINE);
83+
else
84+
pr_debug("Can't online CPU%d.\n", cpu);
85+
break;
86+
default:
87+
ret = -EINVAL;
88+
}
89+
90+
cpu_hotplug_driver_unlock();
91+
92+
return ret;
93+
}
94+
95+
static int __init debug_hotplug_cpu(void)
96+
{
97+
_debug_hotplug_cpu(0, 0);
98+
return 0;
99+
}
100+
101+
late_initcall_sync(debug_hotplug_cpu);
102+
#endif /* CONFIG_DEBUG_HOTPLUG_CPU0 */
103+
53104
int __ref arch_register_cpu(int num)
54105
{
55106
struct cpuinfo_x86 *c = &cpu_data(num);

‎arch/x86/power/cpu.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <asm/suspend.h>
2222
#include <asm/debugreg.h>
2323
#include <asm/fpu-internal.h> /* pcntxt_mask */
24+
#include <asm/cpu.h>
2425

2526
#ifdef CONFIG_X86_32
2627
static struct saved_context saved_context;
@@ -263,6 +264,43 @@ static int bsp_pm_callback(struct notifier_block *nb, unsigned long action,
263264
case PM_HIBERNATION_PREPARE:
264265
ret = bsp_check();
265266
break;
267+
#ifdef CONFIG_DEBUG_HOTPLUG_CPU0
268+
case PM_RESTORE_PREPARE:
269+
/*
270+
* When system resumes from hibernation, online CPU0 because
271+
* 1. it's required for resume and
272+
* 2. the CPU was online before hibernation
273+
*/
274+
if (!cpu_online(0))
275+
_debug_hotplug_cpu(0, 1);
276+
break;
277+
case PM_POST_RESTORE:
278+
/*
279+
* When a resume really happens, this code won't be called.
280+
*
281+
* This code is called only when user space hibernation software
282+
* prepares for snapshot device during boot time. So we just
283+
* call _debug_hotplug_cpu() to restore to CPU0's state prior to
284+
* preparing the snapshot device.
285+
*
286+
* This works for normal boot case in our CPU0 hotplug debug
287+
* mode, i.e. CPU0 is offline and user mode hibernation
288+
* software initializes during boot time.
289+
*
290+
* If CPU0 is online and user application accesses snapshot
291+
* device after boot time, this will offline CPU0 and user may
292+
* see different CPU0 state before and after accessing
293+
* the snapshot device. But hopefully this is not a case when
294+
* user debugging CPU0 hotplug. Even if users hit this case,
295+
* they can easily online CPU0 back.
296+
*
297+
* To simplify this debug code, we only consider normal boot
298+
* case. Otherwise we need to remember CPU0's state and restore
299+
* to that state and resolve racy conditions etc.
300+
*/
301+
_debug_hotplug_cpu(0, 0);
302+
break;
303+
#endif
266304
default:
267305
break;
268306
}

0 commit comments

Comments
 (0)