[PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend()

André Draszik andre.draszik at linaro.org
Fri Dec 4 02:05:28 PST 2026


With only the upper bound of the trip window armed, the thermal core
only polls a CPU zone at its passive polling period while the zone is
inside its window. Because cluster temperatures swing by 15 K or more
within 15 ms (heating under load or hardware-throttling at the hot
trip), the core's two-sample trend lags the zone and step_wise lets the
big cluster run into the hot trip, where the hardware throttles it.

Add .get_trend() to report rising at or above the trip and dropping
below it, caching the last .get_temp() reading under tz->lock.

Pixel 6, non-debug kernel, 250 ms polling, one boot, 2 to 3 runs per
cell. Columns are TMU interrupts, peak temperature of the big cluster
zone and the throughput of a busy loop on the two Cortex-X1 cores in
million iterations per second.

Both Cortex-X1 cores loaded for 8 s:

          step_wise                    power_allocator
  before  85-232 101-102 °C 0.87-1.10  28 82-83 °C 0.50-0.51
  after   4-6    98-100 °C  1.03-1.06  28 83-85 °C 0.46-0.49

All eight cores loaded for 60 s under step_wise:

  before  3700-4450 104-105 °C 0.64-0.66
  after   9-95      100-101 °C 0.72-0.77

"arm64: dts: exynos: gs101: tune CPU thermal zones" tunes DT polling and
sustainable-power for power_allocator.

Signed-off-by: André Draszik <andre.draszik at linaro.org>
---
 drivers/thermal/samsung/acpm-tmu.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index ff7a07dbd58a..5c3285f0bd20 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -77,8 +77,9 @@ struct acpm_tmu_sensor {
 	struct acpm_tmu_priv *priv;
 	struct mutex lock; /* protects sensor state */
 	enum thermal_device_mode mode;
-	/* Last requested upper bound, protected by the thermal zone lock */
+	/* Protected by the thermal zone lock */
 	int high;
+	int temp;
 	bool enabled;
 };
 
@@ -232,6 +233,26 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 		return ret;
 
 	*temp = acpm_temp * MILLIDEGREE_PER_DEGREE;
+	sensor->temp = *temp;
+
+	return 0;
+}
+
+static int acpm_tmu_get_trend(struct thermal_zone_device *tz,
+			      const struct thermal_trip *trip,
+			      enum thermal_trend *trend)
+{
+	struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
+
+	if (sensor->temp == THERMAL_TEMP_INVALID)
+		return -EINVAL;
+
+	/*
+	 * Cluster temperatures swing faster than polling can track, so a
+	 * two-sample delta is unreliable.
+	 */
+	*trend = sensor->temp >= trip->temperature ? THERMAL_TREND_RAISING :
+						      THERMAL_TREND_DROPPING;
 
 	return 0;
 }
@@ -414,6 +435,7 @@ static int acpm_tmu_change_mode(struct thermal_zone_device *tz,
 static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
 	.change_mode = acpm_tmu_change_mode,
 	.get_temp = acpm_tmu_get_temp,
+	.get_trend = acpm_tmu_get_trend,
 	.set_trips = acpm_tmu_set_trips,
 	.set_trip_temp = acpm_tmu_set_trip_temp,
 };
@@ -569,6 +591,7 @@ static int acpm_tmu_probe(struct platform_device *pdev)
 		sensor->group = &data->sensor_groups[i];
 		sensor->priv = priv;
 		sensor->high = INT_MAX;
+		sensor->temp = THERMAL_TEMP_INVALID;
 
 		tzd = devm_thermal_of_zone_register(dev, i, sensor,
 						    &acpm_tmu_sensor_ops);

-- 
2.56.1.915.g69d5ec7298-goog




More information about the linux-arm-kernel mailing list