arm64: support poll_idle()
v10 cover arm64: support poll_idle()
Hi,
This patchset adds support for polling in idle on arm64 via poll_idle() and adds the requisite support to acpi-idle and cpuidle-haltpoll.
v10 is a respin of v9 with the timed wait barrier logic (smp_cond_load_relaxed_timewait()) moved out into a separate series [0]. (The barrier patches could also do with some eyes.)
Why poll in idle?
==
The benefit of polling in idle is to reduce the cost (and latency) of remote wakeups. When enabled, these can be done just by setting the need-resched bit, eliding the IPI, and the cost of handling the interrupt on the receiver.
Comparing sched-pipe performance on a guest VM:
# perf stat -r 5 --cpu 4,5 -e task-clock,cycles,instructions \ -e sched:sched_wake_idle_without_ipi perf bench sched pipe -l 1000000 --cpu 4
# without polling in idle
Performance counter stats for 'CPU(s) 4,5' (5 runs):
25,229.57 msec task-clock # 2.000 CPUs utilized ( +- 7.75% )
45,821,250,284 cycles # 1.816 GHz ( +- 10.07% )
26,557,496,665 instructions # 0.58 insn per cycle ( +- 0.21% )0 sched:sched_wake_idle_without_ipi # 0.000 /sec
12.615 +- 0.977 seconds time elapsed ( +- 7.75% )
# polling in idle (with haltpoll):
Performance counter stats for 'CPU(s) 4,5' (5 runs):
15,131.58 msec task-clock # 2.000 CPUs utilized ( +- 10.00% )
34,158,188,839 cycles # 2.257 GHz ( +- 6.91% )
20,824,950,916 instructions # 0.61 insn per cycle ( +- 0.09% )
1,983,822 sched:sched_wake_idle_without_ipi # 131.105 K/sec ( +- 0.78% )7.566 +- 0.756 seconds time elapsed ( +- 10.00% )
Comparing the two cases, there's a significant drop in both cycles and instructions executed. And a signficant drop in the wakeup latency.
Tomohiro Misono and Haris Okanovic also report similar latency improvements on Grace and Graviton systems (for v7) [1] [2]. Haris also tested a modified v9 on top of the split out barrier primitives.
Lifeng also reports improved context switch latency on a bare-metal machine with acpi-idle [3].
Series layout
==
- patches 1-3,
"cpuidle/poll_state: poll via smp_cond_load_relaxed_timewait()" "cpuidle: rename ARCH_HAS_CPU_RELAX to ARCH_HAS_OPTIMIZED_POLL" "Kconfig: move ARCH_HAS_OPTIMIZED_POLL to arch/Kconfig"
switch poll_idle() to using the new barrier interface. Also, do some munging of related kconfig options.
- patches 4-5,
"arm64: define TIF_POLLING_NRFLAG"
"arm64: add support for poll_idle()"
add arm64 support for the polling flag and enable poll_idle() support.
- patches 6, 7-11,
"ACPI: processor_idle: Support polling state for LPI"
"cpuidle-haltpoll: define arch_haltpoll_want()" "governors/haltpoll: drop kvm_para_available() check" "cpuidle-haltpoll: condition on ARCH_CPUIDLE_HALTPOLL"
"arm64: idle: export arch_cpu_idle()"
"arm64: support cpuidle-haltpoll"
add support for polling via acpi-idle, and cpuidle-haltpoll.
Changelog
==
v10: respin of v9
- sent out smp_cond_load_relaxed_timeout() separately [0]
- Dropped from this series:
"asm-generic: add barrier smp_cond_load_relaxed_timeout()" "arm64: barrier: add support for smp_cond_relaxed_timeout()" "arm64/delay: move some constants out to a separate header" "arm64: support WFET in smp_cond_relaxed_timeout()"
- reworded some commit messages
v9:
- reworked the series to address a comment from Catalin Marinas about how v8 was abusing semantics of smp_cond_load_relaxed().
- add poll_idle() support in acpi-idle (Lifeng Zheng)
- dropped some earlier "Tested-by", "Reviewed-by" due to the above rework.
v8: No logic changes. Largely respin of v7, with changes noted below:
- move selection of ARCH_HAS_OPTIMIZED_POLL on arm64 to its own patch.
(patch-9 "arm64: select ARCH_HAS_OPTIMIZED_POLL")
- address comments simplifying arm64 support (Will Deacon) (patch-11 "arm64: support cpuidle-haltpoll")
v7: No significant logic changes. Mostly a respin of v6.
- minor cleanup in poll_idle() (Christoph Lameter)
- fixes conflicts due to code movement in arch/arm64/kernel/cpuidle.c (Tomohiro Misono)
v6:
- reordered the patches to keep poll_idle() and ARCH_HAS_OPTIMIZED_POLL changes together (comment from Christoph Lameter)
- threshes out the commit messages a bit more (comments from Christoph Lameter, Sudeep Holla)
- also rework selection of cpuidle-haltpoll. Now selected based on the architectural selection of ARCH_CPUIDLE_HALTPOLL.
- moved back to arch_haltpoll_want() (comment from Joao Martins) Also, arch_haltpoll_want() now takes the force parameter and is now responsible for the complete selection (or not) of haltpoll.
- fixes the build breakage on i386
- fixes the cpuidle-haltpoll module breakage on arm64 (comment from Tomohiro Misono, Haris Okanovic)
v5:
- rework the poll_idle() loop around smp_cond_load_relaxed() (review comment from Tomohiro Misono.)
- also rework selection of cpuidle-haltpoll. Now selected based on the architectural selection of ARCH_CPUIDLE_HALTPOLL.
- arch_haltpoll_supported() (renamed from arch_haltpoll_want()) on arm64 now depends on the event-stream being enabled.
- limit POLL_IDLE_RELAX_COUNT on arm64 (review comment from Haris Okanovic)
- ARCH_HAS_CPU_RELAX is now renamed to ARCH_HAS_OPTIMIZED_POLL.
v4 changes from v3:
- change 7/8 per Rafael input: drop the parens and use ret for the final check
- add 8/8 which renames the guard for building poll_state
v3 changes from v2:
- fix 1/7 per Petr Mladek - remove ARCH_HAS_CPU_RELAX from arch/x86/Kconfig
- add Ack-by from Rafael Wysocki on 2/7
v2 changes from v1:
- added patch 7 where we change cpu_relax with smp_cond_load_relaxed per PeterZ (this improves by 50% at least the CPU cycles consumed in the tests above:
10,716,881,137 now vs 14,503,014,257 before)
- removed the ifdef from patch 1 per RafaelW
Would appreciate any review comments.
Ankur
[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/TY3PR01MB111481E9B0AF263ACC8EA5D4AE5BA2@TY3PR01MB11148.jpnprd01.prod.outlook.com/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
Ankur Arora (6):
cpuidle/poll_state: poll via smp_cond_load_relaxed_timewait()
cpuidle: rename ARCH_HAS_CPU_RELAX to ARCH_HAS_OPTIMIZED_POLL
arm64: add support for poll_idle()
cpuidle-haltpoll: condition on ARCH_CPUIDLE_HALTPOLL
arm64: idle: export arch_cpu_idle()
arm64: support cpuidle-haltpoll
Joao Martins (4):
Kconfig: move ARCH_HAS_OPTIMIZED_POLL to arch/Kconfig
arm64: define TIF_POLLING_NRFLAG
cpuidle-haltpoll: define arch_haltpoll_want() governors/haltpoll: drop kvm_para_available() check
Lifeng Zheng (1):
ACPI: processor_idle: Support polling state for LPI
arch/Kconfig | 3 ++ arch/arm64/Kconfig | 7 ++++ arch/arm64/include/asm/cpuidle_haltpoll.h | 20 +++++++++++ arch/arm64/include/asm/thread_info.h | 2 ++ arch/arm64/kernel/idle.c | 1 + arch/x86/Kconfig | 5 ++- arch/x86/include/asm/cpuidle_haltpoll.h | 1 + arch/x86/kernel/kvm.c | 13 +++++++ drivers/acpi/processor_idle.c | 43 +++++++++++++++++++---- drivers/cpuidle/Kconfig | 5 ++- drivers/cpuidle/Makefile | 2 +- drivers/cpuidle/cpuidle-haltpoll.c | 12 +------ drivers/cpuidle/governors/haltpoll.c | 6 +--- drivers/cpuidle/poll_state.c | 27 +++++--------- drivers/idle/Kconfig | 1 + include/linux/cpuidle.h | 2 +- include/linux/cpuidle_haltpoll.h | 5 +++ 17 files changed, 105 insertions(+), 50 deletions(-) create mode 100644 arch/arm64/include/asm/cpuidle_haltpoll.h
Signature · 1 line
2.43.5
PATCH v10 1/11 cpuidle/poll_state: poll via smp_cond_load_relaxed_timewait()
The inner loop in poll_idle() polls to see if the thread's TIF_NEED_RESCHED bit is set. The loop exits once the condition is met, or if the poll time limit has been exceeded.
To minimize the number of instructions executed in each iteration, the time check is rate-limited. In addition, each loop iteration executes cpu_relax() which on certain platforms provides a hint to the pipeline that the loop is busy-waiting, which allows the processor to reduce power consumption.
However, cpu_relax() is defined optimally only on x86. On arm64, for instance, it is implemented as a YIELD which only serves as a hint to the CPU that it prioritize a different hardware thread if one is available. arm64, does expose a more optimal polling mechanism via smp_cond_load_relaxed_timewait() which uses LDXR, WFE to wait until a store to a specified region, or until a timeout.
These semantics are essentially identical to what we want from poll_idle(). So, restructure the loop to use smp_cond_load_relaxed_timewait() instead.
The generated code remains close to the original version.
--- drivers/cpuidle/poll_state.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
drivers/cpuidle/poll_state.c +8 -19
@@ -8,35 +8,24 @@#include <linux/sched/clock.h> #include <linux/sched/idle.h> -#define POLL_IDLE_RELAX_COUNT 200 - static int __cpuidle poll_idle(struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { -u64 time_start; - - time_start =local_clock_noinstr (); dev->poll_time_limit = false;raw_local_irq_enable ();if (!current_set_polling_and_test ()) { -unsigned int loop_count =0 ; -u64 limit; +unsigned long flags; +u64 time_start =local_clock_noinstr (); +u64 limit =cpuidle_poll_time (drv, dev); - limit =cpuidle_poll_time (drv, dev); + flags =smp_cond_load_relaxed_timewait (¤t_thread_info ()->flags, +VAL & _TIF_NEED_RESCHED, +local_clock_noinstr (), + time_start + limit); -while (!need_resched ()) { -cpu_relax (); -if (loop_count++ <POLL_IDLE_RELAX_COUNT ) -continue ; - - loop_count =0 ; -if (local_clock_noinstr () - time_start > limit) { - dev->poll_time_limit = true; -break ; - } - } + dev->poll_time_limit = !(flags & _TIF_NEED_RESCHED); }raw_local_irq_disable ();
Signature · 1 line
2.43.5
Re: [PATCH v10 01/11] cpuidle/poll_state: poll via smp_cond_load_relaxed_timewait()
Quoted 66 lines · Ankur Arora
The inner loop in
poll_idle()polls to see if the thread'sTIF_NEED_RESCHEDbit is set. The loop exits once the condition is met, or if the poll time limit has been exceeded.To minimize the number of instructions executed in each iteration, the time check is rate-limited. In addition, each loop iteration executes
cpu_relax()which on certain platforms provides a hint to the pipeline that the loop is busy-waiting, which allows the processor to reduce power consumption.However,
cpu_relax()is defined optimally only on x86. On arm64, for instance, it is implemented as a YIELD which only serves as a hint to the CPU that it prioritize a different hardware thread if one is available. arm64, does expose a more optimal polling mechanism viasmp_cond_load_relaxed_timewait()which uses LDXR, WFE to wait until a store to a specified region, or until a timeout.These semantics are essentially identical to what we want from
poll_idle(). So, restructure the loop to usesmp_cond_load_relaxed_timewait()instead.The generated code remains close to the original version.
Suggested-by Catalin Marinas <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- drivers/cpuidle/poll_state.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)drivers/cpuidle/poll_state.c +7
-12@@ -8,35 +8,24 @@#include <linux/sched/clock.h> #include <linux/sched/idle.h> -#define POLL_IDLE_RELAX_COUNT 200 - static int __cpuidle poll_idle(struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { -u64 time_start; - - time_start =local_clock_noinstr (); dev->poll_time_limit = false;raw_local_irq_enable ();if (!current_set_polling_and_test ()) { -unsigned int loop_count =0 ; -u64 limit; +unsigned long flags; +u64 time_start =local_clock_noinstr (); +u64 limit =cpuidle_poll_time (drv, dev); - limit =cpuidle_poll_time (drv, dev); + flags =smp_cond_load_relaxed_timewait (¤t_thread_info ()->flags, +VAL & _TIF_NEED_RESCHED, +local_clock_noinstr (), + time_start + limit); -while (!need_resched ()) { -cpu_relax (); -if (loop_count++ <POLL_IDLE_RELAX_COUNT ) -continue ;
drivers/cpuidle/poll_state.c line 30
Quoted 10 lines
drivers/cpuidle/poll_state.c +1
-7- - loop_count =0 ; -if (local_clock_noinstr () - time_start > limit) { - dev->poll_time_limit = true; -break ; - } - } + dev->poll_time_limit = !(flags & _TIF_NEED_RESCHED); }raw_local_irq_disable ();
The barrier-v2 [1] interface is slightly different from the one proposed in v1 (which this series is based on.)
[1] https://lore.kernel.org/lkml/[email protected]/
For testing please use the following patch. It adds a new parameter (__smp_cond_timewait_coarse) explicitly specifying the waiting policy.
--
drivers/cpuidle/poll_state.c +9 -19
@@ -8,35 +8,25 @@#include <linux/sched/clock.h> #include <linux/sched/idle.h> -#define POLL_IDLE_RELAX_COUNT 200 - static int __cpuidle poll_idle(struct cpuidle_device *dev,struct cpuidle_driver *drv,int index) { -u64 time_start; - - time_start =local_clock_noinstr (); dev->poll_time_limit = false;raw_local_irq_enable ();if (!current_set_polling_and_test ()) { -unsigned int loop_count =0 ; -u64 limit; +unsigned long flags; +u64 time_start =local_clock_noinstr (); +u64 limit =cpuidle_poll_time (drv, dev); - limit =cpuidle_poll_time (drv, dev); + flags =smp_cond_load_relaxed_timewait (¤t_thread_info ()->flags, +VAL & _TIF_NEED_RESCHED, + __smp_cond_timewait_coarse, +local_clock_noinstr (), + time_start + limit); -while (!need_resched ()) { -cpu_relax (); -if (loop_count++ <POLL_IDLE_RELAX_COUNT ) -continue ; - - loop_count =0 ; -if (local_clock_noinstr () - time_start > limit) { - dev->poll_time_limit = true; -break ; - } - } + dev->poll_time_limit = !(flags & _TIF_NEED_RESCHED); }raw_local_irq_disable ();
--
ankur
PATCH v10 2/11 cpuidle: rename ARCH_HAS_CPU_RELAX to ARCH_HAS_OPTIMIZED_POLL
In reply to Ankur AroraARCH_HAS_CPU_RELAX is defined on architectures that provide an primitive (via cpu_relax()) that can be used as part of a polling mechanism -- one that would be cheaper than spinning in a tight loop.
However, recent changes in poll_idle() mean that a higher level primitive -- smp_cond_load_relaxed_timewait() is used for polling. This would in-turn use cpu_relax() or an architecture specific implementation. On ARM64 in particular this turns into a WFE which waits on a store to a cacheline instead of a busy poll.
Accordingly condition the polling drivers on ARCH_HAS_OPTIMIZED_POLL instead of ARCH_HAS_CPU_RELAX. While at it, make both intel-idle and cpuidle-haltpoll, which depend on poll_idle() being available, explicitly depend on ARCH_HAS_OPTIMIZED_POLL.
--- arch/x86/Kconfig | 2 +- drivers/acpi/processor_idle.c | 4 ++-- drivers/cpuidle/Kconfig | 2 +- drivers/cpuidle/Makefile | 2 +- drivers/idle/Kconfig | 1 + include/linux/cpuidle.h | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/Kconfig +1 -1
@@ -381,7 +381,7 @@ config ARCH_MAY_HAVE_PC_FDC config GENERIC_CALIBRATE_DELAY def_bool y -config ARCH_HAS_CPU_RELAX +config ARCH_HAS_OPTIMIZED_POLL def_bool y config ARCH_HIBERNATION_POSSIBLE
drivers/acpi/processor_idle.c +2 -2
@@ -35,7 +35,7 @@#include <asm/cpu.h> #endif -#define ACPI_IDLE_STATE_START (IS_ENABLED(CONFIG_ARCH_HAS_CPU_RELAX) ? 1 : 0) +#define ACPI_IDLE_STATE_START (IS_ENABLED(CONFIG_ARCH_HAS_OPTIMIZED_POLL) ? 1 : 0)static unsigned int max_cstate__read_mostly =ACPI_PROCESSOR_MAX_POWER ;module_param (max_cstate, uint,0400 );
@@ -779,7 +779,7 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr)if (max_cstate ==0 ) max_cstate =1 ; -if (IS_ENABLED (CONFIG_ARCH_HAS_CPU_RELAX )) { +if (IS_ENABLED (CONFIG_ARCH_HAS_OPTIMIZED_POLL )) {cpuidle_poll_state_init (drv); count =1 ; }else {
drivers/cpuidle/Kconfig +1 -1
@@ -73,7 +73,7 @@ endmenu config HALTPOLL_CPUIDLE tristate "Halt poll cpuidle driver" - depends on X86 && KVM_GUEST + depends on X86 && KVM_GUEST && ARCH_HAS_OPTIMIZED_POLL select CPU_IDLE_GOV_HALTPOLL default y help
drivers/cpuidle/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o obj-$(CONFIG_DT_IDLE_GENPD) += dt_idle_genpd.o -obj-$(CONFIG_ARCH_HAS_CPU_RELAX) += poll_state.o +obj-$(CONFIG_ARCH_HAS_OPTIMIZED_POLL) += poll_state.o obj-$(CONFIG_HALTPOLL_CPUIDLE) += cpuidle-haltpoll.o ##################################################################################
drivers/idle/Kconfig +1 -0
@@ -4,6 +4,7 @@ config INTEL_IDLE depends on CPU_IDLE depends on X86 depends on CPU_SUP_INTEL + depends on ARCH_HAS_OPTIMIZED_POLL help Enable intel_idle, a cpuidle driver that includes knowledge of native Intel hardware idle features. The acpi_idle driver
include/linux/cpuidle.h +1 -1
@@ -275,7 +275,7 @@ static inline void cpuidle_coupled_parallel_barrier(struct cpuidle_device *dev, }#endif -#if defined(CONFIG_CPU_IDLE ) && defined(CONFIG_ARCH_HAS_CPU_RELAX ) +#if defined(CONFIG_CPU_IDLE ) && defined(CONFIG_ARCH_HAS_OPTIMIZED_POLL )void cpuidle_poll_state_init (struct cpuidle_driver *drv);#else static inline void cpuidle_poll_state_init (struct cpuidle_driver *drv) {}
Signature · 1 line
2.43.5
PATCH v10 3/11 Kconfig: move ARCH_HAS_OPTIMIZED_POLL to arch/Kconfig
In reply to Ankur AroraFrom: Joao Martins <[email protected]>
ARCH_HAS_OPTIMIZED_POLL gates selection of polling while idle in poll_idle(). Move the configuration option to arch/Kconfig to allow non-x86 architectures to select it.
Note that ARCH_HAS_OPTIMIZED_POLL should probably be exclusive with GENERIC_IDLE_POLL_SETUP (which controls the generic polling logic in cpu_idle_poll()). However, that would remove boot options (hlt=, nohlt=). So, leave it untouched for now.
--- arch/Kconfig | 3 +++ arch/x86/Kconfig | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/Kconfig +3 -0
@@ -274,6 +274,9 @@ config HAVE_ARCH_TRACEHOOK config HAVE_DMA_CONTIGUOUS bool +config ARCH_HAS_OPTIMIZED_POLL + bool + config GENERIC_SMP_IDLE_THREAD bool
arch/x86/Kconfig +1 -3
@@ -142,6 +142,7 @@ config X86 select ARCH_WANTS_NO_INSTR select ARCH_WANT_GENERAL_HUGETLB select ARCH_WANT_HUGE_PMD_SHARE + select ARCH_HAS_OPTIMIZED_POLL select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANT_OPTIMIZE_DAX_VMEMMAP if X86_64 select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP if X86_64
@@ -381,9 +382,6 @@ config ARCH_MAY_HAVE_PC_FDC config GENERIC_CALIBRATE_DELAY def_bool y -config ARCH_HAS_OPTIMIZED_POLL - def_bool y - config ARCH_HIBERNATION_POSSIBLE def_bool y
Signature · 1 line
2.43.5
PATCH v10 4/11 arm64: define TIF_POLLING_NRFLAG
In reply to Ankur AroraFrom: Joao Martins <[email protected]>
Commit 842514849a61 ("arm64: Remove TIF_POLLING_NRFLAG") had removed TIF_POLLING_NRFLAG because arm64 only supported non-polled idling via cpu_do_idle().
To support polling in idle via poll_idle() define TIF_POLLING_NRFLAG which is set while polling.
We reuse the same bit for the definition.
--- arch/arm64/include/asm/thread_info.h | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/include/asm/thread_info.h +2 -0
@@ -69,6 +69,7 @@ void arch_setup_new_exec(void);#define TIF_SYSCALL_TRACEPOINT 10/* syscall tracepoint for ftrace */ #define TIF_SECCOMP 11/* syscall secure computing */ #define TIF_SYSCALL_EMU 12/* syscall emulation active */ +#define TIF_POLLING_NRFLAG 16/* set while polling in poll_idle() */ #define TIF_MEMDIE 18/* is terminating due to OOM killer */ #define TIF_FREEZE 19#define TIF_RESTORE_SIGMASK 20
@@ -92,6 +93,7 @@ void arch_setup_new_exec(void);#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)#define _TIF_SECCOMP (1 << TIF_SECCOMP)#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU) +#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)#define _TIF_UPROBE (1 << TIF_UPROBE)#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)#define _TIF_32BIT (1 << TIF_32BIT)
Signature · 1 line
2.43.5
PATCH v10 5/11 arm64: add support for poll_idle()
In reply to Ankur AroraPolling in idle helps reduce the cost of remote wakeups: if the target sets TIF_POLLING_NRFLAG (as it does while polling in idle), the scheduler can do remote wakeups just by setting the TIF_NEED_RESCHED.
This contrasts with sending an IPI, and incurring the cost of handling the cost of the interrupt on the receiver.
Enabling poll_idle() needs a cheap mechanism to do the actual polling (via smp_cond_load_relaxed_timewait()) and TIF_POLLING_NRFLAG support.
arm64 has both of these. So, select ARCH_HAS_OPTIMIZED_POLL.
--- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/Kconfig +1 -0
@@ -39,6 +39,7 @@ config ARM64 select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_NONLEAF_PMD_YOUNG if ARM64_HAFT + select ARCH_HAS_OPTIMIZED_POLL select ARCH_HAS_PTE_DEVMAP select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_HW_PTE_YOUNG
Signature · 1 line
2.43.5
PATCH v10 6/11 ACPI: processor_idle: Support polling state for LPI
In reply to Ankur AroraFrom: Lifeng Zheng <[email protected]>
Initialize an optional polling state besides LPI states.
Wrap up a new enter method to correctly reflect the actual entered state when the polling state is enabled.
--- drivers/acpi/processor_idle.c | 39 ++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-)
drivers/acpi/processor_idle.c +34 -5
@@ -1191,20 +1191,46 @@ static int acpi_idle_lpi_enter(struct cpuidle_device *dev,return -EINVAL ; } +/* To correctly reflect the entered state if the poll state is enabled. */ +static int acpi_idle_lpi_enter_with_poll_state (struct cpuidle_device *dev, +struct cpuidle_driver *drv,int index) +{ +int entered_state; + +if (unlikely (index <1 )) +return -EINVAL ; + + entered_state =acpi_idle_lpi_enter (dev, drv, index -1 ); +if (entered_state <0 ) +return entered_state; + +return entered_state +1 ; +} +static int acpi_processor_setup_lpi_states (struct acpi_processor *pr) { -int i; +int i, count;struct acpi_lpi_state *lpi;struct cpuidle_state *state;struct cpuidle_driver *drv = &acpi_idle_driver; + typeof(state->enter) enter_method;if (!pr->flags.has_lpi)return -EOPNOTSUPP ; +if (IS_ENABLED (CONFIG_ARCH_HAS_OPTIMIZED_POLL )) { +cpuidle_poll_state_init (drv); + count =1 ; + enter_method = acpi_idle_lpi_enter_with_poll_state; + }else { + count =0 ; + enter_method = acpi_idle_lpi_enter; + } +for (i =0 ; i < pr->power.count && i <CPUIDLE_STATE_MAX ; i++) { lpi = &pr->power.lpi_states[i]; - state = &drv->states[i]; + state = &drv->states[count];snprintf (state->name,CPUIDLE_NAME_LEN ,"LPI-%d" , i);strscpy (state->desc, lpi->desc,CPUIDLE_DESC_LEN ); state->exit_latency = lpi->wake_latency;
@@ -1212,11 +1238,14 @@ static int acpi_processor_setup_lpi_states(struct acpi_processor *pr) state->flags |=arch_get_idle_state_flags (lpi->arch_flags);if (i !=0 && lpi->entry_method ==ACPI_CSTATE_FFH ) state->flags |=CPUIDLE_FLAG_RCU_IDLE ; - state->enter = acpi_idle_lpi_enter; - drv->safe_state_index = i; + state->enter = enter_method; + drv->safe_state_index = count; + count++; +if (count ==CPUIDLE_STATE_MAX ) +break ; } - drv->state_count = i; + drv->state_count = count;return 0 ; }
Signature · 1 line
2.43.5
PATCH v10 7/11 cpuidle-haltpoll: define arch_haltpoll_want()
In reply to Ankur AroraFrom: Joao Martins <[email protected]>
While initializing haltpoll we check if KVM supports the realtime hint and if idle is overridden at boot.
Both of these checks are x86 specific. So, in pursuit of making cpuidle-haltpoll architecture independent, move these checks out of common code.
--- arch/x86/include/asm/cpuidle_haltpoll.h | 1 + arch/x86/kernel/kvm.c | 13 +++++++++++++ drivers/cpuidle/cpuidle-haltpoll.c | 12 +----------- include/linux/cpuidle_haltpoll.h | 5 +++++ 4 files changed, 20 insertions(+), 11 deletions(-)
arch/x86/include/asm/cpuidle_haltpoll.h +1 -0
@@ -4,5 +4,6 @@void arch_haltpoll_enable (unsigned int cpu);void arch_haltpoll_disable (unsigned int cpu); +bool arch_haltpoll_want (bool force);#endif
arch/x86/kernel/kvm.c +13 -0
@@ -1155,4 +1155,17 @@ void arch_haltpoll_disable(unsigned int cpu) smp_call_function_single(cpu, kvm_enable_host_haltpoll, NULL, 1); }EXPORT_SYMBOL_GPL (arch_haltpoll_disable); + +bool arch_haltpoll_want (bool force) +{ +/* Do not load haltpoll if idle= is passed */ +if (boot_option_idle_override !=IDLE_NO_OVERRIDE ) +return false; + +if (!kvm_para_available ()) +return false; + +return kvm_para_has_hint (KVM_HINTS_REALTIME ) || force; +} +EXPORT_SYMBOL_GPL (arch_haltpoll_want);#endif
drivers/cpuidle/cpuidle-haltpoll.c +1 -11
@@ -15,7 +15,6 @@#include <linux/cpuidle.h> #include <linux/module.h> #include <linux/sched/idle.h> -#include <linux/kvm_para.h> #include <linux/cpuidle_haltpoll.h> static bool force__read_mostly ;
@@ -93,21 +92,12 @@ static void haltpoll_uninit(void) haltpoll_cpuidle_devices =NULL ; } -static bool haltpoll_want (void ) -{ -return kvm_para_has_hint (KVM_HINTS_REALTIME ) || force; -} -static int __init haltpoll_init (void ) {int ret;struct cpuidle_driver *drv = &haltpoll_driver; -/* Do not load haltpoll if idle= is passed */ -if (boot_option_idle_override !=IDLE_NO_OVERRIDE ) -return -ENODEV ; - -if (!kvm_para_available () || !haltpoll_want ()) +if (!arch_haltpoll_want (force))return -ENODEV ;cpuidle_poll_state_init (drv);
include/linux/cpuidle_haltpoll.h +5 -0
@@ -12,5 +12,10 @@ static inline void arch_haltpoll_enable(unsigned int cpu)static inline void arch_haltpoll_disable (unsigned int cpu) { } + +static inline bool arch_haltpoll_want (bool force) +{ +return false; +}#endif #endif
Signature · 1 line
2.43.5
PATCH v10 8/11 governors/haltpoll: drop kvm_para_available() check
In reply to Ankur AroraFrom: Joao Martins <[email protected]>
The haltpoll governor is selected either by the cpuidle-haltpoll driver, or explicitly by the user.
In particular, it is never selected by default since it has the lowest rating of all governors (menu=20, teo=19, ladder=10/25, haltpoll=9).
So, we can safely forgo the kvm_para_available() check. This also allows cpuidle-haltpoll to be tested on baremetal.
--- drivers/cpuidle/governors/haltpoll.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/cpuidle/governors/haltpoll.c +1 -5
@@ -18,7 +18,6 @@#include <linux/tick.h> #include <linux/sched.h> #include <linux/module.h> -#include <linux/kvm_para.h> #include <trace/events/power.h> static unsigned int guest_halt_poll_ns__read_mostly =200000 ;
@@ -148,10 +147,7 @@ static struct cpuidle_governor haltpoll_governor = {static int __init init_haltpoll (void ) { -if (kvm_para_available ()) -return cpuidle_register_governor (&haltpoll_governor); - -return 0 ; +return cpuidle_register_governor (&haltpoll_governor); }postcore_initcall (init_haltpoll);
Signature · 1 line
2.43.5
Re: [PATCH v10 08/11] governors/haltpoll: drop kvm_para_available() check
Quoted 2 lines · Ankur Arora
So, we can safely forgo the
kvm_para_available()check. This also allows cpuidle-haltpoll to be tested on baremetal.
I would hope that we will have this functionality as the default on baremetal after testing in the future.
Reviewed-by; Christoph Lameter (Ampere) <[email protected]>
Re: [PATCH v10 08/11] governors/haltpoll: drop kvm_para_available() check
Quoted 7 lines · Christoph Lameter (Ampere)
Quoted 2 lines · Ankur Arora
So, we can safely forgo the
kvm_para_available()check. This also allows cpuidle-haltpoll to be tested on baremetal.I would hope that we will have this functionality as the default on baremetal after testing in the future.
Yeah, supporting haltpoll style adaptive polling on baremetal has some way to go.
But, with Lifeng's patch-6 "ACPI: processor_idle: Support polling state for LPI" we do get polling support in acpi-idle.
Quoted 1 line
Reviewed-by; Christoph Lameter (Ampere) <[email protected]>
Thanks Christoph!
--
ankur
PATCH v10 9/11 cpuidle-haltpoll: condition on ARCH_CPUIDLE_HALTPOLL
In reply to Ankur AroraThe cpuidle-haltpoll driver and its namesake governor are selected under KVM_GUEST on X86. KVM_GUEST in-turn selects ARCH_CPUIDLE_HALTPOLL and defines the requisite arch_haltpoll_{enable,disable}() functions.
So remove the explicit dependence of HALTPOLL_CPUIDLE on KVM_GUEST, and instead use ARCH_CPUIDLE_HALTPOLL as proxy for architectural support for haltpoll.
Also change "halt poll" to "haltpoll" in one of the summary clauses, since the second form is used everywhere else.
--- arch/x86/Kconfig | 1 + drivers/cpuidle/Kconfig | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/Kconfig +1 -0
@@ -847,6 +847,7 @@ config KVM_GUEST config ARCH_CPUIDLE_HALTPOLL def_bool n + depends on KVM_GUEST prompt "Disable host haltpoll when loading haltpoll driver" help If virtualized under KVM, disable host haltpoll.
drivers/cpuidle/Kconfig +2 -3
@@ -35,7 +35,6 @@ config CPU_IDLE_GOV_TEO config CPU_IDLE_GOV_HALTPOLL bool "Haltpoll governor (for virtualized systems)" - depends on KVM_GUEST help This governor implements haltpoll idle state selection, to be used in conjunction with the haltpoll cpuidle driver, allowing
@@ -72,8 +71,8 @@ source "drivers/cpuidle/Kconfig.riscv" endmenu config HALTPOLL_CPUIDLE - tristate "Halt poll cpuidle driver" - depends on X86 && KVM_GUEST && ARCH_HAS_OPTIMIZED_POLL + tristate "Haltpoll cpuidle driver" + depends on ARCH_CPUIDLE_HALTPOLL && ARCH_HAS_OPTIMIZED_POLL select CPU_IDLE_GOV_HALTPOLL default y help
Signature · 1 line
2.43.5
PATCH v10 10/11 arm64: idle: export arch_cpu_idle()
In reply to Ankur AroraNeeded for cpuidle-haltpoll.
--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kernel/idle.c +1 -0
@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle (); } +EXPORT_SYMBOL_GPL (arch_cpu_idle);
Signature · 1 line
2.43.5
Re: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
Quoted 13 lines · Ankur Arora
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/idle.c +0
-0
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 2 lines
arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();
Hi, Ankur,
With haltpoll_driver registered, arch_cpu_idle() on x86 can select mwait_idle() in idle threads.
It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
Should arch_cpu_idle() on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?
Thanks.
Shuai
Re: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
Quoted 26 lines · Shuai Xue
Quoted 26 lines
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 8 lines · Ankur Arora
Quoted 8 lines
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)Quoted 7 lines
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 7 lines
arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();Hi, Ankur,
With
haltpoll_driverregistered,arch_cpu_idle()on x86 can selectmwait_idle()in idle threads.
Quoted 7 lines
Quoted 7 lines
It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
Should
arch_cpu_idle()on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?
WFE will wake from the event stream, which can have short sub-ms periods on many systems. May be something to consider when WFET is more widely available.
Quoted 5 lines
Quoted 5 lines
Thanks.
Shuai
Regards,
Haris Okanovic
AWS Graviton Software
Re: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
In reply to Shuai XueQuoted 17 lines · Shuai Xue
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 13 lines · Ankur Arora
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();Hi, Ankur,
Quoted 7 lines
With
haltpoll_driverregistered,arch_cpu_idle()on x86 can selectmwait_idle()in idle threads.It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
MWAIT is more capable than WFE -- it allows selection of deeper idle state. IIRC C2/C3.
Quoted 2 lines
Should
arch_cpu_idle()on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?
Avoiding the wakeup IPI needs TIF_NR_POLLING and polling in idle support that this series adds.
As Haris notes, the negative with only using WFE is that it only allows a single idle state, one that is fairly shallow because the event-stream causes a wakeup every 100us.
--
ankur
Shuai Xue
Tested-byRe: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
Quoted 37 lines · Ankur Arora
Quoted 17 lines · Shuai Xue
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 13 lines · Ankur Arora
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();Hi, Ankur,
Quoted 7 lines
With
haltpoll_driverregistered,arch_cpu_idle()on x86 can selectmwait_idle()in idle threads.It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
MWAIT is more capable than WFE -- it allows selection of deeper idle state. IIRC C2/C3.
Quoted 2 lines
Should
arch_cpu_idle()on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?Avoiding the wakeup IPI needs
TIF_NR_POLLINGand polling in idle support that this series adds.
Quoted 6 lines
As Haris notes, the negative with only using WFE is that it only allows a single idle state, one that is fairly shallow because the event-stream causes a wakeup every 100us.
--
ankur
Hi, Ankur and Haris
Got it, thanks for explaination :)
Comparing sched-pipe performance on Rund with Yitian 710, *IPC improved 35%*:
w/o haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):
32521.53 msec task-clock # 2.000 CPUs utilized ( +- 1.16% )
38081402726 cycles # 1.171 GHz ( +- 1.70% )
27324614561 instructions # 0.72 insn per cycle ( +- 0.12% )
181 sched:sched_wake_idle_without_ipi # 0.006 K/secw/ haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):
9477.15 msec task-clock # 2.000 CPUs utilized ( +- 0.89% )
21486828269 cycles # 2.267 GHz ( +- 0.35% )
23867109747 instructions # 1.11 insn per cycle ( +- 0.11% )
1925207 sched:sched_wake_idle_without_ipi # 0.203 M/secComparing sched-pipe performance on QEMU with Kunpeng 920, *IPC improved 10%*:
w/o haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):
34,007.89 msec task-clock # 2.000 CPUs utilized ( +- 8.86% )
4,407,859,620 cycles # 0.130 GHz ( +- 84.92% )
2,482,046,461 instructions # 0.56 insn per cycle ( +- 88.27% )
16 sched:sched_wake_idle_without_ipi # 0.470 /sec ( +- 98.77% )
17.00 +- 1.51 seconds time elapsed ( +- 8.86% )w/ haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):
16,894.37 msec task-clock # 2.000 CPUs utilized ( +- 3.80% )
8,703,158,826 cycles # 0.515 GHz ( +- 31.31% )
5,379,257,839 instructions # 0.62 insn per cycle ( +- 30.03% )
549,434 sched:sched_wake_idle_without_ipi # 32.522 K/sec ( +- 30.05% )8.447 +- 0.321 seconds time elapsed ( +- 3.80% )
Thanks.
Shuai
Re: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
Quoted 40 lines · Shuai Xue
Quoted 31 lines · Ankur Arora
Quoted 17 lines · Shuai Xue
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 13 lines · Ankur Arora
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();Hi, Ankur,
Quoted 7 lines
With
haltpoll_driverregistered,arch_cpu_idle()on x86 can selectmwait_idle()in idle threads.It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
MWAIT is more capable than WFE -- it allows selection of deeper idle state. IIRC C2/C3.
Quoted 2 lines
Should
arch_cpu_idle()on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?Quoted 7 lines
Avoiding the wakeup IPI needs
TIF_NR_POLLINGand polling in idle support that this series adds.
As Haris notes, the negative with only using WFE is that it only allows a single idle state, one that is fairly shallow because the event-stream causes a wakeup every 100us.
--
ankur
Quoted 5 lines
Hi, Ankur and Haris
Got it, thanks for explaination :)
Comparing sched-pipe performance on Rund with Yitian 710, *IPC improved 35%*:
Thanks for testing Shuai. I wasn't expecting the IPC to improve by quite that much :). The reduced instructions make sense since we don't have to handle the IRQ anymore but we would spend some of the saved cycles waiting in WFE instead.
I'm not familiar with the Yitian 710. Can you check if you are running with WFE? That's the __smp_cond_load_relaxed_timewait() path vs the __smp_cond_load_relaxed_spinwait() path in [0]. Same question for the Kunpeng 920.
Also, I'm working on a new version of the series in [1]. Would you be okay trying that out?
Thanks
Ankur
[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 42 lines
w/o haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):32521.53 msec task-clock # 2.000 CPUs utilized ( +- 1.16% ) 38081402726 cycles # 1.171 GHz ( +- 1.70% ) 27324614561 instructions # 0.72 insn per cycle ( +- 0.12% ) 181 sched:sched_wake_idle_without_ipi # 0.006 K/secw/ haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):9477.15 msec task-clock # 2.000 CPUs utilized ( +- 0.89% ) 21486828269 cycles # 2.267 GHz ( +- 0.35% ) 23867109747 instructions # 1.11 insn per cycle ( +- 0.11% ) 1925207 sched:sched_wake_idle_without_ipi # 0.203 M/secComparing sched-pipe performance on QEMU with Kunpeng 920, *IPC improved 10%*:
w/o haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):34,007.89 msec task-clock # 2.000 CPUs utilized ( +- 8.86% ) 4,407,859,620 cycles # 0.130 GHz ( +- 84.92% ) 2,482,046,461 instructions # 0.56 insn per cycle ( +- 88.27% ) 16 sched:sched_wake_idle_without_ipi # 0.470 /sec ( +- 98.77% ) 17.00 +- 1.51 seconds time elapsed ( +- 8.86% )w/ haltpoll
Performance counter stats for 'CPU(s) 0,1' (5 runs):16,894.37 msec task-clock # 2.000 CPUs utilized ( +- 3.80% ) 8,703,158,826 cycles # 0.515 GHz ( +- 31.31% ) 5,379,257,839 instructions # 0.62 insn per cycle ( +- 30.03% ) 549,434 sched:sched_wake_idle_without_ipi # 32.522 K/sec ( +- 30.05% )8.447 +- 0.321 seconds time elapsed ( +- 3.80% )Tested-by Shuai Xue <[email protected]>Thanks.
Shuai
Re: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
Quoted 54 lines · Ankur Arora
Quoted 40 lines · Shuai Xue
Quoted 31 lines · Ankur Arora
Quoted 17 lines · Shuai Xue
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 13 lines · Ankur Arora
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();Hi, Ankur,
Quoted 7 lines
With
haltpoll_driverregistered,arch_cpu_idle()on x86 can selectmwait_idle()in idle threads.It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
MWAIT is more capable than WFE -- it allows selection of deeper idle state. IIRC C2/C3.
Quoted 2 lines
Should
arch_cpu_idle()on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?Quoted 7 lines
Avoiding the wakeup IPI needs
TIF_NR_POLLINGand polling in idle support that this series adds.
As Haris notes, the negative with only using WFE is that it only allows a single idle state, one that is fairly shallow because the event-stream causes a wakeup every 100us.
--
ankurQuoted 5 lines
Hi, Ankur and Haris
Got it, thanks for explaination :)
Comparing sched-pipe performance on Rund with Yitian 710, *IPC improved 35%*:
Thanks for testing Shuai. I wasn't expecting the IPC to improve by quite that much :). The reduced instructions make sense since we don't have to handle the IRQ anymore but we would spend some of the saved cycles waiting in WFE instead.
Quoted 4 lines
I'm not familiar with the Yitian 710. Can you check if you are running with WFE? That's the
__smp_cond_load_relaxed_timewait()path vs the__smp_cond_load_relaxed_spinwait()path in [0]. Same question for the Kunpeng 920.
Yes, it running with __smp_cond_load_relaxed_timewait().
I use perf-probe to check if WFE is available in Guest:
perf probe 'arch_timer_evtstrm_available%return r=$retval' perf record -e probe:arch_timer_evtstrm_available__return -aR sleep 1 perf script
swapper 0 [000] 1360.063049: probe:arch_timer_evtstrm_available__return: (ffff800080a5c640 <- ffff800080d42764) r=0x1
arch_timer_evtstrm_available returns true, so__smp_cond_load_relaxed_timewait() is used.
Quoted 3 lines
Also, I'm working on a new version of the series in [1]. Would you be okay trying that out?
Sure. Please cc me when you send out a new version.
Quoted 7 lines
Thanks
Ankur[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/[email protected]/
Thanks.
Shuai
Re: [PATCH v10 10/11] arm64: idle: export arch_cpu_idle()
Quoted 61 lines · Shuai Xue
Quoted 47 lines · Ankur Arora
Quoted 40 lines · Shuai Xue
Quoted 31 lines · Ankur Arora
Quoted 17 lines · Shuai Xue
arch/arm64/kernel/idle.c void __cpuidle arch_cpu_idle(void) · line 44
Quoted 13 lines · Ankur Arora
Needed for cpuidle-haltpoll.
Acked-by Will Deacon <[email protected]>Signed-off-by Ankur Arora <[email protected]>--- arch/arm64/kernel/idle.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/idle.c +0
-0@@ -43,3 +43,4 @@ void __cpuidle arch_cpu_idle(void)*/ cpu_do_idle ();Hi, Ankur,
Quoted 7 lines
With
haltpoll_driverregistered,arch_cpu_idle()on x86 can selectmwait_idle()in idle threads.It use MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.
MWAIT is more capable than WFE -- it allows selection of deeper idle state. IIRC C2/C3.
Quoted 2 lines
Should
arch_cpu_idle()on arm64 also use the LDXR/WFE to avoid wakeup IPI like x86 monitor/mwait?Quoted 7 lines
Avoiding the wakeup IPI needs
TIF_NR_POLLINGand polling in idle support that this series adds.
As Haris notes, the negative with only using WFE is that it only allows a single idle state, one that is fairly shallow because the event-stream causes a wakeup every 100us.
--
ankurQuoted 5 lines
Hi, Ankur and Haris
Got it, thanks for explaination :)
Comparing sched-pipe performance on Rund with Yitian 710, *IPC improved 35%*:
Quoted 8 lines
Thanks for testing Shuai. I wasn't expecting the IPC to improve by quite that much :). The reduced instructions make sense since we don't have to handle the IRQ anymore but we would spend some of the saved cycles waiting in WFE instead.
I'm not familiar with the Yitian 710. Can you check if you are running with WFE? That's the__smp_cond_load_relaxed_timewait()path vs the__smp_cond_load_relaxed_spinwait()path in [0]. Same question for the Kunpeng 920.Yes, it running with
__smp_cond_load_relaxed_timewait().I use perf-probe to check if WFE is available in Guest:
Quoted 7 lines
perf probe 'arch_timer_evtstrm_available%return r=$retval' perf record -e probe:arch_timer_evtstrm_available__return -aR sleep 1 perf script
swapper 0 [000] 1360.063049: probe:arch_timer_evtstrm_available__return: (ffff800080a5c640<-ffff800080d42764) r=0x1
arch_timer_evtstrm_availablereturns true, so__smp_cond_load_relaxed_timewait()is used.
Great. Thanks for checking.
Quoted 4 lines
Quoted 2 lines
Also, I'm working on a new version of the series in [1]. Would you be okay trying that out?
Sure. Please cc me when you send out a new version.
Will do. Thanks!
--
ankur
PATCH v10 11/11 arm64: support cpuidle-haltpoll
In reply to Ankur AroraAdd architectural support for the cpuidle-haltpoll driver by defining arch_haltpoll_*(). Also define ARCH_CPUIDLE_HALTPOLL to allow cpuidle-haltpoll to be selected.
--- arch/arm64/Kconfig | 6 ++++++ arch/arm64/include/asm/cpuidle_haltpoll.h | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 arch/arm64/include/asm/cpuidle_haltpoll.h
arch/arm64/Kconfig +6 -0
@@ -2485,6 +2485,12 @@ config ARCH_HIBERNATION_HEADER config ARCH_SUSPEND_POSSIBLE def_bool y +config ARCH_CPUIDLE_HALTPOLL + bool "Enable selection of the cpuidle-haltpoll driver" + help + cpuidle-haltpoll allows for adaptive polling based on + current load before entering the idle state. + endmenu # "Power management options" menu "CPU Power Management"
arch/arm64/include/asm/cpuidle_haltpoll.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ARCH_HALTPOLL_H +#define _ARCH_HALTPOLL_H + +static inline void arch_haltpoll_enable (unsigned int cpu) { } +static inline void arch_haltpoll_disable (unsigned int cpu) { } + +static inline bool arch_haltpoll_want (bool force) +{ +/* +* Enabling haltpoll requires KVM support for arch_haltpoll_enable(), +* arch_haltpoll_disable(). +* +* Given that that's missing right now, only allow force loading for +* haltpoll. +*/ +return force; +} +#endif
Signature · 1 line
2.43.5
Quoted 8 lines · Ankur Arora
Hi,
This patchset adds support for polling in idle on arm64 via
poll_idle()and adds the requisite support to acpi-idle and cpuidle-haltpoll.v10 is a respin of v9 with the timed wait barrier logic (
smp_cond_load_relaxed_timewait()) moved out into a separate series [0]. (The barrier patches could also do with some eyes.)
Sent a v2 for the barrier series:
https://lore.kernel.org/lkml/[email protected]/
Ankur
Quoted 196 lines
Why poll in idle?
==The benefit of polling in idle is to reduce the cost (and latency) of remote wakeups. When enabled, these can be done just by setting the need-resched bit, eliding the IPI, and the cost of handling the interrupt on the receiver.
Comparing sched-pipe performance on a guest VM:
# perf stat -r 5 --cpu 4,5 -e task-clock,cycles,instructions \ -e sched:sched_wake_idle_without_ipi perf bench sched pipe -l 1000000 --cpu 4# without polling in idlePerformance counter stats for 'CPU(s) 4,5' (5 runs):
25,229.57 msec task-clock # 2.000 CPUs utilized ( +- 7.75% ) 45,821,250,284 cycles # 1.816 GHz ( +- 10.07% ) 26,557,496,665 instructions # 0.58 insn per cycle ( +- 0.21% )0 sched:sched_wake_idle_without_ipi # 0.000 /sec
12.615 +- 0.977 seconds time elapsed ( +- 7.75% )
# polling in idle (with haltpoll):Performance counter stats for 'CPU(s) 4,5' (5 runs):
15,131.58 msec task-clock # 2.000 CPUs utilized ( +- 10.00% ) 34,158,188,839 cycles # 2.257 GHz ( +- 6.91% ) 20,824,950,916 instructions # 0.61 insn per cycle ( +- 0.09% ) 1,983,822 sched:sched_wake_idle_without_ipi # 131.105 K/sec ( +- 0.78% )7.566 +- 0.756 seconds time elapsed ( +- 10.00% )Comparing the two cases, there's a significant drop in both cycles and instructions executed. And a signficant drop in the wakeup latency.
Tomohiro Misono and Haris Okanovic also report similar latency improvements on Grace and Graviton systems (for v7) [1] [2]. Haris also tested a modified v9 on top of the split out barrier primitives.
Lifeng also reports improved context switch latency on a bare-metal machine with acpi-idle [3].
Series layout
==- patches 1-3,
"cpuidle/poll_state: poll via
smp_cond_load_relaxed_timewait()" "cpuidle: renameARCH_HAS_CPU_RELAXtoARCH_HAS_OPTIMIZED_POLL" "Kconfig: moveARCH_HAS_OPTIMIZED_POLLtoarch/Kconfig"switch
poll_idle()to using the new barrier interface. Also, do some munging of related kconfig options.- patches 4-5,
"arm64: define
TIF_POLLING_NRFLAG"
"arm64: add support forpoll_idle()"add arm64 support for the polling flag and enable
poll_idle()support.- patches 6, 7-11,
"ACPI:
processor_idle: Support polling state for LPI""cpuidle-haltpoll: define
arch_haltpoll_want()" "governors/haltpoll: dropkvm_para_available()check" "cpuidle-haltpoll: condition onARCH_CPUIDLE_HALTPOLL""arm64: idle: export
arch_cpu_idle()"
"arm64: support cpuidle-haltpoll"add support for polling via acpi-idle, and cpuidle-haltpoll.
Changelog
==v10: respin of v9
- sent outsmp_cond_load_relaxed_timeout()separately [0]
- Dropped from this series:
"asm-generic: add barriersmp_cond_load_relaxed_timeout()" "arm64: barrier: add support forsmp_cond_relaxed_timeout()" "arm64/delay: move some constants out to a separate header" "arm64: support WFET insmp_cond_relaxed_timeout()"- reworded some commit messages
v9:
- reworked the series to address a comment from Catalin Marinas about how v8 was abusing semantics ofsmp_cond_load_relaxed().
- addpoll_idle()support in acpi-idle (Lifeng Zheng)
- dropped some earlier "Tested-by", "Reviewed-by" due to the above rework.v8: No logic changes. Largely respin of v7, with changes noted below:
- move selection of
ARCH_HAS_OPTIMIZED_POLLon arm64 to its own patch.
(patch-9 "arm64: selectARCH_HAS_OPTIMIZED_POLL")- address comments simplifying arm64 support (Will Deacon) (patch-11 "arm64: support cpuidle-haltpoll")
v7: No significant logic changes. Mostly a respin of v6.
- minor cleanup in
poll_idle()(Christoph Lameter)
- fixes conflicts due to code movement inarch/arm64/kernel/cpuidle.c(Tomohiro Misono)v6:
- reordered the patches to keep
poll_idle()andARCH_HAS_OPTIMIZED_POLLchanges together (comment from Christoph Lameter)
- threshes out the commit messages a bit more (comments from Christoph Lameter, Sudeep Holla)
- also rework selection of cpuidle-haltpoll. Now selected based on the architectural selection ofARCH_CPUIDLE_HALTPOLL.
- moved back toarch_haltpoll_want()(comment from Joao Martins) Also,arch_haltpoll_want()now takes the force parameter and is now responsible for the complete selection (or not) of haltpoll.
- fixes the build breakage on i386
- fixes the cpuidle-haltpoll module breakage on arm64 (comment from Tomohiro Misono, Haris Okanovic)v5:
- rework thepoll_idle()loop aroundsmp_cond_load_relaxed()(review comment from Tomohiro Misono.)
- also rework selection of cpuidle-haltpoll. Now selected based on the architectural selection ofARCH_CPUIDLE_HALTPOLL.
-arch_haltpoll_supported()(renamed fromarch_haltpoll_want()) on arm64 now depends on the event-stream being enabled.
- limitPOLL_IDLE_RELAX_COUNTon arm64 (review comment from Haris Okanovic)
-ARCH_HAS_CPU_RELAXis now renamed toARCH_HAS_OPTIMIZED_POLL.v4 changes from v3:
- change 7/8 per Rafael input: drop the parens and use ret for the final check
- add 8/8 which renames the guard for buildingpoll_statev3 changes from v2:
- fix 1/7 per Petr Mladek - removeARCH_HAS_CPU_RELAXfromarch/x86/Kconfig
- add Ack-by from Rafael Wysocki on 2/7v2 changes from v1:
- added patch 7 where we changecpu_relaxwithsmp_cond_load_relaxedper PeterZ (this improves by 50% at least the CPU cycles consumed in the tests above:10,716,881,137 now vs 14,503,014,257 before)- removed the ifdef from patch 1 per RafaelW
Would appreciate any review comments.
Ankur
[0] https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/TY3PR01MB111481E9B0AF263ACC8EA5D4AE5BA2@TY3PR01MB11148.jpnprd01.prod.outlook.com/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/Ankur Arora (6):
cpuidle/poll_state: poll viasmp_cond_load_relaxed_timewait()
cpuidle: renameARCH_HAS_CPU_RELAXtoARCH_HAS_OPTIMIZED_POLL
arm64: add support forpoll_idle()
cpuidle-haltpoll: condition onARCH_CPUIDLE_HALTPOLL
arm64: idle: exportarch_cpu_idle()
arm64: support cpuidle-haltpollJoao Martins (4):
Kconfig: moveARCH_HAS_OPTIMIZED_POLLtoarch/Kconfig
arm64: defineTIF_POLLING_NRFLAG
cpuidle-haltpoll: definearch_haltpoll_want()governors/haltpoll: dropkvm_para_available()checkLifeng Zheng (1):
ACPI:processor_idle: Support polling state for LPIarch/Kconfig | 3 ++ arch/arm64/Kconfig | 7 ++++ arch/arm64/include/asm/cpuidle_haltpoll.h | 20 +++++++++++ arch/arm64/include/asm/thread_info.h | 2 ++ arch/arm64/kernel/idle.c | 1 + arch/x86/Kconfig | 5 ++- arch/x86/include/asm/cpuidle_haltpoll.h | 1 + arch/x86/kernel/kvm.c | 13 +++++++ drivers/acpi/processor_idle.c | 43 +++++++++++++++++++---- drivers/cpuidle/Kconfig | 5 ++- drivers/cpuidle/Makefile | 2 +-
Quoted 8 lines
drivers/cpuidle/cpuidle-haltpoll.c | 12 +------ drivers/cpuidle/governors/haltpoll.c | 6 +--- drivers/cpuidle/poll_state.c | 27 +++++--------- drivers/idle/Kconfig | 1 + include/linux/cpuidle.h | 2 +- include/linux/cpuidle_haltpoll.h | 5 +++ 17 files changed, 105 insertions(+), 50 deletions(-) create mode 100644 arch/arm64/include/asm/cpuidle_haltpoll.h
--
ankur