Skip to content

Commit 9ca12ac

Browse files
npigginIngo Molnar
authored andcommitted
kernel/cpu: Allow non-zero CPU to be primary for suspend / kexec freeze
This patch provides an arch option, ARCH_SUSPEND_NONZERO_CPU, to opt-in to allowing suspend to occur on one of the housekeeping CPUs rather than hardcoded CPU0. This will allow CPU0 to be a nohz_full CPU with a later change. It may be possible for platforms with hardware/firmware restrictions on suspend/wake effectively support this by handing off the final stage to CPU0 when kernel housekeeping is no longer required. Another option is to make housekeeping / nohz_full mask dynamic at runtime, but the complexity could not be justified at this time. Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rafael J . Wysocki <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 2f1a6fb commit 9ca12ac

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

arch/powerpc/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ config ARCH_SUSPEND_POSSIBLE
318318
(PPC_85xx && !PPC_E500MC) || PPC_86xx || PPC_PSERIES \
319319
|| 44x || 40x
320320

321+
config ARCH_SUSPEND_NONZERO_CPU
322+
def_bool y
323+
depends on PPC_POWERNV || PPC_PSERIES
324+
321325
config PPC_DCR_NATIVE
322326
bool
323327

include/linux/cpu.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ extern void enable_nonboot_cpus(void);
140140

141141
static inline int suspend_disable_secondary_cpus(void)
142142
{
143-
return freeze_secondary_cpus(0);
143+
int cpu = 0;
144+
145+
if (IS_ENABLED(CONFIG_PM_SLEEP_SMP_NONZERO_CPU))
146+
cpu = -1;
147+
148+
return freeze_secondary_cpus(cpu);
144149
}
145150
static inline void suspend_enable_secondary_cpus(void)
146151
{

kernel/cpu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/notifier.h>
1010
#include <linux/sched/signal.h>
1111
#include <linux/sched/hotplug.h>
12+
#include <linux/sched/isolation.h>
1213
#include <linux/sched/task.h>
1314
#include <linux/sched/smt.h>
1415
#include <linux/unistd.h>
@@ -1199,8 +1200,15 @@ int freeze_secondary_cpus(int primary)
11991200
int cpu, error = 0;
12001201

12011202
cpu_maps_update_begin();
1202-
if (!cpu_online(primary))
1203+
if (primary == -1) {
12031204
primary = cpumask_first(cpu_online_mask);
1205+
if (!housekeeping_cpu(primary, HK_FLAG_TIMER))
1206+
primary = housekeeping_any_cpu(HK_FLAG_TIMER);
1207+
} else {
1208+
if (!cpu_online(primary))
1209+
primary = cpumask_first(cpu_online_mask);
1210+
}
1211+
12041212
/*
12051213
* We take down all of the non-boot CPUs in one shot to avoid races
12061214
* with the userspace trying to use the CPU hotplug at the same time

kernel/power/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ config PM_SLEEP_SMP
114114
depends on PM_SLEEP
115115
select HOTPLUG_CPU
116116

117+
config PM_SLEEP_SMP_NONZERO_CPU
118+
def_bool y
119+
depends on PM_SLEEP_SMP
120+
depends on ARCH_SUSPEND_NONZERO_CPU
121+
---help---
122+
If an arch can suspend (for suspend, hibernate, kexec, etc) on a
123+
non-zero numbered CPU, it may define ARCH_SUSPEND_NONZERO_CPU. This
124+
will allow nohz_full mask to include CPU0.
125+
117126
config PM_AUTOSLEEP
118127
bool "Opportunistic sleep"
119128
depends on PM_SLEEP

0 commit comments

Comments
 (0)