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 <[email protected]>
---
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);
+}
+
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 */
};
/**
--
2.25.1
On Tue, Dec 12, 2023 at 2:48 PM Lukasz Luba <[email protected]> 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 <[email protected]>
> ---
> 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.
> };
>
> /**
> --