cpuidle: (POWER) cpuidle driver for pSeries
Subsystems (2)
v3 cover cpuidle: (POWER) cpuidle driver for pSeries
This patch series ports the cpuidle framework for ppc64 platform and implements a cpuidle back-end driver for ppc64 (pSeries) platform. Currently idle states are managed by pseries_{dedicated,shared}_idle_sleep() routines in arch/powerpc/platforms/pseries/setup.c. There are two idle states (snooze and cede) that are exploited by
these routines based on simple heuristics.
Moving the idle states over to cpuidle framework can take advantage of the advanced heuristics, tunables, and features provided by cpuidle framework. Additional idle states like extended cede with hints would be included and exploited using the cpuidle framework. The statistics and tracing infrastructure provided by the cpuidle framework also helps in enabling power management related tools and help tune the system and applications.
This series aims to maintain compatibility and functionality to existing pSeries idle cpu management code. There are no new functions or idle states added as part of this series.
The previous version of this patch can be found at
https://lkml.org/lkml/2011/11/17/127
Changes from the previous version (v2):
1] Rebased to latest 3.2-rc3
2] Incorporated the changes from the feedback provided by Ben
in the previous version of this series.
This patch series includes:
[1/4] - Provides arch specific cpu_idle_wait() function required by cpuidle
subsystem.
[2/4] - pseries_idle cpuidle driver
[3/4] - Enables cpuidle for pSeries and directly calls cpuidle_idle_call() [4/4] - Handles powersave=off kernel boot parameter and disables registration
of pseries_idle cpuidle driver.
This series has been tested on ppc64 pSeries POWER7 system with the snooze and cede states
--
arch/powerpc/Kconfig | 4 arch/powerpc/include/asm/processor.h | 3 arch/powerpc/include/asm/system.h | 9 + arch/powerpc/kernel/idle.c | 27 ++ arch/powerpc/kernel/sysfs.c | 2 arch/powerpc/platforms/Kconfig | 6 arch/powerpc/platforms/pseries/Kconfig | 9 + arch/powerpc/platforms/pseries/Makefile | 1 arch/powerpc/platforms/pseries/processor_idle.c | 329 +++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 3 arch/powerpc/platforms/pseries/setup.c | 104 +------ arch/powerpc/platforms/pseries/smp.c | 1 include/linux/cpuidle.h | 2 13 files changed, 411 insertions(+), 89 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/processor_idle.c
-Deepthi
RFC PATCH v3 1/4 cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
This patch provides cpu_idle_wait() routine for the powerpc platform which is required by the cpuidle subsystem. This routine is required to change the idle handler on SMP systems. The equivalent routine for x86 is in arch/x86/kernel/process.c but the powerpc implementation is different.
cpuidle_disable variable is to enable/disable cpuidle framework if power_save option is set during the boot time.
--- arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 27 +++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 0 deletions(-)
arch/powerpc/Kconfig +4 -0
@@ -87,6 +87,10 @@ config ARCH_HAS_ILOG2_U64 bool default y if 64BIT +config ARCH_HAS_CPU_IDLE_WAIT + bool + default y + config GENERIC_HWEIGHT bool default y
arch/powerpc/include/asm/processor.h +2 -0
@@ -382,6 +382,8 @@ static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32) }#endif +enum idle_boot_override {IDLE_NO_OVERRIDE =0 ,IDLE_POWERSAVE_OFF }; +#endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_PROCESSOR_H */
arch/powerpc/include/asm/system.h +1 -0
@@ -221,6 +221,7 @@ extern unsigned long klimit;extern void *zalloc_maybe_bootmem (size_t size,gfp_t mask);extern int powersave_nap;/* set if nap mode can be used in idle loop */ +void cpu_idle_wait (void );/* * Atomic exchange
arch/powerpc/kernel/idle.c +27 -0
@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long cpuidle_disable =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (cpuidle_disable); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + cpuidle_disable =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);
@@ -102,6 +106,29 @@ void cpu_idle(void) } } + +/* +* cpu_idle_wait - Used to ensure that all the CPUs come out of the old +* idle loop and start using the new idle loop. +* Required while changing idle handler on SMP systems. +* Caller must have changed idle handler to the new value before the call. +* This window may be larger on shared systems. +*/ +void cpu_idle_wait (void ) +{ +int cpu; +smp_mb (); + +/* kick all the CPUs so that they exit out of old idle routine */ +get_online_cpus (); +for_each_online_cpu (cpu) { +if (cpu !=smp_processor_id ()) +smp_send_reschedule (cpu); + } +put_online_cpus (); +} +EXPORT_SYMBOL_GPL (cpu_idle_wait); +int powersave_nap;#ifdef CONFIG_SYSCTL
RFC PATCH v3 1/4 cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Deepthi DharwarThis patch provides cpu_idle_wait() routine for the powerpc platform which is required by the cpuidle subsystem. This routine is required to change the idle handler on SMP systems. The equivalent routine for x86 is in arch/x86/kernel/process.c but the powerpc implementation is different.
cpuidle_disable variable is to enable/disable cpuidle framework if power_save option is set during the boot time.
--- arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 27 +++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 0 deletions(-)
arch/powerpc/Kconfig +4 -0
@@ -87,6 +87,10 @@ config ARCH_HAS_ILOG2_U64 bool default y if 64BIT +config ARCH_HAS_CPU_IDLE_WAIT + bool + default y + config GENERIC_HWEIGHT bool default y
arch/powerpc/include/asm/processor.h +2 -0
@@ -382,6 +382,8 @@ static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32) }#endif +enum idle_boot_override {IDLE_NO_OVERRIDE =0 ,IDLE_POWERSAVE_OFF }; +#endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_PROCESSOR_H */
arch/powerpc/include/asm/system.h +1 -0
@@ -221,6 +221,7 @@ extern unsigned long klimit;extern void *zalloc_maybe_bootmem (size_t size,gfp_t mask);extern int powersave_nap;/* set if nap mode can be used in idle loop */ +void cpu_idle_wait (void );/* * Atomic exchange
arch/powerpc/kernel/idle.c +27 -0
@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long cpuidle_disable =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (cpuidle_disable); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + cpuidle_disable =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);
@@ -102,6 +106,29 @@ void cpu_idle(void) } } + +/* +* cpu_idle_wait - Used to ensure that all the CPUs come out of the old +* idle loop and start using the new idle loop. +* Required while changing idle handler on SMP systems. +* Caller must have changed idle handler to the new value before the call. +* This window may be larger on shared systems. +*/ +void cpu_idle_wait (void ) +{ +int cpu; +smp_mb (); + +/* kick all the CPUs so that they exit out of old idle routine */ +get_online_cpus (); +for_each_online_cpu (cpu) { +if (cpu !=smp_processor_id ()) +smp_send_reschedule (cpu); + } +put_online_cpus (); +} +EXPORT_SYMBOL_GPL (cpu_idle_wait); +int powersave_nap;#ifdef CONFIG_SYSCTL
RFC PATCH v3 2/4 cpuidle: (POWER) cpuidle driver for pSeries
In reply to Deepthi DharwarThis patch implements a back-end cpuidle driver for pSeries based on pseries_dedicated_idle_loop and pseries_shared_idle_loop routines. The driver is built only if CONFIG_CPU_IDLE is set. This cpuidle driver uses global registration of idle states and not per-cpu.
--- arch/powerpc/include/asm/system.h | 8 + arch/powerpc/kernel/sysfs.c | 2 arch/powerpc/platforms/pseries/Kconfig | 9 + arch/powerpc/platforms/pseries/Makefile | 1 arch/powerpc/platforms/pseries/processor_idle.c | 326 +++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 3 arch/powerpc/platforms/pseries/setup.c | 3 arch/powerpc/platforms/pseries/smp.c | 1 8 files changed, 350 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/processor_idle.c
arch/powerpc/include/asm/system.h +8 -0
@@ -223,6 +223,14 @@ extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);extern int powersave_nap;/* set if nap mode can be used in idle loop */ void cpu_idle_wait (void ); +#ifdef CONFIG_PSERIES_IDLE +extern void update_smt_snooze_delay (int snooze); +extern int pseries_notify_cpuidle_add_cpu (int cpu); +#else +static inline void update_smt_snooze_delay (int snooze) {} +static inline int pseries_notify_cpuidle_add_cpu (int cpu) {return 0 ; } +#endif +/* * Atomic exchange *
arch/powerpc/kernel/sysfs.c +2 -0
@@ -18,6 +18,7 @@#include <asm/machdep.h> #include <asm/smp.h> #include <asm/pmc.h> +#include <asm/system.h> #include "cacheinfo.h"
@@ -51,6 +52,7 @@ static ssize_t store_smt_snooze_delay(struct sys_device *dev,return -EINVAL ;per_cpu (smt_snooze_delay, cpu->sysdev.id) = snooze; +update_smt_snooze_delay (snooze);return count; }
arch/powerpc/platforms/pseries/Kconfig +9 -0
@@ -120,3 +120,12 @@ config DTL which are accessible through a debugfs file. Say N if you are unsure. + +config PSERIES_IDLE + tristate "Cpuidle driver for pSeries platforms" + depends on CPU_IDLE + depends on PPC_PSERIES + default y + help + Select this option to enable processor idle state management + through cpuidle subsystem.
arch/powerpc/platforms/pseries/Makefile +1 -0
@@ -22,6 +22,7 @@ obj-$(CONFIG_PHYP_DUMP) += phyp_dump.o obj-$(CONFIG_CMM) += cmm.o obj-$(CONFIG_DTL) += dtl.o obj-$(CONFIG_IO_EVENT_IRQ) += io_event_irq.o +obj-$(CONFIG_PSERIES_IDLE) += processor_idle.o ifeq ($(CONFIG_PPC_PSERIES),y) obj-$(CONFIG_SUSPEND) += suspend.o
arch/powerpc/platforms/pseries/processor_idle.c new file +326 -0
326 lines not on this page · raw message
arch/powerpc/platforms/pseries/pseries.h +3 -0
@@ -57,4 +57,7 @@ extern struct device_node *dlpar_configure_connector(u32);extern int dlpar_attach_node (struct device_node *);extern int dlpar_detach_node (struct device_node *); +/* Snooze Delay, pseries_idle */ +DECLARE_PER_CPU (long, smt_snooze_delay); +#endif /* _PSERIES_PSERIES_H */
arch/powerpc/platforms/pseries/setup.c +0 -3
@@ -586,9 +586,6 @@ static int __init pSeries_probe(void)return 1 ; } - -DECLARE_PER_CPU (long, smt_snooze_delay); -static void pseries_dedicated_idle_sleep (void ) {unsigned int cpu =smp_processor_id ();
arch/powerpc/platforms/pseries/smp.c +1 -0
@@ -148,6 +148,7 @@ static void __devinit smp_xics_setup_cpu(int cpu)set_cpu_current_state (cpu,CPU_STATE_ONLINE );set_default_offline_state (cpu);#endif +pseries_notify_cpuidle_add_cpu (cpu); }static int __devinit smp_pSeries_kick_cpu (int nr)
RFC PATCH v3 3/4 cpuidle: (POWER) Enable cpuidle and directly call cpuidle_idle_call() for pSeries
In reply to Deepthi DharwarThis patch enables cpuidle for pSeries and pSeries_idle is directly called from the idle loop. As a result of pSeries_idle, cpuidle driver registered with cpuidle subsystem comes into action. On failure of loading of the driver or cpuidle framework default idle is executed as part of the function. This patch
also removes the routines pseries_shared_idle_sleep and pseries_dedicated_idle_sleep as they are now implemented as part of pseries_idle cpuidle driver.
--- arch/powerpc/platforms/Kconfig | 6 ++ arch/powerpc/platforms/pseries/setup.c | 101 +++++--------------------------- include/linux/cpuidle.h | 2 - 3 files changed, 23 insertions(+), 86 deletions(-)
arch/powerpc/platforms/Kconfig +6 -0
@@ -211,6 +211,12 @@ config PPC_PASEMI_CPUFREQ endmenu +menu "CPUIdle driver" + +source "drivers/cpuidle/Kconfig" + +endmenu + config PPC601_SYNC_FIX bool "Workarounds for PPC601 bugs" depends on 6xx && (PPC_PREP || PPC_PMAC)
arch/powerpc/platforms/pseries/setup.c +17 -84
133 lines not on this page · raw message
include/linux/cpuidle.h +0 -2
@@ -130,7 +130,6 @@ struct cpuidle_driver {#ifdef CONFIG_CPU_IDLE extern void disable_cpuidle (void );extern int cpuidle_idle_call (void ); -extern int cpuidle_register_driver (struct cpuidle_driver *drv);struct cpuidle_driver *cpuidle_get_driver (void );extern void cpuidle_unregister_driver (struct cpuidle_driver *drv);
@@ -145,7 +144,6 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);#else static inline void disable_cpuidle (void ) { }static inline int cpuidle_idle_call (void ) {return -ENODEV ; } -static inline int cpuidle_register_driver (struct cpuidle_driver *drv) {return -ENODEV ; }static inline struct cpuidle_driver *cpuidle_get_driver (void ) {return NULL ; }
RFC PATCH v3 3/4 cpuidle: (POWER) Enable cpuidle and directly call cpuidle_idle_call() for pSeries
In reply to Deepthi DharwarThis patch enables cpuidle for pSeries and pSeries_idle is directly called from the idle loop. As a result of pSeries_idle, cpuidle driver registered with cpuidle subsystem comes into action. On failure of loading of the driver or cpuidle framework default idle is executed as part of the function. This patch
also removes the routines pseries_shared_idle_sleep and pseries_dedicated_idle_sleep as they are now implemented as part of pseries_idle cpuidle driver.
--- arch/powerpc/platforms/Kconfig | 6 ++ arch/powerpc/platforms/pseries/setup.c | 101 +++++--------------------------- include/linux/cpuidle.h | 2 - 3 files changed, 23 insertions(+), 86 deletions(-)
arch/powerpc/platforms/Kconfig +6 -0
@@ -211,6 +211,12 @@ config PPC_PASEMI_CPUFREQ endmenu +menu "CPUIdle driver" + +source "drivers/cpuidle/Kconfig" + +endmenu + config PPC601_SYNC_FIX bool "Workarounds for PPC601 bugs" depends on 6xx && (PPC_PREP || PPC_PMAC)
arch/powerpc/platforms/pseries/setup.c +17 -84
133 lines not on this page · raw message
include/linux/cpuidle.h +0 -2
@@ -130,7 +130,6 @@ struct cpuidle_driver {#ifdef CONFIG_CPU_IDLE extern void disable_cpuidle (void );extern int cpuidle_idle_call (void ); -extern int cpuidle_register_driver (struct cpuidle_driver *drv);struct cpuidle_driver *cpuidle_get_driver (void );extern void cpuidle_unregister_driver (struct cpuidle_driver *drv);
@@ -145,7 +144,6 @@ extern void cpuidle_disable_device(struct cpuidle_device *dev);#else static inline void disable_cpuidle (void ) { }static inline int cpuidle_idle_call (void ) {return -ENODEV ; } -static inline int cpuidle_register_driver (struct cpuidle_driver *drv) {return -ENODEV ; }static inline struct cpuidle_driver *cpuidle_get_driver (void ) {return NULL ; }
RFC PATCH v3 4/4 cpuidle: (POWER) Handle power_save=off
In reply to Deepthi DharwarThis patch makes pseries_idle_driver not to be registered when power_save=off kernel boot option is specified. The cpuidle_disable variable used here is similar to
its usage on x86. If cpuidle_disable is set then sysfs entries for cpuidle framework are not created and the required drivers are not loaded.
--- arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/platforms/pseries/processor_idle.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/processor.h +1 -0
@@ -382,6 +382,7 @@ static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32) }#endif +extern unsigned long cpuidle_disable;enum idle_boot_override {IDLE_NO_OVERRIDE =0 ,IDLE_POWERSAVE_OFF };#endif /* __KERNEL__ */
arch/powerpc/platforms/pseries/processor_idle.c +3 -0
@@ -269,6 +269,9 @@ static int pseries_idle_probe(void)if (!firmware_has_feature (FW_FEATURE_SPLPAR ))return -ENODEV ; +if (cpuidle_disable !=IDLE_NO_OVERRIDE ) +return -ENODEV ; +if (max_idle_state ==0 ) {printk (KERN_DEBUG "pseries processor idle disabled.\n" );return -EPERM ;