mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 14:33:24 -04:00
s390/idle: Introduce cpuidle for s390
Introduce generic cpuidle driver on s390. Use a two stage approach to handle idle scenarios and use idle governor for idle stage selection. Two stages are, from shallow to deep, idle polling and enabled wait. Suggested-by: Christian Borntraeger <borntraeger@linux.ibm.com> Suggested-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Mete Durlu <meted@linux.ibm.com> Reviewed-by: Heiko Carstens <hca@linux.ibm.com> Reviewed-by: Christian Loehle <christian.loehle@arm.com> Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
This commit is contained in:
committed by
Vasily Gorbik
parent
397565b519
commit
01c162e27a
@@ -6851,6 +6851,13 @@ L: linux-riscv@lists.infradead.org
|
||||
S: Maintained
|
||||
F: drivers/cpuidle/cpuidle-riscv-sbi.c
|
||||
|
||||
CPUIDLE DRIVER - S390
|
||||
M: Mete Durlu <meted@linux.ibm.com>
|
||||
L: linux-pm@vger.kernel.org
|
||||
L: linux-s390@vger.kernel.org
|
||||
S: Maintained
|
||||
F: drivers/cpuidle/cpuidle-s390.c
|
||||
|
||||
CPUMASK API [RUST]
|
||||
M: Viresh Kumar <viresh.kumar@linaro.org>
|
||||
R: Yury Norov <yury.norov@gmail.com>
|
||||
@@ -23790,6 +23797,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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -705,6 +708,8 @@ config KERNEL_IMAGE_BASE
|
||||
|
||||
endmenu
|
||||
|
||||
source "drivers/cpuidle/Kconfig"
|
||||
|
||||
menu "Memory setup"
|
||||
|
||||
config ARCH_SPARSEMEM_ENABLE
|
||||
|
||||
@@ -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
|
||||
|
||||
11
drivers/cpuidle/Kconfig.s390
Normal file
11
drivers/cpuidle/Kconfig.s390
Normal file
@@ -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.
|
||||
@@ -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
|
||||
|
||||
115
drivers/cpuidle/cpuidle-s390.c
Normal file
115
drivers/cpuidle/cpuidle-s390.c
Normal file
@@ -0,0 +1,115 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* s390 generic CPU idle driver.
|
||||
*
|
||||
* Copyright IBM Corp. 2026
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) "CPUidle s390: " fmt
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/cpuidle.h>
|
||||
#include <linux/cpu.h>
|
||||
#include <linux/sched/clock.h>
|
||||
|
||||
static __cpuidle int s390_enter_idle(struct cpuidle_device *dev,
|
||||
struct cpuidle_driver *drv,
|
||||
int index)
|
||||
{
|
||||
arch_cpu_idle();
|
||||
return index;
|
||||
}
|
||||
|
||||
static struct cpuidle_driver s390_cpuidle_driver = {
|
||||
.cpumask = (struct cpumask *)cpu_present_mask,
|
||||
.name = "s390-idle",
|
||||
.states = {
|
||||
{ /* entry 0 is for polling */},
|
||||
{
|
||||
.enter = s390_enter_idle,
|
||||
.name = "IDLE",
|
||||
.desc = "ENABLED WAIT",
|
||||
},
|
||||
},
|
||||
.safe_state_index = 0,
|
||||
.state_count = 2,
|
||||
};
|
||||
|
||||
static int s390_cpuidle_cpu_online(unsigned int cpu)
|
||||
{
|
||||
struct cpuidle_device *dev = &per_cpu(cpuidle_dev, cpu);
|
||||
int rc;
|
||||
|
||||
if (dev->registered) {
|
||||
cpuidle_pause_and_lock();
|
||||
rc = cpuidle_enable_device(dev);
|
||||
cpuidle_resume_and_unlock();
|
||||
if (rc)
|
||||
pr_err("Failed to enable cpuidle device on cpu %u\n", cpu);
|
||||
} else {
|
||||
dev->cpu = cpu;
|
||||
rc = cpuidle_register_device(dev);
|
||||
if (rc)
|
||||
pr_err("Failed to register cpuidle driver on cpu %u\n", cpu);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int s390_cpuidle_cpu_dead(unsigned int cpu)
|
||||
{
|
||||
struct cpuidle_device *dev = &per_cpu(cpuidle_dev, cpu);
|
||||
|
||||
if (!dev->registered)
|
||||
return 0;
|
||||
cpuidle_pause_and_lock();
|
||||
cpuidle_disable_device(dev);
|
||||
cpuidle_resume_and_unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The target_residency and exit_latency values are benchmark-derived estimates
|
||||
* that remain non-deterministic due to s390's virtualized architecture.
|
||||
*
|
||||
* Configuration strategy:
|
||||
* - Poll idle state: Values derived from the next enabled idle state (EW)
|
||||
* - Enabled Wait state: Values selected based on idle behavior and empirical
|
||||
* measurement data
|
||||
*
|
||||
* Goal is to improve responsiveness for workloads with frequent sleep/wakeup
|
||||
* cycles while minimizing any side effects.
|
||||
*/
|
||||
static void __init s390_cpuidle_ew_tune(void)
|
||||
{
|
||||
struct cpuidle_state *state = &s390_cpuidle_driver.states[1];
|
||||
|
||||
if (machine_is_lpar()) {
|
||||
state->target_residency = 5;
|
||||
state->exit_latency = 5;
|
||||
} else {
|
||||
state->target_residency = 1;
|
||||
state->exit_latency = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int __init s390_cpuidle_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
s390_cpuidle_ew_tune();
|
||||
cpuidle_poll_state_init(&s390_cpuidle_driver);
|
||||
rc = cpuidle_register(&s390_cpuidle_driver, NULL);
|
||||
if (rc)
|
||||
return rc;
|
||||
rc = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
|
||||
"cpuidle/s390:online",
|
||||
s390_cpuidle_cpu_online,
|
||||
s390_cpuidle_cpu_dead);
|
||||
if (rc < 0) {
|
||||
cpuidle_unregister(&s390_cpuidle_driver);
|
||||
pr_err("Failed to allocate hotplug state: cpuidle/s390:online\n");
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
device_initcall(s390_cpuidle_init);
|
||||
Reference in New Issue
Block a user