Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT
@ 2026-12-04 10:05 André Draszik
  2026-12-04 10:05 ` [PATCH v2 1/6] arm64: dts: exynos: gs101: raise critical trips André Draszik
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

Hi,

The acpm-tmu driver wakes the thermal core in a storm of interrupts
whenever a GS101 CPU thermal zone is inside its trip window or at its
hot trip: on Pixel 6 that is up to 330 interrupts per second while
power_allocator throttles the two Cortex-X1 cores. This series stops
the storm and adjusts the thermal zones in gs101-tmu.dtsi.

- Raise the critical trips from 105 °C to 115 °C; today a loaded phone
  comes within 3 K of an emergency shutdown.
- Poll the CPU zones every 10 ms while throttling, give them
  sustainable-power, and align switch-on and little-mitigate with the
  vendor DT.
- Add the ACPM TMU set_hysteresis op, which the storm fix needs.
- Collect the pending bits of all probes of a sensor group, stop the
  interrupt storm, and report the trend of a zone relative to its trip
  so that step_wise does not depend on the storm (three patches).

Pixel 6, non-debug kernel. 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. "base" is
next-20261123 with the prerequisite below applied, as ranges over
several boots ("patches 1-2" and "patches 3-6" are from a single boot
each).

Both Cortex-X1 cores loaded for 8 s:

                 step_wise                   power_allocator
  base           49-694  99-100 °C 1.02-1.23 0-2650  58-85 °C 0.23-0.72
  patches 1-2    187-223 99-100 °C 1.14-1.22 125-142 88 °C    1.05
  patches 3-6    3-5     96-99 °C  1.07-1.18 28      81-83 °C 0.49-0.52
  patches 1,3-6  2-6     96-99 °C  1.01-1.12 29-30   81-89 °C 0.48-0.52
  patches 1-6    3-4     93-95 °C  1.08-1.18 4-6     89-91 °C 1.03-1.14

(In one base power_allocator run the big cluster stayed at 500 MHz and
58 °C for all 8 s, below the 80 °C switch-on trip, with 0 interrupts.)

First 110 s after boot: 91 TMU interrupts on base, 7 with patches
1,3-6.

All eight cores loaded for 60 s, step_wise:

  base           101-102 °C within 22 s; the test stops the load there
  patches 1-2    598-793 99 °C      0.84-0.89
  patches 3-6    8       98 °C      0.81 (run 0); 101-102 °C in 0.9 s*
  patches 1,3-6  11-75   100-101 °C 0.68-0.74
  patches 1-6    5       91-93 °C   0.70-0.79

* Two warm back-to-back runs stopped at the 101 °C safety limit (32
  and 30 interrupts), 3 K below the unpatched 105 °C critical trip.

All eight cores loaded for 60 s, power_allocator:

  base           165**   75 °C    0.46
  patches 1-2    44      92 °C    0.75
  patches 3-6    272     82 °C    0.44
  patches 1,3-6  368     84 °C    0.42
  patches 1-6    4-5     91-92 °C 0.69-0.77

** Single base run: the big cluster stayed at 984 MHz (<=75 °C, below
   the 80 °C switch-on trip) for 59.98 s and the mid cluster only hit
   80 °C for ~6 s before staying at 799 MHz (67-71 °C). On patches 3-6
   and 1,3-6, the 272 and 368 interrupts are repeated 80 °C crossings
   without sustainable-power (~4.5-6/s), not a comparator storm.

The vendor kernel polls these zones every 50 ms; 50 ms suffices for
step_wise, but power_allocator oscillates at 50 ms and 20 ms with its
default gains (see patch 2 for numbers).

Merging across maintainer trees:
The series is ordered so that patches 1-2 (DT) and patches 3-6
(firmware + thermal) can be merged in parallel for the same merge
window:

- Patches 1-2 via the Samsung SoC DT tree: no build dependency on
  patches 3-6; gs101-tmu.dtsi is only in linux-next so far, not
  v7.4-rc1. Alone, patches 1-2 match or improve on base across all three
  tables above and saw 35 boot TMU interrupts at 120 s uptime vs 91 at
  110 s and 113 at 62 s on base. The only trade-off while waiting for
  patches 3-6 is noisier moderate load in 70-79 °C as switch-on drops
  to 70 °C: 30 s mid-cluster load peaking at 75 °C saw 91 interrupts and
  259 ms kworker time vs 26 and 7 ms on base.
- Patches 3-6 together via the thermal tree, with an Ack on patch 3 from
  the Samsung/ACPM maintainers or via an immutable branch; patch 5 does
  not build without patch 3. Alone on the unmodified DT, patches 3-6
  stop the storm (3 boot interrupts at 105 s uptime, 0 during 30 s
  mid-cluster load), while power_allocator stays throttled hard until
  patch 2 lands.
- Patches 1,3-6 without patch 2: step_wise is no worse than base with
  the 115 °C critical margin, and power_allocator keeps throttling hard
  until patch 2 lands.
- Patch 6 (.get_trend()) changes step_wise behaviour and can be taken
  or discussed separately, as patches 3-5 do not depend on it; without
  it, step_wise overshoots more once the storm is gone (numbers in
  patch 6).

Prerequisites:
- thermal/drivers/samsung/acpm-tmu: Fix spurious CPU throttling (v3)
  https://lore.kernel.org/r/20261125173959.2198116-1-christian.loehle@arm.com
  Patch 5 builds on its slot 7 handling. It is not in next-20261202.

This series is based on next-20261202. The comparison tables above are
from next-20261123; the acpm-tmu driver, thermal_core.c, the step_wise
and power_allocator governors, the ACPM TMU interface and gs101-tmu.dtsi
are identical in the two. The three driver patches were measured one
after the other in one boot on next-20261202 (non-debug, with patch 1
only in the DT); those numbers are in patches 4-6.

The full v2 series was then verified on Pixel 6 (Oriole) on
next-20261202 with step_wise and power_allocator (8 s dual-X1 and 60 s
all-core loads, plus .set_trip_temp(), .change_mode() and hwmon reads):
- Non-debug kernel: 2-5 TMU interrupts per run, peak big-cluster
  temperature 90-95 °C (0 hot-trip crossings), 1.16-1.21 M iter/s
  (step_wise) and 1.04-1.05 M iter/s (power_allocator) on dual-X1.
- Debug kernel with KASAN and lockdep (debug_locks: 1, zero splats):
  5 TMU interrupts per run, peak big-cluster temperature 91-94 °C
  (0 hot-trip crossings). The debug kernel needs these pending series
  on top:
- usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator
  fixes (v3)
  https://lore.kernel.org/r/20261130-max77759-wait-v3-0-1ee9034dd228@linaro.org
- phy: samsung-ufs: fix gs101 OOB read and use counted config tables
  https://lore.kernel.org/r/20261127-gs101-ufs-phy-oob-v1-0-144b0e04c3a8@linaro.org
Without them, a lockdep report in tcpci_maxim or a KASAN report in the
UFS PHY driver switches lock debugging off during boot. On
next-20261123 the debug kernel also needed "pinctrl: samsung: keep bus
clock enabled", which is in next-20261202.
Not tested: suspend/resume, Pixel 6 Pro (Raven) and probes colder than
about 10 °C.
Known limitation: while a zone sits at its hot trip, the TMU still
raises about 100 interrupts per second (see patch 5); they no longer
wake the thermal core.

Cheers
Andre'

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
Changes in v2:
- Rebase onto next-20261202 and update the prerequisites.
- Split the driver fix (v1 patch 4) into three: OR the pending bits
  (patch 4), fix the storm (patch 5), add .get_trend() (patch 6), with
  tightened comments and no functional change to the combined code. Each
  state was measured on its own; patches 4-6 carry their own numbers.
- Patch 5: the TMU raises an interrupt once per threshold crossing of
  each probe, not for as long as a probe is beyond a threshold; correct
  the commit message and two comments accordingly.
- Patch 5: state that the BIT(8) interrupts at the hot trip remain, and
  that user-space thresholds below the current temperature rely on
  polling.
- Patch 2: say that power_allocator recomputes its power budget on
  every zone update instead of claiming that its control loop runs at
  the polling period; give the heating rate per sensor reading instead
  of "within 8 ms".
- Refer to the other patches of this series by subject instead of by
  number in commit messages, as the patches go through different trees.
- Link to v1: https://lore.kernel.org/r/20261201-b4-acpm-tmu-irq-storm-v1-0-265039ee23d5@linaro.org

---
André Draszik (6):
      arm64: dts: exynos: gs101: raise critical trips
      arm64: dts: exynos: gs101: tune CPU thermal zones
      firmware: samsung: acpm: add TMU set_hysteresis op
      thermal/drivers/samsung: acpm-tmu: OR pending bits
      thermal/drivers/samsung: acpm-tmu: fix IRQ storm
      thermal/drivers/samsung: acpm-tmu: add .get_trend()

 arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi   |  23 ++--
 drivers/firmware/samsung/exynos-acpm-tmu.c         |  29 ++++-
 drivers/firmware/samsung/exynos-acpm-tmu.h         |   3 +
 drivers/firmware/samsung/exynos-acpm.c             |   1 +
 drivers/thermal/samsung/acpm-tmu.c                 | 133 ++++++++++++++-------
 .../linux/firmware/samsung/exynos-acpm-protocol.h  |   3 +
 6 files changed, 135 insertions(+), 57 deletions(-)
---
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
change-id: 20261127-b4-acpm-tmu-irq-storm-dc0fabb5e387
prerequisite-message-id: <20261125173959.2198116-1-christian.loehle@arm.com>
prerequisite-patch-id: e76cca78612886c74f766e2724c499e67208fcae

Best regards,
-- 
André Draszik <andre.draszik@linaro.org>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/6] arm64: dts: exynos: gs101: raise critical trips
  2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
@ 2026-12-04 10:05 ` André Draszik
  2026-12-04 10:05 ` [PATCH v2 2/6] arm64: dts: exynos: gs101: tune CPU thermal zones André Draszik
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

The critical trips of the three GS101 CPU thermal zones are at 105 °C,
only 5 K above their hot trips at 100 °C.

The acpm-tmu driver programs the hot trip into the TMU as the
temperature at which the hardware throttles the CPUs, so a loaded
cluster is expected to reach 100 °C and to exceed it briefly. On Pixel 6
with all eight cores loaded under step_wise, the big cluster zone
reaches 101-102 °C within 22 s in four of four test runs (two boots,
sampled every 100 ms, load stopped at 101 °C), leaving only 3 K of
margin before emergency shutdown.

Raise the critical trips to 115 °C, matching the final trip of these
zones in the vendor gs101.dtsi.

Fixes: c916d3263609 ("arm64: dts: exynos: gs101: Add thermal management unit")
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi b/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi
index 5ca8360ee97e..b81c332e6c42 100644
--- a/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi
+++ b/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi
@@ -46,7 +46,7 @@ little_hot: little-hot {
 				};
 
 				little_critical: little-critical {
-					temperature = <105000>;
+					temperature = <115000>;
 					hysteresis = <2000>;
 					type = "critical";
 				};
@@ -86,7 +86,7 @@ mid_hot: mid-hot {
 				};
 
 				mid_critical: mid-critical {
-					temperature = <105000>;
+					temperature = <115000>;
 					hysteresis = <2000>;
 					type = "critical";
 				};
@@ -126,7 +126,7 @@ big_hot: big-hot {
 				};
 
 				big_critical: big-critical {
-					temperature = <105000>;
+					temperature = <115000>;
 					hysteresis = <2000>;
 					type = "critical";
 				};

-- 
2.56.1.915.g69d5ec7298-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/6] arm64: dts: exynos: gs101: tune CPU thermal zones
  2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
  2026-12-04 10:05 ` [PATCH v2 1/6] arm64: dts: exynos: gs101: raise critical trips André Draszik
@ 2026-12-04 10:05 ` André Draszik
  2026-12-04 10:05 ` [PATCH v2 3/6] firmware: samsung: acpm: add TMU set_hysteresis op André Draszik
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

The GS101 CPU thermal zones are polled every 250 ms while a passive
trip is exceeded and have no sustainable-power.

A 250 ms polling period is too slow for these clusters: on Pixel 6 with
both Cortex-X1 cores loaded, the big cluster zone rises from 85 °C to
above 100 °C from one sensor reading to the next (about 13 ms apart).
With all eight cores loaded for 60 s under step_wise, the big cluster
zone reaches the hot trip at 100 °C, where the hardware throttles the
CPUs. power_allocator recomputes its power budget only on zone updates,
which outside TMU interrupts happen once per polling period. Without
sustainable-power, it estimates the budget from the lowest OPPs and
keeps the big cluster at 851-984 MHz for about 90% of an 8 s dual-X1
run.

Poll every 10 ms instead. Add sustainable-power, lower the switch-on
trips from 80 °C to 70 °C and raise little-mitigate from 90 °C to
95 °C; these are the values of the vendor kernel's gs101.dtsi
(sustainable_power, switch-on and control temperature), and boards can
override them.

The vendor kernel polls every 50 ms. 50 ms suffices for step_wise, but
not for power_allocator: with the gains it derives from
sustainable-power (100 mW/K above and 200 mW/K below the control
temperature of the big cluster) it oscillates at 50 ms and at 20 ms,
and is only steady at 10 ms. The vendor kernel's own controller uses
60 mW/K. Using the vendor's k_po/k_pu/k_i/integral_cutoff gains via
sysfs stabilizes power_allocator at 50 ms (5-7 interrupts, 92-93 °C,
1.05-1.11 M iter/s), but those gains have no DT binding.

Pixel 6, non-debug kernel. 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. Measured with
"thermal/drivers/samsung: acpm-tmu: fix IRQ storm" and
"thermal/drivers/samsung: acpm-tmu: add .get_trend()" applied; all rows
but the first have sustainable-power and the updated trips applied.

Both Cortex-X1 cores loaded for 8 s, 2 to 10 runs per cell from up to
three boots:

  polling (ms)  step_wise                  power_allocator
  250 (before)  2-6 96-99 °C 1.01-1.12   29-30  81-89 °C 0.48-0.52
  250           4-8 95-99 °C 1.01-1.12   30-32  91-93 °C 0.80-0.87
  50            3-4 93-95 °C 1.09-1.18   97-116 91-93 °C 0.87-1.02
  20            3-4 91-93 °C 1.06-1.15   5-202  90-92 °C 0.79-1.09
  10            3-4 93-95 °C 1.08-1.18   4-6    89-91 °C 1.03-1.14

All eight cores loaded for 60 s, 1 to 7 runs per cell:

  polling (ms)  step_wise                   power_allocator
  250 (before)  11-75 100-101 °C 0.68-0.74  368   84 °C    0.42
  250           44-46 101 °C     0.69-0.73  162   99 °C    0.52
  50            5-6   95-98 °C   0.75-0.80  573   97 °C    0.51
  20            5     92-94 °C   0.71-0.79  5-389 91-92 °C 0.62-0.78
  10            5     91-93 °C   0.70-0.79  4-5   91-92 °C 0.69-0.77

A zone is only polled while its switch-on trip is active (above 70 °C
until cooling below 68 °C), so an idle phone is not polled at all. With
the switch-on trips lowered so that all three zones of an idle phone are
polled continuously, polling takes less than 1% of one CPU at 10 ms,
and the battery current rises by 42-49 mA at 10 ms, 20 ms and 50 ms
alike, and by 24 mA at 250 ms.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi b/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi
index b81c332e6c42..4be34b4087c8 100644
--- a/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi
+++ b/arch/arm64/boot/dts/exynos/google/gs101-tmu.dtsi
@@ -12,8 +12,9 @@
 / {
 	thermal-zones {
 		cpucl0-thermal {
-			polling-delay-passive = <250>;
+			polling-delay-passive = <10>;
 			polling-delay = <0>;
+			sustainable-power = <200>;
 			thermal-sensors = <&tmu_top 2>;
 
 			cooling-maps {
@@ -28,13 +29,13 @@ map0 {
 
 			trips {
 				little_switch_on: little-switch-on {
-					temperature = <80000>;
+					temperature = <70000>;
 					hysteresis = <2000>;
 					type = "passive";
 				};
 
 				little_mitigate: little-mitigate {
-					temperature = <90000>;
+					temperature = <95000>;
 					hysteresis = <5000>;
 					type = "passive";
 				};
@@ -54,8 +55,9 @@ little_critical: little-critical {
 		};
 
 		cpucl1-thermal {
-			polling-delay-passive = <250>;
+			polling-delay-passive = <10>;
 			polling-delay = <0>;
+			sustainable-power = <1000>;
 			thermal-sensors = <&tmu_top 1>;
 
 			cooling-maps {
@@ -68,7 +70,7 @@ map0 {
 
 			trips {
 				mid_switch_on: mid-switch-on {
-					temperature = <80000>;
+					temperature = <70000>;
 					hysteresis = <2000>;
 					type = "passive";
 				};
@@ -94,8 +96,9 @@ mid_critical: mid-critical {
 		};
 
 		cpucl2-thermal {
-			polling-delay-passive = <250>;
+			polling-delay-passive = <10>;
 			polling-delay = <0>;
+			sustainable-power = <2000>;
 			thermal-sensors = <&tmu_top 0>;
 
 			cooling-maps {
@@ -108,7 +111,7 @@ map0 {
 
 			trips {
 				big_switch_on: big-switch-on {
-					temperature = <80000>;
+					temperature = <70000>;
 					hysteresis = <2000>;
 					type = "passive";
 				};

-- 
2.56.1.915.g69d5ec7298-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/6] firmware: samsung: acpm: add TMU set_hysteresis op
  2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
  2026-12-04 10:05 ` [PATCH v2 1/6] arm64: dts: exynos: gs101: raise critical trips André Draszik
  2026-12-04 10:05 ` [PATCH v2 2/6] arm64: dts: exynos: gs101: tune CPU thermal zones André Draszik
@ 2026-12-04 10:05 ` André Draszik
  2026-12-04 10:05 ` [PATCH v2 4/6] thermal/drivers/samsung: acpm-tmu: OR pending bits André Draszik
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

The ACPM TMU protocol has no helper for the ACPM_TMU_HYSTERESIS (0x16)
command, so all eight threshold slots of a zone keep the firmware's
default hysteresis of 5 K.

When a zone is enabled, the firmware programs the falling comparator of
each slot to threshold - hysteresis. A client enabling a slot's
interrupt therefore always gets a falling interrupt 5 K below its
threshold and cannot adjust it.

Add acpm_tmu_set_hysteresis() and expose it through struct acpm_tmu_ops.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 drivers/firmware/samsung/exynos-acpm-tmu.c         | 29 +++++++++++++++++-----
 drivers/firmware/samsung/exynos-acpm-tmu.h         |  3 +++
 drivers/firmware/samsung/exynos-acpm.c             |  1 +
 .../linux/firmware/samsung/exynos-acpm-protocol.h  |  3 +++
 4 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/samsung/exynos-acpm-tmu.c b/drivers/firmware/samsung/exynos-acpm-tmu.c
index c68d60b4c0b3..c92ab9a00e2a 100644
--- a/drivers/firmware/samsung/exynos-acpm-tmu.c
+++ b/drivers/firmware/samsung/exynos-acpm-tmu.c
@@ -26,6 +26,7 @@
 #define ACPM_TMU_INTEN		0x12
 #define ACPM_TMU_CONTROL	0x13
 #define ACPM_TMU_IRQ_CLEAR	0x14
+#define ACPM_TMU_HYSTERESIS	0x16
 
 #define ACPM_TMU_TX_DATA_LEN	8
 #define ACPM_TMU_RX_DATA_LEN	7
@@ -115,20 +116,20 @@ int acpm_tmu_read_temp(struct acpm_handle *handle, unsigned int acpm_chan_id,
 	return 0;
 }
 
-int acpm_tmu_set_threshold(struct acpm_handle *handle,
-			   unsigned int acpm_chan_id, u8 tz,
-			   const u8 temperature[8], size_t tlen)
+static int acpm_tmu_set_data(struct acpm_handle *handle,
+			     unsigned int acpm_chan_id, u8 type, u8 tz,
+			     const u8 *data, size_t len)
 {
 	union acpm_tmu_msg msg = {0};
 	struct acpm_xfer xfer;
 	int ret;
 
-	if (tlen > ACPM_TMU_TX_DATA_LEN)
+	if (len > ACPM_TMU_TX_DATA_LEN)
 		return -EINVAL;
 
-	msg.tx.type = ACPM_TMU_THRESHOLD;
+	msg.tx.type = type;
 	msg.tx.tzid = tz;
-	memcpy(msg.tx.data, temperature, tlen);
+	memcpy(msg.tx.data, data, len);
 
 	acpm_set_xfer(&xfer, msg.data, ARRAY_SIZE(msg.data), acpm_chan_id,
 		      true);
@@ -140,6 +141,22 @@ int acpm_tmu_set_threshold(struct acpm_handle *handle,
 	return acpm_tmu_to_linux_err(msg.rx.ret);
 }
 
+int acpm_tmu_set_threshold(struct acpm_handle *handle,
+			   unsigned int acpm_chan_id, u8 tz,
+			   const u8 temperature[8], size_t tlen)
+{
+	return acpm_tmu_set_data(handle, acpm_chan_id, ACPM_TMU_THRESHOLD,
+				 tz, temperature, tlen);
+}
+
+int acpm_tmu_set_hysteresis(struct acpm_handle *handle,
+			    unsigned int acpm_chan_id, u8 tz,
+			    const u8 hysteresis[8], size_t hlen)
+{
+	return acpm_tmu_set_data(handle, acpm_chan_id, ACPM_TMU_HYSTERESIS,
+				 tz, hysteresis, hlen);
+}
+
 int acpm_tmu_set_interrupt_enable(struct acpm_handle *handle,
 				  unsigned int acpm_chan_id, u8 tz, u8 inten)
 {
diff --git a/drivers/firmware/samsung/exynos-acpm-tmu.h b/drivers/firmware/samsung/exynos-acpm-tmu.h
index 8b89f29fda67..960bbc86afc8 100644
--- a/drivers/firmware/samsung/exynos-acpm-tmu.h
+++ b/drivers/firmware/samsung/exynos-acpm-tmu.h
@@ -17,6 +17,9 @@ int acpm_tmu_read_temp(struct acpm_handle *handle, unsigned int acpm_chan_id,
 int acpm_tmu_set_threshold(struct acpm_handle *handle,
 			   unsigned int acpm_chan_id, u8 tz,
 			   const u8 temperature[8], size_t tlen);
+int acpm_tmu_set_hysteresis(struct acpm_handle *handle,
+			    unsigned int acpm_chan_id, u8 tz,
+			    const u8 hysteresis[8], size_t hlen);
 int acpm_tmu_set_interrupt_enable(struct acpm_handle *handle,
 				  unsigned int acpm_chan_id, u8 tz, u8 inten);
 int acpm_tmu_tz_control(struct acpm_handle *handle, unsigned int acpm_chan_id,
diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c
index 15d2f708b0c7..383b27235eb9 100644
--- a/drivers/firmware/samsung/exynos-acpm.c
+++ b/drivers/firmware/samsung/exynos-acpm.c
@@ -689,6 +689,7 @@ static const struct acpm_ops exynos_acpm_driver_ops = {
 		.init = acpm_tmu_init,
 		.read_temp = acpm_tmu_read_temp,
 		.set_threshold = acpm_tmu_set_threshold,
+		.set_hysteresis = acpm_tmu_set_hysteresis,
 		.set_interrupt_enable = acpm_tmu_set_interrupt_enable,
 		.tz_control = acpm_tmu_tz_control,
 		.clear_tz_irq = acpm_tmu_clear_tz_irq,
diff --git a/include/linux/firmware/samsung/exynos-acpm-protocol.h b/include/linux/firmware/samsung/exynos-acpm-protocol.h
index c6b35c0ff300..8d4d3f5a33a8 100644
--- a/include/linux/firmware/samsung/exynos-acpm-protocol.h
+++ b/include/linux/firmware/samsung/exynos-acpm-protocol.h
@@ -41,6 +41,9 @@ struct acpm_tmu_ops {
 	int (*set_threshold)(struct acpm_handle *handle,
 			     unsigned int acpm_chan_id, u8 tz,
 			     const u8 temperature[8], size_t tlen);
+	int (*set_hysteresis)(struct acpm_handle *handle,
+			      unsigned int acpm_chan_id, u8 tz,
+			      const u8 hysteresis[8], size_t hlen);
 	int (*set_interrupt_enable)(struct acpm_handle *handle,
 				    unsigned int acpm_chan_id, u8 tz, u8 inten);
 	int (*tz_control)(struct acpm_handle *handle, unsigned int acpm_chan_id,

-- 
2.56.1.915.g69d5ec7298-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/6] thermal/drivers/samsung: acpm-tmu: OR pending bits
  2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
                   ` (2 preceding siblings ...)
  2026-12-04 10:05 ` [PATCH v2 3/6] firmware: samsung: acpm: add TMU set_hysteresis op André Draszik
@ 2026-12-04 10:05 ` André Draszik
  2026-12-04 10:05 ` [PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm André Draszik
  2026-12-04 10:05 ` [PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend() André Draszik
  5 siblings, 0 replies; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

Each probe of a sensor group has its own pending register, so stopping
at the first non-zero probe in acpm_tmu_clear_pending_irq() prevents
the interrupt handler from seeing which comparators fired across the
group.

OR the pending registers of all probes of the group and return the
result. No functional change intended: the handler still clears the
interrupt and notifies the thermal core if any bit is pending.
"thermal/drivers/samsung: acpm-tmu: fix IRQ storm" uses the returned
bits to decide whether to notify the thermal core.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 drivers/thermal/samsung/acpm-tmu.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index 08856d713d5d..56f0b6c70519 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -393,12 +393,12 @@ static const struct thermal_zone_device_ops acpm_tmu_sensor_ops = {
 	.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 +407,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 +421,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)

-- 
2.56.1.915.g69d5ec7298-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm
  2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
                   ` (3 preceding siblings ...)
  2026-12-04 10:05 ` [PATCH v2 4/6] thermal/drivers/samsung: acpm-tmu: OR pending bits André Draszik
@ 2026-12-04 10:05 ` André Draszik
  2026-12-04 10:23   ` sashiko-bot
  2026-12-04 10:05 ` [PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend() André Draszik
  5 siblings, 1 reply; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

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@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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend()
  2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
                   ` (4 preceding siblings ...)
  2026-12-04 10:05 ` [PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm André Draszik
@ 2026-12-04 10:05 ` André Draszik
  2026-12-04 10:21   ` sashiko-bot
  5 siblings, 1 reply; 9+ messages in thread
From: André Draszik @ 2026-12-04 10:05 UTC (permalink / raw)
  To: Tudor Ambarus, Krzysztof Kozlowski, Peter Griffin, Alim Akhtar,
	Bartlomiej Zolnierkiewicz, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Alexey Klimov, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: Christian Loehle, linux-samsung-soc, linux-arm-kernel, linux-pm,
	devicetree, linux-kernel, André Draszik

With only the upper bound of the trip window armed, the thermal core
only polls a CPU zone at its passive polling period while the zone is
inside its window. Because cluster temperatures swing by 15 K or more
within 15 ms (heating under load or hardware-throttling at the hot
trip), the core's two-sample trend lags the zone and step_wise lets the
big cluster run into the hot trip, where the hardware throttles it.

Add .get_trend() to report rising at or above the trip and dropping
below it, caching the last .get_temp() reading under tz->lock.

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  85-232 101-102 °C 0.87-1.10  28 82-83 °C 0.50-0.51
  after   4-6    98-100 °C  1.03-1.06  28 83-85 °C 0.46-0.49

All eight cores loaded for 60 s under step_wise:

  before  3700-4450 104-105 °C 0.64-0.66
  after   9-95      100-101 °C 0.72-0.77

"arm64: dts: exynos: gs101: tune CPU thermal zones" tunes DT polling and
sustainable-power for power_allocator.

Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 drivers/thermal/samsung/acpm-tmu.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
index ff7a07dbd58a..5c3285f0bd20 100644
--- a/drivers/thermal/samsung/acpm-tmu.c
+++ b/drivers/thermal/samsung/acpm-tmu.c
@@ -77,8 +77,9 @@ struct acpm_tmu_sensor {
 	struct acpm_tmu_priv *priv;
 	struct mutex lock; /* protects sensor state */
 	enum thermal_device_mode mode;
-	/* Last requested upper bound, protected by the thermal zone lock */
+	/* Protected by the thermal zone lock */
 	int high;
+	int temp;
 	bool enabled;
 };
 
@@ -232,6 +233,26 @@ 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.
+	 */
+	*trend = sensor->temp >= trip->temperature ? THERMAL_TREND_RAISING :
+						      THERMAL_TREND_DROPPING;
 
 	return 0;
 }
@@ -414,6 +435,7 @@ 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,
 };
@@ -569,6 +591,7 @@ static int acpm_tmu_probe(struct platform_device *pdev)
 		sensor->group = &data->sensor_groups[i];
 		sensor->priv = priv;
 		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.915.g69d5ec7298-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend()
  2026-12-04 10:05 ` [PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend() André Draszik
@ 2026-12-04 10:21   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-04 10:21 UTC (permalink / raw)
  To: André Draszik; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] thermal: samsung: acpm-tmu: misleading lock comment for enabled
  field
--

commit 9274d2c76141cde5cf418c0a8513c6b4c3588d49
Author: André Draszik <andre.draszik@linaro.org>

thermal/drivers/samsung: acpm-tmu: add .get_trend()

This commit adds a .get_trend() callback to the Samsung ACPM TMU driver
that caches the last .get_temp() reading and reports a rising or dropping
trend relative to the trip temperature.

> diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
> index ff7a07dbd58aa..5c3285f0bd200 100644
> --- a/drivers/thermal/samsung/acpm-tmu.c
> +++ b/drivers/thermal/samsung/acpm-tmu.c
> @@ -77,8 +77,9 @@ struct acpm_tmu_sensor {
>  	struct acpm_tmu_priv *priv;
>  	struct mutex lock; /* protects sensor state */
>  	enum thermal_device_mode mode;
> -	/* Last requested upper bound, protected by the thermal zone lock */
> +	/* Protected by the thermal zone lock */
>  	int high;
> +	int temp;
>  	bool enabled;
>  };

[Severity: Low]
Does the broadened comment now make it look like enabled is also protected by
the thermal zone lock?

enabled is actually protected by sensor->lock (with READ_ONCE()/WRITE_ONCE()
for the fast path in acpm_tmu_get_temp()), and acpm_tmu_control() updates it
during suspend and resume without holding tz->lock.  Moving enabled next to
mode above this comment, or adding a separating comment, would keep the
locking annotation accurate.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-b4-acpm-tmu-irq-storm-v2-0-614fe39140ce@linaro.org?part=6

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm
  2026-12-04 10:05 ` [PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm André Draszik
@ 2026-12-04 10:23   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-04 10:23 UTC (permalink / raw)
  To: André Draszik; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] thermal: acpm-tmu: ignoring low in acpm_tmu_set_trips()
  breaks re-arming
--

commit abc25375b3a7d07fcb911c6b0a8a4096a41cd842
Author: André Draszik <andre.draszik@linaro.org>

thermal/drivers/samsung: acpm-tmu: fix IRQ storm

This commit stops the ACPM TMU IRQ storm by programming only the upper
trip bound into slot 0, parking its falling comparator via
set_hysteresis(), and only notifying the thermal core when
ACPM_TMU_INTPEND_RISE0 is pending.

> diff --git a/drivers/thermal/samsung/acpm-tmu.c b/drivers/thermal/samsung/acpm-tmu.c
> index 56f0b6c70519d..ff7a07dbd58aa 100644
> --- a/drivers/thermal/samsung/acpm-tmu.c
> +++ b/drivers/thermal/samsung/acpm-tmu.c

[ ... ]

> @@ -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);

[Severity: Medium]
Does discarding low in acpm_tmu_set_trips() break re-arming of rising
user-space thresholds below the lowest passive trip on unpolled zones?

On GS101, gs101-tmu.dtsi sets polling-delay = <0> with the lowest passive
trip at 70 C.  If userspace registers a threshold at 50 C with both
THERMAL_THRESHOLD_WAY_UP and THERMAL_THRESHOLD_WAY_DOWN, the first upward
crossing fires RISE[0] and sets low = 50000 and high = 70000.

Because the zone is below 70 C, tz->passive stays 0 and
monitor_thermal_zone() schedules no polling.  Cooling below 50 C never
runs __thermal_zone_device_update(), leaving tz->temperature stale above
50 C and RISE[0] at 70 C so later upward crossings of 50 C stop firing.

The same issue affects non-passive trips if userspace lowers a hot trip
below 70 C or raises the passive trips via sysfs, since OF trips have
THERMAL_TRIP_FLAG_RW_TEMP and crossing a non-passive trip leaves
tz->passive at 0, keeping it stuck in tz->trips_reached after cooling.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-b4-acpm-tmu-irq-storm-v2-0-614fe39140ce@linaro.org?part=5

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-04 10:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 10:05 [PATCH v2 0/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm and tune GS101 DT André Draszik
2026-12-04 10:05 ` [PATCH v2 1/6] arm64: dts: exynos: gs101: raise critical trips André Draszik
2026-12-04 10:05 ` [PATCH v2 2/6] arm64: dts: exynos: gs101: tune CPU thermal zones André Draszik
2026-12-04 10:05 ` [PATCH v2 3/6] firmware: samsung: acpm: add TMU set_hysteresis op André Draszik
2026-12-04 10:05 ` [PATCH v2 4/6] thermal/drivers/samsung: acpm-tmu: OR pending bits André Draszik
2026-12-04 10:05 ` [PATCH v2 5/6] thermal/drivers/samsung: acpm-tmu: fix IRQ storm André Draszik
2026-12-04 10:23   ` sashiko-bot
2026-12-04 10:05 ` [PATCH v2 6/6] thermal/drivers/samsung: acpm-tmu: add .get_trend() André Draszik
2026-12-04 10:21   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox