From: Ilia Snezhkov via B4 Relay <devnull+iasnezhkov.gmail.com@kernel.org>
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 [thread overview]
Message-ID: <20261130154855.95907-1-iasnezhkov@gmail.com> (raw)
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)
reply other threads:[~2026-11-30 15:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261130154855.95907-1-iasnezhkov@gmail.com \
--to=devnull+iasnezhkov.gmail.com@kernel.org \
--cc=daniel.lezcano@kernel.org \
--cc=iasnezhkov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=phone-devel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
/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