mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tudor Ambarus <tudor.ambarus@linaro.org>
To: Christian Loehle <christian.loehle@arm.com>,
	bzolnier@gmail.com, Daniel Lezcano <daniel.lezcano@kernel.org>
Cc: krzk@kernel.org, rafael@kernel.org, lukasz.luba@arm.com,
	linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	linux-pm@vger.kernel.org, Juan Yescas <jyescas@google.com>
Subject: Re: [PATCH] thermal: samsung: acpm-tmu: Fix spurious CPU throttling
Date: Wed, 18 Nov 2026 15:28:45 +0200	[thread overview]
Message-ID: <4d51fe5f-d233-44d4-a50e-ef168b6f0402@linaro.org> (raw)
In-Reply-To: <b2b0ddc6-964f-4d8d-86d4-a0bc24d9022e@arm.com>



On 11/18/26 2:06 PM, Christian Loehle wrote:
> On 11/17/26 16:41, Christian Loehle wrote:
>> 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!
> 
> Okay, maybe I'm missing something but AFAICS we have to do the set_trip_temp
> because thermal core looks only at min/max and may skip set_trips() in case

ah, you're right!

> these are unchanged, missing a critical update.
> So the minimal I see working is making 'critical' (again, this is my
> interpretation of the value, if you want it named anything else, just shoot)
> non-writable by failing it's set_trip_temp()?
> Or is there another way?

While I like it, the problem is that the trip is writable in sysfs but
always failing.

An alternative is to touch the core and let OF drivers mark trips
read-only but maybe this is not suitable for a quick fix. We need to
involve Daniel.

So I think your v1 approach of caching and updating the hardware from
.set_trip_temp() is the right one after all. I'd just look up the
critical trip in .set_trips() instead of caching it from probe, and
cache the last programmed thresholds and interrupt mask.

Would something along the lines work?

diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 7c30401f8fc7..b2e5b1f6641a 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -39,6 +39,10 @@
 
 #define GS101_REG_INTPEND(i)		((i) * 0x50 + 0xf8)
 
+#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
+
 enum {
 	P0_INTPEND,
 	P1_INTPEND,
@@ -70,6 +74,9 @@ struct acpm_tmu_sensor {
 	struct acpm_tmu_priv *priv;
 	struct mutex lock; /* protects sensor state */
 	enum thermal_device_mode mode;
+	/* Last programmed thresholds, protected by the thermal zone lock */
+	u8 thresholds[ACPM_TMU_NUM_THRESHOLDS];
+	u8 inten;
 	bool enabled;
 };
 
@@ -228,7 +235,8 @@ 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[ACPM_TMU_NUM_THRESHOLDS],
+				      u8 inten)
 {
 	struct acpm_tmu_priv *priv = sensor->priv;
 	struct acpm_handle *handle = priv->handle;
@@ -249,7 +257,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, ACPM_TMU_NUM_THRESHOLDS);
 	if (!ret) {
 		ret = ops->set_interrupt_enable(handle, mbox_chan_id,
 						acpm_sensor_id, inten);
@@ -267,14 +275,56 @@ static int acpm_tmu_update_thresholds(struct acpm_tmu_sensor *sensor,
 	return ret;
 }
 
+static int acpm_tmu_get_crit_temp(struct thermal_trip *trip, void *arg)
+{
+	int *temp = arg;
+
+	if (trip->type == THERMAL_TRIP_CRITICAL &&
+	    trip->temperature != THERMAL_TEMP_INVALID)
+		*temp = min(*temp, trip->temperature);
+
+	return 0;
+}
+
+static int acpm_tmu_program_thresholds(struct acpm_tmu_sensor *sensor,
+				       u8 thresholds[ACPM_TMU_NUM_THRESHOLDS],
+				       u8 inten)
+{
+	struct device *dev = sensor->priv->dev;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret)
+		return ret;
+
+	ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+	if (!ret) {
+		memcpy(sensor->thresholds, thresholds, sizeof(sensor->thresholds));
+		sensor->inten = inten;
+	}
+
+	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);
-	struct acpm_tmu_priv *priv = sensor->priv;
-	struct device *dev = priv->dev;
-	u8 thresholds[2] = {};
+	u8 thresholds[ACPM_TMU_NUM_THRESHOLDS] = {};
+	int crit = INT_MAX;
 	u8 inten = 0;
-	int ret;
+
+	/*
+	 * The firmware programs all thresholds at once. Set the hardware trip
+	 * to the lowest critical trip temperature, so that it never fires
+	 * below the point where the thermal core shuts the system down. If
+	 * the zone has no critical trip, crit stays INT_MAX and is clamped to
+	 * the highest threshold value.
+	 */
+	for_each_thermal_trip(tz, acpm_tmu_get_crit_temp, &crit);
+	thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] =
+		clamp_val(crit / MILLIDEGREE_PER_DEGREE, 0, 255);
 
 	/* If a valid lower bound exists, set the threshold and enable its interrupt */
 	if (low > -INT_MAX) {
@@ -288,15 +338,28 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
 		inten |= BIT(1);
 	}
 
-	ret = pm_runtime_resume_and_get(dev);
-	if (ret)
-		return ret;
+	return acpm_tmu_program_thresholds(sensor, thresholds, inten);
+}
 
-	ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
+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);
+	u8 thresholds[ACPM_TMU_NUM_THRESHOLDS];
 
-	pm_runtime_put_autosuspend(dev);
+	if (trip->type != THERMAL_TRIP_CRITICAL)
+		return 0;
 
-	return ret;
+	/*
+	 * The thermal core skips .set_trips() when the low/high window does
+	 * not change, so update the hardware trip threshold here, keeping the
+	 * last programmed window.
+	 */
+	memcpy(thresholds, sensor->thresholds, sizeof(thresholds));
+	thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] =
+		clamp_val(temp / MILLIDEGREE_PER_DEGREE, 0, 255);
+
+	return acpm_tmu_program_thresholds(sensor, thresholds, sensor->inten);
 }
 
 static int acpm_tmu_change_mode(struct thermal_zone_device *tz,
@@ -329,6 +392,7 @@ static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
 	.change_mode = acpm_tmu_change_mode,
 	.get_temp = acpm_tmu_get_temp,
 	.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)



  reply	other threads:[~2026-11-18 13:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  8:34 Christian Loehle
2026-11-17 15:37 ` Tudor Ambarus
2026-11-17 16:41   ` Christian Loehle
2026-11-18 12:06     ` Christian Loehle
2026-11-18 13:28       ` Tudor Ambarus [this message]
2026-11-18 14:01         ` Tudor Ambarus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d51fe5f-d233-44d4-a50e-ef168b6f0402@linaro.org \
    --to=tudor.ambarus@linaro.org \
    --cc=bzolnier@gmail.com \
    --cc=christian.loehle@arm.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=jyescas@google.com \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®