From: Ilia Snezhkov To: rafael@kernel.org, daniel.lezcano@kernel.org Cc: rui.zhang@intel.com, lukasz.luba@arm.com, linux-pm@vger.kernel.org, phone-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] thermal: core: drop duplicate CDEV_STATE_UPDATE netlink events Date: Mon, 30 Nov 2026 15:48:55 +0000 Message-Id: <20261130154855.95907-1-iasnezhkov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796053735; l=4851; i=iasnezhkov@gmail.com; s=mindone2026; h=from:subject:message-id; bh=U5PQ8WXftCP6fNuFsTpnl0jBQfbBRfXc6q7BviETLxE=; b=ovzZJMnxWfHrFGMtKiNFSd5gMUn/YB7X3wMnarYj98qckXg+uFx/U7zIpTTVTwcnJzjMxkyVJ UtAChIPnNQCDCwY97Hn1vKZzWoobaiV25uHg5oCQQOH+3QGN2ofIEb8 X-Developer-Key: i=iasnezhkov@gmail.com; a=ed25519; pk=hQgXfiWi4ukk2jh4BHu1vRVhg9BUivo//AFp50AKMag= X-Endpoint-Received: by B4 Relay for iasnezhkov@gmail.com/mindone2026 with auth_id=1643 List-Id: B4 Relay Submissions 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 --- 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)