[PATCH 4/4] thermal/drivers/samsung: acpm-tmu: fix IRQ storm
From: André Draszik
Date: Tue Dec 01 2026 - 08:20:18 EST
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 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, RISE[0] (temp >= low)
and FALL[1] (temp < high - 5 K) stay asserted for as long as the
temperature is inside the window.
2. All GS101 sensor groups consist of several probes.
ACPM_TMU_READ_TEMP returns the maximum across the probes, but the
comparators are ORed across them. A falling comparator at low
therefore fires for as long as any probe is below low, even while
the zone temperature is above it.
3. The firmware always sets BIT(8) in the interrupt enable register,
whatever mask is requested; BIT(8) asserts while the zone is at or
above the slot 7 threshold. acpm_tmu_clear_pending_irq() stops at
the first probe with a pending bit, and 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. OR all probes' pending bits, clear the IRQ
if any is set, and notify the thermal core only on RISE[0] (BIT(0)) so
parked FALL[0] cannot 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).
Stopping the interrupts also removes the sub-poll sampling that
step_wise relies on. Without .get_trend(), the core uses the delta
between two samples, while cluster temperatures change by 15 K within
15 ms (heating under load, or hardware-throttling at the hot trip). In
tests without .get_trend(), the big cluster zone hit 100-102 °C in
6/7 dual-X1 runs and 106-111 °C under all-core load. Add .get_trend()
to report rising at or above the trip and dropping below it, caching
the last .get_temp() reading under tz->lock.
TMU interrupts on Pixel 6 (non-debug kernel, 250 ms DT, before/after):
before after
first 110 s after boot 91 7
8 s dual-X1 load, power_allocator 0-2650 29-30
8 s dual-X1 load, step_wise 49-694 2-6
Under dual-X1 step_wise load, peak big-cluster temperature drops from
99-100 °C to 96-99 °C at comparable throughput (1.01-1.12 vs 1.02-1.23 M
iter/s), and 60 s all-core load reaches 100-101 °C instead of hitting
101-102 °C within 22 s. Patch 2 tunes DT polling and sustainable-power
for power_allocator.
Fixes: 50a2c5d4062a ("thermal/drivers/samsung: Add Exynos ACPM TMU driver GS101")
Signed-off-by: André Draszik <andre.draszik@xxxxxxxxxx>
---
drivers/thermal/samsung/acpm-tmu.c | 138 ++++++++++++++++++++++++++-----------
1 file changed, 97 insertions(+), 41 deletions(-)
diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 08856d713d5d..ceae8915a491 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,9 +77,10 @@ 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;
+ /* Last temperature read, protected by the thermal zone lock */
+ int temp;
bool enabled;
};
@@ -230,12 +234,33 @@ 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; report trend relative to the trip.
+ */
+ *trend = sensor->temp >= trip->temperature ? THERMAL_TREND_RAISING :
+ THERMAL_TREND_DROPPING;
return 0;
}
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 +283,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 +305,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 +327,54 @@ 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 a valid upper bound exists, set the threshold and enable its interrupt */
+ 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;
+ }
+
+ /*
+ * ACPM enables both RISE[i] and FALL[i] (= threshold - hysteresis) per
+ * bit in inten, and multi-probe groups OR FALL across probes, causing
+ * cooler probes to storm. Program only high in slot 0 with
+ * hysteresis = high so firmware parks FALL[0] at its minimum code;
+ * cooling below low relies on thermal core 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 +385,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 +398,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;
/*
@@ -389,16 +437,17 @@ 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,
};
-static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
+static u32 acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
{
struct acpm_tmu_priv *priv = sensor->priv;
const struct acpm_tmu_ops *ops = &priv->handle->ops->tmu;
unsigned long mask = sensor->group->mask;
- bool pending_irq = false;
+ u32 pending = 0;
int i, ret;
u32 val;
@@ -407,16 +456,13 @@ static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
for_each_set_bit(i, &mask, EXYNOS_TMU_SENSORS_MAX_COUNT) {
ret = regmap_field_read(priv->regmap_fields[i], &val);
if (ret)
- return false;
+ return 0;
- if (val) {
- pending_irq = true;
- break;
- }
+ pending |= val;
}
- if (!pending_irq)
- return false;
+ if (!pending)
+ return 0;
ret = ops->clear_tz_irq(priv->handle, priv->mbox_chan_id,
sensor->group->id);
@@ -424,10 +470,10 @@ static bool acpm_tmu_clear_pending_irq(struct acpm_tmu_sensor *sensor)
dev_err_ratelimited(priv->dev,
"Sensor %u: failed to clear IRQ (%d)\n",
sensor->group->id, ret);
- return false;
+ return 0;
}
- return true;
+ return pending;
}
static irqreturn_t acpm_tmu_thread_fn(int irq, void *id)
@@ -445,14 +491,24 @@ 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);
+ /*
+ * Firmware forces BIT(8) enabled (fires at/above slot 7) and
+ * enables parked FALL[0]; only notify the core on RISE[0].
+ */
+ if (pending & ACPM_TMU_INTPEND_RISE0)
+ thermal_zone_device_update(sensor->tzd,
+ THERMAL_EVENT_UNSPECIFIED);
}
pm_runtime_put_autosuspend(dev);
@@ -539,8 +595,8 @@ 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;
+ sensor->temp = THERMAL_TEMP_INVALID;
tzd = devm_thermal_of_zone_register(dev, i, sensor,
&acpm_tmu_sensor_ops);
--
2.56.1.839.g22a8290db9-goog