Skip to contentSkip to conversation

New idle device-tree format and support for versioned stop state

RFC In review Abhishek Goel 2 participants 5 messages Aug 23, 2019 – Aug 27, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover New idle device-tree format and support for versioned stop state

Background
------------------

Previously if a older kernel runs on a newer firmware, it may enable all available states irrespective of its capability of handling it. Consider a case that some stop state has a bug, we end up disabling all the stop states. This patch introduces selective control to solve this problem.

Previous version of these patches can be found at:
https://lkml.org/lkml/2018/10/11/544
These patch however also had patches for support of opal save-restore which now I am decoupling and will take them seperately.
I have posted the corresponding skiboot patches for this kernel patchset here : https://patchwork.ozlabs.org/cover/1144587/

What's new?
--------------------

Add stop states under ibm,idle-states in addition to the current array based device tree properties.

New device tree format adds a compatible flag which has version corresponding to every state, so that only kernel which has the capability to handle the version of stop state will enable it. Drawback of the array based dt node is that versioning of idle states is not possible.

Older kernel will still see stop0 and stop0_lite in older format and we will deprecate it after some time.

Consider a case that stop4 has a bug. We take the following steps to mitigate the problem.

1) Change compatible string for stop4 in OPAL to "stop4,v2" from "stop4,v1", i.e. basicallly bump up the previous version and ship the new firmware.

2) The kernel will ignore stop4 as it won't be able to recognize this new version. Kernel will also ignore all the deeper states because its possible that a cpu have requested for a deeper state but was never able to enter into it. But we will still have shallower states that are there before stop 4. This, thus prevents from completely disabling stop states.

Linux kernel can now look at the version string and decide if it has the ability to handle that idle state. Henceforth, if kernel does not know about a version, it will skip that state and all the deeper state.

Once when the workaround are implemented into the kernel, we can bump up the known version in kernel for that state, so that support can be enabled once again in kernel.

New Device-tree :

Final output

       power-mgt {
            ...
         ibm,enabled-stop-levels = <0xec000000>;
         ibm,cpu-idle-state-psscr-mask = <0x0 0x3003ff 0x0 0x3003ff>;
         ibm,cpu-idle-state-latencies-ns = <0x3e8 0x7d0>;
         ibm,cpu-idle-state-psscr = <0x0 0x330 0x0 0x300330>;
         ibm,cpu-idle-state-flags = <0x100000 0x101000>;
         ibm,cpu-idle-state-residency-ns = <0x2710 0x4e20>;
         ibm,idle-states {
                     stop4 {
                         flags = <0x207000>;
                         compatible = "stop4,v1",
                         psscr-mask = <0x0 0x3003ff>;
                         latency-ns = <0x186a0>;
                         residency-ns = <0x989680>;
                         psscr = <0x0 0x300374>;
			 ...
                  };
                    ...
                    stop11 {
                         ...
                         compatible = "stop11,v1",
                         ...
                  };
             };

Abhishek Goel (3):
cpuidle/powernv : Pass state pointer instead of values to stop loop cpuidle/powernv: Add support for versioned stop states cpuidle/powernv : Add flags to identify stop state type

 arch/powerpc/include/asm/cpuidle.h    |   8 +-
 arch/powerpc/include/asm/opal-api.h   |   7 +
 arch/powerpc/include/asm/processor.h  |   5 +-
 arch/powerpc/platforms/powernv/idle.c | 371 +++++++++++++++++++++-----
 drivers/cpuidle/cpuidle-powernv.c     |  81 +++---
 5 files changed, 363 insertions(+), 109 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

RFC 1/3 cpuidle/powernv : Pass state pointer instead of values to stop loop

Instead of passing psscr_val and psscr_mask, we will pass state pointer to stop loop. This will help to figure out the method to enter/exit idle state. Removed psscr_mask and psscr_val from driver idle code. Same has also been done in platform idle code.
Also, added some cleanups and debugging info.

---
 arch/powerpc/include/asm/processor.h  |  5 +-
 arch/powerpc/platforms/powernv/idle.c | 50 ++++++++-----------
 drivers/cpuidle/cpuidle-powernv.c     | 69 +++++++++++++--------------
 3 files changed, 55 insertions(+), 69 deletions(-)
arch/powerpc/include/asm/processor.h +2 -3
index a9993e7a443b..855666e8d271 100644
@@ -39,6 +39,7 @@
 #include <linux/thread_info.h>
 #include <asm/ptrace.h>
 #include <asm/hw_breakpoint.h>
+#include <asm/cpuidle.h>
 
 /* We do _not_ want to define new machine types at all, those must die
  * in favor of using the device-tree
@@ -419,9 +420,7 @@ enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
 extern int powersave_nap;	/* set if nap mode can be used in idle loop */
 
 extern void power7_idle_type(unsigned long type);
-extern void power9_idle_type(unsigned long stop_psscr_val,
-			      unsigned long stop_psscr_mask);
-
+extern void power9_idle_type(struct pnv_idle_states_t *state);
 extern void flush_instruction_cache(void);
 extern void hard_reset_now(void);
 extern void poweroff_now(void);
arch/powerpc/platforms/powernv/idle.c +21 -29

135 lines not on this page · raw message

drivers/cpuidle/cpuidle-powernv.c +32 -37

150 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

RFC 2/3 cpuidle/powernv: Add support for versioned stop states

In reply to Abhishek Goel

New device tree format adds a compatible flag which has version corresponding to every state, so that only kernel which has the capability to handle the version of stop state will enable it. Drawback of the array based dt node is that versioning of idle states is not possible.

Older kernel will still see stop0 and stop0_lite in older format and we will deprecate it after some time.

Consider a case that stop4 has a bug. We take the following steps to mitigate the problem.

1) Change compatible string for stop4 in OPAL to "stop4,v2" from "stop4,v1", i.e. basicallly bump up the previous version and ship the new firmware.
2) The kernel will ignore stop4 as it won't be able to recognize this new version. Kernel will also ignore all the deeper states because its possible that a cpu have requested for a deeper state but was never able to enter into it. But we will still have shallower states that are there before stop 4. This, thus prevents from completely disabling stop states.

Linux kernel can now look at the version string and decide if it has the ability to handle that idle state. Henceforth, if kernel does not know about a version, it will skip that state and all the deeper state.

Once when the workaround are implemented into the kernel, we can bump up the known version in kernel for that state, so that support can be enabled once again in kernel.

New Device-tree :

Final output

       power-mgt {
            ...
         ibm,enabled-stop-levels = <0xec000000>;
         ibm,cpu-idle-state-psscr-mask = <0x0 0x3003ff 0x0 0x3003ff>;
         ibm,cpu-idle-state-latencies-ns = <0x3e8 0x7d0>;
         ibm,cpu-idle-state-psscr = <0x0 0x330 0x0 0x300330>;
         ibm,cpu-idle-state-flags = <0x100000 0x101000>;
         ibm,cpu-idle-state-residency-ns = <0x2710 0x4e20>;
         ibm,idle-states {
                     stop4 {
                         flags = <0x207000>;
                         compatible = "stop4,v1",
                         psscr-mask = <0x0 0x3003ff>;
                         latency-ns = <0x186a0>;
                         residency-ns = <0x989680>;
                         psscr = <0x0 0x300374>;
			 ...
                  };
                    ...
                    stop11 {
                         ...
                         compatible = "stop11,v1",
                         ...
                  };
             };

Since state pointer is being passed to stop loop, I have separated idle fast path for lite, shallow and deep states. This improves the readability of the code and also future maintainability of the code. Stop handle corresponding to each state can be called directly since state pointer is being passed now.

---
 arch/powerpc/include/asm/cpuidle.h    |   8 +-
 arch/powerpc/platforms/powernv/idle.c | 331 +++++++++++++++++++++++---
 2 files changed, 299 insertions(+), 40 deletions(-)
arch/powerpc/include/asm/cpuidle.h +6 -2
index 9844b3ded187..5eb9a98fcb86 100644
@@ -70,15 +70,19 @@
 
 #ifndef __ASSEMBLY__
 
-#define PNV_IDLE_NAME_LEN    16
+#define PNV_VERSION_LEN		25
+#define PNV_IDLE_NAME_LEN	16
 struct pnv_idle_states_t {
 	char name[PNV_IDLE_NAME_LEN];
+	char compat_version[PNV_VERSION_LEN];
 	u32 latency_ns;
 	u32 residency_ns;
 	u64 psscr_val;
 	u64 psscr_mask;
-	u32 flags;
+	u64 flags;
 	bool valid;
+	unsigned long (*stop_handle)(struct pnv_idle_states_t *state,
+				     bool mmu_on);
 };
 
 extern struct pnv_idle_states_t *pnv_idle_states;
arch/powerpc/platforms/powernv/idle.c +293 -38

441 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

RFC 3/3 cpuidle/powernv : Add flags to identify stop state type

In reply to Abhishek Goel

Removed threshold latency which was being used to decide if a state is cpuidle type or not. This decision can be taken using flags, as this information has been encapsulated in the state->flags and being read from idle device-tree.

---
 arch/powerpc/include/asm/opal-api.h |  7 +++++++
 drivers/cpuidle/cpuidle-powernv.c   | 16 +++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/opal-api.h +7 -0
index 383242eb0dea..b9068fee21d8 100644
@@ -233,6 +233,13 @@
 #define OPAL_PM_STOP_INST_FAST		0x00100000
 #define OPAL_PM_STOP_INST_DEEP		0x00200000
 
+/*
+ * Flags for stop states to distinguish between cpuidle and
+ * cpuoffline type of states.
+ */
+#define OPAL_PM_STOP_CPUIDLE		0x01000000
+#define OPAL_PM_STOP_CPUHOTPLUG		0x02000000
+
 /*
  * OPAL_CONFIG_CPU_IDLE_STATE parameters
  */
drivers/cpuidle/cpuidle-powernv.c +9 -7
index 1b6c84d4ac77..1a33a548b769 100644
@@ -270,8 +270,13 @@ static int powernv_add_idle_states(void)
 		goto out;
 	}
 
-	/* TODO: Count only states which are eligible for cpuidle */
-	dt_idle_states = nr_pnv_idle_states;
+	/* Count only cpuidle states*/
+	for (i = 0; i < nr_pnv_idle_states; i++) {
+		if (pnv_idle_states[i].flags & OPAL_PM_STOP_CPUIDLE)
+			dt_idle_states++;
+	}
+	pr_info("idle states in dt = %d , states with idle flag = %d",
+				nr_pnv_idle_states, dt_idle_states);
 
 	/*
 	 * Since snooze is used as first idle state, max idle states allowed is
@@ -300,11 +305,8 @@ static int powernv_add_idle_states(void)
 			continue;
 		}
 
-		/*
-		 * If an idle state has exit latency beyond
-		 * POWERNV_THRESHOLD_LATENCY_NS then don't use it in cpu-idle.
-		 */
-		if (state->latency_ns > POWERNV_THRESHOLD_LATENCY_NS) {
+		/* Check whether a state is of cpuidle type */
+		if ((state->flags & OPAL_PM_STOP_CPUIDLE) != state->flags) {
 			pr_info("State %d is not idletype\n", i);
 			continue;
 		}
Signature · 1 line
2.17.1
#4 lore raw
In reply to Abhishek Goel

Abhishek Goel's on August 23, 2019 5:09 pm:

Quoted 71 lines

Background
------------------

Previously if a older kernel runs on a newer firmware, it may enable all available states irrespective of its capability of handling it. Consider a case that some stop state has a bug, we end up disabling all the stop states. This patch introduces selective control to solve this problem.

Previous version of these patches can be found at:
https://lkml.org/lkml/2018/10/11/544
These patch however also had patches for support of opal save-restore which now I am decoupling and will take them seperately.
I have posted the corresponding skiboot patches for this kernel patchset here : https://patchwork.ozlabs.org/cover/1144587/

What's new?
--------------------

Add stop states under ibm,idle-states in addition to the current array based device tree properties.

New device tree format adds a compatible flag which has version corresponding to every state, so that only kernel which has the capability to handle the version of stop state will enable it. Drawback of the array based dt node is that versioning of idle states is not possible.

Older kernel will still see stop0 and stop0_lite in older format and we will deprecate it after some time.

Consider a case that stop4 has a bug. We take the following steps to mitigate the problem.

1) Change compatible string for stop4 in OPAL to "stop4,v2" from "stop4,v1", i.e. basicallly bump up the previous version and ship the new firmware.

2) The kernel will ignore stop4 as it won't be able to recognize this new version. Kernel will also ignore all the deeper states because its possible that a cpu have requested for a deeper state but was never able to enter into it. But we will still have shallower states that are there before stop 4. This, thus prevents from completely disabling stop states.

Linux kernel can now look at the version string and decide if it has the ability to handle that idle state. Henceforth, if kernel does not know about a version, it will skip that state and all the deeper state.

Once when the workaround are implemented into the kernel, we can bump up the known version in kernel for that state, so that support can be enabled once again in kernel.

New Device-tree :

Final output

       power-mgt {
            ...
         ibm,enabled-stop-levels = <0xec000000>;
         ibm,cpu-idle-state-psscr-mask = <0x0 0x3003ff 0x0 0x3003ff>;
         ibm,cpu-idle-state-latencies-ns = <0x3e8 0x7d0>;
         ibm,cpu-idle-state-psscr = <0x0 0x330 0x0 0x300330>;
         ibm,cpu-idle-state-flags = <0x100000 0x101000>;
         ibm,cpu-idle-state-residency-ns = <0x2710 0x4e20>;
         ibm,idle-states {
                     stop4 {
                         flags = <0x207000>;
                         compatible = "stop4,v1",
                         psscr-mask = <0x0 0x3003ff>;
                         latency-ns = <0x186a0>;
                         residency-ns = <0x989680>;
                         psscr = <0x0 0x300374>;
			 ...
Quoted 8 lines
                  };
                    ...
                    stop11 {
                         ...
                         compatible = "stop11,v1",
                         ...
                  };
             };

I'm not sure about this. I think the real problem we have is that the OPAL stop API is not actually implementation independent. Because we *can* selectively disable stop states in the firmware if there is a hardware/firmware problem with them.

So we need a way to rev ISA/Book4/OPAL stuff so the kernel won't try to use it if it's incapable.

We have that today in dt-cpu-ftrs. POWER9 advertises the "idle-stop" feature. An incompatible implementation could advertise idle-stop-v4.

That won't allow individual states to remain back compatible, but if there is a new implementation which changes any behaviour it needs to be incopmatible, even if Linux happens to not rely on said behaviour yet. So I don't think we can keep any of them (except stop0 lite) compatible, so I don't see a real downside (we'll have to discuss this offline).

Thanks,
Nick