Avoid calling cpu_pm functions for retention idle states
Subsystems (2)
cover Avoid calling cpu_pm functions for retention idle states
CPU_PM_CPU_IDLE_ENTER() treats all idle states whose idx != 0 as a state that loses some context, but we can have deeper idle states that doesn't lose any software context. If a CPU is entering such a low power idle state where it retains the context, then there is no need to call cpu_pm_enter()/cpu_pm_exit().
Add a new macro(CPU_PM_CPU_IDLE_ENTER_RETENTION) to be used by cpuidle drivers when they are entering retention state. By not calling cpu_pm_enter and cpu_pm_exit we reduce the latency involved in entering and exiting the retention states.
On ARM64 based Qualcomm server platform we measured below overhead for for calling cpu_pm_enter and cpu_pm_exit for retention states.
workload: stress --hdd #CPUs --hdd-bytes 32M -t 30 Overhead of cpu_pm_enter - 1.2us(Average), 6.5us(Max) Overhead of cpu_pm_exit - 3.1us(Average), 11.1us(Max)
Listed below are 5 functions that were notified on ENTER/EXIT on the test platform:
gic_cpu_pm_notifier
arch_timer_cpu_pm_notify
cpu_pm_pmu_notify
hyp_init_cpu_pm_notifier
fpsimd_cpu_pm_notifier
Prashanth Prakash (2):
cpuidle: Add new macro to enter a retention idle state ARM64 / cpuidle: Use new cpuidle macro for entering retention state
arch/arm64/kernel/cpuidle.c | 8 +++++++- include/linux/cpuidle.h | 38 +++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-)
Signature · 3 lines
Qualcomm Datacenter Technologies on behalf of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH 1/2 cpuidle: Add new macro to enter a retention idle state
If a CPU is entering a low power idle state where it doesn't lose any context, then there is no need to call cpu_pm_enter()/cpu_pm_exit(). Add a new macro(CPU_PM_CPU_IDLE_ENTER_RETENTION) to be used by cpuidle drivers when they are entering retention state. By not calling cpu_pm_enter and cpu_pm_exit we reduce the latency involved in entering and exiting the retention idle states.
On ARM64 based Qualcomm Server Platform we measured below overhead for for calling cpu_pm_enter and cpu_pm_exit for retention states.
workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead of cpu_pm_enter - 1.2us Average overhead of cpu_pm_exit - 3.1us
--- include/linux/cpuidle.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
include/linux/cpuidle.h +23 -15
@@ -258,21 +258,29 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)#endif #define CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx) \ -({ \ - int __ret; \ - \ - if (!idx) { \ - cpu_do_idle(); \ - return idx; \ - } \ - \ - __ret = cpu_pm_enter(); \ - if (!__ret) { \ - __ret = low_level_idle_enter(idx); \ - cpu_pm_exit(); \ - } \ - \ - __ret ? -1 : idx; \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 0) + +#define CPU_PM_CPU_IDLE_ENTER_RETENTION (low_level_idle_enter, idx) \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 1) + +#define __CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx, is_retention) \ +({ \ + int __ret = 0; \ + \ + if (!idx) { \ + cpu_do_idle(); \ + return idx; \ + } \ + \ + if (!is_retention) \ + __ret = cpu_pm_enter(); \ + if (!__ret) { \ + __ret = low_level_idle_enter(idx); \ + if (!is_retention) \ + cpu_pm_exit(); \ + } \ + \ + __ret ? -1 : idx; \ })#endif /* _LINUX_CPUIDLE_H */
Signature · 3 lines
Qualcomm Datacenter Technologies on behalf of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH 2/2 ARM64 / cpuidle: Use new cpuidle macro for entering retention state
In reply to Prashanth PrakashCPU_PM_CPU_IDLE_ENTER_RETENTION skips calling cpu_pm_enter() and cpu_pm_exit(). By not calling cpu_pm functions in idle entry/exit paths we can reduce the latency involved in entering and exiting the low power idle state.
On ARM64 based Qualcomm server platform we measured below overhead for calling cpu_pm_enter and cpu_pm_exit for retention states.
workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead of cpu_pm_enter - 1.2us Average overhead of cpu_pm_exit - 3.1us
--- arch/arm64/kernel/cpuidle.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpuidle.c +7 -1
@@ -47,6 +47,8 @@ int arm_cpuidle_suspend(int index)#include <acpi/processor.h> +#define ARM64_LPI_IS_RETENTION_STATE (arch_flags) (!(arch_flags)) +int acpi_processor_ffh_lpi_probe (unsigned int cpu) {return arm_cpuidle_init (cpu);
@@ -54,6 +56,10 @@ int acpi_processor_ffh_lpi_probe(unsigned int cpu)int acpi_processor_ffh_lpi_enter (struct acpi_lpi_state *lpi) { -return CPU_PM_CPU_IDLE_ENTER (arm_cpuidle_suspend, lpi->index); +if (ARM64_LPI_IS_RETENTION_STATE (lpi->arch_flags)) +return CPU_PM_CPU_IDLE_ENTER_RETENTION (arm_cpuidle_suspend, + lpi->index); +else +return CPU_PM_CPU_IDLE_ENTER (arm_cpuidle_suspend, lpi->index); }#endif
Signature · 3 lines
Qualcomm Datacenter Technologies on behalf of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH 2/2 ARM64 / cpuidle: Use new cpuidle macro for entering retention state
Quoted 22 lines · Prashanth Prakash
CPU_PM_CPU_IDLE_ENTER_RETENTIONskips callingcpu_pm_enter()andcpu_pm_exit(). By not callingcpu_pmfunctions in idle entry/exit paths we can reduce the latency involved in entering and exiting the low power idle state.On ARM64 based Qualcomm server platform we measured below overhead for calling
cpu_pm_enterandcpu_pm_exitfor retention states.workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead ofcpu_pm_enter- 1.2us Average overhead ofcpu_pm_exit- 3.1usSigned-off-by Prashanth Prakash <[email protected]>--- arch/arm64/kernel/cpuidle.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/arm64/kernel/cpuidle.c +0
-0
arch/arm64/kernel/cpuidle.c int arm_cpuidle_suspend(int index) · line 51
Quoted 5 lines
arch/arm64/kernel/cpuidle.c +2
-0@@ -47,6 +47,8 @@ int arm_cpuidle_suspend(int index)#include <acpi/processor.h> +#define ARM64_LPI_IS_RETENTION_STATE (arch_flags) (!(arch_flags)) +
Ideally we could cater both ACPI LPI and DT using PSCI parameters. No ? Just thinking it out loud as I see no reason to restrict this just to ACPI LPIs.
Signature · 2 lines
Regards, Sudeep
PATCH 1/2 cpuidle: Add new macro to enter a retention idle state
In reply to Prashanth PrakashQuoted 48 lines · Prashanth Prakash
If a CPU is entering a low power idle state where it doesn't lose any context, then there is no need to call cpu_pm_enter()/cpu_pm_exit(). Add a new
macro(CPU_PM_CPU_IDLE_ENTER_RETENTION)to be used by cpuidle drivers when they are entering retention state. By not callingcpu_pm_enterandcpu_pm_exitwe reduce the latency involved in entering and exiting the retention idle states.On ARM64 based Qualcomm Server Platform we measured below overhead for for calling
cpu_pm_enterandcpu_pm_exitfor retention states.workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead ofcpu_pm_enter- 1.2us Average overhead ofcpu_pm_exit- 3.1usSigned-off-by Prashanth Prakash <[email protected]>--- include/linux/cpuidle.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)include/linux/cpuidle.h +6
-15@@ -258,21 +258,29 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)#endif #define CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx) \ -({ \ - int __ret; \ - \ - if (!idx) { \ - cpu_do_idle(); \ - return idx; \ - } \ - \ - __ret = cpu_pm_enter(); \ - if (!__ret) { \ - __ret = low_level_idle_enter(idx); \ - cpu_pm_exit(); \ - } \ - \ - __ret ? -1 : idx; \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 0) + +#define CPU_PM_CPU_IDLE_ENTER_RETENTION (low_level_idle_enter, idx) \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 1) + +#define __CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx, is_retention) \
include/linux/cpuidle.h static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 276
Quoted 10 lines
include/linux/cpuidle.h +10
-0+({ \ + int __ret = 0; \ + \ + if (!idx) { \ + cpu_do_idle(); \ + return idx; \ + } \ + \ + if (!is_retention) \ + __ret = cpu_pm_enter(); \
I am fine with this change as initial step. But I am wondering if we will have a retention state which loses partial state ?
The specification has flags to specify that difference but will we see that in reality is a different question. If we see such hardware, then we may need to revert this and handle in the callbacks as we can't skip cpu_pm notifier callbacks all together right ?
Signature · 3 lines
-- Regards, Sudeep
PATCH 2/2 ARM64 / cpuidle: Use new cpuidle macro for entering retention state
In reply to Sudeep HollaQuoted 26 lines · Sudeep Holla
Quoted 23 lines · Prashanth Prakash
CPU_PM_CPU_IDLE_ENTER_RETENTIONskips callingcpu_pm_enter()andcpu_pm_exit(). By not callingcpu_pmfunctions in idle entry/exit paths we can reduce the latency involved in entering and exiting the low power idle state.On ARM64 based Qualcomm server platform we measured below overhead for calling
cpu_pm_enterandcpu_pm_exitfor retention states.workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead ofcpu_pm_enter- 1.2us Average overhead ofcpu_pm_exit- 3.1usSigned-off-by Prashanth Prakash <[email protected]>--- arch/arm64/kernel/cpuidle.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/arm64/kernel/cpuidle.c +0
-0@@ -47,6 +47,8 @@ int arm_cpuidle_suspend(int index)
Quoted 9 lines
arch/arm64/kernel/cpuidle.c int arm_cpuidle_suspend(int index) · line 51
Quoted 4 lines
arch/arm64/kernel/cpuidle.c +2
-0#include <acpi/processor.h> +#define ARM64_LPI_IS_RETENTION_STATE (arch_flags) (!(arch_flags)) +Ideally we could cater both ACPI LPI and DT using PSCI parameters. No ? Just thinking it out loud as I see no reason to restrict this just to ACPI LPIs.
Just to add, after chatting with Lorenzo, I see PSCI covers only core states but that then leads to my question in the other patch: do we need partial state save/restore ever ? If not, then we can still use PSCI flag in both DT and ACPI.
Signature · 2 lines
Regards, Sudeep
PATCH 1/2 cpuidle: Add new macro to enter a retention idle state
In reply to Sudeep HollaHi Sudeep,
Quoted 63 lines · Sudeep Holla
Quoted 48 lines · Prashanth Prakash
If a CPU is entering a low power idle state where it doesn't lose any context, then there is no need to call cpu_pm_enter()/cpu_pm_exit(). Add a new
macro(CPU_PM_CPU_IDLE_ENTER_RETENTION)to be used by cpuidle drivers when they are entering retention state. By not callingcpu_pm_enterandcpu_pm_exitwe reduce the latency involved in entering and exiting the retention idle states.On ARM64 based Qualcomm Server Platform we measured below overhead for for calling
cpu_pm_enterandcpu_pm_exitfor retention states.workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead ofcpu_pm_enter- 1.2us Average overhead ofcpu_pm_exit- 3.1usSigned-off-by Prashanth Prakash <[email protected]>--- include/linux/cpuidle.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)include/linux/cpuidle.h +6
-15@@ -258,21 +258,29 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)#endif #define CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx) \ -({ \ - int __ret; \ - \ - if (!idx) { \ - cpu_do_idle(); \ - return idx; \ - } \ - \ - __ret = cpu_pm_enter(); \ - if (!__ret) { \ - __ret = low_level_idle_enter(idx); \ - cpu_pm_exit(); \ - } \ - \ - __ret ? -1 : idx; \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 0) + +#define CPU_PM_CPU_IDLE_ENTER_RETENTION (low_level_idle_enter, idx) \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 1) + +#define __CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx, is_retention) \include/linux/cpuidle.h static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 276
Quoted 10 lines
include/linux/cpuidle.h +10
-0+({ \ + int __ret = 0; \ + \ + if (!idx) { \ + cpu_do_idle(); \ + return idx; \ + } \ + \ + if (!is_retention) \ + __ret = cpu_pm_enter(); \I am fine with this change as initial step. But I am wondering if we will have a retention state which loses partial state ?
Quoted 4 lines
The specification has flags to specify that difference but will we see that in reality is a different question. If we see such hardware, then we may need to revert this and handle in the callbacks as we can't skip
cpu_pmnotifier callbacks all together right ?
I agree. This is a initial and quick first step and will help only fully retention states.
If there are devices with partial retention states and necessary support in cpu PM framework we can revert this and handle it in more generic way.
--
Thanks,
Prashanth
PATCH 1/2 cpuidle: Add new macro to enter a retention idle state
Quoted 7 lines · Prashanth
Hi Sudeep,
Quoted 3 lines · Sudeep Holla
I am fine with this change as initial step. But I am wondering if we will have a retention state which loses partial state ?
Quoted 9 lines
Quoted 4 lines
The specification has flags to specify that difference but will we see that in reality is a different question. If we see such hardware, then we may need to revert this and handle in the callbacks as we can't skip
cpu_pmnotifier callbacks all together right ?I agree. This is a initial and quick first step and will help only fully retention states.
If there are devices with partial retention states and necessary support in cpu PM framework we can revert this and handle it in more generic way.
Sounds good. Just wanted to be aware of that fact. Hope we don't get such crazy hardware(but you never know).
Signature · 2 lines
Regards, Sudeep
PATCH 1/2 cpuidle: Add new macro to enter a retention idle state
In reply to Prashanth PrakashQuoted 59 lines · CET Prashanth Prakash
If a CPU is entering a low power idle state where it doesn't lose any context, then there is no need to call cpu_pm_enter()/cpu_pm_exit(). Add a new
macro(CPU_PM_CPU_IDLE_ENTER_RETENTION)to be used by cpuidle drivers when they are entering retention state. By not callingcpu_pm_enterandcpu_pm_exitwe reduce the latency involved in entering and exiting the retention idle states.On ARM64 based Qualcomm Server Platform we measured below overhead for for calling
cpu_pm_enterandcpu_pm_exitfor retention states.workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead ofcpu_pm_enter- 1.2us Average overhead ofcpu_pm_exit- 3.1usSigned-off-by Prashanth Prakash <[email protected]>--- include/linux/cpuidle.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)include/linux/cpuidle.h +16
-15@@ -258,21 +258,29 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)#endif #define CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx) \ -({ \ - int __ret; \ - \ - if (!idx) { \ - cpu_do_idle(); \ - return idx; \ - } \ - \ - __ret = cpu_pm_enter(); \ - if (!__ret) { \ - __ret = low_level_idle_enter(idx); \ - cpu_pm_exit(); \ - } \ - \ - __ret ? -1 : idx; \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 0) + +#define CPU_PM_CPU_IDLE_ENTER_RETENTION (low_level_idle_enter, idx) \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 1) + +#define __CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx, is_retention) \ +({ \ + int __ret = 0; \ + \ + if (!idx) { \ + cpu_do_idle(); \ + return idx; \ + } \ + \ + if (!is_retention) \ + __ret = cpu_pm_enter(); \
include/linux/cpuidle.h static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 286
Quoted 10 lines
include/linux/cpuidle.h +7
-0+if (!__ret) { \ + __ret =low_level_idle_enter (idx); \ +if (!is_retention) \ +cpu_pm_exit (); \ + } \ + \ + __ret ?-1 : idx; \ })#endif /* _LINUX_CPUIDLE_H */
The ordering of the macros seems kind of backwards. The inner-most ones usually go first (which is more natural for a human reader too).
Thanks,
Rafael
PATCH 1/2 cpuidle: Add new macro to enter a retention idle state
Quoted 68 lines · Rafael J. Wysocki
Quoted 67 lines · CET Prashanth Prakash
If a CPU is entering a low power idle state where it doesn't lose any context, then there is no need to call cpu_pm_enter()/cpu_pm_exit(). Add a new
macro(CPU_PM_CPU_IDLE_ENTER_RETENTION)to be used by cpuidle drivers when they are entering retention state. By not callingcpu_pm_enterandcpu_pm_exitwe reduce the latency involved in entering and exiting the retention idle states.On ARM64 based Qualcomm Server Platform we measured below overhead for for calling
cpu_pm_enterandcpu_pm_exitfor retention states.workload: stress --hdd #CPUs --hdd-bytes 32M -t 30
Average overhead ofcpu_pm_enter- 1.2us Average overhead ofcpu_pm_exit- 3.1usSigned-off-by Prashanth Prakash <[email protected]>--- include/linux/cpuidle.h | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)include/linux/cpuidle.h +23
-15@@ -258,21 +258,29 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)#endif #define CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx) \ -({ \ - int __ret; \ - \ - if (!idx) { \ - cpu_do_idle(); \ - return idx; \ - } \ - \ - __ret = cpu_pm_enter(); \ - if (!__ret) { \ - __ret = low_level_idle_enter(idx); \ - cpu_pm_exit(); \ - } \ - \ - __ret ? -1 : idx; \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 0) + +#define CPU_PM_CPU_IDLE_ENTER_RETENTION (low_level_idle_enter, idx) \ + __CPU_PM_CPU_IDLE_ENTER(low_level_idle_enter, idx, 1) + +#define __CPU_PM_CPU_IDLE_ENTER (low_level_idle_enter, idx, is_retention) \ +({ \ + int __ret = 0; \ + \ + if (!idx) { \ + cpu_do_idle(); \ + return idx; \ + } \ + \ + if (!is_retention) \ + __ret = cpu_pm_enter(); \ + if (!__ret) { \ + __ret = low_level_idle_enter(idx); \ + if (!is_retention) \ + cpu_pm_exit(); \ + } \ + \ + __ret ? -1 : idx; \ })
Quoted 4 lines
include/linux/cpuidle.h static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 286
Quoted 2 lines
include/linux/cpuidle.h +0
-0#endif /* _LINUX_CPUIDLE_H */ The ordering of the macros seems kind of backwards. The inner-most ones usually go first (which is more natural for a human reader too).
I will change it and send out v2.
Thanks,
Prashanth