Skip to contentSkip to conversation

s390/idle: CPU idle driver

PATCH Superseded Mete Durlu 4 participants 13 messages Jun 9 – Jun 17

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Mete Durlu

author maintainer
#0 lore raw

v2 cover s390/idle: CPU idle driver

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

- Implementation Overview
-----------------------------------------------------------------------

The driver implements two idle states;

**Polling Idle (shallow state)**
- Busy-loop implementation that prevents SIE-exit during short idle periods
- Zero exit latency, optimized for latency-sensitive workloads
- Maintains CPU with the guest, improving response times

**Enabled Wait (deep state)**
- Traditional EW state that signals hypervisor availability
- Higher exit latency but more efficient for longer idle periods

The TEO governor dynamically selects between these states by monitoring next timer interrupts and system interrupt frequency, choosing the most appropriate idle state for each situation.

- Performance Benefits
-----------------------------------------------------------------------

Benchmark results across LPAR, KVM, and z/VM guests demonstrate significant improvements for latency-sensitive and scheduler-intensive workloads:

```
Benchmark    | LPAR  | z/VM  | KVM   |
-----------------------------------------
cyclictest   | +45%  | +50%  | +30%  |
hackbench    | +5%   | +12%  | -     |
pgbench      | +2%   | +15%  | +2%   |
uperf        | +50%* | +-5%  | +-5%  |
```

*Single-threaded uperf scenarios show 50-70% improvements on LPAR. Multi-threaded results show slight improvements overall.

Additionally, fio and ioping tests show latency distribution shifts toward lower values with reduced minimum and average latencies.

- Configuration
-----------------------------------------------------------------------

Idle state parameters are tuned per hypervisor type after benchmarks:

**LPAR:**
- Polling: 5us target residency, 0us exit latency
- EW: 5us target residency, 5us exit latency

**KVM/z/VM:**
- Polling: 1us target residency, 0us exit latency
- EW: 1us target residency, 1us exit latency

---
Mete Durlu (5):
s390/tick: Remove CIF_NOHZ_DELAY flag
tick: Remove arch_needs_cpu
s390: Enable TIF_POLLING_NRFLAG
s390/idle: Introduce cpuidle for s390
s390/configs: Enable cpuidle driver on s390

 MAINTAINERS                         |   8 +++
 arch/s390/Kconfig                   |   5 ++
 arch/s390/configs/debug_defconfig   |   2 +
 arch/s390/configs/defconfig         |   2 +
 arch/s390/include/asm/processor.h   |   4 --
 arch/s390/include/asm/thread_info.h |   1 +
 arch/s390/kernel/idle.c             |   1 -
 arch/s390/kernel/irq.c              |   4 --
 arch/s390/kernel/smp.c              |   1 -
 drivers/cpuidle/Kconfig             |   5 ++
 drivers/cpuidle/Kconfig.s390        |  11 ++++
 drivers/cpuidle/Makefile            |   4 ++
 drivers/cpuidle/cpuidle-s390.c      | 104 ++++++++++++++++++++++++++++++++++++
 include/linux/tick.h                |   3 --
 kernel/time/tick-sched.c            |   7 ++-
 15 files changed, 145 insertions(+), 17 deletions(-)

---
base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce
change-id: 20260609-idledriver-217e2b2712a3

Best regards,

Signature · 1 line
Mete Durlu <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/5 s390/tick: Remove CIF_NOHZ_DELAY flag

Remove obsolete tick delay heuristic [1]. The upcoming cpuidle driver handles frequent sleep/wakeup cycles more effectively.

[1] https://lore.kernel.org/all/[email protected]/

---
 arch/s390/include/asm/processor.h | 4 ----
 arch/s390/kernel/idle.c           | 1 -
 arch/s390/kernel/irq.c            | 4 ----
 arch/s390/kernel/smp.c            | 1 -
 4 files changed, 10 deletions(-)
arch/s390/include/asm/processor.h +0 -4
index 78195ee5e99f..3666198cc364 100644
@@ -14,12 +14,10 @@
 
 #include <linux/bits.h>
 
-#define CIF_NOHZ_DELAY		2	/* delay HZ disable for a tick */
 #define CIF_ENABLED_WAIT	5	/* in enabled wait state */
 #define CIF_MCCK_GUEST		6	/* machine check happening in guest */
 #define CIF_DEDICATED_CPU	7	/* this CPU is dedicated */
 
-#define _CIF_NOHZ_DELAY		BIT(CIF_NOHZ_DELAY)
 #define _CIF_ENABLED_WAIT	BIT(CIF_ENABLED_WAIT)
 #define _CIF_MCCK_GUEST		BIT(CIF_MCCK_GUEST)
 #define _CIF_DEDICATED_CPU	BIT(CIF_DEDICATED_CPU)
@@ -96,8 +94,6 @@ static __always_inline bool test_cpu_flag_of(int flag, int cpu)
 	return test_bit(flag, &per_cpu(pcpu_devices, cpu).flags);
 }
 
-#define arch_needs_cpu() test_cpu_flag(CIF_NOHZ_DELAY)
-
 static inline void get_cpu_id(struct cpuid *ptr)
 {
 	asm volatile("stidp %0" : "=Q" (*ptr));
arch/s390/kernel/idle.c +0 -1
index 1f1b06b6b4ef..8c63f440da2e 100644
@@ -42,7 +42,6 @@ void noinstr arch_cpu_idle(void)
 	/* Wait for external, I/O or machine check interrupt. */
 	psw_mask = PSW_KERNEL_BITS | PSW_MASK_WAIT |
 		   PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
-	clear_cpu_flag(CIF_NOHZ_DELAY);
 	set_cpu_flag(CIF_ENABLED_WAIT);
 	if (smp_cpu_mtid)
 		stcctm(MT_DIAG, smp_cpu_mtid, (u64 *)&idle->mt_cycles_enter);
arch/s390/kernel/irq.c +0 -4
index d10a17e6531d..61d17954c34c 100644
@@ -161,7 +161,6 @@ void noinstr do_io_irq(struct pt_regs *regs)
 	if (from_idle)
 		account_idle_time_irq();
 
-	set_cpu_flag(CIF_NOHZ_DELAY);
 	do {
 		regs->tpi_info = get_lowcore()->tpi_info;
 		if (get_lowcore()->tpi_info.adapter_IO)
@@ -358,9 +357,6 @@ static irqreturn_t do_ext_interrupt(int irq, void *dummy)
 	int index;
 
 	ext_code.int_code = regs->int_code;
-	if (ext_code.code != EXT_IRQ_CLK_COMP)
-		set_cpu_flag(CIF_NOHZ_DELAY);
-
 	index = ext_hash(ext_code.code);
 	rcu_read_lock();
 	hlist_for_each_entry_rcu(p, &ext_int_hash[index], entry) {
arch/s390/kernel/smp.c +0 -1
index 50bb499cf3e5..cd5ccbe3a18d 100644
@@ -910,7 +910,6 @@ int __cpu_disable(void)
 	cregs[6].val  &= ~0xff000000UL;	/* disable all I/O interrupts */
 	cregs[14].val &= ~0x1f000000UL;	/* disable most machine checks */
 	__local_ctl_load(0, 15, cregs);
-	clear_cpu_flag(CIF_NOHZ_DELAY);
 	return 0;
 }
 
Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH v2 2/5 tick: Remove arch_needs_cpu

In reply to Mete Durlu

Remove unused arch_needs_cpu() hook. No architectures use it after s390 removed its use case.

---
 include/linux/tick.h     | 3 ---
 kernel/time/tick-sched.c | 7 +++----
 2 files changed, 3 insertions(+), 7 deletions(-)
include/linux/tick.h +0 -3
index 738007d6f577..0f6757f81839 100644
@@ -44,9 +44,6 @@ static inline void tick_unfreeze(void) { }
 
 #ifdef CONFIG_TICK_ONESHOT
 extern void tick_irq_enter(void);
-#  ifndef arch_needs_cpu
-#   define arch_needs_cpu() (0)
-#  endif
 # else
 static inline void tick_irq_enter(void) { }
 #endif
kernel/time/tick-sched.c +3 -4
index cbbb87a0c6e7..cee18999d818 100644
@@ -943,8 +943,7 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu)
 	ts->timer_expires_base = basemono;
 
 	/*
-	 * Keep the periodic tick, when RCU, architecture or irq_work
-	 * requests it.
+	 * Keep the periodic tick, when RCU or irq_work requests it.
 	 * Aside of that, check whether the local timer softirq is
 	 * pending. If so, its a bad idea to call get_next_timer_interrupt(),
 	 * because there is an already expired timer, so it will request
@@ -952,8 +951,8 @@ static ktime_t tick_nohz_next_event(struct tick_sched *ts, int cpu)
 	 * minimal delta, which brings us back to this place
 	 * immediately. Lather, rinse and repeat...
 	 */
-	if (rcu_needs_cpu() || arch_needs_cpu() ||
-	    irq_work_needs_cpu() || local_timer_softirq_pending()) {
+	if (rcu_needs_cpu() || irq_work_needs_cpu() ||
+	    local_timer_softirq_pending()) {
 		next_tick = basemono + TICK_NSEC;
 	} else {
 		/*
Signature · 1 line
2.54.0
author maintainer
#4 lore raw

PATCH v2 3/5 s390: Enable TIF_POLLING_NRFLAG

In reply to Mete Durlu

Enable TIF_POLLING_NRFLAG to support idle polling state in the upcoming cpuidle driver.

---
 arch/s390/include/asm/thread_info.h | 1 +
 1 file changed, 1 insertion(+)
arch/s390/include/asm/thread_info.h +1 -0
index 6a548a819400..2554cef3a6a5 100644
@@ -61,6 +61,7 @@ void arch_setup_new_exec(void);
  */
 #define HAVE_TIF_NEED_RESCHED_LAZY
 #define HAVE_TIF_RESTORE_SIGMASK
+#define HAVE_TIF_POLLING_NRFLAG
 
 #include <asm-generic/thread_info_tif.h>
 
Signature · 1 line
2.54.0
author maintainer
#5 lore raw

PATCH v2 4/5 s390/idle: Introduce cpuidle for s390

In reply to Mete Durlu

Introduce generic cpuidle driver on s390. Use a two stage approach to handle idle scenarios and use TEO governor for idle stage selection. Two stages are, from shallow to deep, idle polling and enabled wait.

---
 MAINTAINERS                    |   8 ++++
 arch/s390/Kconfig              |   5 ++
 drivers/cpuidle/Kconfig        |   5 ++
 drivers/cpuidle/Kconfig.s390   |  11 +++++
 drivers/cpuidle/Makefile       |   4 ++
 drivers/cpuidle/cpuidle-s390.c | 104 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 137 insertions(+)
MAINTAINERS +8 -0
index e035a3be797c..127e32c5fb4e 100644
@@ -6766,6 +6766,13 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/cpuidle/cpuidle-riscv-sbi.c
 
+CPUIDLE DRIVER - S390
+M:	Mete Durlu <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	drivers/cpuidle/cpuidle-s390.c
+
 CPUMASK API [RUST]
 M:	Viresh Kumar <[email protected]>
 R:	Yury Norov <[email protected]>
@@ -23497,6 +23504,7 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git
 F:	Documentation/driver-api/s390-drivers.rst
 F:	Documentation/arch/s390/
 F:	arch/s390/
+F:	drivers/cpuidle/cpuidle-s390.c
 F:	drivers/s390/
 F:	drivers/watchdog/diag288_wdt.c
 
arch/s390/Kconfig +5 -0
index ecbcbb781e40..8548f5b6b247 100644
@@ -20,6 +20,9 @@ config ARCH_HAS_ILOG2_U64
 config ARCH_PROC_KCORE_TEXT
 	def_bool y
 
+config ARCH_HAS_CPU_RELAX
+	def_bool y
+
 config GENERIC_HWEIGHT
 	def_bool !HAVE_MARCH_Z196_FEATURES
 
@@ -708,6 +711,8 @@ config KERNEL_IMAGE_BASE
 
 endmenu
 
+source "drivers/cpuidle/Kconfig"
+
 menu "Memory setup"
 
 config ARCH_SPARSEMEM_ENABLE
drivers/cpuidle/Kconfig +5 -0
index d6d8386d3f02..00e2562041fd 100644
@@ -71,6 +71,11 @@ depends on RISCV
 source "drivers/cpuidle/Kconfig.riscv"
 endmenu
 
+menu "S390 CPU Idle Drivers"
+depends on S390
+source "drivers/cpuidle/Kconfig.s390"
+endmenu
+
 config HALTPOLL_CPUIDLE
 	tristate "Halt poll cpuidle driver"
 	depends on X86 && KVM_GUEST
drivers/cpuidle/Kconfig.s390 new file +11 -0
new file mode 100644
index 000000000000..0b170d9a190b
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# S390 CPU Idle drivers
+#
+
+config S390_CPUIDLE
+	bool "S390 CPU idle driver"
+	default y
+	help
+          Select this option to enable processor idle state management
+          through cpuidle subsystem.
drivers/cpuidle/Makefile +4 -0
index 1de9e92c5b0f..88cbc2a7aea8 100644
@@ -42,3 +42,7 @@ obj-$(CONFIG_POWERNV_CPUIDLE)		+= cpuidle-powernv.o
 ###############################################################################
 # RISC-V drivers
 obj-$(CONFIG_RISCV_SBI_CPUIDLE)		+= cpuidle-riscv-sbi.o
+
+###############################################################################
+# S390 drivers
+obj-$(CONFIG_S390_CPUIDLE)		+= cpuidle-s390.o
drivers/cpuidle/cpuidle-s390.c new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#6 lore raw

PATCH v2 5/5 s390/configs: Enable cpuidle driver on s390

In reply to Mete Durlu

Enable cpuidle infrastructure, teo governor and s390 cpuidle driver by default. They can be disabled via config options before compile or via setting cpuidle.off kernel commandline option. When cpuidle.off=1 set, given architecture's specific implementation is used as a fallback without any governor or idle state support.

During runtime individual states of cpuidle driver can also be disabled via sysfs attributes.

Ex:
echo 1 > /sys/devices/system/cpu<N>/cpuidle/state<M>/disable

---
 arch/s390/configs/debug_defconfig | 2 ++
 arch/s390/configs/defconfig       | 2 ++
 2 files changed, 4 insertions(+)
arch/s390/configs/debug_defconfig +2 -0
index 730c90b4a876..39f2c56bd29d 100644
@@ -29,6 +29,8 @@ CONFIG_CGROUP_PIDS=y
 CONFIG_CGROUP_RDMA=y
 CONFIG_CGROUP_FREEZER=y
 CONFIG_CGROUP_HUGETLB=y
+CONFIG_CPU_IDLE=y
+CONFIG_CPU_IDLE_GOV_TEO=y
 CONFIG_CPUSETS=y
 CONFIG_CGROUP_DEVICE=y
 CONFIG_CGROUP_CPUACCT=y
arch/s390/configs/defconfig +2 -0
index dd5fc1426c88..723ce48ce8d1 100644
@@ -27,6 +27,8 @@ CONFIG_CGROUP_PIDS=y
 CONFIG_CGROUP_RDMA=y
 CONFIG_CGROUP_FREEZER=y
 CONFIG_CGROUP_HUGETLB=y
+CONFIG_CPU_IDLE=y
+CONFIG_CPU_IDLE_GOV_TEO=y
 CONFIG_CPUSETS=y
 CONFIG_CGROUP_DEVICE=y
 CONFIG_CGROUP_CPUACCT=y
Signature · 1 line
2.54.0
maintainer Reviewed-by on the v2 series
#7 lore raw
In reply to Mete Durlu
Quoted 10 lines · Mete Durlu

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

...

Quoted 7 lines

Mete Durlu (5):
s390/tick: Remove CIF_NOHZ_DELAY flag
tick: Remove arch_needs_cpu
s390: Enable TIF_POLLING_NRFLAG
s390/idle: Introduce cpuidle for s390
s390/configs: Enable cpuidle driver on s390

Quoted 16 lines
 MAINTAINERS                         |   8 +++
 arch/s390/Kconfig                   |   5 ++
 arch/s390/configs/debug_defconfig   |   2 +
 arch/s390/configs/defconfig         |   2 +
 arch/s390/include/asm/processor.h   |   4 --
 arch/s390/include/asm/thread_info.h |   1 +
 arch/s390/kernel/idle.c             |   1 -
 arch/s390/kernel/irq.c              |   4 --
 arch/s390/kernel/smp.c              |   1 -
 drivers/cpuidle/Kconfig             |   5 ++
 drivers/cpuidle/Kconfig.s390        |  11 ++++
 drivers/cpuidle/Makefile            |   4 ++
 drivers/cpuidle/cpuidle-s390.c      | 104 ++++++++++++++++++++++++++++++++++++
 include/linux/tick.h                |   3 --
 kernel/time/tick-sched.c            |   7 ++-
 15 files changed, 145 insertions(+), 17 deletions(-)

Looks all good to me.

#8 lore raw
In reply to Mete Durlu
Quoted 10 lines · Mete Durlu

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

So if (according to v1) there's no data (yet) that teo is much preferred, I would remove all mentions of it in code and patch descriptions? A cpuidle driver requiring a specific governor sort-of violates the abstraction.
In case teo does work much better for you, which I wouldn't doubt for a second from what your system looks like, it would be nice to present some data on it. Additionally I think setting it in the defconfig alone is probably enough?

Quoted 45 lines

- Implementation Overview
-----------------------------------------------------------------------

The driver implements two idle states;

**Polling Idle (shallow state)**
- Busy-loop implementation that prevents SIE-exit during short idle periods
- Zero exit latency, optimized for latency-sensitive workloads
- Maintains CPU with the guest, improving response times

**Enabled Wait (deep state)**
- Traditional EW state that signals hypervisor availability
- Higher exit latency but more efficient for longer idle periods

The TEO governor dynamically selects between these states by monitoring next timer interrupts and system interrupt frequency, choosing the most appropriate idle state for each situation.

- Performance Benefits
-----------------------------------------------------------------------

Benchmark results across LPAR, KVM, and z/VM guests demonstrate significant improvements for latency-sensitive and scheduler-intensive workloads:

```
Benchmark    | LPAR  | z/VM  | KVM   |
-----------------------------------------
cyclictest   | +45%  | +50%  | +30%  |
hackbench    | +5%   | +12%  | -     |
pgbench      | +2%   | +15%  | +2%   |
uperf        | +50%* | +-5%  | +-5%  |
```

*Single-threaded uperf scenarios show 50-70% improvements on LPAR. Multi-threaded results show slight improvements overall.

Additionally, fio and ioping tests show latency distribution shifts toward lower values with reduced minimum and average latencies.

- Configuration
-----------------------------------------------------------------------

Idle state parameters are tuned per hypervisor type after benchmarks:

Quoted 8 lines

**LPAR:**
- Polling: 5us target residency, 0us exit latency
- EW: 5us target residency, 5us exit latency

**KVM/z/VM:**
- Polling: 1us target residency, 0us exit latency
- EW: 1us target residency, 1us exit latency

I think this would also be useful in cpuidle-s390.c in particular the different residency+latency values for LPAR and KVM/z/VM and what they aim to achieve for you.

Additionally polling is initialised to 0/0 by poll_state.c, so I don't know where you're taking these values from?

author maintainer
#9 lore raw
Quoted 12 lines · Christian Loehle
Quoted 10 lines · Mete Durlu

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

Quoted 4 lines

So if (according to v1) there's no data (yet) that teo is much preferred, I would remove all mentions of it in code and patch descriptions? A cpuidle driver requiring a specific governor sort-of violates the abstraction.

True, s/TEO governor/idle governor/g + s/TEO/idle governor/g should be good enough.

Quoted 5 lines

In case teo does work much better for you, which I wouldn't doubt for a second from what your system looks like, it would be nice to present some data on it. Additionally I think setting it in the defconfig alone is probably enough?

I ran a quick menu vs teo run on an LPAR.
There was no significant change between the results of the benchmarks except for slightly higher cpu utilization when using menu governor. I can put it down to the cover letter. The only noticeable change is on my micro benchmark where I use epoll_wait() to make two threads on different cores ping each other.

micro-benchmark | teo | menu
-------------------------------------
avg time | ~21.6sec | ~24.3sec

Idle framework tries to find the specified governor in the driver struct but if it can't find it or no governor was specified it uses the next available one, so setting teo on defconfig and disabling rest of the governors can be good enough to pick teo.

Quoted 9 lines
Quoted 9 lines

- Configuration
-----------------------------------------------------------------------

Idle state parameters are tuned per hypervisor type after benchmarks:

**LPAR:**
- Polling: 5us target residency, 0us exit latency
- EW: 5us target residency, 5us exit latency

Quoted 7 lines
Quoted 4 lines

**KVM/z/VM:**
- Polling: 1us target residency, 0us exit latency
- EW: 1us target residency, 1us exit latency

I think this would also be useful in cpuidle-s390.c in particular the different residency+latency values for LPAR and KVM/z/VM and what they aim to achieve for you.

We can put down a comment like below;

/*
* After various benchmark runs the tuneables for idle driver has shown
* the best performance with the following values;
* for LPAR:
* - Polling: 5us target residency, 0us exit latency
* - EW: 5us target residency, 5us exit latency
*
* for KVM/z/VM:
* - Polling: 1us target residency, 0us exit latency
* - EW: 1us target residency, 1us exit latency
*/

Is that what you are looking for or something more extensive to cover what sort of behavior it causes and why it benefits the performance? I wouldn't really like to put down lengthy comments here to be honest.

Quoted 2 lines

Additionally polling is initialised to 0/0 by poll_state.c, so I don't know where you're taking these values from?

Having a look at the implementation of poll_idle() in poll_state.c. The polling time limit (target_residency) is acquired from cpuidle_poll_time(), which tries to find an enabled state deeper than polling state and returns its target_residency. Since we only have two states, it automatically means EW state's target_residency, or IDLE_POLL_MAX if it is disabled.

If I am not mistaken governor also uses the next enabled state to calculate the target_residency of the polling state.

author maintainer
#10 lore raw
Quoted 89 lines · Mete Durlu
Quoted 12 lines · Christian Loehle
Quoted 10 lines · Mete Durlu

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

Quoted 4 lines

So if (according to v1) there's no data (yet) that teo is much preferred, I would remove all mentions of it in code and patch descriptions? A cpuidle driver requiring a specific governor sort-of violates the abstraction.

True, s/TEO governor/idle governor/g + s/TEO/idle governor/g should be good enough.

Quoted 5 lines

In case teo does work much better for you, which I wouldn't doubt for a second from what your system looks like, it would be nice to present some data on it. Additionally I think setting it in the defconfig alone is probably enough?

I ran a quick menu vs teo run on an LPAR.
There was no significant change between the results of the benchmarks except for slightly higher cpu utilization when using menu governor. I can put it down to the cover letter. The only noticeable change is on my micro benchmark where I use epoll_wait() to make two threads on different cores ping each other.

micro-benchmark |   teo    |   menu
-------------------------------------
avg time        | ~21.6sec | ~24.3sec

Idle framework tries to find the specified governor in the driver struct but if it can't find it or no governor was specified it uses the next available one, so setting teo on defconfig and disabling rest of the governors can be good enough to pick teo.

Quoted 9 lines
Quoted 9 lines

- Configuration
-----------------------------------------------------------------------

Idle state parameters are tuned per hypervisor type after benchmarks:

**LPAR:**
- Polling: 5us target residency, 0us exit latency
- EW: 5us target residency, 5us exit latency

Quoted 7 lines
Quoted 4 lines

**KVM/z/VM:**
- Polling: 1us target residency, 0us exit latency
- EW: 1us target residency, 1us exit latency

I think this would also be useful in cpuidle-s390.c in particular the different residency+latency values for LPAR and KVM/z/VM and what they aim to achieve for you.

We can put down a comment like below;

/*
 * After various benchmark runs the tuneables for idle driver has shown
 * the best performance with the following values;
 * for LPAR:
 * - Polling: 5us target residency, 0us exit latency
 * - EW: 5us target residency, 5us exit latency
 *
 * for KVM/z/VM:
 * - Polling: 1us target residency, 0us exit latency
 * - EW: 1us target residency, 1us exit latency
 */

Is that what you are looking for or something more extensive to cover what sort of behavior it causes and why it benefits the performance? I wouldn't really like to put down lengthy comments here to be honest.

Quoted 2 lines

Additionally polling is initialised to 0/0 by poll_state.c, so I don't know where you're taking these values from?

Having a look at the implementation of poll_idle() in poll_state.c. The polling time limit (target_residency) is acquired from cpuidle_poll_time(), which tries to find an enabled state deeper than polling state and returns its target_residency. Since we only have two states, it automatically means EW state's target_residency, or IDLE_POLL_MAX if it is disabled.

Quoted 4 lines

If I am not mistaken governor also uses the next enabled state to calculate the target_residency of the polling state.

Friendly ping.

#11 lore raw
In reply to Mete Durlu
Quoted 34 lines · Mete Durlu
Quoted 12 lines · Christian Loehle
Quoted 10 lines · Mete Durlu

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

Quoted 4 lines

So if (according to v1) there's no data (yet) that teo is much preferred, I would remove all mentions of it in code and patch descriptions? A cpuidle driver requiring a specific governor sort-of violates the abstraction.

True, s/TEO governor/idle governor/g + s/TEO/idle governor/g should be good enough.

Quoted 5 lines

In case teo does work much better for you, which I wouldn't doubt for a second from what your system looks like, it would be nice to present some data on it. Additionally I think setting it in the defconfig alone is probably enough?

I ran a quick menu vs teo run on an LPAR.
There was no significant change between the results of the benchmarks except for slightly higher cpu utilization when using menu governor. I can put it down to the cover letter. The only noticeable change is on my micro benchmark where I use epoll_wait() to make two threads on different cores ping each other.

Quoted 9 lines

micro-benchmark |   teo    |   menu
-------------------------------------
avg time        | ~21.6sec | ~24.3sec

Idle framework tries to find the specified governor in the driver struct but if it can't find it or no governor was specified it uses the next available one, so setting teo on defconfig and disabling rest of the governors can be good enough to pick teo.

Thanks for testing!

Quoted 32 lines
Quoted 10 lines
Quoted 10 lines

- Configuration
-----------------------------------------------------------------------

Idle state parameters are tuned per hypervisor type after benchmarks:

**LPAR:**
- Polling: 5us target residency, 0us exit latency
- EW: 5us target residency, 5us exit latency

Quoted 7 lines
Quoted 4 lines

**KVM/z/VM:**
- Polling: 1us target residency, 0us exit latency
- EW: 1us target residency, 1us exit latency

I think this would also be useful in cpuidle-s390.c in particular the different residency+latency values for LPAR and KVM/z/VM and what they aim to achieve for you.

We can put down a comment like below;

/*
 * After various benchmark runs the tuneables for idle driver has shown
 * the best performance with the following values;
 * for LPAR:
 * - Polling: 5us target residency, 0us exit latency
 * - EW: 5us target residency, 5us exit latency
 *
 * for KVM/z/VM:
 * - Polling: 1us target residency, 0us exit latency
 * - EW: 1us target residency, 1us exit latency
 */

Quoted 3 lines

Is that what you are looking for or something more extensive to cover what sort of behavior it causes and why it benefits the performance? I wouldn't really like to put down lengthy comments here to be honest.

Why not?
At least to me the values are hard to follow and without knowing what they represent.
For example is this actually the worst case exit latency for these systems? Also from a cpuidle perspective residency == latency isn't outright wrong but certainly always a little suspicious.

Quoted 10 lines
Quoted 3 lines

Additionally polling is initialised to 0/0 by poll_state.c, so I don't know where you're taking these values from?

Having a look at the implementation of poll_idle() in poll_state.c. The polling time limit (target_residency) is acquired from cpuidle_poll_time(), which tries to find an enabled state deeper than polling state and returns its target_residency. Since we only have two states, it automatically means EW state's target_residency, or IDLE_POLL_MAX if it is disabled.

I agree that cpuidle_poll_time() can derive the polling time limit from a deeper enabled state, but it only does that for states with target_residency_ns >= CPUIDLE_POLL_MIN (10us). With the proposed s390 EW values of 1us/5us, that state is skipped and the poll limit falls back to CPUIDLE_POLL_MAX (TICK_NSEC / 16).

Quoted 4 lines

If I am not mistaken governor also uses the next enabled state to calculate the target_residency of the polling state.

With just two state that is practically what happens in the selection algorithm anyway, yes.

author maintainer
#12 lore raw
Quoted 14 lines · Christian Loehle
Quoted 13 lines · Mete Durlu
Quoted 12 lines · Christian Loehle
Quoted 10 lines · Mete Durlu

v1 -> v2:

* Add idle driver enteries to MAINTAINERS file (Christian Loehle)
* Remove extra line break left in drivers/cpuidle/Kconfig.s390 (Christian Loehle)

This patch series introduces a CPU idle driver for s390 architecture that leverages the existing cpu idle infrastructure and TEO (Timer Events Oriented) governor to optimize idle state selection based on timer events and interrupt patterns.

...

Quoted 36 lines
Quoted 32 lines
Quoted 10 lines
Quoted 10 lines

- Configuration
-----------------------------------------------------------------------

Idle state parameters are tuned per hypervisor type after benchmarks:

**LPAR:**
- Polling: 5us target residency, 0us exit latency
- EW: 5us target residency, 5us exit latency

Quoted 7 lines
Quoted 4 lines

**KVM/z/VM:**
- Polling: 1us target residency, 0us exit latency
- EW: 1us target residency, 1us exit latency

I think this would also be useful in cpuidle-s390.c in particular the different residency+latency values for LPAR and KVM/z/VM and what they aim to achieve for you.

We can put down a comment like below;

/*
 * After various benchmark runs the tuneables for idle driver has shown
 * the best performance with the following values;
 * for LPAR:
 * - Polling: 5us target residency, 0us exit latency
 * - EW: 5us target residency, 5us exit latency
 *
 * for KVM/z/VM:
 * - Polling: 1us target residency, 0us exit latency
 * - EW: 1us target residency, 1us exit latency
 */

Quoted 3 lines

Is that what you are looking for or something more extensive to cover what sort of behavior it causes and why it benefits the performance? I wouldn't really like to put down lengthy comments here to be honest.

Quoted 6 lines

Why not?
At least to me the values are hard to follow and without knowing what they represent.
For example is this actually the worst case exit latency for these systems? Also from a cpuidle perspective residency == latency isn't outright wrong but certainly always a little suspicious.

Since s390 is running virtualized machines, the values are not deterministic. The values picked here are the best estimates backed by testing. That is why I didn't want to put anything down initially but of course the comment can also describe that. I'll add that in the next version.

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

Additionally polling is initialised to 0/0 by poll_state.c, so I don't know where you're taking these values from?

Having a look at the implementation of poll_idle() in poll_state.c. The polling time limit (target_residency) is acquired from cpuidle_poll_time(), which tries to find an enabled state deeper than polling state and returns its target_residency. Since we only have two states, it automatically means EW state's target_residency, or IDLE_POLL_MAX if it is disabled.

Quoted 5 lines

I agree that cpuidle_poll_time() can derive the polling time limit from a deeper enabled state, but it only does that for states with target_residency_ns >= CPUIDLE_POLL_MIN (10us). With the proposed s390 EW values of 1us/5us, that state is skipped and the poll limit falls back to CPUIDLE_POLL_MAX (TICK_NSEC / 16).

Ah missed that CPUIDLE_POLL_MIN is 10us and had it wrong as less or equal to 1us. For 1000Hz CPUIDLE_POLL_MAX calculates to 6250ns which is close enough for LPAR (5us) but for KVM and ZVM case (1us) it is a bit off.

Although, the benchmarks didn't reflect a problem. To verify I did a quick test run with the following applied on a KVM and a ZVM guest;

drivers/cpuidle/cpuidle-s390.c +14 -0
@@ -72,6 +72,20 @@ static int s390_cpuidle_cpu_dead(unsigned int cpu)
        return 0;
 }
 
+static void __init s390_cpuidle_poll_tune(void)
+{
+       struct cpuidle_device *dev;
+       int cpu;
+
+       for_each_present_cpu(cpu) {
+               dev = &per_cpu(cpuidle_dev, cpu);
+               if (machine_is_lpar())
+                       dev->poll_limit_ns = 5000;
+               else
+                       dev->poll_limit_ns = 1000;
+       }
+}
+
 

This causes cpuidle_poll_time() to exit early as poll_limit_ns is already set for the polling cpu.

The results are quite similar to original benchmark results I collected, therefore I don't think it is worth adding it to the patch series.

...

That said, one could argue that the value of CPUIDLE_POLL_MIN could be
reconsidered. Looking at the comments above and also the introducing
commit 7a25759eaa04 ("cpuidle: Select polling interval based on a c-state with a longer target residency")

```
/*
 * Min polling interval of 10usec is a guess. It is assuming that
 * for most users, the time for a single ping-pong workload like
 * perf bench pipe would generally complete within 10usec but
 * this is hardware dependent. Actual time can be estimated with
 *
 * perf bench sched pipe -l 10000
 *
...
#define CPUIDLE_POLL_MIN 10000
```

- On s390 "perf bench sched pipe -l 10000" results in usecs/op values in between 0.9-3.5 usecs.

- On my x86 laptop this range is between 1-2 usecs/op.

Based on that observation and reading the commit message I'd say there should be some improvements possible there but, this should be tackled with a different patch series. In fact I'd like to give it a go after this patch series.

Thanks for having a look. I'll send a new version shortly.