* [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling
@ 2026-11-17 8:34 Christian Loehle
2026-11-17 15:37 ` Tudor Ambarus
0 siblings, 1 reply; 3+ messages in thread
From: Christian Loehle @ 2026-11-17 8:34 UTC (permalink / raw)
To: tudor.ambarus, bzolnier
Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel,
linux-samsung-soc, linux-pm, Christian Loehle
acpm_tmu_set_trips() supplies two thresholds, but the ACPM command
writes all eight slots, zero-filling the rest. On GS101, slot 7
controls autonomous CPU throttling even when its interrupt is masked.
Programming it to 0 C limits all three CPU clusters to about 200 MHz
on Pixel 6, while cpufreq continues to report the requested
frequencies.
Program slot 7 from the zone's critical trip before enabling the
sensor and preserve it when updating the low/high interrupt window.
Cache the three temperatures so a writable critical trip can update
the hardware without changing that window.
Reject critical temperatures that cannot be represented by the
firmware's unsigned degree-Celsius byte.
Fixes: 50a2c5d4062a ("thermal/drivers/samsung: Add Exynos ACPM TMU driver GS101")
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
drivers/thermal/samsung/acpm-tmu.c | 62 ++++++++++++++++++++++++++----
1 file changed, 55 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index b86dfa3c3ddb..1d8076f91fe7 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -37,6 +37,8 @@
EXYNOS_TMU_SENSOR(2))
#define GS101_REG_INTPEND(i) ((i) * 0x50 + 0xf8)
+#define GS101_TMU_THRESHOLD_COUNT 8
+#define GS101_TMU_CRITICAL_THRESHOLD 7
enum {
P0_INTPEND,
@@ -68,6 +70,9 @@ struct acpm_tmu_sensor {
struct thermal_zone_device *tzd;
struct acpm_tmu_priv *priv;
struct mutex lock; /* protects sensor state */
+ int low;
+ int high;
+ int critical;
bool enabled;
};
@@ -250,7 +255,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[2], u8 inten)
+ u8 thresholds[GS101_TMU_THRESHOLD_COUNT], u8 inten)
{
struct acpm_tmu_priv *priv = sensor->priv;
struct acpm_handle *handle = priv->handle;
@@ -260,7 +265,7 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
bool was_enabled;
int ret, restore_ret;
- guard(mutex)(&sensor->lock);
+ lockdep_assert_held(&sensor->lock);
was_enabled = sensor->enabled;
@@ -271,7 +276,7 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
}
ret = ops->set_threshold(handle, mbox_chan_id, acpm_sensor_id,
- thresholds, 2);
+ thresholds, GS101_TMU_THRESHOLD_COUNT);
if (!ret) {
ret = ops->set_interrupt_enable(handle, mbox_chan_id,
acpm_sensor_id, inten);
@@ -289,15 +294,21 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
return ret;
}
-static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
+static int acpm_tmu_set_thresholds(struct acpm_tmu_sensor *sensor,
+ int low, int high, int critical)
{
- struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
struct acpm_tmu_priv *priv = sensor->priv;
struct device *dev = priv->dev;
- u8 thresholds[2] = {};
+ u8 thresholds[GS101_TMU_THRESHOLD_COUNT] = {};
u8 inten = 0;
int ret;
+ if (critical < 0 || critical > 255 * MILLIDEGREE_PER_DEGREE)
+ return -EINVAL;
+
+ /* Slot 7 throttles CPU clocks independently of the interrupt mask. */
+ thresholds[GS101_TMU_CRITICAL_THRESHOLD] = critical / MILLIDEGREE_PER_DEGREE;
+
/* 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);
@@ -315,15 +326,43 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
return ret;
ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+ if (!ret) {
+ sensor->low = low;
+ sensor->high = high;
+ sensor->critical = critical;
+ }
pm_runtime_put_autosuspend(dev);
return ret;
}
+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);
+
+ guard(mutex)(&sensor->lock);
+
+ return acpm_tmu_set_thresholds(sensor, low, high, sensor->critical);
+}
+
+static int acpm_tmu_set_trip_temp(struct thermal_zone_device *tz,
+ const struct thermal_trip *trip, int temp)
+{
+ struct acpm_tmu_sensor *sensor = thermal_zone_device_priv(tz);
+
+ if (trip->type != THERMAL_TRIP_CRITICAL)
+ return 0;
+
+ guard(mutex)(&sensor->lock);
+
+ return acpm_tmu_set_thresholds(sensor, sensor->low, sensor->high, temp);
+}
+
static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
.get_temp = acpm_tmu_get_temp,
.set_trips = acpm_tmu_set_trips,
+ .set_trip_temp = acpm_tmu_set_trip_temp,
};
static int acpm_tmu_has_pending_irq(struct acpm_tmu_sensor *sensor,
@@ -469,6 +508,7 @@ static int acpm_tmu_probe(struct platform_device *pdev)
for (i = 0; i < priv->num_sensors; i++) {
struct acpm_tmu_sensor *sensor = &priv->sensors[i];
+ int critical;
mutex_init(&sensor->lock);
sensor->group = &data->sensor_groups[i];
@@ -488,8 +528,16 @@ static int acpm_tmu_probe(struct platform_device *pdev)
goto err_rollback;
}
+ ret = thermal_zone_get_crit_temp(sensor->tzd, &critical);
+ if (ret) {
+ ret = dev_err_probe(dev, ret, "Sensor %d has no critical trip\n", i);
+ goto err_rollback;
+ }
+
mutex_lock(&sensor->lock);
- ret = acpm_tmu_op_tz_control(sensor, true);
+ ret = acpm_tmu_set_thresholds(sensor, -INT_MAX, INT_MAX, critical);
+ if (!ret)
+ ret = acpm_tmu_op_tz_control(sensor, true);
mutex_unlock(&sensor->lock);
if (ret) {
ret = dev_err_probe(dev, ret, "Failed to enable sensor %d\n", i);
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling
2026-11-17 8:34 [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling Christian Loehle
@ 2026-11-17 15:37 ` Tudor Ambarus
2026-11-17 16:41 ` Christian Loehle
0 siblings, 1 reply; 3+ messages in thread
From: Tudor Ambarus @ 2026-11-17 15:37 UTC (permalink / raw)
To: Christian Loehle, bzolnier
Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel,
linux-samsung-soc, linux-pm, Juan Yescas
Hi, Christian,
Thanks for the patch!
On 11/17/26 10:34 AM, Christian Loehle wrote:
> acpm_tmu_set_trips() supplies two thresholds, but the ACPM command
> writes all eight slots, zero-filling the rest. On GS101, slot 7
> controls autonomous CPU throttling even when its interrupt is masked.
> Programming it to 0 C limits all three CPU clusters to about 200 MHz
> on Pixel 6, while cpufreq continues to report the requested
> frequencies.
Could you share how you discovered this? I don't have access to the
ACPM firmware sources, and the downstream driver doesn't state it
either.
How did you measure the actual CPU frequency, given that cpufreq
keeps reporting the requested one?
Do you know whether slots 2-6 have any side effects as well?
Also note that Daniel has already queued a set of acpm-tmu fixes in
thermal/linux-next, so this patch will need to be reworked on top of
them.
>
> Program slot 7 from the zone's critical trip before enabling the
> sensor and preserve it when updating the low/high interrupt window.
> Cache the three temperatures so a writable critical trip can update
> the hardware without changing that window.
I think this can be handled with a smaller change: look up the
critical trip in .set_trips() itself. The zone lock is held there, so
for_each_thermal_trip() can be used. That avoids caching
low/high/critical, the .set_trip_temp() callback and the probe changes.
Cheers,
ta
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling
2026-11-17 15:37 ` Tudor Ambarus
@ 2026-11-17 16:41 ` Christian Loehle
0 siblings, 0 replies; 3+ messages in thread
From: Christian Loehle @ 2026-11-17 16:41 UTC (permalink / raw)
To: Tudor Ambarus, bzolnier
Cc: krzk, rafael, daniel.lezcano, lukasz.luba, linux-kernel,
linux-samsung-soc, linux-pm, Juan Yescas
On 11/17/26 15:37, Tudor Ambarus wrote:
> Hi, Christian,
>
> Thanks for the patch!
>
> On 11/17/26 10:34 AM, Christian Loehle wrote:
>> acpm_tmu_set_trips() supplies two thresholds, but the ACPM command
>> writes all eight slots, zero-filling the rest. On GS101, slot 7
>> controls autonomous CPU throttling even when its interrupt is masked.
>> Programming it to 0 C limits all three CPU clusters to about 200 MHz
>> on Pixel 6, while cpufreq continues to report the requested
>> frequencies.
>
> Could you share how you discovered this? I don't have access to the
> ACPM firmware sources, and the downstream driver doesn't state it
> either.
Neither do I, I discovered this randomly through running regression tests
on Energy-Aware Scheduling on the Pixel6 and acpm-tmu (7.4-rc1) causes a
massive energy regression (+~1000%) for the same workloads.
The reason is this DVFS throttling.
>
> How did you measure the actual CPU frequency, given that cpufreq
> keeps reporting the requested one?
PMU counters CPU_CYCLES
>
> Do you know whether slots 2-6 have any side effects as well?
I hadn't discovered any.
>
> Also note that Daniel has already queued a set of acpm-tmu fixes in
> thermal/linux-next, so this patch will need to be reworked on top of
> them.
will rebase then!
>
>>
>> Program slot 7 from the zone's critical trip before enabling the
>> sensor and preserve it when updating the low/high interrupt window.
>> Cache the three temperatures so a writable critical trip can update
>> the hardware without changing that window.
>
> I think this can be handled with a smaller change: look up the
> critical trip in .set_trips() itself. The zone lock is held there, so
> for_each_thermal_trip() can be used. That avoids caching
> low/high/critical, the .set_trip_temp() callback and the probe changes.
Ah yep you're right, will fix and resend.
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 16:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 8:34 [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling Christian Loehle
2026-11-17 15:37 ` Tudor Ambarus
2026-11-17 16:41 ` Christian Loehle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®