2022-12-01 09:44:01

by Di Shen

[permalink] [raw]
Subject: [PATCH] thermal/of: Allow users to set governor for a thermal zone in DT

The governor of all thermal zones can be initialized in
thermal_zone_device_register_with_trips(), but it is always the
def_governor, this means the governor of all thermal zones are
the same.

Allow users to set governor for a specific thermal zone in DT, in
this way, users can use different policies for thermal management.

Signed-off-by: Di Shen <[email protected]>
---
drivers/thermal/thermal_of.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index d4b6335ace15..5dd4101dffb6 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -355,6 +355,7 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
int coef[2];
int ncoef = ARRAY_SIZE(coef);
int prop, ret;
+ const char *governor_name;

tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
if (!tzp)
@@ -365,6 +366,9 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
if (!of_property_read_u32(np, "sustainable-power", &prop))
tzp->sustainable_power = prop;

+ if (!of_property_read_string(np, "policy", &governor_name))
+ strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH);
+
/*
* For now, the thermal framework supports only one sensor per
* thermal zone. Thus, we are considering only the first two
--
2.17.1


2022-12-01 19:15:35

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] thermal/of: Allow users to set governor for a thermal zone in DT

Hi Di,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/thermal]
[also build test WARNING on linus/master v6.1-rc7 next-20221201]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Di-Shen/thermal-of-Allow-users-to-set-governor-for-a-thermal-zone-in-DT/20221201-165820
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal
patch link: https://lore.kernel.org/r/20221201085423.10360-1-di.shen%40unisoc.com
patch subject: [PATCH] thermal/of: Allow users to set governor for a thermal zone in DT
config: ia64-allyesconfig
compiler: ia64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/6ac4585641eca02d031f54111ca54507d5a3dc56
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Di-Shen/thermal-of-Allow-users-to-set-governor-for-a-thermal-zone-in-DT/20221201-165820
git checkout 6ac4585641eca02d031f54111ca54507d5a3dc56
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

In function 'thermal_of_parameters_init',
inlined from 'thermal_of_zone_register' at drivers/thermal/thermal_of.c:626:8:
>> drivers/thermal/thermal_of.c:370:17: warning: 'strncpy' specified bound 20 equals destination size [-Wstringop-truncation]
370 | strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/strncpy +370 drivers/thermal/thermal_of.c

351
352 static struct thermal_zone_params *thermal_of_parameters_init(struct device_node *np)
353 {
354 struct thermal_zone_params *tzp;
355 int coef[2];
356 int ncoef = ARRAY_SIZE(coef);
357 int prop, ret;
358 const char *governor_name;
359
360 tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
361 if (!tzp)
362 return ERR_PTR(-ENOMEM);
363
364 tzp->no_hwmon = true;
365
366 if (!of_property_read_u32(np, "sustainable-power", &prop))
367 tzp->sustainable_power = prop;
368
369 if (!of_property_read_string(np, "policy", &governor_name))
> 370 strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH);
371
372 /*
373 * For now, the thermal framework supports only one sensor per
374 * thermal zone. Thus, we are considering only the first two
375 * values as slope and offset.
376 */
377 ret = of_property_read_u32_array(np, "coefficients", coef, ncoef);
378 if (ret) {
379 coef[0] = 1;
380 coef[1] = 0;
381 }
382
383 tzp->slope = coef[0];
384 tzp->offset = coef[1];
385
386 return tzp;
387 }
388

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (3.45 kB)
config (327.90 kB)
Download all attachments

2022-12-02 09:23:40

by Di Shen

[permalink] [raw]
Subject: [PATCH V2] thermal/of: Allow users to set governor for a thermal zone in DT

The governor of all thermal zones can be initialized in
thermal_zone_device_register_with_trips(), but it is always the
def_governor, this means the governor of all thermal zones are
the same.

Allow users to set governor for a specific thermal zone in DT, in
this way, users can use different policies for thermal management.

Signed-off-by: Di Shen <[email protected]>
---
drivers/thermal/thermal_of.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index d4b6335ace15..4a29ac3be2ac 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -355,6 +355,7 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
int coef[2];
int ncoef = ARRAY_SIZE(coef);
int prop, ret;
+ const char *governor_name;

tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
if (!tzp)
@@ -365,6 +366,11 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
if (!of_property_read_u32(np, "sustainable-power", &prop))
tzp->sustainable_power = prop;

+ if (!of_property_read_string(np, "policy", &governor_name)) {
+ strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH - 1);
+ tzp->governor_name[THERMAL_NAME_LENGTH - 1] = '\0';
+ }
+
/*
* For now, the thermal framework supports only one sensor per
* thermal zone. Thus, we are considering only the first two
--
2.17.1

2022-12-02 17:20:16

by Matthias Kaehlcke

[permalink] [raw]
Subject: Re: [PATCH V2] thermal/of: Allow users to set governor for a thermal zone in DT

On Fri, Dec 02, 2022 at 05:11:11PM +0800, Di Shen wrote:
> The governor of all thermal zones can be initialized in
> thermal_zone_device_register_with_trips(), but it is always the
> def_governor, this means the governor of all thermal zones are
> the same.
>
> Allow users to set governor for a specific thermal zone in DT, in
> this way, users can use different policies for thermal management.

There have been other attempts in the past of adding this to the
device tree (e.g. [1]), which were rejected since the DT should
describe the hardware, not policy. Userspace can configure thermal
zones to use a non-default governor through sysfs.

[1] https://lore.kernel.org/all/3b80853abb45a9e067cf7a16754b07bb67712457.1520274879.git.amit.kucheria@linaro.org/


>
> Signed-off-by: Di Shen <[email protected]>
> ---
> drivers/thermal/thermal_of.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index d4b6335ace15..4a29ac3be2ac 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -355,6 +355,7 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
> int coef[2];
> int ncoef = ARRAY_SIZE(coef);
> int prop, ret;
> + const char *governor_name;
>
> tzp = kzalloc(sizeof(*tzp), GFP_KERNEL);
> if (!tzp)
> @@ -365,6 +366,11 @@ static struct thermal_zone_params *thermal_of_parameters_init(struct device_node
> if (!of_property_read_u32(np, "sustainable-power", &prop))
> tzp->sustainable_power = prop;
>
> + if (!of_property_read_string(np, "policy", &governor_name)) {
> + strncpy(tzp->governor_name, governor_name, THERMAL_NAME_LENGTH - 1);
> + tzp->governor_name[THERMAL_NAME_LENGTH - 1] = '\0';
> + }
> +
> /*
> * For now, the thermal framework supports only one sensor per
> * thermal zone. Thus, we are considering only the first two
> --
> 2.17.1
>