Skip to contentSkip to conversation

ACPI / processor_idle: Add ACPI v6.0 LPI support

PATCH Superseded Sudeep Holla 4 participants 16 messages Jun 28, 2016 – Jul 7, 2016

Subsystems (5)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v7 cover ACPI / processor_idle: Add ACPI v6.0 LPI support

ACPI 6.0 introduced LPI(Low Power Idle) states that provides an alternate method to describe processor idle states. It extends the specification to allow the expression of idle states like C-states selectable by the OSPM when a processor goes idle, but may affect more than one processor, and may affect other system components.

LPI extensions leverages the processor container device(again introduced in ACPI 6.0) allowing to express which parts of the system are affected by a given LPI state. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This series aims at providing basic and initial support for platform coordinated LPI states.

v6[6]->v7:
- Removed cpuidle-arm.h and introduced HAVE_GENERIC_CPUIDLE_ENTER and move the common code to cpuidle_generic_enter{,_state}
- Factored out common code between psci_{dt,acpi}_cpu_init_idle

v5[5]->v6:
- Added support for autopromotable state by not flattening them
- Moved arm_enter_idle_state to cpuidle-arm.h as it can be reused in ARM64 backend for ACPI LPI
- Other review comments(mainly for ARM64 from Lorenzo)
- Dropped support for skipping PM notifier as it needs to be fixed in GICv3 code(will be done separately)

v4[4]->v5:
- Addressed all the comments from Rafael
- Added support for retention mode(Prashant)
- Handled acpi_processor_get_power_info return value correctly(Vikas)
- Dropped __init from arm_cpuidle_init
- Merged psci prepartory patch into arm64 lpi support

v3[3]->v4:
- Dropped the preparatory patches that are merged already
- Added ARM64 arch specific callback implementations
- Addressed most of the review comments from Rafael

v2[2]->v3:
- rebased against v4.4-rc3
- fixed couple of issues reported by Prashanth and review comments from Ashwin

v1[1]->v2[2]:
- Fixed support for ACPI0010 processor container
- moved sleep state code out of processor_idle

Code is also available @[7]

Regards,
Sudeep

[1] http://marc.info/?l=linux-acpi&m=143871041601132&w=2
[2] http://marc.info/?l=linux-acpi&m=144241209800788&w=2
[3] http://marc.info/?l=linux-acpi&m=144906557814813&w=2
[4] http://marc.info/?l=linux-acpi&m=146106902731359&w=2
[5] http://marc.info/?l=linux-acpi&m=146298107608349&w=2
[6] http://marc.info/?l=linux-acpi&m=146661754618838&w=2
[7] git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux.git for_review/arm64_lpi

Sudeep Holla (6):
ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE ACPI / processor_idle: Add support for Low Power Idle(LPI) states
arm64: cpuidle: drop __init section marker to arm_cpuidle_init
cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms
arm64: add support for ACPI Low Power Idle(LPI)
ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

 arch/arm/Kconfig                |   1 +
 arch/arm/kernel/cpuidle.c       |   4 +-
 arch/arm64/Kconfig              |   1 +
 arch/arm64/kernel/cpuidle.c     |  24 +-
 drivers/acpi/Kconfig            |   6 +-
 drivers/acpi/bus.c              |  14 +-
 drivers/acpi/processor_driver.c |   2 +-
 drivers/acpi/processor_idle.c   | 544 ++++++++++++++++++++++++++++++++++------
 drivers/cpuidle/Kconfig         |   3 +
 drivers/cpuidle/cpuidle-arm.c   |  21 +-
 drivers/cpuidle/cpuidle.c       |  35 +++
 drivers/firmware/psci.c         | 122 +++++++--
 include/acpi/processor.h        |  26 +-
 include/linux/acpi.h            |   4 +
 include/linux/cpuidle.h         |   8 +
 15 files changed, 680 insertions(+), 135 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v7 1/6 ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

ACPI 6.0 adds a new method to specify the CPU idle states(C-states) called Low Power Idle(LPI) states. Since new architectures like ARM64 use only LPIs, introduce ACPI_PROCESSOR_CSTATE to encapsulate all the code supporting the old style C-states(_CST).

This patch will help to extend the processor_idle module to support LPI.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/acpi/Kconfig          |  4 +++
 drivers/acpi/processor_idle.c | 80 ++++++++++++++++++++++++++++---------------
 include/acpi/processor.h      |  2 +-
 3 files changed, 58 insertions(+), 28 deletions(-)
drivers/acpi/Kconfig +4 -0
index b7e2e776397d..1358fb7d7a68 100644
@@ -213,6 +213,10 @@ config ACPI_CPU_FREQ_PSS
 	bool
 	select THERMAL
 
+config ACPI_PROCESSOR_CSTATE
+	def_bool y
+	depends on IA64 || X86
+
 config ACPI_PROCESSOR_IDLE
 	bool
 	select CPU_IDLE
drivers/acpi/processor_idle.c +53 -27

111 lines not on this page · raw message

include/acpi/processor.h +1 -1
index 6f1805dd5d3c..48779d678122 100644
@@ -242,7 +242,7 @@ extern int acpi_processor_get_performance_info(struct acpi_processor *pr);
 DECLARE_PER_CPU(struct acpi_processor *, processors);
 extern struct acpi_processor_errata errata;
 
-#ifdef ARCH_HAS_POWER_INIT
+#if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
 					unsigned int cpu);
 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
Signature · 1 line
2.7.4
#2 lore raw

PATCH v7 2/6 ACPI / processor_idle: Add support for Low Power Idle(LPI) states

In reply to Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/acpi/bus.c              |  14 +-
 drivers/acpi/processor_driver.c |   2 +-
 drivers/acpi/processor_idle.c   | 468 +++++++++++++++++++++++++++++++++++-----
 include/acpi/processor.h        |  24 ++-
 include/linux/acpi.h            |   4 +
 5 files changed, 452 insertions(+), 60 deletions(-)
drivers/acpi/bus.c +13 -1
index 262ca31b86d9..80ebb05e387c 100644
@@ -302,6 +302,14 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
 EXPORT_SYMBOL(acpi_run_osc);
 
 bool osc_sb_apei_support_acked;
+
+/*
+ * ACPI 6.0 Section 8.4.4.2 Idle State Coordination
+ * OSPM supports platform coordinated low power idle(LPI) states
+ */
+bool osc_pc_lpi_support_confirmed;
+EXPORT_SYMBOL_GPL(osc_pc_lpi_support_confirmed);
+
 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
 static void acpi_bus_osc_support(void)
 {
@@ -322,6 +330,7 @@ static void acpi_bus_osc_support(void)
 		capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
 
 	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
+	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT;
 
 	if (!ghes_disable)
 		capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
@@ -329,9 +338,12 @@ static void acpi_bus_osc_support(void)
 		return;
 	if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
 		u32 *capbuf_ret = context.ret.pointer;
-		if (context.ret.length > OSC_SUPPORT_DWORD)
+		if (context.ret.length > OSC_SUPPORT_DWORD) {
 			osc_sb_apei_support_acked =
 				capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
+			osc_pc_lpi_support_confirmed =
+				capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_PCLPI_SUPPORT;
+		}
 		kfree(context.ret.pointer);
 	}
 	/* do we need to check other returned cap? Sounds no */
drivers/acpi/processor_driver.c +1 -1
index d2fa8cb82d2b..0ca14ac7bb28 100644
@@ -90,7 +90,7 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
 						  pr->performance_platform_limit);
 		break;
 	case ACPI_PROCESSOR_NOTIFY_POWER:
-		acpi_processor_cst_has_changed(pr);
+		acpi_processor_power_state_has_changed(pr);
 		acpi_bus_generate_netlink_event(device->pnp.device_class,
 						  dev_name(&device->dev), event, 0);
 		break;
drivers/acpi/processor_idle.c +413 -55

564 lines not on this page · raw message

include/acpi/processor.h +21 -3
index 48779d678122..e2dcb0c51554 100644
@@ -39,6 +39,7 @@
 #define ACPI_CSTATE_SYSTEMIO	0
 #define ACPI_CSTATE_FFH		1
 #define ACPI_CSTATE_HALT	2
+#define ACPI_CSTATE_INTEGER	3
 
 #define ACPI_CX_DESC_LEN	32
 
@@ -67,9 +68,25 @@ struct acpi_processor_cx {
 	char desc[ACPI_CX_DESC_LEN];
 };
 
+struct acpi_lpi_state {
+	u32 min_residency;
+	u32 wake_latency; /* worst case */
+	u32 flags;
+	u32 arch_flags;
+	u32 res_cnt_freq;
+	u32 enable_parent_state;
+	u64 address;
+	u8 index;
+	u8 entry_method;
+	char desc[ACPI_CX_DESC_LEN];
+};
+
 struct acpi_processor_power {
 	int count;
-	struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
+	union {
+		struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
+		struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER];
+	};
 	int timer_broadcast_on_state;
 };
 
@@ -189,6 +206,7 @@ struct acpi_processor_flags {
 	u8 bm_control:1;
 	u8 bm_check:1;
 	u8 has_cst:1;
+	u8 has_lpi:1;
 	u8 power_setup_done:1;
 	u8 bm_rld_set:1;
 	u8 need_hotplug_init:1;
@@ -371,7 +389,7 @@ extern struct cpuidle_driver acpi_idle_driver;
 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
 int acpi_processor_power_init(struct acpi_processor *pr);
 int acpi_processor_power_exit(struct acpi_processor *pr);
-int acpi_processor_cst_has_changed(struct acpi_processor *pr);
+int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 #else
 static inline int acpi_processor_power_init(struct acpi_processor *pr)
@@ -384,7 +402,7 @@ static inline int acpi_processor_power_exit(struct acpi_processor *pr)
 	return -ENODEV;
 }
 
-static inline int acpi_processor_cst_has_changed(struct acpi_processor *pr)
+static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
 {
 	return -ENODEV;
 }
include/linux/acpi.h +4 -0
index 288fac5294f5..65754566ae17 100644
@@ -444,8 +444,12 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
 #define OSC_SB_HOTPLUG_OST_SUPPORT		0x00000008
 #define OSC_SB_APEI_SUPPORT			0x00000010
 #define OSC_SB_CPC_SUPPORT			0x00000020
+#define OSC_SB_CPCV2_SUPPORT			0x00000040
+#define OSC_SB_PCLPI_SUPPORT			0x00000080
+#define OSC_SB_OSLPI_SUPPORT			0x00000100
 
 extern bool osc_sb_apei_support_acked;
+extern bool osc_pc_lpi_support_confirmed;
 
 /* PCI Host Bridge _OSC: Capabilities DWORD 2: Support Field */
 #define OSC_PCI_EXT_CONFIG_SUPPORT		0x00000001
Signature · 1 line
2.7.4
#8 lore raw

PATCH v7 3/6 arm64: cpuidle: drop __init section marker to arm_cpuidle_init

In reply to Sudeep Holla

Commit ea389daa7fd9 ("arm64: cpuidle: add __init section marker to arm_cpuidle_init") added the __init annotation to arm_cpuidle_init as it was not needed after booting which was correct at that time.

However with the introduction of ACPI LPI support, this will be used from cpuhotplug path in ACPI processor driver.

This patch drops the __init annotation from arm_cpuidle_init to avoid the following warning:

WARNING: vmlinux.o(.text+0x113c8): Section mismatch in reference from the
function acpi_processor_ffh_lpi_probe() to the function .init.text:arm_cpuidle_init()
The function acpi_processor_ffh_lpi_probe() references
the function __init arm_cpuidle_init().
This is often because acpi_processor_ffh_lpi_probe lacks a __init annotation or the annotation of arm_cpuidle_init is wrong.

---
 arch/arm64/kernel/cpuidle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/cpuidle.c +1 -1
index e11857fce05f..06786fdaadeb 100644
@@ -15,7 +15,7 @@
 #include <asm/cpuidle.h>
 #include <asm/cpu_ops.h>
 
-int __init arm_cpuidle_init(unsigned int cpu)
+int arm_cpuidle_init(unsigned int cpu)
 {
 	int ret = -EOPNOTSUPP;
 
Signature · 1 line
2.7.4
#9 lore raw

PATCH v7 4/6 cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms

In reply to Sudeep Holla

The function arm_enter_idle_state is exactly the same in both generic ARM{32,64} CPUIdle driver and will be the same even on ARM64 backend for ACPI processor idle driver. So we can unify it and move it as generic_cpuidle_enter by introducing HAVE_GENERIC_CPUIDLE_ENTER and enabling the same on both ARM{32,64}.

This is in preparation of reuse of the generic cpuidle entry function for ACPI LPI support on ARM64.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
---
 arch/arm/Kconfig              |  1 +
 arch/arm/kernel/cpuidle.c     |  4 ++--
 arch/arm64/Kconfig            |  1 +
 arch/arm64/kernel/cpuidle.c   |  6 +++---
 drivers/cpuidle/Kconfig       |  3 +++
 drivers/cpuidle/cpuidle-arm.c | 21 +--------------------
 drivers/cpuidle/cpuidle.c     | 35 +++++++++++++++++++++++++++++++++++
 include/linux/cpuidle.h       |  8 ++++++++
 8 files changed, 54 insertions(+), 25 deletions(-)
arch/arm/Kconfig +1 -0
index 90542db1220d..52b3dca0381c 100644
@@ -54,6 +54,7 @@ config ARM
 	select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
 	select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
 	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
+	select HAVE_GENERIC_CPUIDLE_ENTER
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7))
 	select HAVE_IDE if PCI || ISA || PCMCIA
arch/arm/kernel/cpuidle.c +2 -2
index a44b268e12e1..49704e333bfc 100644
@@ -41,7 +41,7 @@ int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
 }
 
 /**
- * arm_cpuidle_suspend() - function to enter low power idle states
+ * cpuidle_generic_enter() - function to enter low power idle states
  * @index: an integer used as an identifier for the low level PM callbacks
  *
  * This function calls the underlying arch specific low level PM code as
@@ -50,7 +50,7 @@ int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
  * Returns -EOPNOTSUPP if no suspend callback is defined, the result of the
  * callback otherwise.
  */
-int arm_cpuidle_suspend(int index)
+int cpuidle_generic_enter(int index)
 {
 	int ret = -EOPNOTSUPP;
 	int cpu = smp_processor_id();
arch/arm64/Kconfig +1 -0
index 5a0a691d4220..0916b6e6c8ef 100644
@@ -76,6 +76,7 @@ config ARM64
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_GRAPH_TRACER
+	select HAVE_GENERIC_CPUIDLE_ENTER
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_HW_BREAKPOINT if PERF_EVENTS
 	select HAVE_IRQ_TIME_ACCOUNTING
arch/arm64/kernel/cpuidle.c +3 -3
index 06786fdaadeb..bade1b04ff12 100644
@@ -9,10 +9,10 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/cpuidle.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 
-#include <asm/cpuidle.h>
 #include <asm/cpu_ops.h>
 
 int arm_cpuidle_init(unsigned int cpu)
@@ -27,13 +27,13 @@ int arm_cpuidle_init(unsigned int cpu)
 }
 
 /**
- * cpu_suspend() - function to enter a low-power idle state
+ * cpuidle_generic_enter() - function to enter a low-power idle state
  * @arg: argument to pass to CPU suspend operations
  *
  * Return: 0 on success, -EOPNOTSUPP if CPU suspend hook not initialized, CPU
  * operations back-end error code otherwise.
  */
-int arm_cpuidle_suspend(int index)
+int cpuidle_generic_enter(int index)
 {
 	int cpu = smp_processor_id();
 
drivers/cpuidle/Kconfig +3 -0
index 7e48eb5bf0a7..e557289cff90 100644
@@ -45,4 +45,7 @@ endif
 
 config ARCH_NEEDS_CPU_IDLE_COUPLED
 	def_bool n
+
+config HAVE_GENERIC_CPUIDLE_ENTER
+	def_bool n
 endmenu
drivers/cpuidle/cpuidle-arm.c +1 -20
index e342565e8715..13012d8eba53 100644
@@ -36,26 +36,7 @@
 static int arm_enter_idle_state(struct cpuidle_device *dev,
 				struct cpuidle_driver *drv, int idx)
 {
-	int ret;
-
-	if (!idx) {
-		cpu_do_idle();
-		return idx;
-	}
-
-	ret = cpu_pm_enter();
-	if (!ret) {
-		/*
-		 * Pass idle state index to cpu_suspend which in turn will
-		 * call the CPU ops suspend protocol with idle index as a
-		 * parameter.
-		 */
-		ret = arm_cpuidle_suspend(idx);
-
-		cpu_pm_exit();
-	}
-
-	return ret ? -1 : idx;
+	return cpuidle_generic_enter_state(idx);
 }
 
 static struct cpuidle_driver arm_idle_driver = {
drivers/cpuidle/cpuidle.c +35 -0
index a4d0059e232c..e490dea98b89 100644
@@ -16,6 +16,7 @@
 #include <linux/pm_qos.h>
 #include <linux/cpu.h>
 #include <linux/cpuidle.h>
+#include <linux/cpu_pm.h>
 #include <linux/ktime.h>
 #include <linux/hrtimer.h>
 #include <linux/module.h>
@@ -255,6 +256,40 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
 }
 
 /**
+ * cpuidle_generic_enter_state - enter into the specified idle state using the
+ *				 generic callback if implemented
+ *
+ * @index: the index in the idle state table
+ *
+ * Returns the index in the idle state, -1 in case of error.
+ */
+int cpuidle_generic_enter_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
+		return idx;
+	}
+
+	ret = cpu_pm_enter();
+	if (!ret) {
+		/*
+		 * Pass idle state index to cpu_suspend which in turn will
+		 * call the CPU ops suspend protocol with idle index as a
+		 * parameter.
+		 */
+		ret = cpuidle_generic_enter(idx);
+
+		cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;
+}
+
+EXPORT_SYMBOL_GPL(cpuidle_generic_enter_state);
+
+/**
  * cpuidle_enter - enter into the specified idle state
  *
  * @drv:   the cpuidle driver tied with the cpu
include/linux/cpuidle.h +8 -0
index 07b83d32f66c..9fd3c10166fa 100644
@@ -154,6 +154,7 @@ extern int cpuidle_play_dead(void);
 extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
 static inline struct cpuidle_device *cpuidle_get_device(void)
 {return __this_cpu_read(cpuidle_devices); }
+extern int cpuidle_generic_enter_state(int idx);
 #else
 static inline void disable_cpuidle(void) { }
 static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
@@ -190,6 +191,7 @@ static inline int cpuidle_play_dead(void) {return -ENODEV; }
 static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
 	struct cpuidle_device *dev) {return NULL; }
 static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
+static inline int cpuidle_generic_enter_state(int idx) { return -1; }
 #endif
 
 #if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND)
@@ -246,6 +248,12 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
 {return 0;}
 #endif
 
+#ifdef CONFIG_HAVE_GENERIC_CPUIDLE_ENTER
+extern int cpuidle_generic_enter(int idx);
+#else
+static inline int cpuidle_generic_enter(int idx) { return -1; }
+#endif
+
 #ifdef CONFIG_ARCH_HAS_CPU_RELAX
 #define CPUIDLE_DRIVER_STATE_START	1
 #else
Signature · 1 line
2.7.4
#14 lore raw

PATCH v7 5/6 arm64: add support for ACPI Low Power Idle(LPI)

In reply to Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 arch/arm64/kernel/cpuidle.c |  16 ++++++
 drivers/firmware/psci.c     | 122 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 116 insertions(+), 22 deletions(-)
arch/arm64/kernel/cpuidle.c +16 -0
index bade1b04ff12..dc241e8de75c 100644
@@ -9,6 +9,7 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/acpi.h>
 #include <linux/cpuidle.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -39,3 +40,18 @@ int cpuidle_generic_enter(int index)
 
 	return cpu_ops[cpu]->cpu_suspend(index);
 }
+
+#ifdef CONFIG_ACPI
+
+#include <acpi/processor.h>
+
+int acpi_processor_ffh_lpi_probe(unsigned int cpu)
+{
+	return arm_cpuidle_init(cpu);
+}
+
+int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
+{
+	return cpuidle_generic_enter_state(lpi->index);
+}
+#endif
drivers/firmware/psci.c +100 -22

164 lines not on this page · raw message

Signature · 1 line
2.7.4
#15 lore raw

PATCH v7 6/6 ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

In reply to Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/acpi/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/Kconfig +1 -1
index 1358fb7d7a68..d74275c0f374 100644
@@ -238,7 +238,7 @@ config ACPI_CPPC_LIB
 config ACPI_PROCESSOR
 	tristate "Processor"
 	depends on X86 || IA64 || ARM64
-	select ACPI_PROCESSOR_IDLE if X86 || IA64
+	select ACPI_PROCESSOR_IDLE
 	select ACPI_CPU_FREQ_PSS if X86 || IA64
 	default y
 	help
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v7 2/6] ACPI / processor_idle: Add support for Low Power Idle(LPI) states

In reply to Sudeep Holla
Quoted 12 lines · Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 5 lines

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>

---

Hi Sudeep,

I looked at the acpi processor idle code sometime ago and from my POV, it was awful, unnecessary complex and very difficult to maintain. The usage of flags all over the places is significant of the lack of control of the written code.

Even if you are not responsible of this implementation, the current situation forces you to add more awful code on top of that, which is clearly against "making Linux better".

IMO, the current code deserves a huge cleanup before applying anything new : cstate and lpi should be investigated to be self-contained in their respective file and consolidated, the global variable usage should be killed, redundant flag checking removed by recapturing the code flow, etc ... I believe the usage of acpi probe table could be one entry point to begin this cleanup.

Signature · 11 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw

Re: [PATCH v7 2/6] ACPI / processor_idle: Add support for Low Power Idle(LPI) states

Quoted 20 lines · Daniel Lezcano
Quoted 13 lines · Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy
node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 5 lines

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 7 lines

Hi Sudeep,

I looked at the acpi processor idle code sometime ago and from my POV, it was awful, unnecessary complex and very difficult to maintain. The usage of flags all over the places is significant of the lack of control of the written code.

So you have any specific things in mind ? That's too broad and I know it's not so clean, but it's so for legacy reasons. I would leave that to Rafael to decide as it takes lots of testing to clean up these code.

Quoted 4 lines

Even if you are not responsible of this implementation, the current situation forces you to add more awful code on top of that, which is clearly against "making Linux better".

OK

Quoted 7 lines

IMO, the current code deserves a huge cleanup before applying anything new : cstate and lpi should be investigated to be self-contained in their respective file and consolidated, the global variable usage should be killed, redundant flag checking removed by recapturing the code flow, etc ... I believe the usage of acpi probe table could be one entry point to begin this cleanup.

This is not a static table.

Signature · 2 lines
Regards,
Sudeep
#5 lore raw

Re: [PATCH v7 2/6] ACPI / processor_idle: Add support for Low Power Idle(LPI) states

Quoted 30 lines · Sudeep Holla
Quoted 20 lines · Daniel Lezcano
Quoted 13 lines · Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy
node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 5 lines

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 7 lines

Hi Sudeep,

I looked at the acpi processor idle code sometime ago and from my POV, it was awful, unnecessary complex and very difficult to maintain. The usage of flags all over the places is significant of the lack of control of the written code.

Quoted 3 lines

So you have any specific things in mind ? That's too broad and I know it's not so clean, but it's so for legacy reasons. I would leave that to Rafael to decide as it takes lots of testing to clean up these code.

The cleanup needs to be done at one point.

Question is when to do it, before adding LPI support or after doing that (and each option has its pros and cons IMO).

Quoted 6 lines
Quoted 4 lines

Even if you are not responsible of this implementation, the current situation forces you to add more awful code on top of that, which is clearly against "making Linux better".

OK

So if there are cases in which you need to make the code more complex because of the legacy stuff in there, I'd say it's better to clean it up first.

Thanks,
Rafael

#6 lore raw

Re: [PATCH v7 2/6] ACPI / processor_idle: Add support for Low Power Idle(LPI) states

Quoted 45 lines · Rafael J. Wysocki
Quoted 30 lines · Sudeep Holla
Quoted 20 lines · Daniel Lezcano
Quoted 13 lines · Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy
node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 5 lines

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 7 lines

Hi Sudeep,

I looked at the acpi processor idle code sometime ago and from my POV, it was awful, unnecessary complex and very difficult to maintain. The usage of flags all over the places is significant of the lack of control of the written code.

Quoted 3 lines

So you have any specific things in mind ? That's too broad and I know it's not so clean, but it's so for legacy reasons. I would leave that to Rafael to decide as it takes lots of testing to clean up these code.

The cleanup needs to be done at one point.

Question is when to do it, before adding LPI support or after doing that (and each option has its pros and cons IMO).

Quoted 5 lines
Quoted 4 lines

Even if you are not responsible of this implementation, the current situation forces you to add more awful code on top of that, which is clearly against "making Linux better".

Quoted 6 lines
Quoted 1 line

OK

So if there are cases in which you need to make the code more complex because of the legacy stuff in there, I'd say it's better to clean it up first.

I am not sure if Daniel was referring to anything specific. I have cleaned up in patch 1/6 for cstate. More cleanups can be done there but needs better understanding and reasoning for the current code which I don't have as they are mostly x86 related.

Unless someone points me what they would like to change and how, I don't have much in my mind to do here. Yes it may not look as clean as other code in the kernel relatively, but without complete understanding of the history/reasoning for the current state of code I wouldn't touch anything I don't understand.

I am open to make changes if there's something specific. Sorry I can't go ahead making changes the way I think based on some vague idea that the current code is not clean.

Signature · 2 lines
Regards,
Sudeep
#7 lore raw

Re: [PATCH v7 2/6] ACPI / processor_idle: Add support for Low Power Idle(LPI) states

Quoted 75 lines · Sudeep Holla
Quoted 53 lines · Rafael J. Wysocki
Quoted 36 lines · Sudeep Holla
Quoted 25 lines · Daniel Lezcano
Quoted 15 lines · Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor
hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy
node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 6 lines

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 7 lines

Hi Sudeep,

I looked at the acpi processor idle code sometime ago and from my POV, it was awful, unnecessary complex and very difficult to maintain. The usage of flags all over the places is significant of the lack of control of the written code.

Quoted 3 lines

So you have any specific things in mind ? That's too broad and I know it's not so clean, but it's so for legacy reasons. I would leave that to Rafael to decide as it takes lots of testing to clean up these code.

The cleanup needs to be done at one point.

Question is when to do it, before adding LPI support or after doing that (and each option has its pros and cons IMO).

Quoted 5 lines
Quoted 4 lines

Even if you are not responsible of this implementation, the current situation forces you to add more awful code on top of that, which is clearly against "making Linux better".

Quoted 7 lines
Quoted 1 line

OK

So if there are cases in which you need to make the code more complex because of the legacy stuff in there, I'd say it's better to clean it up first.

I am not sure if Daniel was referring to anything specific. I have cleaned up in patch 1/6 for cstate. More cleanups can be done there but needs better understanding and reasoning for the current code which I don't have as they are mostly x86 related.

Unless someone points me what they would like to change and how, I don't have much in my mind to do here. Yes it may not look as clean as other code in the kernel relatively, but without complete understanding of the history/reasoning for the current state of code I wouldn't touch anything I don't understand.

Quoted 3 lines

I am open to make changes if there's something specific. Sorry I can't go ahead making changes the way I think based on some vague idea that the current code is not clean.

Fair enough.

#10 lore raw

Re: [PATCH v7 4/6] cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms

In reply to Sudeep Holla
Quoted 29 lines · Sudeep Holla

The function arm_enter_idle_state is exactly the same in both generic ARM{32,64} CPUIdle driver and will be the same even on ARM64 backend for ACPI processor idle driver. So we can unify it and move it as generic_cpuidle_enter by introducing HAVE_GENERIC_CPUIDLE_ENTER and enabling the same on both ARM{32,64}.

This is in preparation of reuse of the generic cpuidle entry function for ACPI LPI support on ARM64.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
---
 arch/arm/Kconfig              |  1 +
 arch/arm/kernel/cpuidle.c     |  4 ++--
 arch/arm64/Kconfig            |  1 +
 arch/arm64/kernel/cpuidle.c   |  6 +++---
 drivers/cpuidle/Kconfig       |  3 +++
 drivers/cpuidle/cpuidle-arm.c | 21 +--------------------
 drivers/cpuidle/cpuidle.c     | 35 +++++++++++++++++++++++++++++++++++
 include/linux/cpuidle.h       |  8 ++++++++
 8 files changed, 54 insertions(+), 25 deletions(-)
arch/arm/Kconfig +0 -0
index 90542db1220d..52b3dca0381c 100644

arch/arm/Kconfig config ARM · line 57

Quoted 4 lines
arch/arm/Kconfig +1 -0
@@ -54,6 +54,7 @@ config ARM
 	select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
 	select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
 	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
+	select HAVE_GENERIC_CPUIDLE_ENTER

That "generic" part in the name concerns me a bit, because the thing is not really generic. It is "common on ARM" rather.

Quoted 136 lines
arch/arm/Kconfig +0 -0
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_HW_BREAKPOINT if (PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7))
 	select HAVE_IDE if PCI || ISA || PCMCIA
arch/arm/kernel/cpuidle.c +2 -2
index a44b268e12e1..49704e333bfc 100644
@@ -41,7 +41,7 @@ int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
 }
 
 /**
- * arm_cpuidle_suspend() - function to enter low power idle states
+ * cpuidle_generic_enter() - function to enter low power idle states
  * @index: an integer used as an identifier for the low level PM callbacks
  *
  * This function calls the underlying arch specific low level PM code as
@@ -50,7 +50,7 @@ int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
  * Returns -EOPNOTSUPP if no suspend callback is defined, the result of the
  * callback otherwise.
  */
-int arm_cpuidle_suspend(int index)
+int cpuidle_generic_enter(int index)
 {
 	int ret = -EOPNOTSUPP;
 	int cpu = smp_processor_id();
arch/arm64/Kconfig +1 -0
index 5a0a691d4220..0916b6e6c8ef 100644
@@ -76,6 +76,7 @@ config ARM64
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_GRAPH_TRACER
+	select HAVE_GENERIC_CPUIDLE_ENTER
 	select HAVE_GENERIC_DMA_COHERENT
 	select HAVE_HW_BREAKPOINT if PERF_EVENTS
 	select HAVE_IRQ_TIME_ACCOUNTING
arch/arm64/kernel/cpuidle.c +3 -3
index 06786fdaadeb..bade1b04ff12 100644
@@ -9,10 +9,10 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/cpuidle.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 
-#include <asm/cpuidle.h>
 #include <asm/cpu_ops.h>
 
 int arm_cpuidle_init(unsigned int cpu)
@@ -27,13 +27,13 @@ int arm_cpuidle_init(unsigned int cpu)
 }
 
 /**
- * cpu_suspend() - function to enter a low-power idle state
+ * cpuidle_generic_enter() - function to enter a low-power idle state
  * @arg: argument to pass to CPU suspend operations
  *
  * Return: 0 on success, -EOPNOTSUPP if CPU suspend hook not initialized, CPU
  * operations back-end error code otherwise.
  */
-int arm_cpuidle_suspend(int index)
+int cpuidle_generic_enter(int index)
 {
 	int cpu = smp_processor_id();
 
drivers/cpuidle/Kconfig +3 -0
index 7e48eb5bf0a7..e557289cff90 100644
@@ -45,4 +45,7 @@ endif
 
 config ARCH_NEEDS_CPU_IDLE_COUPLED
 	def_bool n
+
+config HAVE_GENERIC_CPUIDLE_ENTER
+	def_bool n
 endmenu
drivers/cpuidle/cpuidle-arm.c +1 -20
index e342565e8715..13012d8eba53 100644
@@ -36,26 +36,7 @@
 static int arm_enter_idle_state(struct cpuidle_device *dev,
 				struct cpuidle_driver *drv, int idx)
 {
-	int ret;
-
-	if (!idx) {
-		cpu_do_idle();
-		return idx;
-	}
-
-	ret = cpu_pm_enter();
-	if (!ret) {
-		/*
-		 * Pass idle state index to cpu_suspend which in turn will
-		 * call the CPU ops suspend protocol with idle index as a
-		 * parameter.
-		 */
-		ret = arm_cpuidle_suspend(idx);
-
-		cpu_pm_exit();
-	}
-
-	return ret ? -1 : idx;
+	return cpuidle_generic_enter_state(idx);
 }
 
 static struct cpuidle_driver arm_idle_driver = {
drivers/cpuidle/cpuidle.c +8 -0
index a4d0059e232c..e490dea98b89 100644
@@ -16,6 +16,7 @@
 #include <linux/pm_qos.h>
 #include <linux/cpu.h>
 #include <linux/cpuidle.h>
+#include <linux/cpu_pm.h>
 #include <linux/ktime.h>
 #include <linux/hrtimer.h>
 #include <linux/module.h>
@@ -255,6 +256,40 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
 }
 
 /**
+ * cpuidle_generic_enter_state - enter into the specified idle state using the
+ *				 generic callback if implemented
+ *
+ * @index: the index in the idle state table
+ *
+ * Returns the index in the idle state, -1 in case of error.
+ */

drivers/cpuidle/cpuidle.c int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) · line 275

Quoted 10 lines
drivers/cpuidle/cpuidle.c +10 -0
+int cpuidle_generic_enter_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
+		return idx;
+	}
+
+	ret = cpu_pm_enter();

If you look at the users of cpu_pm_enter(), they are all ARM. Nobody else uses it, so at least please put cpuidle_generic_enter_state() under a #ifdef to avoid building it in vain on non-ARM.

Quoted 41 lines
drivers/cpuidle/cpuidle.c +17 -0
+	if (!ret) {
+		/*
+		 * Pass idle state index to cpu_suspend which in turn will
+		 * call the CPU ops suspend protocol with idle index as a
+		 * parameter.
+		 */
+		ret = cpuidle_generic_enter(idx);
+
+		cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;
+}
+
+EXPORT_SYMBOL_GPL(cpuidle_generic_enter_state);
+
+/**
  * cpuidle_enter - enter into the specified idle state
  *
  * @drv:   the cpuidle driver tied with the cpu
include/linux/cpuidle.h +2 -0
index 07b83d32f66c..9fd3c10166fa 100644
@@ -154,6 +154,7 @@ extern int cpuidle_play_dead(void);
 extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
 static inline struct cpuidle_device *cpuidle_get_device(void)
 {return __this_cpu_read(cpuidle_devices); }
+extern int cpuidle_generic_enter_state(int idx);
 #else
 static inline void disable_cpuidle(void) { }
 static inline bool cpuidle_not_available(struct cpuidle_driver *drv,
@@ -190,6 +191,7 @@ static inline int cpuidle_play_dead(void) {return -ENODEV; }
 static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
 	struct cpuidle_device *dev) {return NULL; }
 static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; }
+static inline int cpuidle_generic_enter_state(int idx) { return -1; }
 #endif
 
 #if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND)

include/linux/cpuidle.h static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 252

Quoted 5 lines
include/linux/cpuidle.h +2 -0
@@ -246,6 +248,12 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
 {return 0;}
 #endif
 
+#ifdef CONFIG_HAVE_GENERIC_CPUIDLE_ENTER
+extern int cpuidle_generic_enter(int idx);

And if you put it under the #ifdef here, its definition also should go under the same #ifdef.

include/linux/cpuidle.h static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 259

Quoted 8 lines
include/linux/cpuidle.h +4 -0
+#else
+static inline int cpuidle_generic_enter(int idx) { return -1; }
+#endif
+
 #ifdef CONFIG_ARCH_HAS_CPU_RELAX
 #define CPUIDLE_DRIVER_STATE_START	1
 #else

Thanks,
Rafael

#11 lore raw

Re: [PATCH v7 4/6] cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms

Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Sudeep Holla

The function arm_enter_idle_state is exactly the same in both generic ARM{32,64} CPUIdle driver and will be the same even on ARM64 backend for ACPI processor idle driver. So we can unify it and move it as generic_cpuidle_enter by introducing HAVE_GENERIC_CPUIDLE_ENTER and enabling the same on both ARM{32,64}.

This is in preparation of reuse of the generic cpuidle entry function for ACPI LPI support on ARM64.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
---
  arch/arm/Kconfig              |  1 +
  arch/arm/kernel/cpuidle.c     |  4 ++--
  arch/arm64/Kconfig            |  1 +
  arch/arm64/kernel/cpuidle.c   |  6 +++---
  drivers/cpuidle/Kconfig       |  3 +++
  drivers/cpuidle/cpuidle-arm.c | 21 +--------------------
  drivers/cpuidle/cpuidle.c     | 35 +++++++++++++++++++++++++++++++++++
  include/linux/cpuidle.h       |  8 ++++++++
  8 files changed, 54 insertions(+), 25 deletions(-)
Quoted 13 lines

arch/arm/Kconfig config ARM · line 57

Quoted 9 lines
arch/arm/Kconfig +1 -0
index 90542db1220d..52b3dca0381c 100644
@@ -54,6 +54,7 @@ config ARM
  	select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
  	select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
  	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
+	select HAVE_GENERIC_CPUIDLE_ENTER

That "generic" part in the name concerns me a bit, because the thing is not really generic. It is "common on ARM" rather.

I agree and that's exactly what I told Daniel. It's rather just *ARM Generic*. Any preference on the name ? I had it header file under include/linu/cpuidle-arm.h in the previous version. Do you prefer that ?

[..]

Quoted 17 lines
Quoted 17 lines
arch/arm/Kconfig +13 -0
@@ -255,6 +256,40 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
  }
 
  /**
+ * cpuidle_generic_enter_state - enter into the specified idle state using the
+ *				 generic callback if implemented
+ *
+ * @index: the index in the idle state table
+ *
+ * Returns the index in the idle state, -1 in case of error.
+ */
+int cpuidle_generic_enter_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
Quoted 9 lines

arch/arm/Kconfig int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) · line 275

Quoted 4 lines
arch/arm/Kconfig +4 -0
+		return idx;
+	}
+
+	ret = cpu_pm_enter();

If you look at the users of cpu_pm_enter(), they are all ARM. Nobody else uses it, so at least please put cpuidle_generic_enter_state() under a #ifdef to avoid building it in vain on non-ARM.

Agreed, that should be taken care once I do the changes you are suggesting below.

[...]

Quoted 10 lines

arch/arm/Kconfig static inline int cpuidle_register_governor(struct cpuidle_governor *gov) · line 252

Quoted 6 lines
arch/arm/Kconfig +2 -0
@@ -246,6 +248,12 @@ static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
  {return 0;}
  #endif
 
+#ifdef CONFIG_HAVE_GENERIC_CPUIDLE_ENTER
+extern int cpuidle_generic_enter(int idx);

And if you put it under the #ifdef here, its definition also should go under the same #ifdef.

Yes I will do that.

Signature · 2 lines
Regards,
Sudeep
#12 lore raw

Re: [PATCH v7 4/6] cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms

Quoted 41 lines · Sudeep Holla
Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Sudeep Holla

The function arm_enter_idle_state is exactly the same in both generic ARM{32,64} CPUIdle driver and will be the same even on ARM64 backend for ACPI processor idle driver. So we can unify it and move it as generic_cpuidle_enter by introducing HAVE_GENERIC_CPUIDLE_ENTER and enabling the same on both ARM{32,64}.

This is in preparation of reuse of the generic cpuidle entry function for ACPI LPI support on ARM64.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
---
  arch/arm/Kconfig              |  1 +
  arch/arm/kernel/cpuidle.c     |  4 ++--
  arch/arm64/Kconfig            |  1 +
  arch/arm64/kernel/cpuidle.c   |  6 +++---
  drivers/cpuidle/Kconfig       |  3 +++
  drivers/cpuidle/cpuidle-arm.c | 21 +--------------------
  drivers/cpuidle/cpuidle.c     | 35 +++++++++++++++++++++++++++++++++++
  include/linux/cpuidle.h       |  8 ++++++++
  8 files changed, 54 insertions(+), 25 deletions(-)
Quoted 13 lines

arch/arm/Kconfig config ARM · line 57

Quoted 9 lines
arch/arm/Kconfig +1 -0
index 90542db1220d..52b3dca0381c 100644
@@ -54,6 +54,7 @@ config ARM
  	select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
  	select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
  	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
+	select HAVE_GENERIC_CPUIDLE_ENTER

That "generic" part in the name concerns me a bit, because the thing is not really generic. It is "common on ARM" rather.

Quoted 3 lines

I agree and that's exactly what I told Daniel. It's rather just *ARM Generic*. Any preference on the name ? I had it header file under include/linu/cpuidle-arm.h in the previous version. Do you prefer that ?

Well, I got confused by these names which probably means that they really are confusing. :-)

So the underlying observation is that ->enter() callbacks in some ARM code tend to do the same thing, ie. wrap the cpu_pm_enter()/exit() pair around the actual "low-level enter" routine, so the idea is to move the wrapping to the core and add the symbol plus standard header for the "low-level enter" thing.

But then ->enter has to point to the wrapper and that just invokes a static function defined somewhere.

So in fact what you want is to avoid code duplication in the source, but not in the binary.

For that, I'd use a macro like this:

#define CPU_IDLE_ENTER_WRAPPED(low_level_idle_enter, idx) \

({								\
	int __ret;						\
								\
	if (!idx) {						\
		cpu_do_idle();					\
		return idx;					\
	}							\
								\
	__ret = cpu_pm_enter();					\
	if (!__ret) {						\
		__ret = low_level_idle_enter(idx);		\
		cpu_pm_exit();					\
	}							\
								\
	__ret ? -1 : idx;					\
})

and then, whoever want's to generate a "wrapped" callback, will need to define the low_level_idle_enter thing, say my_low_level_idle_enter() and then do

int idle_enter(int idx)

{
	return CPU_IDLE_ENTER_WRAPPED(my_low_level_idle_enter, idx);
}

and point the ->enter callback to idle_enter().

No need for extra symbols, confusing function names and similar.

And the macro can go into cpuidle.h if you want.

Thanks,
Rafael

#13 lore raw

Re: [PATCH v7 4/6] cpuidle: introduce HAVE_GENERIC_CPUIDLE_ENTER for ARM{32,64} platforms

Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Sudeep Holla
Quoted 38 lines · Rafael J. Wysocki
Quoted 29 lines · Sudeep Holla

The function arm_enter_idle_state is exactly the same in both generic ARM{32,64} CPUIdle driver and will be the same even on ARM64 backend for ACPI processor idle driver. So we can unify it and move it as generic_cpuidle_enter by introducing HAVE_GENERIC_CPUIDLE_ENTER and enabling the same on both ARM{32,64}.

This is in preparation of reuse of the generic cpuidle entry function for ACPI LPI support on ARM64.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
---
   arch/arm/Kconfig              |  1 +
   arch/arm/kernel/cpuidle.c     |  4 ++--
   arch/arm64/Kconfig            |  1 +
   arch/arm64/kernel/cpuidle.c   |  6 +++---
   drivers/cpuidle/Kconfig       |  3 +++
   drivers/cpuidle/cpuidle-arm.c | 21 +--------------------
   drivers/cpuidle/cpuidle.c     | 35 +++++++++++++++++++++++++++++++++++
   include/linux/cpuidle.h       |  8 ++++++++
   8 files changed, 54 insertions(+), 25 deletions(-)
arch/arm/Kconfig +0 -0
index 90542db1220d..52b3dca0381c 100644

arch/arm/Kconfig config ARM · line 57

Quoted 4 lines
arch/arm/Kconfig +1 -0
@@ -54,6 +54,7 @@ config ARM
   	select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
   	select HAVE_FUNCTION_GRAPH_TRACER if (!THUMB2_KERNEL)
   	select HAVE_FUNCTION_TRACER if (!XIP_KERNEL)
+	select HAVE_GENERIC_CPUIDLE_ENTER

That "generic" part in the name concerns me a bit, because the thing is not really generic. It is "common on ARM" rather.

Quoted 7 lines
Quoted 3 lines

I agree and that's exactly what I told Daniel. It's rather just *ARM Generic*. Any preference on the name ? I had it header file under include/linu/cpuidle-arm.h in the previous version. Do you prefer that ?

Well, I got confused by these names which probably means that they really are confusing. :-)

I know and I am all for getting rid of that.

Quoted 41 lines

So the underlying observation is that ->enter() callbacks in some ARM code tend to do the same thing, ie. wrap the cpu_pm_enter()/exit() pair around the actual "low-level enter" routine, so the idea is to move the wrapping to the core and add the symbol plus standard header for the "low-level enter" thing.

But then ->enter has to point to the wrapper and that just invokes a static function defined somewhere.

So in fact what you want is to avoid code duplication in the source, but not in the binary.

For that, I'd use a macro like this:

#define CPU_IDLE_ENTER_WRAPPED(low_level_idle_enter, idx) \

({								\
	int __ret;						\
								\
	if (!idx) {						\
		cpu_do_idle();					\
		return idx;					\
	}							\
								\
	__ret = cpu_pm_enter();					\
	if (!__ret) {						\
		__ret = low_level_idle_enter(idx);		\
		cpu_pm_exit();					\
	}							\
								\
	__ret ? -1 : idx;					\
})

and then, whoever want's to generate a "wrapped" callback, will need to define the low_level_idle_enter thing, say my_low_level_idle_enter() and then do

int idle_enter(int idx)

{
	return CPU_IDLE_ENTER_WRAPPED(my_low_level_idle_enter, idx);
}
Quoted 6 lines

and point the ->enter callback to idle_enter().

No need for extra symbols, confusing function names and similar.

And the macro can go into cpuidle.h if you want.

Sounds good. Thanks for the suggestion. I will respin the series with this change then.

Signature · 2 lines
Regards,
Sudeep