kernel/cpu: Allow non-zero CPU to be primary for suspend / kexec freeze
authorNicholas Piggin <npiggin@gmail.com>
Thu, 11 Apr 2019 03:34:46 +0000 (13:34 +1000)
committerIngo Molnar <mingo@kernel.org>
Fri, 3 May 2019 17:42:58 +0000 (19:42 +0200)
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 <npiggin@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lkml.kernel.org/r/20190411033448.20842-4-npiggin@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/powerpc/Kconfig
include/linux/cpu.h
kernel/cpu.c
kernel/power/Kconfig

index 2d0be82c30619bd405949b64c2847603caf5a67d..bc98b0e37a10594d0f76a918d28e701faac32da8 100644 (file)
@@ -318,6 +318,10 @@ config ARCH_SUSPEND_POSSIBLE
                   (PPC_85xx && !PPC_E500MC) || PPC_86xx || PPC_PSERIES \
                   || 44x || 40x
 
+config ARCH_SUSPEND_NONZERO_CPU
+       def_bool y
+       depends on PPC_POWERNV || PPC_PSERIES
+
 config PPC_DCR_NATIVE
        bool
 
index 7ab2f09c0a14670faf22aa95d16cad5154edcd10..73baab8535c14a8755f5748bdc0ca53423a631c1 100644 (file)
@@ -140,7 +140,12 @@ extern void enable_nonboot_cpus(void);
 
 static inline int suspend_disable_secondary_cpus(void)
 {
-       return freeze_secondary_cpus(0);
+       int cpu = 0;
+
+       if (IS_ENABLED(CONFIG_PM_SLEEP_SMP_NONZERO_CPU))
+               cpu = -1;
+
+       return freeze_secondary_cpus(cpu);
 }
 static inline void suspend_enable_secondary_cpus(void)
 {
index 6754f3ecfd943c97af0b865197d01366abac7c73..d1bf6e2b4752fd84a0e77c445a5e358f0d5a2647 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/notifier.h>
 #include <linux/sched/signal.h>
 #include <linux/sched/hotplug.h>
+#include <linux/sched/isolation.h>
 #include <linux/sched/task.h>
 #include <linux/sched/smt.h>
 #include <linux/unistd.h>
@@ -1199,8 +1200,15 @@ int freeze_secondary_cpus(int primary)
        int cpu, error = 0;
 
        cpu_maps_update_begin();
-       if (!cpu_online(primary))
+       if (primary == -1) {
                primary = cpumask_first(cpu_online_mask);
+               if (!housekeeping_cpu(primary, HK_FLAG_TIMER))
+                       primary = housekeeping_any_cpu(HK_FLAG_TIMER);
+       } else {
+               if (!cpu_online(primary))
+                       primary = cpumask_first(cpu_online_mask);
+       }
+
        /*
         * We take down all of the non-boot CPUs in one shot to avoid races
         * with the userspace trying to use the CPU hotplug at the same time
index f8fe57d1022e368b0ece751ba8c0140f66c965d8..9bbaaab14b36efc189c53152bb4a418872b5fe17 100644 (file)
@@ -114,6 +114,15 @@ config PM_SLEEP_SMP
        depends on PM_SLEEP
        select HOTPLUG_CPU
 
+config PM_SLEEP_SMP_NONZERO_CPU
+       def_bool y
+       depends on PM_SLEEP_SMP
+       depends on ARCH_SUSPEND_NONZERO_CPU
+       ---help---
+       If an arch can suspend (for suspend, hibernate, kexec, etc) on a
+       non-zero numbered CPU, it may define ARCH_SUSPEND_NONZERO_CPU. This
+       will allow nohz_full mask to include CPU0.
+
 config PM_AUTOSLEEP
        bool "Opportunistic sleep"
        depends on PM_SLEEP