diff mbox series

[v2,7/8] thermal/sysfs: Update governors when the 'weight' has changed

Message ID 20231212134844.1213381-8-lukasz.luba@arm.com
State New
Headers show
Series Add callback for cooling list update to speed-up IPA | expand

Commit Message

Lukasz Luba Dec. 12, 2023, 1:48 p.m. UTC
Support governors update when the thermal instance's weight has changed.
This allows to adjust internal state for the governor.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/thermal_sysfs.c | 9 +++++++++
 include/linux/thermal.h         | 1 +
 2 files changed, 10 insertions(+)

Comments

Rafael J. Wysocki Dec. 20, 2023, 2:57 p.m. UTC | #1
On Tue, Dec 12, 2023 at 2:48 PM Lukasz Luba <lukasz.luba@arm.com> wrote:
>
> Support governors update when the thermal instance's weight has changed.
> This allows to adjust internal state for the governor.
>
> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
> ---
>  drivers/thermal/thermal_sysfs.c | 9 +++++++++
>  include/linux/thermal.h         | 1 +
>  2 files changed, 10 insertions(+)
>
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index df85df7d4a88..9afa2e2b76b9 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -957,6 +957,14 @@ weight_show(struct device *dev, struct device_attribute *attr, char *buf)
>         return sprintf(buf, "%d\n", instance->weight);
>  }
>
> +static void handle_weight_update(struct thermal_zone_device *tz)
> +{
> +       if (!tz->governor || !tz->governor->update_tz)
> +               return;
> +
> +       tz->governor->update_tz(tz, THERMAL_INSTANCE_WEIGHT_UPDATE);
> +}

So if you follow my advice from the comment on the first patch, you'll
be able to use the helper as is without introducing a new one.

> +
>  ssize_t weight_store(struct device *dev, struct device_attribute *attr,
>                      const char *buf, size_t count)
>  {
> @@ -974,6 +982,7 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr,
>         /* Don't race with governors using the 'weight' value */
>         mutex_lock(&tz->lock);
>         instance->weight = weight;
> +       handle_weight_update(tz);

So this will become

thermal_governor_update_tz(tz, THERMAL_INSTANCE_WEIGHT_UPDATE);

>         mutex_unlock(&tz->lock);
>
>         return count;
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 9fd0d3fb234a..24176f075fbf 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -52,6 +52,7 @@ enum thermal_notify_event {
>         THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
>         THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
>         THERMAL_INSTANCE_LIST_UPDATE, /* List of thermal instances changed */
> +       THERMAL_INSTANCE_WEIGHT_UPDATE, /* Thermal instance weight changed */

And I'd slightly prefer THERMAL_INSTANCE_WEIGHT_CHANGE.

>  };
>
>  /**
> --
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index df85df7d4a88..9afa2e2b76b9 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -957,6 +957,14 @@  weight_show(struct device *dev, struct device_attribute *attr, char *buf)
 	return sprintf(buf, "%d\n", instance->weight);
 }
 
+static void handle_weight_update(struct thermal_zone_device *tz)
+{
+	if (!tz->governor || !tz->governor->update_tz)
+		return;
+
+	tz->governor->update_tz(tz, THERMAL_INSTANCE_WEIGHT_UPDATE);
+}
+
 ssize_t weight_store(struct device *dev, struct device_attribute *attr,
 		     const char *buf, size_t count)
 {
@@ -974,6 +982,7 @@  ssize_t weight_store(struct device *dev, struct device_attribute *attr,
 	/* Don't race with governors using the 'weight' value */
 	mutex_lock(&tz->lock);
 	instance->weight = weight;
+	handle_weight_update(tz);
 	mutex_unlock(&tz->lock);
 
 	return count;
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 9fd0d3fb234a..24176f075fbf 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -52,6 +52,7 @@  enum thermal_notify_event {
 	THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
 	THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
 	THERMAL_INSTANCE_LIST_UPDATE, /* List of thermal instances changed */
+	THERMAL_INSTANCE_WEIGHT_UPDATE, /* Thermal instance weight changed */
 };
 
 /**