* [PATCH] thermal: core: drop duplicate CDEV_STATE_UPDATE netlink events
@ 2026-11-30 15:48 Ilia Snezhkov via B4 Relay
0 siblings, 0 replies; only message in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-30 15:48 UTC (permalink / raw)
To: rafael, daniel.lezcano
Cc: rui.zhang, lukasz.luba, linux-pm, phone-devel, linux-kernel
From: Ilia Snezhkov <iasnezhkov@gmail.com>
thermal_cdev_set_cur_state() calls thermal_notify_cdev_state_update()
unconditionally on every governor update even when the cooling device
target state did not change. Under polling governors such as
power_allocator, a thermal zone bound to multiple cooling devices
(for example little CPU, big CPU and GPU) broadcasts identical
THERMAL_GENL_EVENT_CDEV_STATE_UPDATE netlink messages on every polling
tick even when each cooling device stays at state 0 or holds a steady
throttling level.
On Android devices running Pixel Thermal HAL's ThermalWatcher (which
logs every received CDEV_STATE_UPDATE event at INFO level), this
generates ~12 redundant netlink broadcasts per second under warm
workloads (~25% of total logcat output during sustained benchmarks)
without representing any actual state transition.
Track the last notified cooling state in struct thermal_cooling_device
(initialized from the existing get_cur_state() call in
thermal_cooling_device_add(), invalidated to THERMAL_CSTATE_INVALID on
sysfs cur_state_store() and thermal_cooling_device_update() under
cdev->lock), and emit thermal_notify_cdev_state_update() only when the
state actually changes.
Leave cdev->ops->set_cur_state(), thermal_cooling_device_stats_update(),
and thermal_debug_cdev_state_update() untouched so drivers that rely on
periodic set_cur_state() invocations keep their existing behavior and no
extra per-tick get_cur_state() hardware reads are introduced.
Tested on an MT6789 smartphone (Linux 6.18) with power_allocator across
a 45C-52C thermal sweep via kprobe on thermal_notify_cdev_state_update():
102 trace_cdev_update calls over 32 ticks emitted 19 netlink
notifications (state transitions only) with 0 consecutive duplicates,
and sysfs cur_state writes invalidated last_state as expected.
Fixes: 55cdf0a283b8 ("thermal: core: Add notifications call in the framework")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
Found and drafted with an AI coding assistant.
drivers/thermal/thermal_core.c | 4 ++++
drivers/thermal/thermal_helpers.c | 8 ++++++--
drivers/thermal/thermal_sysfs.c | 1 +
include/linux/thermal.h | 1 +
4 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index e8d4da0..43b592f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1040,6 +1040,9 @@ int thermal_cooling_device_add(struct thermal_cooling_device *cdev,
if (ret)
current_state = ULONG_MAX;
+ cdev->last_state = current_state <= cdev->max_state ?
+ current_state : THERMAL_CSTATE_INVALID;
+
thermal_cooling_device_setup_sysfs(cdev);
ret = device_add(&cdev->device);
@@ -1188,6 +1191,7 @@ void thermal_cooling_device_update(struct thermal_cooling_device *cdev)
return;
thermal_cooling_device_stats_reinit(cdev);
+ cdev->last_state = THERMAL_CSTATE_INVALID;
list_for_each_entry(ti, &cdev->thermal_instances, cdev_node) {
if (ti->upper == cdev->max_state)
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index b1152ad..4f13eb6 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -144,7 +144,8 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
}
EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
-static int thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev, int state)
+static int thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long state)
{
int ret;
@@ -156,7 +157,10 @@ static int thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev, int s
if (ret)
return ret;
- thermal_notify_cdev_state_update(cdev, state);
+ if (cdev->last_state != state) {
+ cdev->last_state = state;
+ thermal_notify_cdev_state_update(cdev, state);
+ }
thermal_cooling_device_stats_update(cdev, state);
thermal_debug_cdev_state_update(cdev, state);
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 0c2313c..863bcd5 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -558,6 +558,7 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
if (result)
return result;
+ cdev->last_state = THERMAL_CSTATE_INVALID;
thermal_cooling_device_stats_update(cdev, state);
return count;
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 306ad17..494feea 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -124,6 +124,7 @@ struct thermal_cooling_device {
int id;
const char *type;
unsigned long max_state;
+ unsigned long last_state;
struct device device;
void *devdata;
void *stats;
--
2.54.0 (Apple Git-157)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 15:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 15:48 [PATCH] thermal: core: drop duplicate CDEV_STATE_UPDATE netlink events Ilia Snezhkov via B4 Relay
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®