Skip to contentSkip to conversation

DT: bindings: Add cooling cells for idle states

PATCH In review Daniel Lezcano 3 participants 10 messages Dec 19, 2019 – Jan 28, 2020

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

PATCH 1/2 DT: bindings: Add cooling cells for idle states

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/arm/idle-states.txt +11 -0
index 771f5d20ae18..702a19b6b0b2 100644
@@ -346,6 +346,17 @@ follows:
 	idle-states node. Please refer to the entry-method bindings
 	documentation for properties definitions.
 
+	When the idle state is used as a cooling device, the #cooling-cells
+	must be added in order to allow registering it.
+
+	- #cooling-cells:
+		Usage: Optional
+		Type: unsigned
+		Size: one cell
+		Definition: A cooling device specific information. At least
+			    must be two. Refer to the thermal DT bindings for
+			    more details.
+
 ===========================================
 4 - Examples
 ===========================================
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 thermal: cpuidle: Register cpuidle cooling device

The cpuidle driver can be used as a cooling device by injecting idle cycles. The DT binding for the idle state added an optional

When the property is set, register the cpuidle driver with the idle state node pointer as a cooling device. The thermal framework will do the association automatically with the thermal zone via the cooling-device defined in the device tree cooling-maps section.

---
 drivers/cpuidle/dt_idle_states.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/cpuidle/dt_idle_states.c +8 -0
index d06d21a9525d..34bd65197342 100644
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) "DT idle-states: " fmt
 
+#include <linux/cpu_cooling.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
 #include <linux/errno.h>
@@ -205,6 +206,13 @@ int dt_init_idle_driver(struct cpuidle_driver *drv,
 			err = -EINVAL;
 			break;
 		}
+
+		if (of_find_property(state_node, "#cooling-cells", NULL)) {
+			err = cpuidle_of_cooling_register(state_node, drv);
+			if (err)
+				break;
+		}
+
 		of_node_put(state_node);
 	}
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 2/2] thermal: cpuidle: Register cpuidle cooling device

Hi Daniel,

Quoted 26 lines · Daniel Lezcano

The cpuidle driver can be used as a cooling device by injecting idle cycles. The DT binding for the idle state added an optional

When the property is set, register the cpuidle driver with the idle state node pointer as a cooling device. The thermal framework will do the association automatically with the thermal zone via the cooling-device defined in the device tree cooling-maps section.

---
 drivers/cpuidle/dt_idle_states.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/cpuidle/dt_idle_states.c +1 -0
index d06d21a9525d..34bd65197342 100644
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) "DT idle-states: " fmt
 
+#include <linux/cpu_cooling.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
 #include <linux/errno.h>

drivers/cpuidle/dt_idle_states.c int dt_init_idle_driver(struct cpuidle_driver *drv, · line 211

Quoted 6 lines
drivers/cpuidle/dt_idle_states.c +3 -0
@@ -205,6 +206,13 @@ int dt_init_idle_driver(struct cpuidle_driver *drv,
 			err = -EINVAL;
 			break;
 		}
+
+		if (of_find_property(state_node, "#cooling-cells", NULL)) {
+			err = cpuidle_of_cooling_register(state_node, drv);

cpuidle_of_cooling_register() returns a struct thermal_cooling_device *, so you probably want to use PTR_ERR() here.

Could it be a problem that the cooling device isn't unregistered even when all associated cores are taken offline?

#3 lore raw

Re: [PATCH 2/2] thermal: cpuidle: Register cpuidle cooling device

Quoted 24 lines · Matthias Kaehlcke

Hi Daniel,

Quoted 21 lines · Daniel Lezcano

The cpuidle driver can be used as a cooling device by injecting idle cycles. The DT binding for the idle state added an optional

When the property is set, register the cpuidle driver with the idle state node pointer as a cooling device. The thermal framework will do the association automatically with the thermal zone via the cooling-device defined in the device tree cooling-maps section.

---
 drivers/cpuidle/dt_idle_states.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/cpuidle/dt_idle_states.c +0 -0
index d06d21a9525d..34bd65197342 100644
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) "DT idle-states: " fmt
 
Quoted 14 lines

drivers/cpuidle/dt_idle_states.c int dt_init_idle_driver(struct cpuidle_driver *drv, · line 211

Quoted 11 lines
drivers/cpuidle/dt_idle_states.c +4 -0
+#include <linux/cpu_cooling.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
 #include <linux/errno.h>
@@ -205,6 +206,13 @@ int dt_init_idle_driver(struct cpuidle_driver *drv,
 			err = -EINVAL;
 			break;
 		}
+
+		if (of_find_property(state_node, "#cooling-cells", NULL)) {
+			err = cpuidle_of_cooling_register(state_node, drv);

cpuidle_of_cooling_register() returns a struct thermal_cooling_device *, so you probably want to use PTR_ERR() here.

Right, I'm about the send the V6 which returns an int.

Quoted 2 lines

Could it be a problem that the cooling device isn't unregistered even when all associated cores are taken offline?

The cooling device relies on the powercap/idle_inject.c which is based on the smpboot API. This one takes care of parking the per cpu pinned tasks. So AFAICS, it is fine.

Signature · 5 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
maintainer
#4 lore raw
In reply to Daniel Lezcano
Quoted 8 lines · Daniel Lezcano

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

Quoted 4 lines
---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

This is now a schema in my tree. Can you rebase on that and I'll pick up the binding change.

Rob

#5 lore raw

Hi Rob,

Quoted 10 lines · Rob Herring
Quoted 8 lines · Daniel Lezcano

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

Quoted 7 lines
Quoted 4 lines
---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

This is now a schema in my tree. Can you rebase on that and I'll pick up the binding change.

Mmh, I'm now having some doubts about this binding because it will restrict any improvement of the cooling device for the future.

It looks like adding a node to the CPU for the cooling device is more adequate.
eg:
CPU0: cpu@300 {
device_type = "cpu";
compatible = "arm,cortex-a9";
reg = <0x300>;
/* cpufreq controls */
operating-points = <998400 0

          800000 0
          400000 0
          200000 0>;
   clocks = <&prcmu_clk PRCMU_ARMSS>;
   clock-names = "cpu";
   clock-latency = <20000>;
   #cooling-cells = <2>;
   thermal-idle {
      #cooling-cells = <2>;

};
};

[ ... ]

cooling-device = <&{/cpus/cpu@300/thermal-idle}

			THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;

A quick test with different configurations combination shows it is much more flexible and it is open for future changes.

What do you think?

maintainer
#6 lore raw
Quoted 49 lines · Daniel Lezcano

Hi Rob,

Quoted 10 lines · Rob Herring
Quoted 8 lines · Daniel Lezcano

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

Quoted 7 lines
Quoted 4 lines
---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

This is now a schema in my tree. Can you rebase on that and I'll pick up the binding change.

Mmh, I'm now having some doubts about this binding because it will restrict any improvement of the cooling device for the future.

It looks like adding a node to the CPU for the cooling device is more adequate.
eg:

CPU0: cpu@300 {
   device_type = "cpu";
   compatible = "arm,cortex-a9";
   reg = <0x300>;
   /* cpufreq controls */
   operating-points = <998400 0
          800000 0
          400000 0
          200000 0>;
   clocks = <&prcmu_clk PRCMU_ARMSS>;
   clock-names = "cpu";
   clock-latency = <20000>;
   #cooling-cells = <2>;
   thermal-idle {
      #cooling-cells = <2>;
   };
};

[ ... ]

Quoted 7 lines

cooling-device = <&{/cpus/cpu@300/thermal-idle}

                        THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;

A quick test with different configurations combination shows it is much more flexible and it is open for future changes.

What do you think?

Why do you need #cooling-cells in both cpu node and a child node? It's really only 1 device.

Maybe you could add another cell to contain an idle state node if that helps?

Rob

#7 lore raw
Quoted 54 lines · Rob Herring
Quoted 52 lines · Daniel Lezcano

Hi Rob,

Quoted 10 lines · Rob Herring
Quoted 8 lines · Daniel Lezcano

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

Quoted 7 lines
Quoted 4 lines
---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

This is now a schema in my tree. Can you rebase on that and I'll pick up the binding change.

Mmh, I'm now having some doubts about this binding because it will restrict any improvement of the cooling device for the future.

It looks like adding a node to the CPU for the cooling device is more adequate.
eg:

CPU0: cpu@300 {
   device_type = "cpu";
   compatible = "arm,cortex-a9";
   reg = <0x300>;
   /* cpufreq controls */
   operating-points = <998400 0
          800000 0
          400000 0
          200000 0>;
   clocks = <&prcmu_clk PRCMU_ARMSS>;
   clock-names = "cpu";
   clock-latency = <20000>;
   #cooling-cells = <2>;
   thermal-idle {
      #cooling-cells = <2>;
   };
};

[ ... ]

cooling-device = <&{/cpus/cpu@300/thermal-idle}

                        THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
Quoted 6 lines
Quoted 4 lines

A quick test with different configurations combination shows it is much more flexible and it is open for future changes.

What do you think?

Why do you need #cooling-cells in both cpu node and a child node?

The cooling-cells in the CPU node is for the cpufreq cooling device and the one in the thermal-idle is for the idle cooling device. The first one is for backward compatibility. If no cpufreq cooling device exists then the first cooling-cells is not needed. May be we can define "thermal-dvfs" at the same time, so we do the change for both and prevent mixing the old and new bindings?

Quoted 1 line

It's really only 1 device.

The main problem is how the thermal framework is designed. When we register a cooling device we pass the node pointer and the core framework checks it has a #cooling-cells. Then cooling-maps must have a phandle to the node we registered before as a cooling device. This is when the thermal-zone <-> cooling device association is done.

With the cpufreq cooling device, the "CPU slot" is now used and we can't point to it without ambiguity as we can have different cooling device strategies for the same CPU at different temperatures.

Is it acceptable the following?

CPU0: cpu@300 {
[ ... ]

   thermal-idle {
      #cooling-cells = <2>;

};

   thermal-dvfs {
      #cooling-cells = <2>;

}
};

Or alternatively, can we define a passive-cooling node?

thermal-cooling: passive0 {
#cooling-cells = <2>;
strategy="dvfs" | "idle"
cooling-device=<&CPU0>
};

cooling-device = <&passive0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;

Quoted 1 line

Maybe you could add another cell to contain an idle state node if that

helps?

(Assuming you are referring to a phandle to an idle state) The idle states are grouped per cluster because the CPUs belonging to the same cluster have the same idle states characteristics. Because of that, the phandle will point to the same node and it will be impossible to specify a per cpu cooling device, only per cluster.

Signature · 5 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
#8 lore raw

Hi Rob,

a gentle ping on the questions below.

Quoted 115 lines · Daniel Lezcano
Quoted 54 lines · Rob Herring
Quoted 52 lines · Daniel Lezcano

Hi Rob,

Quoted 10 lines · Rob Herring
Quoted 8 lines · Daniel Lezcano

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

Quoted 7 lines
Quoted 4 lines
---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

This is now a schema in my tree. Can you rebase on that and I'll pick up the binding change.

Mmh, I'm now having some doubts about this binding because it will restrict any improvement of the cooling device for the future.

It looks like adding a node to the CPU for the cooling device is more adequate.
eg:

CPU0: cpu@300 {
   device_type = "cpu";
   compatible = "arm,cortex-a9";
   reg = <0x300>;
   /* cpufreq controls */
   operating-points = <998400 0
          800000 0
          400000 0
          200000 0>;
   clocks = <&prcmu_clk PRCMU_ARMSS>;
   clock-names = "cpu";
   clock-latency = <20000>;
   #cooling-cells = <2>;
   thermal-idle {
      #cooling-cells = <2>;
   };
};

[ ... ]

cooling-device = <&{/cpus/cpu@300/thermal-idle}

                        THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
Quoted 6 lines
Quoted 4 lines

A quick test with different configurations combination shows it is much more flexible and it is open for future changes.

What do you think?

Why do you need #cooling-cells in both cpu node and a child node?

The cooling-cells in the CPU node is for the cpufreq cooling device and the one in the thermal-idle is for the idle cooling device. The first one is for backward compatibility. If no cpufreq cooling device exists then the first cooling-cells is not needed. May be we can define "thermal-dvfs" at the same time, so we do the change for both and prevent mixing the old and new bindings?

Quoted 1 line

It's really only 1 device.

The main problem is how the thermal framework is designed. When we register a cooling device we pass the node pointer and the core framework checks it has a #cooling-cells. Then cooling-maps must have a phandle to the node we registered before as a cooling device. This is when the thermal-zone <-> cooling device association is done.

With the cpufreq cooling device, the "CPU slot" is now used and we can't point to it without ambiguity as we can have different cooling device strategies for the same CPU at different temperatures.

Is it acceptable the following?

CPU0: cpu@300 {
   [ ... ]
   thermal-idle {
      #cooling-cells = <2>;
   };

   thermal-dvfs {
      #cooling-cells = <2>;
   }
};

Or alternatively, can we define a passive-cooling node?

thermal-cooling: passive0 {
   #cooling-cells = <2>;
   strategy="dvfs" | "idle"
   cooling-device=<&CPU0>
};

cooling-device = <&passive0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;

Quoted 1 line

Maybe you could add another cell to contain an idle state node if that

helps?

(Assuming you are referring to a phandle to an idle state) The idle states are grouped per cluster because the CPUs belonging to the same cluster have the same idle states characteristics. Because of that, the phandle will point to the same node and it will be impossible to specify a per cpu cooling device, only per cluster.

Signature · 5 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
maintainer
#9 lore raw
In reply to Daniel Lezcano
Quoted 78 lines · Daniel Lezcano
Quoted 54 lines · Rob Herring
Quoted 52 lines · Daniel Lezcano

Hi Rob,

Quoted 10 lines · Rob Herring
Quoted 8 lines · Daniel Lezcano

Add DT documentation to add an idle state as a cooling device. The CPU is actually the cooling device but the definition is already used by frequency capping. As we need to make cpufreq capping and idle injection to co-exist together on the system in order to mitigate at different trip points, the CPU can not be used as the cooling device for idle injection. The idle state can be seen as an hardware feature and therefore as a component for the passive mitigation.

Quoted 7 lines
Quoted 4 lines
---
 Documentation/devicetree/bindings/arm/idle-states.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

This is now a schema in my tree. Can you rebase on that and I'll pick up the binding change.

Mmh, I'm now having some doubts about this binding because it will restrict any improvement of the cooling device for the future.

It looks like adding a node to the CPU for the cooling device is more adequate.
eg:

CPU0: cpu@300 {
   device_type = "cpu";
   compatible = "arm,cortex-a9";
   reg = <0x300>;
   /* cpufreq controls */
   operating-points = <998400 0
          800000 0
          400000 0
          200000 0>;
   clocks = <&prcmu_clk PRCMU_ARMSS>;
   clock-names = "cpu";
   clock-latency = <20000>;
   #cooling-cells = <2>;
   thermal-idle {
      #cooling-cells = <2>;
   };
};

[ ... ]

cooling-device = <&{/cpus/cpu@300/thermal-idle}

                        THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
Quoted 6 lines
Quoted 4 lines

A quick test with different configurations combination shows it is much more flexible and it is open for future changes.

What do you think?

Why do you need #cooling-cells in both cpu node and a child node?

The cooling-cells in the CPU node is for the cpufreq cooling device and the one in the thermal-idle is for the idle cooling device. The first one is for backward compatibility. If no cpufreq cooling device exists then the first cooling-cells is not needed. May be we can define "thermal-dvfs" at the same time, so we do the change for both and prevent mixing the old and new bindings?

Quoted 1 line

It's really only 1 device.

The main problem is how the thermal framework is designed. When we register a cooling device we pass the node pointer and the core framework checks it has a #cooling-cells. Then cooling-maps must have a phandle to the node we registered before as a cooling device. This is when the thermal-zone <-> cooling device association is done.

Quoted 3 lines

With the cpufreq cooling device, the "CPU slot" is now used and we can't point to it without ambiguity as we can have different cooling device strategies for the same CPU at different temperatures.

So why can't you have:

cooling-device = <&cpu0 DVFS>;

cooling-device = <&cpu0 IDLE>;

(any additional cells omitted for simplicity)

Quoted 24 lines

Is it acceptable the following?

CPU0: cpu@300 {
   [ ... ]
   thermal-idle {
      #cooling-cells = <2>;
   };

   thermal-dvfs {
      #cooling-cells = <2>;
   }
};

Or alternatively, can we define a passive-cooling node?

thermal-cooling: passive0 {
   #cooling-cells = <2>;
   strategy="dvfs" | "idle"
   cooling-device=<&CPU0>
};

cooling-device = <&passive0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;

Quoted 8 lines
Quoted 1 line

Maybe you could add another cell to contain an idle state node if that

helps?

(Assuming you are referring to a phandle to an idle state) The idle states are grouped per cluster because the CPUs belonging to the same cluster have the same idle states characteristics. Because of that, the phandle will point to the same node and it will be impossible to specify a per cpu cooling device, only per cluster.

What I meant was a phandle in the cooling cells, so #cooling-cells == 3:

cooling-device = <&cpu0 0 0 &cpu_idle_state>, <&cpu1 0 0 &cpu_idle_state>;

Phandle args being a phandle is a bit unusual, but certainly possible.

Rob