2015-05-11 20:04:27

by Eduardo Valentin

[permalink] [raw]
Subject: [PATCH 0/2] thermal: add support to slope and offset

Hello all,

This is a patch series to add support to slope and offset constants
of a linear extrapolation model. This type of model is very common
across different platforms, and many drivers are attempting
to have its support.

The basic idea is to have this mapping in the thermal core,
as part of thermal_zone_params. In this series, I also add
a simple support to read them from DT, i.e.:
/* hotspot = 1 * adc + 6000 */
coefficients = <1 6000>;

I am copying some of the driver writers that attempted to
use this feature, but by adding their own property. Please,
check if this change is enough to properly map your slope
and offset requirement. Remember, they will be added in your
thermal zone DT node, instead of in your sensor DT node.

BR,

Eduardo Valentin (2):
thermal: support slope and offset coefficients
thermal: of-thermal: add support for reading coefficients property

Documentation/thermal/sysfs-api.txt | 16 ++++++++++++++++
drivers/thermal/of-thermal.c | 26 ++++++++++++++++++++++++--
drivers/thermal/thermal_core.c | 4 ++++
include/linux/thermal.h | 11 +++++++++++
4 files changed, 55 insertions(+), 2 deletions(-)

--
2.3.4


2015-05-11 20:05:12

by Eduardo Valentin

[permalink] [raw]
Subject: [PATCH 1/2] thermal: support slope and offset coefficients

It is common to have a linear extrapolation from
the current sensor readings and the actual temperature
value. This is specially the case when the sensor
is in use to extrapolate hotspots.

This patch adds slope and offset constants for
single sensor linear extrapolation equation. Because
the same sensor can be use in different locations,
from board to board, these constants are added
as part of thermal_zone_params.

The constants are available through sysfs.

It is up to the device driver to determine
the usage of these values.

Signed-off-by: Eduardo Valentin <[email protected]>
---
Documentation/thermal/sysfs-api.txt | 16 ++++++++++++++++
drivers/thermal/thermal_core.c | 4 ++++
include/linux/thermal.h | 11 +++++++++++
3 files changed, 31 insertions(+)

diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt
index 7d44d7f..c1f6864 100644
--- a/Documentation/thermal/sysfs-api.txt
+++ b/Documentation/thermal/sysfs-api.txt
@@ -190,6 +190,8 @@ Thermal zone device sys I/F, created once it's registered:
|---k_i: PID's integral term in the power allocator gov
|---k_d: PID's derivative term in the power allocator
|---integral_cutoff: Offset above which errors are accumulated
+ |---slope: Slope constant applied as linear extrapolation
+ |---offset: Offset constant applied as linear extrapolation

Thermal cooling device sys I/F, created once it's registered:
/sys/class/thermal/cooling_device[0-*]:
@@ -359,6 +361,20 @@ integral_cutoff
Documentation/thermal/power_allocator.txt
RW, Optional

+slope
+ The slope constant used in a linear extrapolation model
+ to determine a hotspot temperature based off the sensor's
+ raw readings. It is up to the device driver to determine
+ the usage of these values.
+ RW, Optional
+
+offset
+ The offset constant used in a linear extrapolation model
+ to determine a hotspot temperature based off the sensor's
+ raw readings. It is up to the device driver to determine
+ the usage of these values.
+ RW, Optional
+
*****************************
* Cooling device attributes *
*****************************
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 962de18..04659bf 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -944,6 +944,8 @@ create_s32_tzp_attr(k_pu);
create_s32_tzp_attr(k_i);
create_s32_tzp_attr(k_d);
create_s32_tzp_attr(integral_cutoff);
+create_s32_tzp_attr(slope);
+create_s32_tzp_attr(offset);
#undef create_s32_tzp_attr

static struct device_attribute *dev_tzp_attrs[] = {
@@ -953,6 +955,8 @@ static struct device_attribute *dev_tzp_attrs[] = {
&dev_attr_k_i,
&dev_attr_k_d,
&dev_attr_integral_cutoff,
+ &dev_attr_slope,
+ &dev_attr_offset,
};

static int create_tzp_attrs(struct device *dev)
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 6bbe11c..037e9df 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -302,6 +302,17 @@ struct thermal_zone_params {

/* threshold below which the error is no longer accumulated */
s32 integral_cutoff;
+
+ /*
+ * @slope: slope of a linear temperature adjustment curve.
+ * Used by thermal zone drivers.
+ */
+ int slope;
+ /*
+ * @offset: offset of a linear temperature adjustment curve.
+ * Used by thermal zone drivers (default 0).
+ */
+ int offset;
};

struct thermal_genl_event {
--
2.3.4

2015-05-11 20:04:46

by Eduardo Valentin

[permalink] [raw]
Subject: [PATCH 2/2] thermal: of-thermal: add support for reading coefficients property

In order to avoid having each driver adding their own
specific DT property to specify slope and offset,
this patch adds a basic coefficient reading from
DT thermal zone node. Right now, as the thermal
framework does not support multiple sensors,
the current coefficients apply only to the only
sensor in the thermal zone.

The supported equation is a simple linear model:
slope * <sensor reading> + offset.

slope and offset are read from the coefficients
DT property. In the same way as it is described in
the DT thermal binding.

So, as of today, the thermal framework will support
only cases like:
/* hotspot = 1 * adc + 6000 */
coefficients = <1 6000>;

Signed-off-by: Eduardo Valentin <[email protected]>
---
drivers/thermal/of-thermal.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 9e8c614..b295b2b 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -58,6 +58,8 @@ struct __thermal_bind_params {
* @mode: current thermal zone device mode (enabled/disabled)
* @passive_delay: polling interval while passive cooling is activated
* @polling_delay: zone polling interval
+ * @slope: slope of the temperature adjustment curve
+ * @offset: offset of the temperature adjustment curve
* @ntrips: number of trip points
* @trips: an array of trip points (0..ntrips - 1)
* @num_tbps: number of thermal bind params
@@ -70,6 +72,8 @@ struct __thermal_zone {
enum thermal_device_mode mode;
int passive_delay;
int polling_delay;
+ int slope;
+ int offset;

/* trip data */
int ntrips;
@@ -716,7 +720,7 @@ static int thermal_of_populate_trip(struct device_node *np,
* @np parameter and fills the read data into a __thermal_zone data structure
* and return this pointer.
*
- * TODO: Missing properties to parse: thermal-sensor-names and coefficients
+ * TODO: Missing properties to parse: thermal-sensor-names
*
* Return: On success returns a valid struct __thermal_zone,
* otherwise, it returns a corresponding ERR_PTR(). Caller must
@@ -728,7 +732,7 @@ thermal_of_build_thermal_zone(struct device_node *np)
struct device_node *child = NULL, *gchild;
struct __thermal_zone *tz;
int ret, i;
- u32 prop;
+ u32 prop, coef[2];

if (!np) {
pr_err("no thermal zone np\n");
@@ -753,6 +757,20 @@ thermal_of_build_thermal_zone(struct device_node *np)
}
tz->polling_delay = prop;

+ /*
+ * REVIST: for now, the thermal framework supports only
+ * one sensor per thermal zone. Thus, we are considering
+ * only the first two values as slope and offset.
+ */
+ ret = of_property_read_u32_array(np, "coefficients", coef, 2);
+ if (ret == 0) {
+ tz->slope = coef[0];
+ tz->offset = coef[1];
+ } else {
+ tz->slope = 1;
+ tz->offset = 0;
+ }
+
/* trips */
child = of_get_child_by_name(np, "trips");

@@ -900,6 +918,10 @@ int __init of_parse_thermal_zones(void)
for (i = 0; i < tz->ntrips; i++)
mask |= 1 << i;

+ /* these two are left for temperature drivers to use */
+ tzp->slope = tz->slope;
+ tzp->offset = tz->offset;
+
zone = thermal_zone_device_register(child->name, tz->ntrips,
mask, tz,
ops, tzp,
--
2.3.4

2015-05-11 20:24:36

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH 0/2] thermal: add support to slope and offset

Hi,

On Mon, May 11, 2015 at 08:04:15PM -0700, Eduardo Valentin wrote:
> Hello all,
>
> This is a patch series to add support to slope and offset constants
> of a linear extrapolation model. This type of model is very common
> across different platforms, and many drivers are attempting
> to have its support.
>
> The basic idea is to have this mapping in the thermal core,
> as part of thermal_zone_params. In this series, I also add
> a simple support to read them from DT, i.e.:
> /* hotspot = 1 * adc + 6000 */
> coefficients = <1 6000>;
>
> I am copying some of the driver writers that attempted to
> use this feature, but by adding their own property. Please,
> check if this change is enough to properly map your slope
> and offset requirement. Remember, they will be added in your
> thermal zone DT node, instead of in your sensor DT node.
>

Forgot to copy Narendran, codeaurora developer

> BR,
>
> Eduardo Valentin (2):
> thermal: support slope and offset coefficients
> thermal: of-thermal: add support for reading coefficients property
>
> Documentation/thermal/sysfs-api.txt | 16 ++++++++++++++++
> drivers/thermal/of-thermal.c | 26 ++++++++++++++++++++++++--
> drivers/thermal/thermal_core.c | 4 ++++
> include/linux/thermal.h | 11 +++++++++++
> 4 files changed, 55 insertions(+), 2 deletions(-)
>
> --
> 2.3.4
>


Attachments:
(No filename) (1.37 kB)
signature.asc (490.00 B)
Digital signature
Download all attachments

2015-05-11 20:25:13

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH 1/2] thermal: support slope and offset coefficients

Copying Narendran.

On Mon, May 11, 2015 at 08:04:16PM -0700, Eduardo Valentin wrote:
> It is common to have a linear extrapolation from
> the current sensor readings and the actual temperature
> value. This is specially the case when the sensor
> is in use to extrapolate hotspots.
>
> This patch adds slope and offset constants for
> single sensor linear extrapolation equation. Because
> the same sensor can be use in different locations,
> from board to board, these constants are added
> as part of thermal_zone_params.
>
> The constants are available through sysfs.
>
> It is up to the device driver to determine
> the usage of these values.


>
> Signed-off-by: Eduardo Valentin <[email protected]>
> ---
> Documentation/thermal/sysfs-api.txt | 16 ++++++++++++++++
> drivers/thermal/thermal_core.c | 4 ++++
> include/linux/thermal.h | 11 +++++++++++
> 3 files changed, 31 insertions(+)
>
> diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt
> index 7d44d7f..c1f6864 100644
> --- a/Documentation/thermal/sysfs-api.txt
> +++ b/Documentation/thermal/sysfs-api.txt
> @@ -190,6 +190,8 @@ Thermal zone device sys I/F, created once it's registered:
> |---k_i: PID's integral term in the power allocator gov
> |---k_d: PID's derivative term in the power allocator
> |---integral_cutoff: Offset above which errors are accumulated
> + |---slope: Slope constant applied as linear extrapolation
> + |---offset: Offset constant applied as linear extrapolation
>
> Thermal cooling device sys I/F, created once it's registered:
> /sys/class/thermal/cooling_device[0-*]:
> @@ -359,6 +361,20 @@ integral_cutoff
> Documentation/thermal/power_allocator.txt
> RW, Optional
>
> +slope
> + The slope constant used in a linear extrapolation model
> + to determine a hotspot temperature based off the sensor's
> + raw readings. It is up to the device driver to determine
> + the usage of these values.
> + RW, Optional
> +
> +offset
> + The offset constant used in a linear extrapolation model
> + to determine a hotspot temperature based off the sensor's
> + raw readings. It is up to the device driver to determine
> + the usage of these values.
> + RW, Optional
> +
> *****************************
> * Cooling device attributes *
> *****************************
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 962de18..04659bf 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -944,6 +944,8 @@ create_s32_tzp_attr(k_pu);
> create_s32_tzp_attr(k_i);
> create_s32_tzp_attr(k_d);
> create_s32_tzp_attr(integral_cutoff);
> +create_s32_tzp_attr(slope);
> +create_s32_tzp_attr(offset);
> #undef create_s32_tzp_attr
>
> static struct device_attribute *dev_tzp_attrs[] = {
> @@ -953,6 +955,8 @@ static struct device_attribute *dev_tzp_attrs[] = {
> &dev_attr_k_i,
> &dev_attr_k_d,
> &dev_attr_integral_cutoff,
> + &dev_attr_slope,
> + &dev_attr_offset,
> };
>
> static int create_tzp_attrs(struct device *dev)
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 6bbe11c..037e9df 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -302,6 +302,17 @@ struct thermal_zone_params {
>
> /* threshold below which the error is no longer accumulated */
> s32 integral_cutoff;
> +
> + /*
> + * @slope: slope of a linear temperature adjustment curve.
> + * Used by thermal zone drivers.
> + */
> + int slope;
> + /*
> + * @offset: offset of a linear temperature adjustment curve.
> + * Used by thermal zone drivers (default 0).
> + */
> + int offset;
> };
>
> struct thermal_genl_event {
> --
> 2.3.4
>


Attachments:
(No filename) (3.72 kB)
signature.asc (490.00 B)
Digital signature
Download all attachments

2015-05-11 20:27:56

by Eduardo Valentin

[permalink] [raw]
Subject: Re: [PATCH 2/2] thermal: of-thermal: add support for reading coefficients property 33 O May 11 Antoine Tenart ( 15K) [PATCH v4 1/3] iio: adc: add support for Berlin

Copying Narendran.

On Mon, May 11, 2015 at 08:04:17PM -0700, Eduardo Valentin wrote:
> In order to avoid having each driver adding their own
> specific DT property to specify slope and offset,
> this patch adds a basic coefficient reading from
> DT thermal zone node. Right now, as the thermal
> framework does not support multiple sensors,
> the current coefficients apply only to the only
> sensor in the thermal zone.
>
> The supported equation is a simple linear model:
> slope * <sensor reading> + offset.
>
> slope and offset are read from the coefficients
> DT property. In the same way as it is described in
> the DT thermal binding.
>
> So, as of today, the thermal framework will support
> only cases like:
> /* hotspot = 1 * adc + 6000 */
> coefficients = <1 6000>;
>
> Signed-off-by: Eduardo Valentin <[email protected]>
> ---
> drivers/thermal/of-thermal.c | 26 ++++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
> index 9e8c614..b295b2b 100644
> --- a/drivers/thermal/of-thermal.c
> +++ b/drivers/thermal/of-thermal.c
> @@ -58,6 +58,8 @@ struct __thermal_bind_params {
> * @mode: current thermal zone device mode (enabled/disabled)
> * @passive_delay: polling interval while passive cooling is activated
> * @polling_delay: zone polling interval
> + * @slope: slope of the temperature adjustment curve
> + * @offset: offset of the temperature adjustment curve
> * @ntrips: number of trip points
> * @trips: an array of trip points (0..ntrips - 1)
> * @num_tbps: number of thermal bind params
> @@ -70,6 +72,8 @@ struct __thermal_zone {
> enum thermal_device_mode mode;
> int passive_delay;
> int polling_delay;
> + int slope;
> + int offset;
>
> /* trip data */
> int ntrips;
> @@ -716,7 +720,7 @@ static int thermal_of_populate_trip(struct device_node *np,
> * @np parameter and fills the read data into a __thermal_zone data structure
> * and return this pointer.
> *
> - * TODO: Missing properties to parse: thermal-sensor-names and coefficients
> + * TODO: Missing properties to parse: thermal-sensor-names
> *
> * Return: On success returns a valid struct __thermal_zone,
> * otherwise, it returns a corresponding ERR_PTR(). Caller must
> @@ -728,7 +732,7 @@ thermal_of_build_thermal_zone(struct device_node *np)
> struct device_node *child = NULL, *gchild;
> struct __thermal_zone *tz;
> int ret, i;
> - u32 prop;
> + u32 prop, coef[2];
>
> if (!np) {
> pr_err("no thermal zone np\n");
> @@ -753,6 +757,20 @@ thermal_of_build_thermal_zone(struct device_node *np)
> }
> tz->polling_delay = prop;
>
> + /*
> + * REVIST: for now, the thermal framework supports only
> + * one sensor per thermal zone. Thus, we are considering
> + * only the first two values as slope and offset.
> + */
> + ret = of_property_read_u32_array(np, "coefficients", coef, 2);
> + if (ret == 0) {
> + tz->slope = coef[0];
> + tz->offset = coef[1];
> + } else {
> + tz->slope = 1;
> + tz->offset = 0;
> + }
> +
> /* trips */
> child = of_get_child_by_name(np, "trips");
>
> @@ -900,6 +918,10 @@ int __init of_parse_thermal_zones(void)
> for (i = 0; i < tz->ntrips; i++)
> mask |= 1 << i;
>
> + /* these two are left for temperature drivers to use */
> + tzp->slope = tz->slope;
> + tzp->offset = tz->offset;
> +
> zone = thermal_zone_device_register(child->name, tz->ntrips,
> mask, tz,
> ops, tzp,
> --
> 2.3.4
>


Attachments:
(No filename) (3.48 kB)
signature.asc (490.00 B)
Digital signature
Download all attachments