[PATCH v2 7/8] thermal/sysfs: Update governors when the 'weight' has changed
From: Lukasz Luba
Date: Tue Dec 12 2023 - 08:48:30 EST
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@xxxxxxx>
---
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