[PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm

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


The driver raises a continuous stream of interrupts whenever a thermal
zone is inside its [low, high] trip window or at or above its hot trip.
On Pixel 6, 8 s of load on the two Cortex-X1 cores under power_allocator
cause up to 2650 TMU interrupts, each of which makes the thermal core
evaluate the zone again.

Three properties of the hardware and the firmware cause this:

1. ACPM_TMU_INTEN enables both the rising (BIT(i)) and the falling
   (BIT(i + 16)) comparator of each slot i in the mask, with
   FALL[i] = threshold[i] - hysteresis[i] and a default hysteresis of
   5 K. With low in slot 0 and high in slot 1, both RISE[0] (at low)
   and FALL[1] (at high - 5 K) sit inside the window and fire
   repeatedly while the zone operates there.
2. All three GS101 CPU sensor groups consist of several probes (5, 2
   and 2). In 3315 logged ACPM_TMU_READ_TEMP replies, the firmware
   always returned the maximum across the group's probes, while each
   probe has its own INTPEND register on the shared IRQ line and
   ACPM_TMU_INTEN applies one mask to the whole group. A cooler probe
   can therefore fire a falling interrupt at low while the reported
   zone temperature remains above low: even in a single-slot test
   (RISE[0] = high, FALL[0] = low), the zone read 2-10 K above low
   (81-101 °C) right after 32 of 35 sampled FALL[0] interrupts.
3. The firmware always sets BIT(8) in the interrupt enable register,
   whatever mask is requested. BIT(8) was only seen pending around the
   slot 7 threshold (zone readings of 98-105 °C with the threshold at
   100 °C), where it fires repeatedly. thermal_zone_device_update()
   runs for any pending bit.

Use slot 0 alone for the window: program RISE[0] = high (rounded up with
DIV_ROUND_UP() so fractional-degree thresholds do not fire immediately
at the truncated degree) and set hysteresis[0] = high via
set_hysteresis(). The firmware then parks FALL[0] at its lowest code
(0x0a4, roughly 10 °C extrapolated from 30-100 °C; behaviour with
probes colder than ~10 °C is untested). Give slot 7 the hot trip's
hysteresis, and unused slots 0 K so their falling comparators do not
wrap to the highest code. Notify the thermal core only if RISE[0]
(BIT(0)) is pending, so that neither BIT(8) nor the parked FALL[0] wake
it.

Consequently, .set_trips() ignores low and relies on polling to detect
cooling below low. Zones with polling-delay = <0> therefore need a
passive lowest trip with non-zero polling-delay-passive (satisfied by
gs101-tmu.dtsi). For the same reason, a user-space threshold below the
current temperature is only reported while the zone is polled.

This does not stop the BIT(8) interrupts themselves: while a zone sits
at its hot trip, every probe still raises BIT(8) each time it rises
above the slot 7 threshold. With the hot trip lowered to 85 °C and both
Cortex-X1 cores loaded, that is about 100 interrupts per second. The
handler clears BIT(8) and notifies the thermal core only if RISE[0] is
pending as well.

Stopping the interrupts also removes the sub-poll sampling that
step_wise relies on: with this patch alone, step_wise lets the big
cluster run into the hot trip, where the BIT(8) interrupts take over.
"thermal/drivers/samsung: acpm-tmu: add .get_trend()" addresses that.

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  22-37  99-100 °C  1.14-1.18  312-1471 83-84 °C 0.51-0.69
  after   85-232 101-102 °C 0.87-1.10  28       82-83 °C 0.50-0.51

All eight cores loaded for 60 s under step_wise, after: 3700-4450
interrupts, 104-105 °C, 0.64-0.66 M iter/s.

Fixes: 50a2c5d4062a ("thermal/drivers/samsung: Add Exynos ACPM TMU driver GS101")
Signed-off-by: André Draszik <andre.draszik at linaro.org>
---
 drivers/thermal/samsung/acpm-tmu.c | 91 +++++++++++++++++++++++++-------------
 1 file changed, 61 insertions(+), 30 deletions(-)

diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 56f0b6c70519..ff7a07dbd58a 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -12,6 +12,8 @@
 #include <linux/err.h>
 #include <linux/firmware/samsung/exynos-acpm-protocol.h>
 #include <linux/interrupt.h>
+#include <linux/limits.h>
+#include <linux/math.h>
 #include <linux/minmax.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
@@ -42,6 +44,7 @@
 #define ACPM_TMU_NUM_THRESHOLDS		8
 /* Threshold 7 throttles the CPUs in hardware, regardless of the INTEN mask. */
 #define ACPM_TMU_HW_TRIP_THRESHOLD	7
+#define ACPM_TMU_INTPEND_RISE0		BIT(0)
 
 enum {
 	P0_INTPEND,
@@ -74,8 +77,7 @@ struct acpm_tmu_sensor {
 	struct acpm_tmu_priv *priv;
 	struct mutex lock; /* protects sensor state */
 	enum thermal_device_mode mode;
-	/* Last requested window, protected by the thermal zone lock */
-	int low;
+	/* Last requested upper bound, protected by the thermal zone lock */
 	int high;
 	bool enabled;
 };
@@ -236,6 +238,7 @@ static int acpm_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 
 static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
 				      u8 thresholds[ACPM_TMU_NUM_THRESHOLDS],
+				      u8 hysteresis[ACPM_TMU_NUM_THRESHOLDS],
 				      u8 inten)
 {
 	struct acpm_tmu_priv *priv = sensor->priv;
@@ -258,10 +261,12 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
 
 	ret = ops->set_threshold(handle, mbox_chan_id, acpm_sensor_id,
 				 thresholds, ACPM_TMU_NUM_THRESHOLDS);
-	if (!ret) {
+	if (!ret)
+		ret = ops->set_hysteresis(handle, mbox_chan_id, acpm_sensor_id,
+					  hysteresis, ACPM_TMU_NUM_THRESHOLDS);
+	if (!ret)
 		ret = ops->set_interrupt_enable(handle, mbox_chan_id,
 						acpm_sensor_id, inten);
-	}
 
 	if (was_enabled) {
 		restore_ret = acpm_tmu_op_tz_control(sensor, true);
@@ -278,15 +283,19 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
 struct acpm_tmu_hot_trip {
 	const struct thermal_trip *updated;
 	int temperature;
+	int hysteresis;
 };
 
-static int acpm_tmu_get_hot_temp(struct thermal_trip *trip, void *arg)
+static int acpm_tmu_get_hot_trip(struct thermal_trip *trip, void *arg)
 {
 	struct acpm_tmu_hot_trip *hot = arg;
 
 	if (trip->type == THERMAL_TRIP_HOT && trip != hot->updated &&
-	    trip->temperature != THERMAL_TEMP_INVALID)
-		hot->temperature = min(hot->temperature, trip->temperature);
+	    trip->temperature != THERMAL_TEMP_INVALID &&
+	    trip->temperature < hot->temperature) {
+		hot->temperature = trip->temperature;
+		hot->hysteresis = trip->hysteresis;
+	}
 
 	return 0;
 }
@@ -296,36 +305,53 @@ static int acpm_tmu_program_thresholds(struct thermal_zone_device *tz,
 {
 	struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
 	struct device *dev = sensor->priv->dev;
-	struct acpm_tmu_hot_trip hot = { trip, INT_MAX };
+	struct acpm_tmu_hot_trip hot = { trip, INT_MAX, 0 };
 	u8 thresholds[ACPM_TMU_NUM_THRESHOLDS] = {};
-	int low = sensor->low, high = sensor->high;
+	u8 hysteresis[ACPM_TMU_NUM_THRESHOLDS] = {};
+	int high = sensor->high;
 	u8 inten = 0;
 	int ret;
 
 	/* Exclude the trip being updated until the proposed value is considered. */
-	for_each_thermal_trip(tz, acpm_tmu_get_hot_temp, &hot);
-	if (temp != THERMAL_TEMP_INVALID)
-		hot.temperature = min(hot.temperature, temp);
-	thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] =
-		clamp_val(hot.temperature / MILLIDEGREE_PER_DEGREE, 0, 255);
-
-	/* If a valid lower bound exists, set the threshold and enable its interrupt */
-	if (low > -INT_MAX) {
-		thresholds[0] = clamp_val(low / MILLIDEGREE_PER_DEGREE, 0, 255);
-		inten |= BIT(0);
+	for_each_thermal_trip(tz, acpm_tmu_get_hot_trip, &hot);
+	if (trip && temp != THERMAL_TEMP_INVALID && temp < hot.temperature) {
+		hot.temperature = temp;
+		hot.hysteresis = trip->hysteresis;
+	}
+
+	if (hot.temperature < INT_MAX) {
+		u8 hot_c = clamp_val(hot.temperature / MILLIDEGREE_PER_DEGREE,
+				     0, U8_MAX);
+
+		thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] = hot_c;
+		hysteresis[ACPM_TMU_HW_TRIP_THRESHOLD] =
+			clamp_val(hot.hysteresis / MILLIDEGREE_PER_DEGREE,
+				  0, hot_c);
+	} else {
+		thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] = U8_MAX;
 	}
 
-	/* If a valid upper bound exists, set the threshold and enable its interrupt */
+	/*
+	 * ACPM enables both RISE[i] and FALL[i] per bit in inten, and probes
+	 * fire independently, so cooler probes would trigger FALL at low while
+	 * the zone is above it. Park FALL[0] at its minimum code with
+	 * hysteresis = high; cooling below low relies on polling.
+	 */
 	if (high < INT_MAX) {
-		thresholds[1] = clamp_val(high / MILLIDEGREE_PER_DEGREE, 0, 255);
-		inten |= BIT(1);
+		u8 high_c = DIV_ROUND_UP(clamp(high, 0,
+					       U8_MAX * MILLIDEGREE_PER_DEGREE),
+					 MILLIDEGREE_PER_DEGREE);
+
+		thresholds[0] = high_c;
+		hysteresis[0] = high_c;
+		inten = BIT(0);
 	}
 
 	ret = pm_runtime_resume_and_get(dev);
 	if (ret)
 		return ret;
 
-	ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+	ret = acpm_tmu_update_thresholds(sensor, thresholds, hysteresis, inten);
 
 	pm_runtime_put_autosuspend(dev);
 
@@ -336,8 +362,7 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
 {
 	struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
 
-	/* The core remembers this window even if programming fails. */
-	sensor->low = low;
+	/* The core remembers high even if programming fails; low relies on polling. */
 	sensor->high = high;
 
 	return acpm_tmu_program_thresholds(tz, NULL, INT_MAX);
@@ -350,7 +375,7 @@ static int acpm_tmu_set_trip_temp(struct thermal_zone_device *tz,
 		return 0;
 
 	if (temp != THERMAL_TEMP_INVALID &&
-	    (temp < 0 || temp > 255 * MILLIDEGREE_PER_DEGREE))
+	    (temp < 0 || temp > U8_MAX * MILLIDEGREE_PER_DEGREE))
 		return -EINVAL;
 
 	/*
@@ -442,14 +467,21 @@ static irqreturn_t acpm_tmu_thread_fn(int irq, void *id)
 
 	for (i = 0; i < priv->num_sensors; i++) {
 		struct acpm_tmu_sensor *sensor = &priv->sensors[i];
+		u32 pending;
+
+		if (!sensor->tzd)
+			continue;
 
-		if (!sensor->tzd || !acpm_tmu_clear_pending_irq(sensor))
+		pending = acpm_tmu_clear_pending_irq(sensor);
+		if (!pending)
 			continue;
 
 		handled = true;
 
-		thermal_zone_device_update(sensor->tzd,
-					   THERMAL_EVENT_UNSPECIFIED);
+		/* Ignore BIT(8) (forced enabled by firmware for slot 7) and parked FALL[0]. */
+		if (pending & ACPM_TMU_INTPEND_RISE0)
+			thermal_zone_device_update(sensor->tzd,
+						   THERMAL_EVENT_UNSPECIFIED);
 	}
 
 	pm_runtime_put_autosuspend(dev);
@@ -536,7 +568,6 @@ static int acpm_tmu_probe(struct platform_device *pdev)
 		mutex_init(&sensor->lock);
 		sensor->group = &data->sensor_groups[i];
 		sensor->priv = priv;
-		sensor->low = -INT_MAX;
 		sensor->high = INT_MAX;
 
 		tzd = devm_thermal_of_zone_register(dev, i, sensor,

-- 
2.56.1.915.g69d5ec7298-goog




More information about the linux-arm-kernel mailing list