Skip to content

Commit 9caaad2

Browse files
committed
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 <[email protected]>
1 parent ec23c1c commit 9caaad2

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

drivers/acpi/thermal.c

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -598,46 +598,54 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
598598
}
599599

600600
static int thermal_get_trend(struct thermal_zone_device *thermal,
601-
int trip, enum thermal_trend *trend)
601+
int trip_index, enum thermal_trend *trend)
602602
{
603603
struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
604-
enum thermal_trip_type type;
605-
int i;
604+
struct acpi_thermal_trip *acpi_trip;
605+
int t, i;
606606

607-
if (thermal_get_trip_type(thermal, trip, &type))
607+
if (!tz || trip_index < 0)
608608
return -EINVAL;
609609

610-
if (type == THERMAL_TRIP_ACTIVE) {
611-
int trip_temp;
612-
int temp = deci_kelvin_to_millicelsius_with_offset(
613-
tz->temperature, tz->kelvin_offset);
614-
if (thermal_get_trip_temp(thermal, trip, &trip_temp))
615-
return -EINVAL;
610+
if (tz->trips.critical.valid)
611+
trip_index--;
612+
613+
if (tz->trips.hot.valid)
614+
trip_index--;
615+
616+
if (trip_index < 0)
617+
return -EINVAL;
616618

617-
if (temp > trip_temp) {
619+
acpi_trip = &tz->trips.passive.trip;
620+
if (acpi_trip->valid && !trip_index--) {
621+
t = tz->trips.passive.tc1 * (tz->temperature -
622+
tz->last_temperature) +
623+
tz->trips.passive.tc2 * (tz->temperature -
624+
acpi_trip->temperature);
625+
if (t > 0)
618626
*trend = THERMAL_TREND_RAISING;
619-
return 0;
620-
} else {
621-
/* Fall back on default trend */
622-
return -EINVAL;
623-
}
627+
else if (t < 0)
628+
*trend = THERMAL_TREND_DROPPING;
629+
else
630+
*trend = THERMAL_TREND_STABLE;
631+
632+
return 0;
624633
}
625634

626-
/*
627-
* tz->temperature has already been updated by generic thermal layer,
628-
* before this callback being invoked
629-
*/
630-
i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) +
631-
tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.trip.temperature);
635+
t = acpi_thermal_temp(tz, tz->temperature);
632636

633-
if (i > 0)
634-
*trend = THERMAL_TREND_RAISING;
635-
else if (i < 0)
636-
*trend = THERMAL_TREND_DROPPING;
637-
else
638-
*trend = THERMAL_TREND_STABLE;
637+
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
638+
acpi_trip = &tz->trips.active[i].trip;
639+
if (acpi_trip->valid && !trip_index--) {
640+
if (t > acpi_thermal_temp(tz, acpi_trip->temperature)) {
641+
*trend = THERMAL_TREND_RAISING;
642+
return 0;
643+
}
644+
break;
645+
}
646+
}
639647

640-
return 0;
648+
return -EINVAL;
641649
}
642650

643651
static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)

0 commit comments

Comments
 (0)