From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796053749; b=xJec9rsaT7RNsxL81RiaWYJnLnPe46ZuYbmgXLil6eepFu0OTNsGXQ6H3ySSj9Td4ZDg 7xXAVGzweQLzERMDrlIGdr7ej/ZXL8zlcqCBzpNjQVjkyDUGPyHgghA4GtYLawRYPm1V+ Fn4z/MRidRfSs00P76FSBEfvjOyXV1M4qcpJDVFtjfBkUO64CeHknQbcREFuBhjF/LeG0 VCtNm6Jjvc+u2aiMda3ZRs9LY9MvWAoJZdlil/FsMyXxHZchHm1e0XX7zeXV/WUPONnA2 8R5zCdxS/3DojEcWLsIdGxZJJxDhdHCYhdJEK9Yopkb0EKZJ8iKuEt+GUcxWVeNCOIw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053749; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Type:X-Mailer:X-Developer-Signature: X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To: Content-Transfer-Encoding; bh=+qkW6VHZvazuuQX0G0Y9koiWlmDZh7cDA4h//bFJ+D8=; b=edJEQARRLzgeH6O5gTys0Sg9fNApTfG2z7pi5NIb05GgybpzQ0Ks7Pdy+lUFggEWNpPo DRhggU++1EmkO72j2X2wZygfNzduuvH7aeppC4GHIso+jpn7nxBFeOLY8JeXJgqz+qxYL x1U6zAk/Q795e8Sm83VF8QqCkf2hm4Q9A6j987G5o9HPI5SNtxMM5xAt5xFJgAAX/t8RR 9sntWX5rJLErVSTweY1LzO55Ry82+NpSbQdr1xwtp8v35qCSaCLuIYKty215GMTd7AHyN z5ECcx+FWGeL2NUGVQi7KOPHEZn6WBGR0fnMEvAW9MhTH/hdcr6StlvS4tEm94fMcjw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FmxkAZMN; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF53B606A31C; Mon, 30 Nov 2026 15:49:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FmxkAZMN Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796053749; b=2vEXa8Vkoe4LaTAWqAEoq4YEsyUyzqI+z8cTkjfGQNksz6mvfTwOUsNN8VB0YWXx02Pn YlFLdojfwKGCQCiAdRuvgZdjzr0JX8I9Ud71GWvIK6S8UXX5kDWvqTaz/rH3fxk1Bplql Aju+BMXkLX5Ux611tVvwZr1RE0RafhNu0zp8APy8mxfcThNQnJl09RL5QnQn+SgAZLMwL rV3v8h+YxYiezngjLsttppx66Zqs58+t0mH8/tMDcKljZAW/BkZvNTOWBvz1ucsGrvNox lR9S9s24Af+3y81ZoWQKw8M6W0a6ot0QmlPen1WAWeF0+2RdsMZnLzYG1cw+3ul74nA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796053749; h=DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Type:X-Mailer:X-Developer-Signature: X-Developer-Key:X-Endpoint-Received:X-Original-From:Reply-To: Content-Transfer-Encoding; bh=+qkW6VHZvazuuQX0G0Y9koiWlmDZh7cDA4h//bFJ+D8=; b=HT/IYzC0PIgeir5hBfy6Op/ZqD5JyPBNzS4qdZVESLprn2Rfu30TjTGhPHz4o+aE6UcS ewIq9+l9kgKxkaoTCdu9nAZjo1rRX+I/J2dba9HsBmjCgoAmZmvhXhJJQxTnr6Zg0TzD3 phzOp2us7uKrSi49RXU6XhhF1KTFqFiH9hUnmSvdUG9ccMDr6INHP/dwXIUVUUvIzyf6J MOs1Hfaf7B83rQiq8VCzr8CNv2n8cbO+pEfMdF+3fW4YIMgA3voOYzwqOc7gCYEj8MUDD +YDcsn7NK+2tszsS6f5kSLAp6sdx+Qy3kDIHoAYvi1xFUuiZfZXHMKphzJ9oGi9k12g== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 732041F00898; Mon, 30 Nov 2026 15:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796053749; bh=+qkW6VHZvazuuQX0G0Y9koiWlmDZh7cDA4h//bFJ+D8=; h=From:To:Cc:Subject:Date:Reply-To; b=FmxkAZMN5IVy/mYqLTZUYgCCnpn0iLV8r6a//4EgOwWQTw+W4i964GXlu0UzZcOsG KlB321iaGu59O+/+YqCw1EbEBSPjrg1kzHeyFutMzvOZjUUJ9xQNZa682I97We9VU2 Xgs60Fg06mRskKfiDGC7W7AiuSzlqDhpU0a9U91l1UrepJVjRxnWU6PE9FK7+GDy6c Q7o1/srNSZbkpN7BisrNBYRt8L7GHz5jZCU8MdW9B83K6Lns1eyVGogKpWG5NpUIjl dQBydAshBf0smlJ8vXOVF4yN3pIylCsy+sTJ3J8pTJe9Rsx5HBNKN5csUh8W8sQNIS LnNnld8VqeI0g== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id DFD6C4E92A; Mon, 30 Nov 2026 15:48:55 +0000 (UTC) From: Ilia Snezhkov via B4 Relay 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> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 X-Original-From: Ilia Snezhkov Reply-To: iasnezhkov@gmail.com Content-Transfer-Encoding: 7bit From: Ilia Snezhkov 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)