diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2023-08-07 20:17:07 +0200 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2023-08-17 11:25:22 +0200 |
commit | 9caaad2ca02cb31fc235249f971cabdf8e11e28d (patch) | |
tree | 1ddd64afa3057eac9444b6c3b99365b10288884c /drivers/acpi | |
parent | ACPI: thermal: Use trip point table to register thermal zones (diff) | |
download | linux-9caaad2ca02cb31fc235249f971cabdf8e11e28d.tar.xz linux-9caaad2ca02cb31fc235249f971cabdf8e11e28d.zip |
ACPI: thermal: Rework thermal_get_trend()
Rework the ACPI thermal driver's .get_trend() callback function,
thermal_get_trend(), so that it does not call thermal_get_trip_type()
and thermal_get_trip_temp() which are going to be dropped.
This reduces the overhead of the function too, because it will always
carry out a trip point lookup once after the change.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/thermal.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index c2fe806fd3d7..bd540e4fb4d0 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -598,46 +598,54 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal, } static int thermal_get_trend(struct thermal_zone_device *thermal, - int trip, enum thermal_trend *trend) + int trip_index, enum thermal_trend *trend) { struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - enum thermal_trip_type type; - int i; + struct acpi_thermal_trip *acpi_trip; + int t, i; - if (thermal_get_trip_type(thermal, trip, &type)) + if (!tz || trip_index < 0) return -EINVAL; - if (type == THERMAL_TRIP_ACTIVE) { - int trip_temp; - int temp = deci_kelvin_to_millicelsius_with_offset( - tz->temperature, tz->kelvin_offset); - if (thermal_get_trip_temp(thermal, trip, &trip_temp)) - return -EINVAL; + if (tz->trips.critical.valid) + trip_index--; + + if (tz->trips.hot.valid) + trip_index--; + + if (trip_index < 0) + return -EINVAL; - if (temp > trip_temp) { + acpi_trip = &tz->trips.passive.trip; + if (acpi_trip->valid && !trip_index--) { + t = tz->trips.passive.tc1 * (tz->temperature - + tz->last_temperature) + + tz->trips.passive.tc2 * (tz->temperature - + acpi_trip->temperature); + if (t > 0) *trend = THERMAL_TREND_RAISING; - return 0; - } else { - /* Fall back on default trend */ - return -EINVAL; - } + else if (t < 0) + *trend = THERMAL_TREND_DROPPING; + else + *trend = THERMAL_TREND_STABLE; + + return 0; } - /* - * tz->temperature has already been updated by generic thermal layer, - * before this callback being invoked - */ - i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) + - tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.trip.temperature); + t = acpi_thermal_temp(tz, tz->temperature); - if (i > 0) - *trend = THERMAL_TREND_RAISING; - else if (i < 0) - *trend = THERMAL_TREND_DROPPING; - else - *trend = THERMAL_TREND_STABLE; + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + acpi_trip = &tz->trips.active[i].trip; + if (acpi_trip->valid && !trip_index--) { + if (t > acpi_thermal_temp(tz, acpi_trip->temperature)) { + *trend = THERMAL_TREND_RAISING; + return 0; + } + break; + } + } - return 0; + return -EINVAL; } static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal) |