cpuidle: (POWER) cpuidle driver for pSeries
Subsystems (2)
RFC PATCH v2 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 requied 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.
--- arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 26 ++++++++++++++++++++++++++ 4 files changed, 33 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 +26 -0
@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long boot_option_idle_override =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (boot_option_idle_override); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + boot_option_idle_override =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);
@@ -102,6 +106,28 @@ 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. +*/ +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 v2 2/4 cpuidle: (POWER) cpuidle driver for pSeries
In reply to Deepthi DharwarThis patch implements a backhand 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 | 317 +++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 3 arch/powerpc/platforms/pseries/setup.c | 3 arch/powerpc/platforms/pseries/smp.c | 1 8 files changed, 341 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 +317 -0
317 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 v2 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 requied 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.
--- arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 26 ++++++++++++++++++++++++++ 4 files changed, 33 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 +26 -0
@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long boot_option_idle_override =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (boot_option_idle_override); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + boot_option_idle_override =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);
@@ -102,6 +106,28 @@ 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. +*/ +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 v2 2/4 cpuidle: (POWER) cpuidle driver for pSeries
In reply to Deepthi DharwarThis patch implements a backhand 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 | 317 +++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 3 arch/powerpc/platforms/pseries/setup.c | 3 arch/powerpc/platforms/pseries/smp.c | 1 8 files changed, 341 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 +317 -0
317 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 v2 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 cpuidle_idle_call() is directly called from the idle loop. As a result pseries_idle cpuidle driver registered with cpuidle subsystem comes into action. 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 | 86 +------------------------------- include/linux/cpuidle.h | 2 - 3 files changed, 8 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 +2 -84
112 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 v2 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 cpuidle_idle_call() is directly called from the idle loop. As a result pseries_idle cpuidle driver registered with cpuidle subsystem comes into action. 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 | 86 +------------------------------- include/linux/cpuidle.h | 2 - 3 files changed, 8 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 +2 -84
112 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 v2 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 boot_option_idle_override variable used here is similar to its usage on x86.
--- arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/platforms/pseries/processor_idle.c | 4 ++++ 2 files changed, 5 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 boot_option_idle_override;enum idle_boot_override {IDLE_NO_OVERRIDE =0 ,IDLE_POWERSAVE_OFF };#endif /* __KERNEL__ */
arch/powerpc/platforms/pseries/processor_idle.c +4 -0
@@ -260,6 +260,10 @@ static int pseries_idle_probe(void)return -EPERM ; } +if (boot_option_idle_override !=IDLE_NO_OVERRIDE ) { +return -ENODEV ; + } +if (!firmware_has_feature (FW_FEATURE_SPLPAR )) {printk (KERN_DEBUG "Using default idle\n" );return -ENODEV ;
RFC PATCH v2 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 boot_option_idle_override variable used here is similar to its usage on x86.
--- arch/powerpc/include/asm/processor.h | 1 + arch/powerpc/platforms/pseries/processor_idle.c | 4 ++++ 2 files changed, 5 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 boot_option_idle_override;enum idle_boot_override {IDLE_NO_OVERRIDE =0 ,IDLE_POWERSAVE_OFF };#endif /* __KERNEL__ */
arch/powerpc/platforms/pseries/processor_idle.c +4 -0
@@ -260,6 +260,10 @@ static int pseries_idle_probe(void)return -EPERM ; } +if (boot_option_idle_override !=IDLE_NO_OVERRIDE ) { +return -ENODEV ; + } +if (!firmware_has_feature (FW_FEATURE_SPLPAR )) {printk (KERN_DEBUG "Using default idle\n" );return -ENODEV ;
v2 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/6/7/375
Changes from the previous version (v1):
1] Rebased to latest 3.2-rc2
2] Incorporated the changes from the feedback provided by Ben
in the previous version of this series.
3] The first three patches in this series posted in v1 are not
re-posted as they were taken from "idle cleanup - v3" posted by Len Brown (https://lkml.org/lkml/2011/4/2/8) which have made to the mainline in 3.1.
This cleanup was a community requirement and major dependency before cpuidle framework can be ported over to powerpc architecture.
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 | 26 ++ 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 | 321 +++++++++++++++++++++++ arch/powerpc/platforms/pseries/pseries.h | 3 arch/powerpc/platforms/pseries/setup.c | 89 ------ arch/powerpc/platforms/pseries/smp.c | 1 include/linux/cpuidle.h | 2 13 files changed, 387 insertions(+), 89 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/processor_idle.c
-Deepthi
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Deepthi DharwarQuoted 10 lines · Deepthi Dharwar
This patch provides
cpu_idle_wait()routine for the powerpc platform which is required by the cpuidle subsystem. This routine is requied to change the idle handler on SMP systems. The equivalent routine for x86 is inarch/x86/kernel/process.cbut the powerpc implementation is different.Signed-off-by Deepthi Dharwar <[email protected]>Signed-off-by Trinabh Gupta <[email protected]>Signed-off-by Arun R Bharadwaj <[email protected]>---
No, that patch also adds this idle boot override thing (can you pick a shorter name for boot_option_idle_override btw ?) which seems unrelated and without any explanation as to what it's supposed to be about.
Additionally, I'm a bit worried (but maybe we already discussed that a while back, I don't know) but cpu_idle_wait() has "wait" in the name, which makes me think it might need to actually -wait- for all cpus to have come out of the function.
Now your implementation doesn't provide that guarantee. It might be fine, I don't know, but if it is, you'd better document it well in the comments surrounding the code, because as it is, all you do is shoot an interrupt which will cause the target CPU to eventually come out of idle some time in the future.
Cheers,
Ben.
Quoted 98 lines
arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 26 ++++++++++++++++++++++++++ 4 files changed, 33 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 yarch/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 +26
-0@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long boot_option_idle_override =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (boot_option_idle_override); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + boot_option_idle_override =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);@@ -102,6 +106,28 @@ 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. +*/ +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 _______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Quoted 5 lines · Deepthi Dharwar
This patch implements a backhand cpuidle driver for pSeries based on
pseries_dedicated_idle_loopandpseries_shared_idle_looproutines. The driver is built only ifCONFIG_CPU_IDLEis set. This cpuidle driver uses global registration of idle states and not per-cpu.
.../...
arch/powerpc/platforms/pseries/processor_idle.c line 31
Quoted 3 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +3
-0+#define MAX_IDLE_STATE_COUNT 2 + +static int max_cstate =MAX_IDLE_STATE_COUNT -1 ;
Why "cstate" ? This isn't an x86 :-)
Quoted 1 line
+static struct
cpuidle_device__percpu*pseries_idle_cpuidle_devices;
Shorter name please. pseries_cpuidle_devs is fine.
Quoted 11 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +11
-0+static struct cpuidle_state *cpuidle_state_table; + +void update_smt_snooze_delay (int snooze) +{ +struct cpuidle_driver *drv =cpuidle_get_driver (); +if (drv) + drv->states[0 ].target_residency = snooze; +} + +static inline void idle_loop_prolog (unsigned long *in_purr,ktime_t *kt_before) +{
arch/powerpc/platforms/pseries/processor_idle.c line 53
Quoted 10 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +10
-0+ + *kt_before =ktime_get_real (); + *in_purr =mfspr (SPRN_PURR ); +/* +* Indicate to the HV that we are idle. Now would be +* a good time to find other work to dispatch. +*/ +get_lppaca ()->idle =1 ; +get_lppaca ()->donate_dedicated_cpu =1 ; +}
I notice that you call this on shared processors as well. The old ocde used to not set donate_dedicated_cpu in that case. I assume that's not a big deal and that the HV will just ignore it in the shared processor case but please add a comment after you've verified it.
Quoted 25 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +25
-0+static inline s64 idle_loop_epilog (unsigned long in_purr,ktime_t kt_before) +{ +get_lppaca ()->wait_state_cycles +=mfspr (SPRN_PURR ) - in_purr; +get_lppaca ()->donate_dedicated_cpu =0 ; +get_lppaca ()->idle =0 ; + +return ktime_to_us (ktime_sub (ktime_get_real (), kt_before)); +} + + +static int snooze_loop (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +unsigned long in_purr; +ktime_t kt_before; + +idle_loop_prolog (&in_purr, &kt_before); + +local_irq_enable (); +set_thread_flag (TIF_POLLING_NRFLAG ); +while (!need_resched ()) { +ppc64_runlatch_off (); +HMT_low (); +HMT_very_low ();
arch/powerpc/platforms/pseries/processor_idle.c line 89
Quoted 10 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +10
-0+ } +HMT_medium (); +clear_thread_flag (TIF_POLLING_NRFLAG ); +smp_mb (); +local_irq_disable (); + + dev->last_residency = + (int )idle_loop_epilog (in_purr, kt_before); +return index; +}
So your snooze loop has no timeout, is that handled by the cpuidle driver using some kind of timer ? That sounds a lot less efficient than passing a max delay to the snooze loop to handle getting into a deeper state after a bit of snoozing rather than interrupting etc...
Quoted 80 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +80
-0+static int dedicated_cede_loop (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +unsigned long in_purr; +ktime_t kt_before; + +idle_loop_prolog (&in_purr, &kt_before); + +ppc64_runlatch_off (); +HMT_medium (); +cede_processor (); + + dev->last_residency = + (int )idle_loop_epilog (in_purr, kt_before); +return index; +} + +static int shared_cede_loop (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +unsigned long in_purr; +ktime_t kt_before; + +idle_loop_prolog (&in_purr, &kt_before); + +/* +* Yield the processor to the hypervisor. We return if +* an external interrupt occurs (which are driven prior +* to returning here) or if a prod occurs from another +* processor. When returning here, external interrupts +* are enabled. +*/ +cede_processor (); + + dev->last_residency = + (int )idle_loop_epilog (in_purr, kt_before); +return index; +} + +/* +* States for dedicated partition case. +*/ +static struct cpuidle_state dedicated_states[MAX_IDLE_STATE_COUNT ] = { + {/* Snooze */ + .name ="snooze" , + .desc ="snooze" , + .flags =CPUIDLE_FLAG_TIME_VALID , + .exit_latency =0 , + .target_residency =0 , + .enter = &snooze_loop }, + {/* CEDE */ + .name ="CEDE" , + .desc ="CEDE" , + .flags =CPUIDLE_FLAG_TIME_VALID , + .exit_latency =1 , + .target_residency =10 , + .enter = &dedicated_cede_loop }, +}; + +/* +* States for shared partition case. +*/ +static struct cpuidle_state shared_states[MAX_IDLE_STATE_COUNT ] = { + {/* Shared Cede */ + .name ="Shared Cede" , + .desc ="Shared Cede" , + .flags =CPUIDLE_FLAG_TIME_VALID , + .exit_latency =0 , + .target_residency =0 , + .enter = &shared_cede_loop }, +}; + +int pseries_notify_cpuidle_add_cpu (int cpu) +{ +struct cpuidle_device *dev = +per_cpu_ptr (pseries_idle_cpuidle_devices, cpu); +if (dev &&cpuidle_get_driver ()) { +cpuidle_disable_device (dev);
arch/powerpc/platforms/pseries/processor_idle.c line 180
Quoted 10 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +10
-0+cpuidle_enable_device (dev); + } +return 0 ; +} + +/* +* pseries_idle_cpuidle_driver_init() +*/ +static int pseries_idle_cpuidle_driver_init (void ) +{
Drop the "idle", those names are too long.
arch/powerpc/platforms/pseries/processor_idle.c line 181
Quoted 1 line
arch/powerpc/platforms/pseries/processor_idle.c new file +1
-0+int cstate;
And use something else than 'cstate', we are among civilized people here ;-)
Quoted 75 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +75
-0+struct cpuidle_driver *drv = &pseries_idle_driver; + + drv->state_count =0 ; + +for (cstate =0 ; cstate <MAX_IDLE_STATE_COUNT ; ++cstate) { + +if (cstate > max_cstate) +break ; + +/* is the state not enabled? */ +if (cpuidle_state_table[cstate].enter ==NULL ) +continue ; + + drv->states[drv->state_count] =/* structure copy */ + cpuidle_state_table[cstate]; + +if (cpuidle_state_table == dedicated_states) + drv->states[drv->state_count].target_residency = +__get_cpu_var (smt_snooze_delay); + + drv->state_count +=1 ; + } + +return 0 ; +} + +/* pseries_idle_devices_uninit(void) +* unregister cpuidle devices and de-allocate memory +*/ +static void pseries_idle_devices_uninit (void ) +{ +int i; +struct cpuidle_device *dev; + +for_each_possible_cpu (i) { + dev =per_cpu_ptr (pseries_idle_cpuidle_devices, i); +cpuidle_unregister_device (dev); + } + +free_percpu (pseries_idle_cpuidle_devices); +return ; +} + +/* pseries_idle_devices_init() +* allocate, initialize and register cpuidle device +*/ +static int pseries_idle_devices_init (void ) +{ +int i; +struct cpuidle_driver *drv = &pseries_idle_driver; +struct cpuidle_device *dev; + + pseries_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device); +if (pseries_idle_cpuidle_devices ==NULL ) +return -ENOMEM ; + +for_each_possible_cpu (i) { + dev =per_cpu_ptr (pseries_idle_cpuidle_devices, i); + dev->state_count = drv->state_count; + dev->cpu = i; +if (cpuidle_register_device (dev)) { +printk (KERN_DEBUG \ +"cpuidle_register_device %d failed!\n" , i); +return -EIO ; + } + } + +return 0 ; +} + +/* +* pseries_idle_probe() +* Choose state table for shared versus dedicated partition +*/ +static int pseries_idle_probe (void )
arch/powerpc/platforms/pseries/processor_idle.c line 266
Quoted 10 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +10
-0+{ +if (max_cstate ==0 ) { +printk (KERN_DEBUG "pseries processor idle disabled.\n" ); +return -EPERM ; + } + +if (!firmware_has_feature (FW_FEATURE_SPLPAR )) { +printk (KERN_DEBUG "Using default idle\n" ); +return -ENODEV ; + }
Don't even printk here, this will happen on all !pseries machines and the debug output isn't useful. Also move the check of max-cstate to after the splpar test.
Overall, I quite like these patches, my comments are all pretty minor, hopefully the next round should be the one.
Cheers,
Ben.
Re: [RFC PATCH v2 3/4] cpuidle: (POWER) Enable cpuidle and directly call cpuidle_idle_call() for pSeries
In reply to Deepthi DharwarQuoted 63 lines · Deepthi Dharwar
This patch enables cpuidle for pSeries and
cpuidle_idle_call()is directly called from the idle loop. As a resultpseries_idlecpuidle driver registered with cpuidle subsystem comes into action. This patch also removes the routinespseries_shared_idle_sleepandpseries_dedicated_idle_sleepas they are now implemented as part ofpseries_idlecpuidle driver.Signed-off-by Deepthi Dharwar <[email protected]>Signed-off-by Trinabh Gupta <[email protected]>Signed-off-by Arun R Bharadwaj <[email protected]>--- arch/powerpc/platforms/Kconfig | 6 ++ arch/powerpc/platforms/pseries/setup.c | 86 +------------------------------- include/linux/cpuidle.h | 2 - 3 files changed, 8 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 +1
-5@@ -39,6 +39,7 @@#include <linux/irq.h> #include <linux/seq_file.h> #include <linux/root_dev.h> +#include <linux/cpuidle.h> #include <asm/mmu.h> #include <asm/processor.h> @@ -74,9 +75,6 @@ EXPORT_SYMBOL(CMO_PageSize);int fwnmi_active;/* TRUE if an FWNMI handler is present */ -static void pseries_shared_idle_sleep (void ); -static void pseries_dedicated_idle_sleep (void ); -static struct device_node *pSeries_mpic_node;static void pSeries_show_cpuinfo (struct seq_file *m)@@ -374,18 +372,9 @@ static void __init pSeries_setup_arch(void)pSeries_nvram_init (); -/* Choose an idle loop */ if (firmware_has_feature (FW_FEATURE_SPLPAR )) {vpa_init (boot_cpuid); -if (get_lppaca ()->shared_proc) {
arch/powerpc/platforms/pseries/setup.c static void __init pSeries_setup_arch(void) · line 378
Quoted 10 lines
arch/powerpc/platforms/pseries/setup.c +1
-8-printk (KERN_DEBUG "Using shared processor idle loop\n" ); - ppc_md.power_save = pseries_shared_idle_sleep; - }else { -printk (KERN_DEBUG "Using dedicated idle loop\n" ); - ppc_md.power_save = pseries_dedicated_idle_sleep; - } - }else { -printk (KERN_DEBUG "Using default idle loop\n" ); + ppc_md.power_save = (void *)cpuidle_idle_call; }
I very very much dislike that cast. You should not have to cast a function pointer ... EVER.
arch/powerpc/platforms/pseries/setup.c static int __init pSeries_probe(void) · line 577
Quoted 5 lines
arch/powerpc/platforms/pseries/setup.c +0
-0if (firmware_has_feature (FW_FEATURE_LPAR ))@@ -586,77 +575,6 @@ static int __init pSeries_probe(void)return 1 ; }
Cheers,
Ben.
Re: [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
In reply to Deepthi DharwarQuoted 4 lines · Deepthi Dharwar
This patch makes
pseries_idle_drivernot to be registered when power_save=off kernel boot option is specified. Theboot_option_idle_overridevariable used here is similar to its usage on x86.
Quick Q. With your changes, the CPU will never get into idle at all until cpuidle initializes and the driver loads.
That means not only much later in the boot process, but potentially never if the distro has the driver as a module and fails to load it, or similar.
Can't that be an issue ? Shouldn't we keep at least one of the basic idle functions as a fallback ?
Cheers,
Ben.
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Benjamin HerrenschmidtHi Ben,
Thanks a lot for the review.
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 6 lines · Deepthi Dharwar
This patch provides
cpu_idle_wait()routine for the powerpc platform which is required by the cpuidle subsystem. This routine is requied to change the idle handler on SMP systems. The equivalent routine for x86 is inarch/x86/kernel/process.cbut the powerpc implementation is different.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Deepthi Dharwar <[email protected]>Signed-off-by Trinabh Gupta <[email protected]>Signed-off-by Arun R Bharadwaj <[email protected]>---
No, that patch also adds this idle boot override thing (can you pick a shorter name for
boot_option_idle_overridebtw ?) which seems unrelated and without any explanation as to what it's supposed to be about.
Yes, we can pick a better and shorter name for this variable. This variable is used to determine if cpuidle framework needs to be enabled and pseries_driver to be loaded or not. We disable cpuidle framework only when powersave_off option is set or not enabled by the user.
Quoted 5 lines
Additionally, I'm a bit worried (but maybe we already discussed that a while back, I don't know) but
cpu_idle_wait()has "wait" in the name, which makes me think it might need to actually -wait- for all cpus to have come out of the function.
cpu_idle_wait is used to ensure that all the CPUs discard old idle handler and update to new one. Required while changing idle handler on SMP systems.
Quoted 5 lines
Now your implementation doesn't provide that guarantee. It might be fine, I don't know, but if it is, you'd better document it well in the comments surrounding the code, because as it is, all you do is shoot an interrupt which will cause the target CPU to eventually come out of idle some time in the future.
I was hoping that sending an explicit reschedule to the cpus would do the trick but sure we can add some documentation around the code.
Quoted 96 lines
Cheers,
Ben.Quoted 92 lines
arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 26 ++++++++++++++++++++++++++ 4 files changed, 33 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 yarch/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 +26
-0@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long boot_option_idle_override =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (boot_option_idle_override); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + boot_option_idle_override =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);@@ -102,6 +106,28 @@ 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. +*/ +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;
Quoted 8 lines
Quoted 6 lines
arch/powerpc/kernel/idle.c +0
-0#ifdef CONFIG_SYSCTL _______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Regards,
Deepthi
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Benjamin HerrenschmidtHi Ben,
Thanks a lot for the review.
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 6 lines · Deepthi Dharwar
This patch provides
cpu_idle_wait()routine for the powerpc platform which is required by the cpuidle subsystem. This routine is requied to change the idle handler on SMP systems. The equivalent routine for x86 is inarch/x86/kernel/process.cbut the powerpc implementation is different.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Deepthi Dharwar <[email protected]>Signed-off-by Trinabh Gupta <[email protected]>Signed-off-by Arun R Bharadwaj <[email protected]>---
No, that patch also adds this idle boot override thing (can you pick a shorter name for
boot_option_idle_overridebtw ?) which seems unrelated and without any explanation as to what it's supposed to be about.
Yes, we can pick a better and shorter name for this variable. This variable is used to determine if cpuidle framework needs to be enabled and pseries_driver to be loaded or not. We disable cpuidle framework only when powersave_off option is set or not enabled by the user.
Quoted 5 lines
Additionally, I'm a bit worried (but maybe we already discussed that a while back, I don't know) but
cpu_idle_wait()has "wait" in the name, which makes me think it might need to actually -wait- for all cpus to have come out of the function.
cpu_idle_wait is used to ensure that all the CPUs discard old idle handler and update to new one. Required while changing idle handler on SMP systems.
Quoted 5 lines
Now your implementation doesn't provide that guarantee. It might be fine, I don't know, but if it is, you'd better document it well in the comments surrounding the code, because as it is, all you do is shoot an interrupt which will cause the target CPU to eventually come out of idle some time in the future.
I was hoping that sending an explicit reschedule to the cpus would do the trick but sure we can add some documentation around the code.
Quoted 96 lines
Cheers,
Ben.Quoted 92 lines
arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/idle.c | 26 ++++++++++++++++++++++++++ 4 files changed, 33 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 yarch/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 +26
-0@@ -39,9 +39,13 @@#define cpu_should_die () 0#endif +unsigned long boot_option_idle_override =IDLE_NO_OVERRIDE ; +EXPORT_SYMBOL (boot_option_idle_override); +static int __init powersave_off (char *arg) { ppc_md.power_save =NULL ; + boot_option_idle_override =IDLE_POWERSAVE_OFF ;return 0 ; }__setup ("powersave=off" , powersave_off);@@ -102,6 +106,28 @@ 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. +*/ +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;
Quoted 8 lines
Quoted 6 lines
arch/powerpc/kernel/idle.c +0
-0#ifdef CONFIG_SYSCTL _______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Regards,
Deepthi
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Deepthi Dharwar
This patch implements a backhand cpuidle driver for pSeries based on
pseries_dedicated_idle_loopandpseries_shared_idle_looproutines. The driver is built only ifCONFIG_CPU_IDLEis set. This cpuidle driver uses global registration of idle states and not per-cpu.
Quoted 7 lines
.../...
arch/powerpc/platforms/pseries/processor_idle.c line 31
Quoted 3 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +3
-0+#define MAX_IDLE_STATE_COUNT 2 + +static int max_cstate =MAX_IDLE_STATE_COUNT -1 ;Why "cstate" ? This isn't an x86 :-)
Sure, I shall change it right away :)
Quoted 4 lines
Quoted 2 lines
+static struct
cpuidle_device__percpu*pseries_idle_cpuidle_devices;Shorter name please.
pseries_cpuidle_devsis fine.
I ll do so.
Quoted 19 lines
Quoted 19 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +18
-0+static struct cpuidle_state *cpuidle_state_table; + +void update_smt_snooze_delay (int snooze) +{ +struct cpuidle_driver *drv =cpuidle_get_driver (); +if (drv) + drv->states[0 ].target_residency = snooze; +} + +static inline void idle_loop_prolog (unsigned long *in_purr,ktime_t *kt_before) +{ + + *kt_before =ktime_get_real (); + *in_purr =mfspr (SPRN_PURR ); +/* +* Indicate to the HV that we are idle. Now would be +* a good time to find other work to dispatch. +*/
Quoted 9 lines
arch/powerpc/platforms/pseries/processor_idle.c line 53
Quoted 3 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +3
-0+get_lppaca ()->idle =1 ; +get_lppaca ()->donate_dedicated_cpu =1 ; +}I notice that you call this on shared processors as well. The old ocde used to not set
donate_dedicated_cpuin that case. I assume that's not a big deal and that the HV will just ignore it in the shared processor case but please add a comment after you've verified it.
Yes, the old code does not set donate_dedicated_cpu. But yes I will try testing it in a shared proc config but also remove this initialization for shared idle loop.
Quoted 32 lines
Quoted 32 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +32
-0+static inline s64 idle_loop_epilog (unsigned long in_purr,ktime_t kt_before) +{ +get_lppaca ()->wait_state_cycles +=mfspr (SPRN_PURR ) - in_purr; +get_lppaca ()->donate_dedicated_cpu =0 ; +get_lppaca ()->idle =0 ; + +return ktime_to_us (ktime_sub (ktime_get_real (), kt_before)); +} + + +static int snooze_loop (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +unsigned long in_purr; +ktime_t kt_before; + +idle_loop_prolog (&in_purr, &kt_before); + +local_irq_enable (); +set_thread_flag (TIF_POLLING_NRFLAG ); +while (!need_resched ()) { +ppc64_runlatch_off (); +HMT_low (); +HMT_very_low (); + } +HMT_medium (); +clear_thread_flag (TIF_POLLING_NRFLAG ); +smp_mb (); +local_irq_disable (); + + dev->last_residency =
Quoted 8 lines
arch/powerpc/platforms/pseries/processor_idle.c line 89
Quoted 3 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +3
-0+ (int )idle_loop_epilog (in_purr, kt_before); +return index; +}So your snooze loop has no timeout, is that handled by the cpuidle driver using some kind of timer ? That sounds a lot less efficient than passing a max delay to the snooze loop to handle getting into a deeper state after a bit of snoozing rather than interrupting etc...
My bad, snooze_loop is essential for a time out. Nope cpuidle driver doesn't have any timer mechanism. I ll fix it. Need to add loop for snooze time.
Quoted 84 lines
Quoted 84 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +84
-0+static int dedicated_cede_loop (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +unsigned long in_purr; +ktime_t kt_before; + +idle_loop_prolog (&in_purr, &kt_before); + +ppc64_runlatch_off (); +HMT_medium (); +cede_processor (); + + dev->last_residency = + (int )idle_loop_epilog (in_purr, kt_before); +return index; +} + +static int shared_cede_loop (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +unsigned long in_purr; +ktime_t kt_before; + +idle_loop_prolog (&in_purr, &kt_before); + +/* +* Yield the processor to the hypervisor. We return if +* an external interrupt occurs (which are driven prior +* to returning here) or if a prod occurs from another +* processor. When returning here, external interrupts +* are enabled. +*/ +cede_processor (); + + dev->last_residency = + (int )idle_loop_epilog (in_purr, kt_before); +return index; +} + +/* +* States for dedicated partition case. +*/ +static struct cpuidle_state dedicated_states[MAX_IDLE_STATE_COUNT ] = { + {/* Snooze */ + .name ="snooze" , + .desc ="snooze" , + .flags =CPUIDLE_FLAG_TIME_VALID , + .exit_latency =0 , + .target_residency =0 , + .enter = &snooze_loop }, + {/* CEDE */ + .name ="CEDE" , + .desc ="CEDE" , + .flags =CPUIDLE_FLAG_TIME_VALID , + .exit_latency =1 , + .target_residency =10 , + .enter = &dedicated_cede_loop }, +}; + +/* +* States for shared partition case. +*/ +static struct cpuidle_state shared_states[MAX_IDLE_STATE_COUNT ] = { + {/* Shared Cede */ + .name ="Shared Cede" , + .desc ="Shared Cede" , + .flags =CPUIDLE_FLAG_TIME_VALID , + .exit_latency =0 , + .target_residency =0 , + .enter = &shared_cede_loop }, +}; + +int pseries_notify_cpuidle_add_cpu (int cpu) +{ +struct cpuidle_device *dev = +per_cpu_ptr (pseries_idle_cpuidle_devices, cpu); +if (dev &&cpuidle_get_driver ()) { +cpuidle_disable_device (dev); +cpuidle_enable_device (dev); + } +return 0 ; +}
Quoted 8 lines
arch/powerpc/platforms/pseries/processor_idle.c line 180
Quoted 6 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +6
-0+ +/* +* pseries_idle_cpuidle_driver_init() +*/ +static int pseries_idle_cpuidle_driver_init (void ) +{Drop the "idle", those names are too long.
Sure.
Quoted 5 lines
arch/powerpc/platforms/pseries/processor_idle.c line 181
Quoted 2 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +1
-0+int cstate;And use something else than 'cstate', we are among civilized people here ;-)
Yes :)
Quoted 82 lines
Quoted 82 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +81
-0+struct cpuidle_driver *drv = &pseries_idle_driver; + + drv->state_count =0 ; + +for (cstate =0 ; cstate <MAX_IDLE_STATE_COUNT ; ++cstate) { + +if (cstate > max_cstate) +break ; + +/* is the state not enabled? */ +if (cpuidle_state_table[cstate].enter ==NULL ) +continue ; + + drv->states[drv->state_count] =/* structure copy */ + cpuidle_state_table[cstate]; + +if (cpuidle_state_table == dedicated_states) + drv->states[drv->state_count].target_residency = +__get_cpu_var (smt_snooze_delay); + + drv->state_count +=1 ; + } + +return 0 ; +} + +/* pseries_idle_devices_uninit(void) +* unregister cpuidle devices and de-allocate memory +*/ +static void pseries_idle_devices_uninit (void ) +{ +int i; +struct cpuidle_device *dev; + +for_each_possible_cpu (i) { + dev =per_cpu_ptr (pseries_idle_cpuidle_devices, i); +cpuidle_unregister_device (dev); + } + +free_percpu (pseries_idle_cpuidle_devices); +return ; +} + +/* pseries_idle_devices_init() +* allocate, initialize and register cpuidle device +*/ +static int pseries_idle_devices_init (void ) +{ +int i; +struct cpuidle_driver *drv = &pseries_idle_driver; +struct cpuidle_device *dev; + + pseries_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device); +if (pseries_idle_cpuidle_devices ==NULL ) +return -ENOMEM ; + +for_each_possible_cpu (i) { + dev =per_cpu_ptr (pseries_idle_cpuidle_devices, i); + dev->state_count = drv->state_count; + dev->cpu = i; +if (cpuidle_register_device (dev)) { +printk (KERN_DEBUG \ +"cpuidle_register_device %d failed!\n" , i); +return -EIO ; + } + } + +return 0 ; +} + +/* +* pseries_idle_probe() +* Choose state table for shared versus dedicated partition +*/ +static int pseries_idle_probe (void ) +{ +if (max_cstate ==0 ) { +printk (KERN_DEBUG "pseries processor idle disabled.\n" ); +return -EPERM ; + } +
Quoted 8 lines
arch/powerpc/platforms/pseries/processor_idle.c line 266
Quoted 4 lines
arch/powerpc/platforms/pseries/processor_idle.c new file +4
-0+if (!firmware_has_feature (FW_FEATURE_SPLPAR )) { +printk (KERN_DEBUG "Using default idle\n" ); +return -ENODEV ; + }Don't even printk here, this will happen on all !pseries machines and the debug output isn't useful. Also move the check of max-cstate to after the splpar test.
I ll move the check above.
Quoted 2 lines
Overall, I quite like these patches, my comments are all pretty minor, hopefully the next round should be the one.
Thank you.
Quoted 5 lines
Cheers,
Ben.
Regards,
Deepthi
Re: [RFC PATCH v2 3/4] cpuidle: (POWER) Enable cpuidle and directly call cpuidle_idle_call() for pSeries
In reply to Benjamin HerrenschmidtQuoted 69 lines · Benjamin Herrenschmidt
Quoted 68 lines · Deepthi Dharwar
This patch enables cpuidle for pSeries and
cpuidle_idle_call()is directly called from the idle loop. As a resultpseries_idlecpuidle driver registered with cpuidle subsystem comes into action. This patch also removes the routinespseries_shared_idle_sleepandpseries_dedicated_idle_sleepas they are now implemented as part ofpseries_idlecpuidle driver.Signed-off-by Deepthi Dharwar <[email protected]>Signed-off-by Trinabh Gupta <[email protected]>Signed-off-by Arun R Bharadwaj <[email protected]>--- arch/powerpc/platforms/Kconfig | 6 ++ arch/powerpc/platforms/pseries/setup.c | 86 +------------------------------- include/linux/cpuidle.h | 2 - 3 files changed, 8 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 +1
-10@@ -39,6 +39,7 @@#include <linux/irq.h> #include <linux/seq_file.h> #include <linux/root_dev.h> +#include <linux/cpuidle.h> #include <asm/mmu.h> #include <asm/processor.h> @@ -74,9 +75,6 @@ EXPORT_SYMBOL(CMO_PageSize);int fwnmi_active;/* TRUE if an FWNMI handler is present */ -static void pseries_shared_idle_sleep (void ); -static void pseries_dedicated_idle_sleep (void ); -static struct device_node *pSeries_mpic_node;static void pSeries_show_cpuinfo (struct seq_file *m)@@ -374,18 +372,9 @@ static void __init pSeries_setup_arch(void)pSeries_nvram_init (); -/* Choose an idle loop */ if (firmware_has_feature (FW_FEATURE_SPLPAR )) {vpa_init (boot_cpuid); -if (get_lppaca ()->shared_proc) { -printk (KERN_DEBUG "Using shared processor idle loop\n" ); - ppc_md.power_save = pseries_shared_idle_sleep; - }else { -printk (KERN_DEBUG "Using dedicated idle loop\n" ); - ppc_md.power_save = pseries_dedicated_idle_sleep;
Quoted 8 lines
arch/powerpc/platforms/pseries/setup.c static void __init pSeries_setup_arch(void) · line 378
Quoted 5 lines
arch/powerpc/platforms/pseries/setup.c +1
-3- } - }else { -printk (KERN_DEBUG "Using default idle loop\n" ); + ppc_md.power_save = (void *)cpuidle_idle_call; }I very very much dislike that cast. You should not have to cast a function pointer ... EVER.
Yes, I ll fix this.
This actually bought out a design flaw with the current pseries idle as mentioned by you in the next patch of the series.
Quoted 11 lines
arch/powerpc/platforms/pseries/setup.c static int __init pSeries_probe(void) · line 577
Quoted 6 lines
arch/powerpc/platforms/pseries/setup.c +0
-0if (firmware_has_feature (FW_FEATURE_LPAR ))@@ -586,77 +575,6 @@ static int __init pSeries_probe(void)return 1 ; }Cheers,
Ben.
Regards,
Deepthi
Re: [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
In reply to Benjamin HerrenschmidtQuoted 9 lines · Benjamin Herrenschmidt
Quoted 4 lines · Deepthi Dharwar
This patch makes
pseries_idle_drivernot to be registered when power_save=off kernel boot option is specified. Theboot_option_idle_overridevariable used here is similar to its usage on x86.Quick Q. With your changes, the CPU will never get into idle at all until cpuidle initializes and the driver loads.
Quoted 7 lines
That means not only much later in the boot process, but potentially never if the distro has the driver as a module and fails to load it, or similar.
Can't that be an issue ? Shouldn't we keep at least one of the basic idle functions as a fallback ?
On an LPAR if cpuidle is disabled, ppc_md.power_save is still set to cpuidle_idle_call by default here. This would result in calling of cpuidle_idle_call repeatedly, only for the call to return -ENODEV. The default idle is never executed.
This would be a major design flaw. No fallback idle routine.
We propose to fix this by checking the return value of ppc_md.power_save() call from void to int.
Right now return value is void, but if we change this to int, this would solve two problems. One being removing the cast to a function pointer in the prev patch and this design flaw stated above.
So by checking the return value of ppc_md.power_save(), we can invoke the default idle on failure. But my only concern is about the effects of changing the ppc_md.power_save() to return int on other powerpc architectures. Would it be a good idea to change the return type to int which would help us flag an error and fallback to default idle?
Quoted 5 lines
Cheers,
Ben.
Regards,
Deepthi
Re: [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
In reply to Benjamin HerrenschmidtQuoted 9 lines · Benjamin Herrenschmidt
Quoted 4 lines · Deepthi Dharwar
This patch makes
pseries_idle_drivernot to be registered when power_save=off kernel boot option is specified. Theboot_option_idle_overridevariable used here is similar to its usage on x86.Quick Q. With your changes, the CPU will never get into idle at all until cpuidle initializes and the driver loads.
Quoted 7 lines
That means not only much later in the boot process, but potentially never if the distro has the driver as a module and fails to load it, or similar.
Can't that be an issue ? Shouldn't we keep at least one of the basic idle functions as a fallback ?
On an LPAR if cpuidle is disabled, ppc_md.power_save is still set to cpuidle_idle_call by default here. This would result in calling of cpuidle_idle_call repeatedly, only for the call to return -ENODEV. The default idle is never executed.
This would be a major design flaw. No fallback idle routine.
We propose to fix this by checking the return value of ppc_md.power_save() call from void to int.
Right now return value is void, but if we change this to int, this would solve two problems. One being removing the cast to a function pointer in the prev patch and this design flaw stated above.
So by checking the return value of ppc_md.power_save(), we can invoke the default idle on failure. But my only concern is about the effects of changing the ppc_md.power_save() to return int on other powerpc architectures. Would it be a good idea to change the return type to int which would help us flag an error and fallback to default idle?
Quoted 5 lines
Cheers,
Ben.
Regards,
Deepthi
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Deepthi DharwarQuoted 16 lines · Deepthi Dharwar
Quoted 4 lines
Additionally, I'm a bit worried (but maybe we already discussed that a while back, I don't know) but
cpu_idle_wait()has "wait" in the name, which makes me think it might need to actually -wait- for all cpus to have come out of the function.
cpu_idle_waitis used to ensure that all the CPUs discard old idle handler and update to new one. Required while changing idle handler on SMP systems.Quoted 5 lines
Now your implementation doesn't provide that guarantee. It might be fine, I don't know, but if it is, you'd better document it well in the comments surrounding the code, because as it is, all you do is shoot an interrupt which will cause the target CPU to eventually come out of idle some time in the future.
Quoted 2 lines
I was hoping that sending an explicit reschedule to the cpus would do the trick but sure we can add some documentation around the code.
Well, the question is what guarantee do you expect. Sending a reschedule IPI will take the other CPUs out of the actual sleep mode, but it will be some time from there back to getting out of the handler function (first back out of hypervisor etc...).
The code as you implemented it doesn't wait for that to happen. It might be fine ... or not. I don't know what semantics you are after precisely.
Cheers,
Ben.
Re: [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
In reply to Deepthi DharwarQuoted 12 lines · Deepthi Dharwar
On an LPAR if cpuidle is disabled, ppc_md.power_save is still set to
cpuidle_idle_callby default here. This would result in calling ofcpuidle_idle_callrepeatedly, only for the call to return-ENODEV. The default idle is never executed.
This would be a major design flaw. No fallback idle routine.We propose to fix this by checking the return value of
ppc_md.power_save()call from void to int.
Right now return value is void, but if we change this to int, this would solve two problems. One being removing the cast to a function pointer in the prev patch and this design flaw stated above.
Quoted 5 lines
So by checking the return value of
ppc_md.power_save(), we can invoke the default idle on failure. But my only concern is about the effects of changing theppc_md.power_save()to return int on other powerpc architectures. Would it be a good idea to change the return type to int which would help us flag an error and fallback to default idle?
I would have preferred an approach where the cpuidle module sets ppc_md.power_save when loaded and restores it when unloaded ... but that would have to go into the cpuidle core as a powerpc specific tweak and might not be generally well received.
So go for it, add the return value, but you'll have to update all the idle functions (grep for power_save in arch/powerpc to find them).
Cheers,
Ben.
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Benjamin HerrenschmidtQuoted 26 lines · Benjamin Herrenschmidt
Quoted 16 lines · Deepthi Dharwar
Quoted 4 lines
Additionally, I'm a bit worried (but maybe we already discussed that a while back, I don't know) but
cpu_idle_wait()has "wait" in the name, which makes me think it might need to actually -wait- for all cpus to have come out of the function.
cpu_idle_waitis used to ensure that all the CPUs discard old idle handler and update to new one. Required while changing idle handler on SMP systems.Quoted 5 lines
Now your implementation doesn't provide that guarantee. It might be fine, I don't know, but if it is, you'd better document it well in the comments surrounding the code, because as it is, all you do is shoot an interrupt which will cause the target CPU to eventually come out of idle some time in the future.
Quoted 2 lines
I was hoping that sending an explicit reschedule to the cpus would do the trick but sure we can add some documentation around the code.
Well, the question is what guarantee do you expect. Sending a reschedule IPI will take the other CPUs out of the actual sleep mode, but it will be some time from there back to getting out of the handler function (first back out of hypervisor etc...).
Quoted 7 lines
The code as you implemented it doesn't wait for that to happen. It might be fine ... or not. I don't know what semantics you are after precisely.
Cheers,
Ben.
Yes, this could be problematic as there is small window for the race condition to occur . Otherwise we need to manually schedule it by running a kernel thread but this would definitely have a overhead and would be an overkill.
Regards,
Deepthi
Re: [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
In reply to Benjamin HerrenschmidtQuoted 20 lines · Benjamin Herrenschmidt
Quoted 12 lines · Deepthi Dharwar
On an LPAR if cpuidle is disabled, ppc_md.power_save is still set to
cpuidle_idle_callby default here. This would result in calling ofcpuidle_idle_callrepeatedly, only for the call to return-ENODEV. The default idle is never executed.
This would be a major design flaw. No fallback idle routine.We propose to fix this by checking the return value of
ppc_md.power_save()call from void to int.
Right now return value is void, but if we change this to int, this would solve two problems. One being removing the cast to a function pointer in the prev patch and this design flaw stated above.Quoted 5 lines
So by checking the return value of
ppc_md.power_save(), we can invoke the default idle on failure. But my only concern is about the effects of changing theppc_md.power_save()to return int on other powerpc architectures. Would it be a good idea to change the return type to int which would help us flag an error and fallback to default idle?
Quoted 8 lines
I would have preferred an approach where the cpuidle module sets ppc_md.power_save when loaded and restores it when unloaded ... but that would have to go into the cpuidle core as a powerpc specific tweak and might not be generally well received.
So go for it, add the return value, but you'll have to update all the idle functions (grep for
power_saveinarch/powerpcto find them).
Thanks Ben. Yes, I will update all the idle functions under powerpc. I will re-work these patches with the discussed changes.
Regards,
Deepthi
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Deepthi DharwarQuoted 5 lines · Deepthi Dharwar
Yes, this could be problematic as there is small window for the race condition to occur . Otherwise we need to manually schedule it by running a kernel thread but this would definitely have a overhead and would be an overkill.
Depends what this "window" is. IE. What are you trying to protect yourself against ? What's the risk ?
If it's just module unload, then stop_machine is probably your friend :-)
Cheers,
Ben.
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Deepthi Dharwar
Yes, this could be problematic as there is small window for the race condition to occur . Otherwise we need to manually schedule it by running a kernel thread but this would definitely have a overhead and would be an overkill.
Quoted 10 lines
Depends what this "window" is. IE. What are you trying to protect yourself against ? What's the risk ?
If it's just module unload, then
stop_machineis probably your friend :-)Cheers,
Ben.
Yup, it is the module unload that I am worried about. Otherwise manually doing it using kernel thread would be an overkill -:(
Regards,
Deepthi
Re: [RFC PATCH v2 1/4] cpuidle: (powerpc) Add cpu_idle_wait() to allow switching of idle routines
In reply to Benjamin HerrenschmidtQuoted 7 lines · Benjamin Herrenschmidt
Quoted 5 lines · Deepthi Dharwar
Yes, this could be problematic as there is small window for the race condition to occur . Otherwise we need to manually schedule it by running a kernel thread but this would definitely have a overhead and would be an overkill.
Quoted 10 lines
Depends what this "window" is. IE. What are you trying to protect yourself against ? What's the risk ?
If it's just module unload, then
stop_machineis probably your friend :-)Cheers,
Ben.
Yup, it is the module unload that I am worried about. Otherwise manually doing it using kernel thread would be an overkill -:(
Regards,
Deepthi
Re: [linux-pm] [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
In reply to Deepthi DharwarQuoted 10 lines · Deepthi Dharwar
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Deepthi Dharwar
On an LPAR if cpuidle is disabled, ppc_md.power_save is still set to
cpuidle_idle_callby default here. This would result in calling ofcpuidle_idle_callrepeatedly, only for the call to return-ENODEV. The default idle is never executed.
This would be a major design flaw. No fallback idle routine.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
We propose to fix this by checking the return value of
ppc_md.power_save()call from void to int.
Right now return value is void, but if we change this to int, this would solve two problems. One being removing the cast to a function pointer in the prev patch and this design flaw stated above.
kernel/idle.c: ppc_md.power_save = NULL;
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
So by checking the return value of
ppc_md.power_save(), we can invoke the default idle on failure. But my only concern is about the effects of changing theppc_md.power_save()to return int on other powerpc architectures. Would it be a good idea to change the return type to int which would help us flag an error and fallback to default idle?Quoted 8 lines
I would have preferred an approach where the cpuidle module sets ppc_md.power_save when loaded and restores it when unloaded ... but that would have to go into the cpuidle core as a powerpc specific tweak and might not be generally well received.
So go for it, add the return value, but you'll have to update all the idle functions (grep for
power_saveinarch/powerpcto find them).Thanks Ben. Yes, I will update all the idle functions under powerpc. I will re-work these patches with the discussed changes.
Quoted 9 lines
Regards,
Deepthi_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm
Hi Ben,
I was trying to add a return value for power_save for all arch/powepc idle functions but a few of them directly call *.S routines, as they are asm.
What would be a good way to change the return value for asm routines ? Do we make a change in asm only, put the return value in r3 or write a wrapper function which would call these asm routines and return an int ?
Regards,
Deepthi
Re: [linux-pm] [RFC PATCH v2 4/4] cpuidle: (POWER) Handle power_save=off
Quoted 9 lines · Deepthi Dharwar
I was trying to add a return value for
power_savefor allarch/powepcidle functions but a few of them directly call *.S routines, as they are asm.What would be a good way to change the return value for asm routines ?
Do we make a change in asm only, put the return value in r3 or write a wrapper function which would call these asm routines and return an int ?
No, add li r3,0 at the end, but beware that their return point might not be ovbvious since we often return from an interrupt which modifies the return address ... Let me know if there's some you can't figure out and I'll help you.
Cheers,
Ben.