* [PATCH v2 1/4] thermal: power_allocator: rework proportional parameter
2016-01-06 8:30 [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
@ 2016-01-06 8:30 ` Leo Yan
2016-01-06 8:30 ` [PATCH v2 2/4] thermal: power_allocator: change k_pu_ratio/k_po_ratio as percentage Leo Yan
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-01-06 8:30 UTC (permalink / raw)
To: Jonathan Corbet, Zhang Rui, Eduardo Valentin, Javi Merino,
Punit Agrawal, Daniel Kurtz, linux-doc, linux-kernel, linux-pm,
Daniel Thompson
Cc: Leo Yan
k_po/k_pu are two proportional term constants and essentially they have
fixed ratio compared with sustainable power. In current implementation,
k_po and k_pu are absolute value after calculation and cannot represent
the ratio relationship with sustainable power; as a result, when change
sustainable power we cannot smoothly change proportional term constant.
So this patch introduces variants k_po_ratio and k_pu_ratio, which
represent the ratio value compared against sustainable power, so smaller
ratio will result in thermal slower ramp. The formulas finally are as
below:
k_pu = k_pu_ratio * sustainable_power /
(desired_temperature - switch_on_temp)
k_po = k_po_ratio * sustainable_power /
(desired_temperature - switch_on_temp)
Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
drivers/thermal/power_allocator.c | 18 ++++++++++++------
include/linux/thermal.h | 4 ++--
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allocator.c
index 1246aa6..76d2b47 100644
--- a/drivers/thermal/power_allocator.c
+++ b/drivers/thermal/power_allocator.c
@@ -155,13 +155,11 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
if (!temperature_threshold)
return;
- if (!tz->tzp->k_po || force)
- tz->tzp->k_po = int_to_frac(sustainable_power) /
- temperature_threshold;
+ if (!tz->tzp->k_po_ratio || force)
+ tz->tzp->k_po_ratio = 1;
- if (!tz->tzp->k_pu || force)
- tz->tzp->k_pu = int_to_frac(2 * sustainable_power) /
- temperature_threshold;
+ if (!tz->tzp->k_pu_ratio || force)
+ tz->tzp->k_pu_ratio = 2;
if (!tz->tzp->k_i || force)
tz->tzp->k_i = int_to_frac(10) / 1000;
@@ -169,6 +167,11 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
* The default for k_d and integral_cutoff is 0, so we can
* leave them as they are.
*/
+
+ tz->tzp->k_po = int_to_frac(tz->tzp->k_po_ratio * sustainable_power) /
+ temperature_threshold;
+ tz->tzp->k_pu = int_to_frac(tz->tzp->k_pu_ratio * sustainable_power) /
+ temperature_threshold;
}
/**
@@ -202,6 +205,9 @@ static u32 pid_controller(struct thermal_zone_device *tz,
if (tz->tzp->sustainable_power) {
sustainable_power = tz->tzp->sustainable_power;
+ estimate_pid_constants(tz, sustainable_power,
+ params->trip_switch_on, control_temp,
+ false);
} else {
sustainable_power = estimate_sustainable_power(tz);
estimate_pid_constants(tz, sustainable_power,
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 613c29b..2638f0b 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -284,13 +284,13 @@ struct thermal_zone_params {
* Proportional parameter of the PID controller when
* overshooting (i.e., when temperature is below the target)
*/
- s32 k_po;
+ s32 k_po, k_po_ratio;
/*
* Proportional parameter of the PID controller when
* undershooting
*/
- s32 k_pu;
+ s32 k_pu, k_pu_ratio;
/* Integral parameter of the PID controller */
s32 k_i;
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] thermal: power_allocator: change k_pu_ratio/k_po_ratio as percentage
2016-01-06 8:30 [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
2016-01-06 8:30 ` [PATCH v2 1/4] thermal: power_allocator: rework proportional parameter Leo Yan
@ 2016-01-06 8:30 ` Leo Yan
2016-01-06 8:30 ` [PATCH v2 3/4] thermal: add sys node for k_pu_ratio/k_po_ratio Leo Yan
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-01-06 8:30 UTC (permalink / raw)
To: Jonathan Corbet, Zhang Rui, Eduardo Valentin, Javi Merino,
Punit Agrawal, Daniel Kurtz, linux-doc, linux-kernel, linux-pm,
Daniel Thompson
Cc: Leo Yan
Change k_pu_ratio/k_po_ratio as percentage value, so can set these
values from sys file nodes with high resolution.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
drivers/thermal/power_allocator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allocator.c
index 76d2b47..c5f36fa 100644
--- a/drivers/thermal/power_allocator.c
+++ b/drivers/thermal/power_allocator.c
@@ -156,10 +156,10 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
return;
if (!tz->tzp->k_po_ratio || force)
- tz->tzp->k_po_ratio = 1;
+ tz->tzp->k_po_ratio = 100;
if (!tz->tzp->k_pu_ratio || force)
- tz->tzp->k_pu_ratio = 2;
+ tz->tzp->k_pu_ratio = 200;
if (!tz->tzp->k_i || force)
tz->tzp->k_i = int_to_frac(10) / 1000;
@@ -169,9 +169,9 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
*/
tz->tzp->k_po = int_to_frac(tz->tzp->k_po_ratio * sustainable_power) /
- temperature_threshold;
+ temperature_threshold / 100;
tz->tzp->k_pu = int_to_frac(tz->tzp->k_pu_ratio * sustainable_power) /
- temperature_threshold;
+ temperature_threshold / 100;
}
/**
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] thermal: add sys node for k_pu_ratio/k_po_ratio
2016-01-06 8:30 [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
2016-01-06 8:30 ` [PATCH v2 1/4] thermal: power_allocator: rework proportional parameter Leo Yan
2016-01-06 8:30 ` [PATCH v2 2/4] thermal: power_allocator: change k_pu_ratio/k_po_ratio as percentage Leo Yan
@ 2016-01-06 8:30 ` Leo Yan
2016-01-06 8:30 ` [PATCH v2 4/4] thermal: power_allocator: document k_pu_ratio/k_po_ratio Leo Yan
2016-01-06 8:48 ` [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-01-06 8:30 UTC (permalink / raw)
To: Jonathan Corbet, Zhang Rui, Eduardo Valentin, Javi Merino,
Punit Agrawal, Daniel Kurtz, linux-doc, linux-kernel, linux-pm,
Daniel Thompson
Cc: Leo Yan
Add two sys nodes for k_pu_ratio and k_po_ratio, so user can set ratio
value from them. Also change k_pu/k_po as read only nodes, it will only
be used to show proportional term constants which are calculated by
ratio.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
drivers/thermal/thermal_core.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index d9e525c..bc149a67 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -955,8 +955,25 @@ static DEVICE_ATTR(sustainable_power, S_IWUSR | S_IRUGO, sustainable_power_show,
} \
static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, name##_show, name##_store)
-create_s32_tzp_attr(k_po);
-create_s32_tzp_attr(k_pu);
+
+#define create_s32_tzp_attr_ro(name) \
+ static ssize_t \
+ name##_show(struct device *dev, struct device_attribute *devattr, \
+ char *buf) \
+ { \
+ struct thermal_zone_device *tz = to_thermal_zone(dev); \
+ \
+ if (tz->tzp) \
+ return sprintf(buf, "%u\n", tz->tzp->name); \
+ else \
+ return -EIO; \
+ } \
+ static DEVICE_ATTR(name, S_IRUGO, name##_show, NULL)
+
+create_s32_tzp_attr_ro(k_po);
+create_s32_tzp_attr_ro(k_pu);
+create_s32_tzp_attr(k_po_ratio);
+create_s32_tzp_attr(k_pu_ratio);
create_s32_tzp_attr(k_i);
create_s32_tzp_attr(k_d);
create_s32_tzp_attr(integral_cutoff);
@@ -968,6 +985,8 @@ static struct device_attribute *dev_tzp_attrs[] = {
&dev_attr_sustainable_power,
&dev_attr_k_po,
&dev_attr_k_pu,
+ &dev_attr_k_po_ratio,
+ &dev_attr_k_pu_ratio,
&dev_attr_k_i,
&dev_attr_k_d,
&dev_attr_integral_cutoff,
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] thermal: power_allocator: document k_pu_ratio/k_po_ratio
2016-01-06 8:30 [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
` (2 preceding siblings ...)
2016-01-06 8:30 ` [PATCH v2 3/4] thermal: add sys node for k_pu_ratio/k_po_ratio Leo Yan
@ 2016-01-06 8:30 ` Leo Yan
2016-01-06 8:48 ` [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-01-06 8:30 UTC (permalink / raw)
To: Jonathan Corbet, Zhang Rui, Eduardo Valentin, Javi Merino,
Punit Agrawal, Daniel Kurtz, linux-doc, linux-kernel, linux-pm,
Daniel Thompson
Cc: Leo Yan
Document k_pu_ratio and k_po_ratio's purpose, and refine formula to
demonstrate to use ratio to calculate k_pu/k_po.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
Documentation/thermal/power_allocator.txt | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/Documentation/thermal/power_allocator.txt b/Documentation/thermal/power_allocator.txt
index a1ce223..8958dab 100644
--- a/Documentation/thermal/power_allocator.txt
+++ b/Documentation/thermal/power_allocator.txt
@@ -114,13 +114,20 @@ whilst temperature is low, and may lead to temperature overshooting.
The default value for `k_pu` is:
- 2 * sustainable_power / (desired_temperature - switch_on_temp)
+ k_pu_ratio * sustainable_power / (desired_temperature - switch_on_temp)
This means that at `switch_on_temp` the output of the controller's
-proportional term will be 2 * `sustainable_power`. The default value
-for `k_po` is:
+proportional term will be k_pu_ratio * `sustainable_power`.
- sustainable_power / (desired_temperature - switch_on_temp)
+The default value for `k_po` is:
+
+ k_po_ratio * sustainable_power / (desired_temperature - switch_on_temp)
+
+k_pu_ratio's default value is 2 and k_po_ratio's default value is 1.
+These two vairants mean the ratio value compared against sustainable power,
+so smaller ratio will result in thermal slower ramp. User can set these two
+ratio value from sys filesystem nodes, finally k_pu and k_po will be
+calculated by updated ratio value.
Focusing on the proportional and feed forward values of the PID
controller equation we have:
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power
2016-01-06 8:30 [PATCH v2 0/4] thermal: re-calculate k_po/k_pu when update sustainable power Leo Yan
` (3 preceding siblings ...)
2016-01-06 8:30 ` [PATCH v2 4/4] thermal: power_allocator: document k_pu_ratio/k_po_ratio Leo Yan
@ 2016-01-06 8:48 ` Leo Yan
4 siblings, 0 replies; 6+ messages in thread
From: Leo Yan @ 2016-01-06 8:48 UTC (permalink / raw)
To: Jonathan Corbet, Zhang Rui, Eduardo Valentin, Javi Merino,
Punit Agrawal, Daniel Kurtz, linux-doc, linux-kernel, linux-pm,
Daniel Thompson
Hi all,
On Wed, Jan 06, 2016 at 04:30:19PM +0800, Leo Yan wrote:
> k_po/k_pu are two proportional term constants and essentially they have
> fixed ratio compared with sustainable power. In current implementation,
> k_po and k_pu are absolute value after calculation and cannot represent
> the ratio relationship with sustainable power; as a result, when change
> sustainable power we cannot smoothly change proportional term constant.
>
> So this patch series introduces k_po_ratio and k_pu_ratio, which
> represent the ratio value compared against sustainable power. Also add
> sys file system nodes for them for easily update them from userspace and
> update a bit in documentation.
>
> Changes from v1:
> * According to Eduardo' comments, move code from thermal_core to
> power_allocator file
> * According to Daniel's review, v1 will introduce accumulated rounding
> errors; v2 patches can dismiss this issue
>
> Leo Yan (4):
> thermal: power_allocator: rework proportional parameter
> thermal: power_allocator: change k_pu_ratio/k_po_ratio as percentage
> thermal: add sys node for k_pu_ratio/k_po_ratio
> thermal: power_allocator: document k_pu_ratio/k_po_ratio
>
> Documentation/thermal/power_allocator.txt | 15 +++++++++++----
> drivers/thermal/power_allocator.c | 18 ++++++++++++------
> drivers/thermal/thermal_core.c | 23 +++++++++++++++++++++--
> include/linux/thermal.h | 4 ++--
> 4 files changed, 46 insertions(+), 14 deletions(-)
Sorry for confusion.
I recognized I used duplicated version number, please drop this series;
I will send a new v3 series.
Thanks,
Leo Yan
^ permalink raw reply [flat|nested] 6+ messages in thread