Linux Power Management development
 help / color / mirror / Atom feed
From: Christian Loehle <christian.loehle@arm.com>
To: Tudor Ambarus <tudor.ambarus@linaro.org>,
	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: Thu, 19 Nov 2026 13:24:15 +0000	[thread overview]
Message-ID: <a1c4e409-2d73-4689-b136-41825ee2b61b@arm.com> (raw)
In-Reply-To: <2cc6efc8-db35-4b40-ab71-815f08ed9dc9@linaro.org>

On 11/18/26 14:01, Tudor Ambarus wrote:
> 
> 
> On 11/18/26 3:28 PM, Tudor Ambarus wrote:
>> Would something along the lines work?
> 
> Thinking more about it, caching the window instead of the raw
> thresholds is simpler and closer to your v1, as inten derives from
> low/high anyway. Maybe this:
> 
> diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
> index 7c30401f8fc7..8422a7c970e7 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 window, protected by the thermal zone lock */
> +	int low;
> +	int high;
>  	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,12 +275,22 @@ 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_get_crit_temp(struct thermal_trip *trip, void *arg)
>  {
> -	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] = {};
> +	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,
> +				       int low, int high, int crit)
> +{
> +	struct device *dev = sensor->priv->dev;
> +	u8 thresholds[ACPM_TMU_NUM_THRESHOLDS] = {};
>  	u8 inten = 0;
>  	int ret;
>  
> @@ -288,17 +306,61 @@ static int acpm_tmu_set_trips(struct thermal_zone_device *tz, int low, int high)
>  		inten |= BIT(1);
>  	}
>  
> +	/*
> +	 * The firmware programs all thresholds at once. Set the hardware trip
> +	 * to the critical trip temperature, so that it never fires below the
> +	 * point where the thermal core shuts the system down.
> +	 */
> +	thresholds[ACPM_TMU_HW_TRIP_THRESHOLD] =
> +		clamp_val(crit / MILLIDEGREE_PER_DEGREE, 0, 255);
> +
>  	ret = pm_runtime_resume_and_get(dev);
>  	if (ret)
>  		return ret;
>  
>  	ret = acpm_tmu_update_thresholds(sensor, thresholds, inten);
> +	if (!ret) {
> +		sensor->low = low;
> +		sensor->high = high;
> +	}
>  
>  	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);
> +	int crit = INT_MAX;
> +
> +	/*
> +	 * Use the lowest critical trip temperature. 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);
> +
> +	return acpm_tmu_program_thresholds(sensor, low, high, crit);
> +}
> +
> +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;
> +
> +	/*
> +	 * 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.
> +	 */
> +	return acpm_tmu_program_thresholds(sensor, sensor->low, sensor->high,
> +					   temp);
> +}
> +
>  static int acpm_tmu_change_mode(struct thermal_zone_device *tz,
>  				enum thermal_device_mode mode)
>  {
> @@ -329,6 +391,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)
> @@ -479,6 +542,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;
>  
>  		tzd = devm_thermal_of_zone_register(dev, i, sensor,
>  						    &acpm_tmu_sensor_ops);
> 

Yup something along those lines would work with some minor fixes if we wanna
handle program failures and restore/undo partials.

The alternative is of course to just hardcode slot 7, downstream uses 115C
as a default value (supplied by DT trip point 'hot'). Or do that as a fix and
then follow-up with a proper wire-up? What do you prefer?

  reply	other threads:[~2026-11-19 13:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-11-18 12:06     ` Christian Loehle
2026-11-18 13:28       ` Tudor Ambarus
2026-11-18 14:01         ` Tudor Ambarus
2026-11-19 13:24           ` Christian Loehle [this message]
2026-11-19 13:48             ` 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=a1c4e409-2d73-4689-b136-41825ee2b61b@arm.com \
    --to=christian.loehle@arm.com \
    --cc=bzolnier@gmail.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 \
    --cc=tudor.ambarus@linaro.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