linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] thermal: hisilicon: enable power allocator for Hi6220
@ 2016-02-20 15:52 Leo Yan
  2016-02-20 15:52 ` [PATCH 1/3] thermal: hisilicon: support to use any sensor Leo Yan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Leo Yan @ 2016-02-20 15:52 UTC (permalink / raw)
  To: Wei Xu, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Catalin Marinas, Will Deacon, Zhang Rui,
	Eduardo Valentin, kongxinwei, Javi Merino, Punit Agrawal
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-pm, Leo Yan

Hi6220 has octa-core so it has quite high power consumption when run
benchmark and introduces high temperature for SoC. So need enable
thermal gover to control temperature and also cannot hurt much for
performance after impose cooling operations on CPU.

This patch series is to enable power allocator for Hi6220. The power
allocator just uses only one sensor, so patch 1 is to fix sensor driver
so let it can initialize driver successfully with only enabling one
sensor.

After profiling on Hikey, the power model has been simplized with only
dynamic coefficent, and now it's convienence to pass it from CPU node.
So patch 2 and 3 bind sensor and pass power model parameters.

This patch series have been tested on 96boards Hikey.


Leo Yan (3):
  thermal: hisilicon: support to use any sensor
  arm64: dts: register Hi6220's thermal sensor
  arm64: dts: register Hi6220's thermal zone for power allocator

 arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 45 +++++++++++++++++++++++++++++++
 drivers/thermal/hisi_thermal.c            | 33 ++++++++++++++---------
 2 files changed, 65 insertions(+), 13 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] thermal: hisilicon: support to use any sensor
  2016-02-20 15:52 [PATCH 0/3] thermal: hisilicon: enable power allocator for Hi6220 Leo Yan
@ 2016-02-20 15:52 ` Leo Yan
  2016-02-20 15:52 ` [PATCH 2/3] arm64: dts: register Hi6220's thermal sensor Leo Yan
  2016-02-20 15:52 ` [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator Leo Yan
  2 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-02-20 15:52 UTC (permalink / raw)
  To: Wei Xu, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Catalin Marinas, Will Deacon, Zhang Rui,
	Eduardo Valentin, kongxinwei, Javi Merino, Punit Agrawal
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-pm, Leo Yan

In current code sensor driver registers all 4 sensors together and if
any of them has not bound to thermal zone successfully then driver will
return failure for driver's initialization. As a result, if DT binds
thermal zone with only one sensor, then the thermal driver will not work
well anymore.

So this patch is to fix this issue. It allows the thermal sensor driver
can register any number sensors at initialization phase, and fix up code
for other related code to skip related sensor's accessing if the sensor
has not been enabled in initialization phase.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 drivers/thermal/hisi_thermal.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 5e820b5..7a3e5d8 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -160,7 +160,7 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp)
 	struct hisi_thermal_sensor *sensor = _sensor;
 	struct hisi_thermal_data *data = sensor->thermal;
 
-	int sensor_id = 0, i;
+	int sensor_id = -1, i;
 	long max_temp = 0;
 
 	*temp = hisi_thermal_get_sensor_temp(data, sensor);
@@ -168,12 +168,19 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp)
 	sensor->sensor_temp = *temp;
 
 	for (i = 0; i < HISI_MAX_SENSORS; i++) {
+		if (!data->sensors[i].tzd)
+			continue;
+
 		if (data->sensors[i].sensor_temp >= max_temp) {
 			max_temp = data->sensors[i].sensor_temp;
 			sensor_id = i;
 		}
 	}
 
+	/* If no sensor has been enabled, then skip to enable irq */
+	if (sensor_id == -1)
+		return 0;
+
 	mutex_lock(&data->thermal_lock);
 	data->irq_bind_sensor = sensor_id;
 	mutex_unlock(&data->thermal_lock);
@@ -226,8 +233,12 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
 		 sensor->thres_temp / 1000);
 	mutex_unlock(&data->thermal_lock);
 
-	for (i = 0; i < HISI_MAX_SENSORS; i++)
+	for (i = 0; i < HISI_MAX_SENSORS; i++) {
+		if (!data->sensors[i].tzd)
+			continue;
+
 		thermal_zone_device_update(data->sensors[i].tzd);
+	}
 
 	return IRQ_HANDLED;
 }
@@ -247,6 +258,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,
 				sensor, &hisi_of_thermal_ops);
 	if (IS_ERR(sensor->tzd)) {
 		ret = PTR_ERR(sensor->tzd);
+		sensor->tzd = NULL;
 		dev_err(&pdev->dev, "failed to register sensor id %d: %d\n",
 			sensor->id, ret);
 		return ret;
@@ -334,25 +346,17 @@ static int hisi_thermal_probe(struct platform_device *pdev)
 	for (i = 0; i < HISI_MAX_SENSORS; ++i) {
 		ret = hisi_thermal_register_sensor(pdev, data,
 						   &data->sensors[i], i);
-		if (ret) {
+		if (ret)
 			dev_err(&pdev->dev,
 				"failed to register thermal sensor: %d\n", ret);
-			goto err_get_sensor_data;
-		}
+		else
+			hisi_thermal_toggle_sensor(&data->sensors[i], true);
 	}
 
 	hisi_thermal_enable_bind_irq_sensor(data);
 	data->irq_enabled = true;
 
-	for (i = 0; i < HISI_MAX_SENSORS; i++)
-		hisi_thermal_toggle_sensor(&data->sensors[i], true);
-
 	return 0;
-
-err_get_sensor_data:
-	clk_disable_unprepare(data->clk);
-
-	return ret;
 }
 
 static int hisi_thermal_remove(struct platform_device *pdev)
@@ -363,6 +367,9 @@ static int hisi_thermal_remove(struct platform_device *pdev)
 	for (i = 0; i < HISI_MAX_SENSORS; i++) {
 		struct hisi_thermal_sensor *sensor = &data->sensors[i];
 
+		if (!sensor->tzd)
+			continue;
+
 		hisi_thermal_toggle_sensor(sensor, false);
 		thermal_zone_of_sensor_unregister(&pdev->dev, sensor->tzd);
 	}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] arm64: dts: register Hi6220's thermal sensor
  2016-02-20 15:52 [PATCH 0/3] thermal: hisilicon: enable power allocator for Hi6220 Leo Yan
  2016-02-20 15:52 ` [PATCH 1/3] thermal: hisilicon: support to use any sensor Leo Yan
@ 2016-02-20 15:52 ` Leo Yan
  2016-02-20 15:52 ` [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator Leo Yan
  2 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-02-20 15:52 UTC (permalink / raw)
  To: Wei Xu, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Catalin Marinas, Will Deacon, Zhang Rui,
	Eduardo Valentin, kongxinwei, Javi Merino, Punit Agrawal
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-pm, Leo Yan

Bind thermal sensor driver for Hi6220.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
index f588be9..50ba1b0 100644
--- a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
@@ -313,5 +313,14 @@
 			interrupts = <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>;
 			#mbox-cells = <3>;
 		};
+
+		tsensor: tsensor@0,f7030700 {
+			compatible = "hisilicon,tsensor";
+			reg = <0x0 0xf7030700 0x0 0x1000>;
+			interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&sys_ctrl 22>;
+			clock-names = "thermal_clk";
+			#thermal-sensor-cells = <1>;
+		};
 	};
 };
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator
  2016-02-20 15:52 [PATCH 0/3] thermal: hisilicon: enable power allocator for Hi6220 Leo Yan
  2016-02-20 15:52 ` [PATCH 1/3] thermal: hisilicon: support to use any sensor Leo Yan
  2016-02-20 15:52 ` [PATCH 2/3] arm64: dts: register Hi6220's thermal sensor Leo Yan
@ 2016-02-20 15:52 ` Leo Yan
  2016-02-24 18:28   ` Javi Merino
  2 siblings, 1 reply; 6+ messages in thread
From: Leo Yan @ 2016-02-20 15:52 UTC (permalink / raw)
  To: Wei Xu, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Catalin Marinas, Will Deacon, Zhang Rui,
	Eduardo Valentin, kongxinwei, Javi Merino, Punit Agrawal
  Cc: linux-arm-kernel, devicetree, linux-kernel, linux-pm, Leo Yan

With profiling Hi6220's power modeling so get dynamic coefficient and
sustainable power. So pass these parameters from DT.

Now enable power allocator wit only one actor for CPU part, so directly
use cluster0's thermal sensor for monitoring temperature.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 36 +++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
index 50ba1b0..3608a3e 100644
--- a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
@@ -6,6 +6,7 @@
 
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/clock/hi6220-clock.h>
+#include <dt-bindings/thermal/thermal.h>
 
 / {
 	compatible = "hisilicon,hi6220";
@@ -87,6 +88,7 @@
 			cooling-max-level = <0>;
 			#cooling-cells = <2>; /* min followed by max */
 			cpu-idle-states = <&CPU_SLEEP &CLUSTER_SLEEP>;
+			dynamic-power-coefficient = <311>;
 		};
 
 		cpu1: cpu@1 {
@@ -322,5 +324,39 @@
 			clock-names = "thermal_clk";
 			#thermal-sensor-cells = <1>;
 		};
+
+		thermal-zones {
+
+			cls0: cls0 {
+				polling-delay = <1000>;
+				polling-delay-passive = <100>;
+				sustainable-power = <3326>;
+
+				/* sensor ID */
+				thermal-sensors = <&tsensor 2>;
+
+				trips {
+					threshold: trip-point@0 {
+						temperature = <65000>;
+						hysteresis = <1000>;
+						type = "passive";
+					};
+
+					target: trip-point@1 {
+						temperature = <75000>;
+						hysteresis = <1000>;
+						type = "passive";
+					};
+				};
+
+				cooling-maps {
+					map0 {
+						trip = <&target>;
+						contribution = <1024>;
+						cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+					};
+				};
+			};
+		};
 	};
 };
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator
  2016-02-20 15:52 ` [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator Leo Yan
@ 2016-02-24 18:28   ` Javi Merino
  2016-02-25  2:41     ` Leo Yan
  0 siblings, 1 reply; 6+ messages in thread
From: Javi Merino @ 2016-02-24 18:28 UTC (permalink / raw)
  To: Leo Yan
  Cc: Wei Xu, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Catalin Marinas, Will Deacon, Zhang Rui,
	Eduardo Valentin, kongxinwei, Punit Agrawal, linux-arm-kernel,
	devicetree, linux-kernel, linux-pm

On Sat, Feb 20, 2016 at 11:52:09PM +0800, Leo Yan wrote:
> With profiling Hi6220's power modeling so get dynamic coefficient and
> sustainable power. So pass these parameters from DT.
> 
> Now enable power allocator wit only one actor for CPU part, so directly
> use cluster0's thermal sensor for monitoring temperature.
> 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>
> ---
>  arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 36 +++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
> index 50ba1b0..3608a3e 100644
> --- a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
> +++ b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
> @@ -6,6 +6,7 @@
>  
>  #include <dt-bindings/interrupt-controller/arm-gic.h>
>  #include <dt-bindings/clock/hi6220-clock.h>
> +#include <dt-bindings/thermal/thermal.h>
>  
>  / {
>  	compatible = "hisilicon,hi6220";
> @@ -87,6 +88,7 @@
>  			cooling-max-level = <0>;
>  			#cooling-cells = <2>; /* min followed by max */
>  			cpu-idle-states = <&CPU_SLEEP &CLUSTER_SLEEP>;
> +			dynamic-power-coefficient = <311>;
>  		};
>  
>  		cpu1: cpu@1 {
> @@ -322,5 +324,39 @@
>  			clock-names = "thermal_clk";
>  			#thermal-sensor-cells = <1>;
>  		};
> +
> +		thermal-zones {
> +
> +			cls0: cls0 {
> +				polling-delay = <1000>;
> +				polling-delay-passive = <100>;
> +				sustainable-power = <3326>;
> +
> +				/* sensor ID */
> +				thermal-sensors = <&tsensor 2>;
> +
> +				trips {
> +					threshold: trip-point@0 {
> +						temperature = <65000>;
> +						hysteresis = <1000>;

As far as I know, hysteresis is ignored in the thermal subsystem right
now, so you could remove it from both trip points.

> +						type = "passive";
> +					};
> +
> +					target: trip-point@1 {
> +						temperature = <75000>;
> +						hysteresis = <1000>;
> +						type = "passive";
> +					};
> +				};
> +
> +				cooling-maps {
> +					map0 {
> +						trip = <&target>;
> +						contribution = <1024>;

As Hikey has only one voltage domain, you only have one cpu cooling
device.  "contribution" is only useful when you have more than one
cooling device, as it's relative to the other cooling device's
contribution.  You can remove contribution from here.

Other than this minor stuff, it looks good to me. FWIW,

Reviewed-by: Javi Merino <javi.merino@arm.com>

> +						cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> +					};
> +				};
> +			};
> +		};
>  	};
>  };

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator
  2016-02-24 18:28   ` Javi Merino
@ 2016-02-25  2:41     ` Leo Yan
  0 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-02-25  2:41 UTC (permalink / raw)
  To: Javi Merino
  Cc: Wei Xu, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell,
	Kumar Gala, Catalin Marinas, Will Deacon, Zhang Rui,
	Eduardo Valentin, kongxinwei, Punit Agrawal, linux-arm-kernel,
	devicetree, linux-kernel, linux-pm

Hi Javi,

Thanks for review.

On Wed, Feb 24, 2016 at 06:28:57PM +0000, Javi Merino wrote:
> On Sat, Feb 20, 2016 at 11:52:09PM +0800, Leo Yan wrote:
> > With profiling Hi6220's power modeling so get dynamic coefficient and
> > sustainable power. So pass these parameters from DT.
> > 
> > Now enable power allocator wit only one actor for CPU part, so directly
> > use cluster0's thermal sensor for monitoring temperature.
> > 
> > Signed-off-by: Leo Yan <leo.yan@linaro.org>
> > ---
> >  arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 36 +++++++++++++++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> > 
> > diff --git a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
> > index 50ba1b0..3608a3e 100644
> > --- a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
> > +++ b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
> > @@ -6,6 +6,7 @@
> >  
> >  #include <dt-bindings/interrupt-controller/arm-gic.h>
> >  #include <dt-bindings/clock/hi6220-clock.h>
> > +#include <dt-bindings/thermal/thermal.h>
> >  
> >  / {
> >  	compatible = "hisilicon,hi6220";
> > @@ -87,6 +88,7 @@
> >  			cooling-max-level = <0>;
> >  			#cooling-cells = <2>; /* min followed by max */
> >  			cpu-idle-states = <&CPU_SLEEP &CLUSTER_SLEEP>;
> > +			dynamic-power-coefficient = <311>;
> >  		};
> >  
> >  		cpu1: cpu@1 {
> > @@ -322,5 +324,39 @@
> >  			clock-names = "thermal_clk";
> >  			#thermal-sensor-cells = <1>;
> >  		};
> > +
> > +		thermal-zones {
> > +
> > +			cls0: cls0 {
> > +				polling-delay = <1000>;
> > +				polling-delay-passive = <100>;
> > +				sustainable-power = <3326>;
> > +
> > +				/* sensor ID */
> > +				thermal-sensors = <&tsensor 2>;
> > +
> > +				trips {
> > +					threshold: trip-point@0 {
> > +						temperature = <65000>;
> > +						hysteresis = <1000>;
> 
> As far as I know, hysteresis is ignored in the thermal subsystem right
> now, so you could remove it from both trip points.

Will remove it.

> > +						type = "passive";
> > +					};
> > +
> > +					target: trip-point@1 {
> > +						temperature = <75000>;
> > +						hysteresis = <1000>;
> > +						type = "passive";
> > +					};
> > +				};
> > +
> > +				cooling-maps {
> > +					map0 {
> > +						trip = <&target>;
> > +						contribution = <1024>;
> 
> As Hikey has only one voltage domain, you only have one cpu cooling
> device.  "contribution" is only useful when you have more than one
> cooling device, as it's relative to the other cooling device's
> contribution.  You can remove contribution from here.
> 
> Other than this minor stuff, it looks good to me. FWIW,
> 
> Reviewed-by: Javi Merino <javi.merino@arm.com>

Thanks for review. Will sent out new version.

Thanks,
Leo Yan

> > +						cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> > +					};
> > +				};
> > +			};
> > +		};
> >  	};
> >  };

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-25  2:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-20 15:52 [PATCH 0/3] thermal: hisilicon: enable power allocator for Hi6220 Leo Yan
2016-02-20 15:52 ` [PATCH 1/3] thermal: hisilicon: support to use any sensor Leo Yan
2016-02-20 15:52 ` [PATCH 2/3] arm64: dts: register Hi6220's thermal sensor Leo Yan
2016-02-20 15:52 ` [PATCH 3/3] arm64: dts: register Hi6220's thermal zone for power allocator Leo Yan
2016-02-24 18:28   ` Javi Merino
2016-02-25  2:41     ` Leo Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).