From f2675e588f928f7f3051765563a18f90332bd57b Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 15 Jan 2024 18:55:13 +0100 Subject: thermal: gov_fair_share: Fix dependency on trip points ordering The computation in the fair share governor's get_trip_level() function currently works under the assumption that the temperature ordering of trips[] in a thermal zone is ascending, which need not be the case. However, get_trip_level() can be made work regardless of whether or not the trips table is ordered by temperature in any way, so change it accordingly. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_fair_share.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_share.c index 538abb7de4e2..4da25a0009d7 100644 --- a/drivers/thermal/gov_fair_share.c +++ b/drivers/thermal/gov_fair_share.c @@ -18,22 +18,24 @@ static int get_trip_level(struct thermal_zone_device *tz) { const struct thermal_trip *trip, *level_trip = NULL; - int trip_level; + int trip_level = -1; for_each_trip(tz, trip) { if (trip->temperature >= tz->temperature) - break; + continue; + + trip_level++; - level_trip = trip; + if (!level_trip || trip->temperature > level_trip->temperature) + level_trip = trip; } /* Bail out if the temperature is not greater than any trips. */ - if (!level_trip) + if (trip_level < 0) return 0; - trip_level = thermal_zone_trip_id(tz, level_trip); - - trace_thermal_zone_trip(tz, trip_level, level_trip->type); + trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, level_trip), + level_trip->type); return trip_level; } -- cgit v1.2.3 From 54d94009cb6f51d3ecd56bfc63c83e789c0b18b4 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 15 Jan 2024 18:57:06 +0100 Subject: thermal: gov_bang_bang: Fix possible cooling device state ping-pong The current behavior of thermal_zone_trip_update() in the bang-bang thermal governor may be problematic for trip points with 0 hysteresis, because when the zone temperature reaches the trip temperature and stays there, it will then cause the cooling device go "on" and "off" alternately, which is not desirable. Address this by requiring the zone temperature to actually fall below trip->temperature - trip->hysteresis for the cooling device to go off. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_bang_bang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_bang.c index 6ddf0accdc98..c3b2943a2db8 100644 --- a/drivers/thermal/gov_bang_bang.c +++ b/drivers/thermal/gov_bang_bang.c @@ -49,7 +49,7 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz, if (instance->target == 0 && tz->temperature >= trip->temperature) instance->target = 1; else if (instance->target == 1 && - tz->temperature <= trip->temperature - trip->hysteresis) + tz->temperature < trip->temperature - trip->hysteresis) instance->target = 0; dev_dbg(&instance->cdev->device, "target=%d\n", -- cgit v1.2.3 From ccd975daa807543a0050ab0a84f8581e3aae62a6 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Fri, 9 Feb 2024 14:49:49 +0100 Subject: thermal: sysfs: Fix up white space in trip_point_temp_store() Remove an excess tab character from an otherwise empty code line. No functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/thermal/thermal_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index f4033865b093..d55f9303afb5 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -136,7 +136,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr, unlock: mutex_unlock(&tz->lock); - + return ret ? ret : count; } -- cgit v1.2.3 From 0fac6893ff6c08d6fab6f56b9550a2c4cee589fd Mon Sep 17 00:00:00 2001 From: Di Shen Date: Wed, 7 Feb 2024 10:09:23 +0800 Subject: thermal: gov_power_allocator: Avoid overwriting PID coefficients from setup time When the PID coefficients k_* are set via sysfs before the IPA algorithm is triggered then the coefficients would be overwritten after IPA throttle() is called. The old configuration values might be different than the new values estimated by the IPA internal algorithm. There might be a time delay when this overwriting happens. It depends on the thermal zone temperature value. The temperature value needs to cross the first trip point value then IPA algorithms start operating. Although, the PID coefficients setup time should not be affected or linked to any later operating phase and values must not be overwritten. This patch initializes params->sustainable_power when the governor binds to thermal zone to avoid overwriting k_*. The basic function won't be affected, as the k_* still can be estimated if the sustainable_power is modified. Signed-off-by: Di Shen Reviewed-by: Lukasz Luba Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_power_allocator.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/thermal') diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 81e061f183ad..1b17dc4c219c 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -711,6 +711,8 @@ static int power_allocator_bind(struct thermal_zone_device *tz) if (!tz->tzp->sustainable_power) dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); + else + params->sustainable_power = tz->tzp->sustainable_power; estimate_pid_constants(tz, tz->tzp->sustainable_power, params->trip_switch_on, -- cgit v1.2.3