From patchwork Fri Oct 4 19:05:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 832899 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B45A01E04AC; Fri, 4 Oct 2024 19:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070994; cv=none; b=kfbFGBpstAc981T/rh+g041IcpwzxRJIqYS45qb51r6BIaZTZf1Pps5gozl0PzOiczNSBIV+ocg27stDs5L+PoqMD83z8dqDEh5Wcbe4Q8y6F/zpJqsvImu3iwC27sC0zBV58GxQK47ASstSmm5s42+6cxloM3UIrtJVEw4yLW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070994; c=relaxed/simple; bh=SP2LqI+kjSAviE0zBp9D61PWBSCXxvORO4Tr/lochTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uPUcTDSq88i08EFHoqz5ugD0d7qf2Ujs9ZG2KatZjY63UxFqNUi40tGmQpcS4nEFzq1tVEGDcNCUZna4etCx7r2oQ+CXvQhV1ErpfLHcMS3G3eO5wQZAA0eFcS4GgnY+KyqpZW70cKxvlO3yycHQvESnO50SnuUn8fCD4cZrbl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=FWl2ii+J reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="FWl2ii+J" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 3f226a37cbbad1de; Fri, 4 Oct 2024 21:43:08 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 692526A9505; Fri, 4 Oct 2024 21:43:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728070988; bh=SP2LqI+kjSAviE0zBp9D61PWBSCXxvORO4Tr/lochTM=; h=From:Subject:Date; b=FWl2ii+JAWmGTQP/2/qeiLsYkth43Lr4+aQafeQ5EskioYc1Rp4CB47NfWxn9tyEM jBtX4gaXAxpCJ9/r5E1fvnhId+gCFC0h/F+u32BENF+z8WugB6uTon964vZMBH9ZaE /wXEXm4BqKmRRQvCm9emLMdi9Fnu78cY5/Wpi5x1LMDdWIdSRra4Qbk8azmnT3RM7o jIcCPYnQFZZq4/xpMdrL/eXp4Nwpv+lAGFFbAFgnx0uyeM5nQ3UCVJwO9ZhN2O4j91 GLeJyLTO4Dn4ELXNJROm8dX2IjyD5Fj5m7bZbWXCzr+Vkmj5jKESAJ7eALYS9VBFwr ys0skxZwvD4Dw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 01/12] thermal: core: Initialize thermal zones before registering them Date: Fri, 04 Oct 2024 21:05:49 +0200 Message-ID: <3336146.44csPzL39Z@rjwysocki.net> In-Reply-To: <2215082.irdbgypaU6@rjwysocki.net> References: <2215082.irdbgypaU6@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvfedgudegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdi X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Since user space can start interacting with a new thermal zone as soon as device_register() called by thermal_zone_device_register_with_trips() returns, it is better to initialize the thermal zone before calling device_register() on it. Fixes: d0df264fbd3c ("thermal/core: Remove pointless thermal_zone_device_reset() function") Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/10527854.nUPlyArG6x@rjwysocki.net/ v1 -> v2: Fix typo in the subject --- drivers/thermal/thermal_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1465,6 +1465,7 @@ thermal_zone_device_register_with_trips( thermal_zone_destroy_device_groups(tz); goto remove_id; } + thermal_zone_device_init(tz); result = device_register(&tz->device); if (result) goto release_device; @@ -1503,7 +1504,6 @@ thermal_zone_device_register_with_trips( mutex_unlock(&thermal_list_lock); - thermal_zone_device_init(tz); /* Update the new thermal zone and mark it as already updated. */ if (atomic_cmpxchg(&tz->need_update, 1, 0)) thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); From patchwork Fri Oct 4 19:09:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 832897 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F16491E04A3; Fri, 4 Oct 2024 19:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070994; cv=none; b=m78k2XlSr27Wz25qs1CUcuIpTgMRIqTfS2qICbXZEGeA2Ji31RNCNXoTaMq6wUgS53ECn7dyqNKQY0fkwSQpAt+3UalyDOd+VVciPRSeEcNlWjeWsM5+jU/zzSPDUWQineoDEUp2FNjuwZD/562OF70e2PLWKvDnCImY8ctBz9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070994; c=relaxed/simple; bh=XDknYcHwRJCGRiktQeXSdagSDdi3Gy/O0jox8ywDg7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RpeFrDip5KTHIO9ltqvQvOx5vDTfXEqmDX8ecOjFkHL305vuWD3aWg4vqUvj+Pc4vh9YEutag0DPy2yJvmInE+IsyKbcaIn8rUFWN17HFG38ZvN7+VKYw7pJdu2/2QXuZ+09y10rjRyPJOUDVzxHHOr4tiBB4iv8vewN5poFtDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=kS0B1Gv6; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="kS0B1Gv6" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 1181a698366aaaa3; Fri, 4 Oct 2024 21:43:08 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id F3A196A9505; Fri, 4 Oct 2024 21:43:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728070988; bh=XDknYcHwRJCGRiktQeXSdagSDdi3Gy/O0jox8ywDg7o=; h=From:Subject:Date; b=kS0B1Gv6ch0y9cLw020dsscYAXrVs71ovPwTgJKvI+xg03bETXolcUAB/XRjJQV41 cXemUPV7c0OUkE7RfgOEl4JpZiprHQQzPj85xi/U5vDq2OS8v6cZGcZ6zhdL7cNsBw fE18v20qsPFhh4LsxFpOUiw0ewNfORlAZxGwqYFFcBFi+FNT1kD35XyPX3/CfdXXL5 5kSY+wNDttq8rf2Ab5FzYdkBBC+oEFuEr6z8CICkSdNKMHABElodS2kKRn75qoB14o sEYGl2fH0eI5YTgb4RlVxMabfKofaSR1iazzvlcOn3ibGcVhefAVLrr1smOx/bVZzU FIdPPbdwnGrdA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 02/12] thermal: core: Rearrange PM notification code Date: Fri, 04 Oct 2024 21:09:23 +0200 Message-ID: <2299090.iZASKD2KPV@rjwysocki.net> In-Reply-To: <2215082.irdbgypaU6@rjwysocki.net> References: <2215082.irdbgypaU6@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvfedgudegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdi X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Move the code run for each thermal zone by the thermal PM notify handler to separate functions. This will help to make some subsequent changes look somewhat more straightforward, among other things. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/4940614.GXAFRqVoOG@rjwysocki.net/ v1 -> v2: The thermal zone guard has not been defined yet, so use lock/unlock directly on the thermal zone lock and update the changelog accordingly. --- drivers/thermal/thermal_core.c | 88 +++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 42 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1675,6 +1675,48 @@ static void thermal_zone_device_resume(s mutex_unlock(&tz->lock); } +static void thermal_zone_pm_prepare(struct thermal_zone_device *tz) +{ + mutex_lock(&tz->lock); + + if (tz->resuming) { + /* + * thermal_zone_device_resume() queued up for this zone has not + * acquired the lock yet, so release it to let the function run + * and wait util it has done the work. + */ + mutex_unlock(&tz->lock); + + wait_for_completion(&tz->resume); + + mutex_lock(&tz->lock); + } + + tz->suspended = true; + + mutex_unlock(&tz->lock); +} + +static void thermal_zone_pm_complete(struct thermal_zone_device *tz) +{ + mutex_lock(&tz->lock); + + cancel_delayed_work(&tz->poll_queue); + + reinit_completion(&tz->resume); + tz->resuming = true; + + /* + * Replace the work function with the resume one, which will restore the + * original work function and schedule the polling work if needed. + */ + INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_resume); + /* Queue up the work without a delay. */ + mod_delayed_work(system_freezable_power_efficient_wq, &tz->poll_queue, 0); + + mutex_unlock(&tz->lock); +} + static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) { @@ -1686,27 +1728,8 @@ static int thermal_pm_notify(struct noti case PM_SUSPEND_PREPARE: mutex_lock(&thermal_list_lock); - list_for_each_entry(tz, &thermal_tz_list, node) { - mutex_lock(&tz->lock); - - if (tz->resuming) { - /* - * thermal_zone_device_resume() queued up for - * this zone has not acquired the lock yet, so - * release it to let the function run and wait - * util it has done the work. - */ - mutex_unlock(&tz->lock); - - wait_for_completion(&tz->resume); - - mutex_lock(&tz->lock); - } - - tz->suspended = true; - - mutex_unlock(&tz->lock); - } + list_for_each_entry(tz, &thermal_tz_list, node) + thermal_zone_pm_prepare(tz); mutex_unlock(&thermal_list_lock); break; @@ -1715,27 +1738,8 @@ static int thermal_pm_notify(struct noti case PM_POST_SUSPEND: mutex_lock(&thermal_list_lock); - list_for_each_entry(tz, &thermal_tz_list, node) { - mutex_lock(&tz->lock); - - cancel_delayed_work(&tz->poll_queue); - - reinit_completion(&tz->resume); - tz->resuming = true; - - /* - * Replace the work function with the resume one, which - * will restore the original work function and schedule - * the polling work if needed. - */ - INIT_DELAYED_WORK(&tz->poll_queue, - thermal_zone_device_resume); - /* Queue up the work without a delay. */ - mod_delayed_work(system_freezable_power_efficient_wq, - &tz->poll_queue, 0); - - mutex_unlock(&tz->lock); - } + list_for_each_entry(tz, &thermal_tz_list, node) + thermal_zone_pm_complete(tz); mutex_unlock(&thermal_list_lock); break; From patchwork Fri Oct 4 19:11:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 832898 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F15F01E049A; Fri, 4 Oct 2024 19:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070994; cv=none; b=rLS83BXy0xwXXFvxxJuh5/HsSi9F2Uz26zBhX/XdZpVszXIoH33EzJUaW+h7LJlfkZPamJzZAppwTiLCGVWNMBUygULGSZZXgzUCwrN30ke2Uvphjccda8fxlkBZD5w+E6D6B+URt6jGiL3LYz/OSgYGOFCK+F7czYHxaBCHGR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070994; c=relaxed/simple; bh=8ITfIM6Ec9kdNrhJlk2YKl1wKqmsQ5rBxLCWpRIt5Cg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uqOsJLt1q1axLTyGpF7WUqyzYop+0E97Wmkyj1x60bosSGtg8S2xVx6+LFbvmuyVn003EHRHG6eqbpjPBS8h/WQxU8U1XZ6I7r0rpR1zVL0BcoAXtmvZCv40ax+/TZ63MSYb5sLZOZZvMr++PnREopUKK1U38/dMeNCoksj8Lrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=emSxUHkO reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="emSxUHkO" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 3f5ef314220bde20; Fri, 4 Oct 2024 21:43:07 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 9500A6A9505; Fri, 4 Oct 2024 21:43:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728070987; bh=8ITfIM6Ec9kdNrhJlk2YKl1wKqmsQ5rBxLCWpRIt5Cg=; h=From:Subject:Date; b=emSxUHkOYVT3uGd3hrbElDd80xCPBkIFrmW177CPtF7zASBRnG+3zjexTapO4RhCT t3IrwkxHESDgQ6WzTtGPy8Sd+LAWyQVXLubpIo9qqLljIkS6R4ixhQ0NlmZOOIk1GL v9/5bgHRHme+tZC7eoO8T8SldE5Z0bTMhaiql7WnKoEOgnWfRbTPZ5J22sPEZnSfrW G5UAlv+InZnw5XGHHNWHouKW2Y4/VlRF96PL9303uzsitocmgwF4p8Zt1Kw6/L7eCG 3lgujA3DPu9wFxMkInLNMbMNEbQldFuhk+ogqjxck53Q2bymr3a9+YIOc09sFdqHRv NL3Cp6YbR/iGQ== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 03/12] thermal: core: Represent suspend-related thermal zone flags as bits Date: Fri, 04 Oct 2024 21:11:53 +0200 Message-ID: <7733910.EvYhyI6sBW@rjwysocki.net> In-Reply-To: <2215082.irdbgypaU6@rjwysocki.net> References: <2215082.irdbgypaU6@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvfedgudegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdi X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki Instead of using two separate fields in struct thermal_zone_device for representing flags related to thermal zone suspend, represent them explicitly as bits in one u8 "state" field. Subsequently, that field will be used for addressing race conditions related to thermal zone initialization and exit. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/2215885.irdbgypaU6@rjwysocki.net/ v1 -> v2: The thermal zone guard has not been introduced yet, so adjust for that. --- drivers/thermal/thermal_core.c | 11 +++++------ drivers/thermal/thermal_core.h | 11 +++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -547,7 +547,7 @@ void __thermal_zone_device_update(struct int low = -INT_MAX, high = INT_MAX; int temp, ret; - if (tz->suspended || tz->mode != THERMAL_DEVICE_ENABLED) + if (tz->state != TZ_STATE_READY || tz->mode != THERMAL_DEVICE_ENABLED) return; ret = __thermal_zone_get_temp(tz, &temp); @@ -1662,7 +1662,7 @@ static void thermal_zone_device_resume(s mutex_lock(&tz->lock); - tz->suspended = false; + tz->state &= ~(TZ_STATE_FLAG_SUSPENDED | TZ_STATE_FLAG_RESUMING); thermal_debug_tz_resume(tz); thermal_zone_device_init(tz); @@ -1670,7 +1670,6 @@ static void thermal_zone_device_resume(s __thermal_zone_device_update(tz, THERMAL_TZ_RESUME); complete(&tz->resume); - tz->resuming = false; mutex_unlock(&tz->lock); } @@ -1679,7 +1678,7 @@ static void thermal_zone_pm_prepare(stru { mutex_lock(&tz->lock); - if (tz->resuming) { + if (tz->state & TZ_STATE_FLAG_RESUMING) { /* * thermal_zone_device_resume() queued up for this zone has not * acquired the lock yet, so release it to let the function run @@ -1692,7 +1691,7 @@ static void thermal_zone_pm_prepare(stru mutex_lock(&tz->lock); } - tz->suspended = true; + tz->state |= TZ_STATE_FLAG_SUSPENDED; mutex_unlock(&tz->lock); } @@ -1704,7 +1703,7 @@ static void thermal_zone_pm_complete(str cancel_delayed_work(&tz->poll_queue); reinit_completion(&tz->resume); - tz->resuming = true; + tz->state |= TZ_STATE_FLAG_RESUMING; /* * Replace the work function with the resume one, which will restore the Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -61,6 +61,11 @@ struct thermal_governor { struct list_head governor_list; }; +#define TZ_STATE_FLAG_SUSPENDED BIT(0) +#define TZ_STATE_FLAG_RESUMING BIT(1) + +#define TZ_STATE_READY 0 + /** * struct thermal_zone_device - structure for a thermal zone * @id: unique id number for each thermal zone @@ -100,8 +105,7 @@ struct thermal_governor { * @node: node in thermal_tz_list (in thermal_core.c) * @poll_queue: delayed work for polling * @notify_event: Last notification event - * @suspended: thermal zone suspend indicator - * @resuming: indicates whether or not thermal zone resume is in progress + * @state: current state of the thermal zone * @trips: array of struct thermal_trip objects */ struct thermal_zone_device { @@ -134,8 +138,7 @@ struct thermal_zone_device { struct list_head node; struct delayed_work poll_queue; enum thermal_notify_event notify_event; - bool suspended; - bool resuming; + u8 state; #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs; #endif From patchwork Fri Oct 4 19:19:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 832895 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8C701E25EF; Fri, 4 Oct 2024 19:43:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070996; cv=none; b=aCuAo8SMN1KLlOTBqwx7YYj3+AHzhQgnairQKTE1gTPmdk1qZ5BW/EYP5ssF4xVxlIFq7R0kk2ajTkFbAJm0y5cjghUc4iJOSmk6xb6vnHkHoBAqPizv3FnY93MOghMLGM/Ga9/Js9ml/Zep6C7vAwZse83TEXDNspRqYG3Slyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070996; c=relaxed/simple; bh=140pHCdKnsVyPWmjFYFklYH1T5pXhEHTWMhrqpvI+eI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aMUw6WPKJLW8SmUatdYJRKC3fcX89JKuIkIwj0Zl9lb9YC48/RaiDwwUXMaIlrCcNxF8Vb3e2cKjaBzJsS4Z2r97WbVpuYbEbMzEdS2RiKSmy8DGZtWcUej8NURInVdJXyxTzG7bmHPGExBWCkrTsohQ7P8HX5fuZchHLl4sICg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=ilmKNxCo reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="ilmKNxCo" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 0224cdf6660a5cb0; Fri, 4 Oct 2024 21:43:06 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 692386A9505; Fri, 4 Oct 2024 21:43:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728070986; bh=140pHCdKnsVyPWmjFYFklYH1T5pXhEHTWMhrqpvI+eI=; h=From:Subject:Date; b=ilmKNxCoYvMLKDS/WXxrAOSe+LE1iYqM9nFABakaxE5QRrHKXBgLtLc0dpZRmVgpz kkyc5IMfJl2iHVty620iwTsg2ovzb8k1Nwl5yJqzdHzytntmkDuvZb5etxSH8gB8x3 gQsWKOwGKHe+IhkQlr9I2pgdZFX9s0vMRbhXUjkXsJx7+yDDKY6ERrbCzP28Wrkcit FweMlK6ytSsdKTbhPYWipc2iAJrSV62APGEfT26Xd3sWyxTyxbX9rivPTdHkldW8WS VJtf0w46wAAztV6OBBi2EVKw2OYF840VnKopxp5yxyVt4QaoqOdoUrYB6WCfH6lJkU 3lEyL9AO60fcA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 05/12] thermal: core: Fix race between zone registration and system suspend Date: Fri, 04 Oct 2024 21:19:21 +0200 Message-ID: <8490245.NyiUUSuA9g@rjwysocki.net> In-Reply-To: <2215082.irdbgypaU6@rjwysocki.net> References: <2215082.irdbgypaU6@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvfedgudegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdi X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki If the registration of a thermal zone takes place at the time when system suspend is started, thermal_pm_notify() can run before the new thermal zone is added to thermal_tz_list and its "suspended" flag will not be set. Consequently, if __thermal_zone_device_update() is called for that thermal zone, it will not return early as expected which may cause some destructive interference with the system suspend or resume flow to occur. To avoid that, make thermal_zone_init_complete() introduced previously set the "suspended" flag for new thermal zones if it runs during system suspend or resume. Fixes: 4e814173a8c4 ("thermal: core: Fix thermal zone suspend-resume synchronization") Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/3335807.44csPzL39Z@rjwysocki.net/ v1 -> v2: Rebase and add a fixes tag. --- drivers/thermal/thermal_core.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -40,6 +40,8 @@ static DEFINE_MUTEX(thermal_governor_loc static struct thermal_governor *def_governor; +static bool thermal_pm_suspended; + /* * Governor section: set of functions to handle thermal governors * @@ -1337,6 +1339,14 @@ static void thermal_zone_init_complete(s mutex_lock(&tz->lock); tz->state &= ~TZ_STATE_FLAG_INIT; + /* + * If system suspend or resume is in progress at this point, the + * new thermal zone needs to be marked as suspended because + * thermal_pm_notify() has run already. + */ + if (thermal_pm_suspended) + tz->state |= TZ_STATE_FLAG_SUSPENDED; + __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); mutex_unlock(&tz->lock); @@ -1514,10 +1524,10 @@ thermal_zone_device_register_with_trips( list_for_each_entry(cdev, &thermal_cdev_list, node) thermal_zone_cdev_bind(tz, cdev); - mutex_unlock(&thermal_list_lock); - thermal_zone_init_complete(tz); + mutex_unlock(&thermal_list_lock); + thermal_notify_tz_create(tz); thermal_debug_tz_add(tz); @@ -1737,6 +1747,8 @@ static int thermal_pm_notify(struct noti case PM_SUSPEND_PREPARE: mutex_lock(&thermal_list_lock); + thermal_pm_suspended = true; + list_for_each_entry(tz, &thermal_tz_list, node) thermal_zone_pm_prepare(tz); @@ -1747,6 +1759,8 @@ static int thermal_pm_notify(struct noti case PM_POST_SUSPEND: mutex_lock(&thermal_list_lock); + thermal_pm_suspended = false; + list_for_each_entry(tz, &thermal_tz_list, node) thermal_zone_pm_complete(tz); From patchwork Fri Oct 4 19:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 832896 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C97A61E04B4; Fri, 4 Oct 2024 19:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070995; cv=none; b=ugJ+lJl9LWF2o+0O0YEl+Vha6QE/TKkuQkRw/WCu769X+G88UJuGWtYYL3j9EOTY3D061WSvlwHD3FP1sEgnRnckP3/OQKIUuQbbSVeEai2NjpvLp9nVlbwkUVqY7w5Ahp/6DcYvRGv0CfGYCBMrgY/WZHQZppoNf9w6ImTErwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070995; c=relaxed/simple; bh=0P2WxnUpd1AyHHvrMH196mT7Oa6TA2+VCu5CwDH3EHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XPL4ss9bR/jJAravPCqeoq9pKB9RdKWxOKnPponJW7CKjp86/Zt2sTg8EpzDU0kGiB08k9dLY76b7rGLMd7eAmKsiqraRuOKSn8RPPA0TWsjH3hmDXk2EsKIvbABp6zEVWBkn6q7gfNGBBZa6DVXl7/7LmjiD+lcFWzo9/BDDOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=kW2VDnhy reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="kW2VDnhy" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id 974918518edb54b4; Fri, 4 Oct 2024 21:43:03 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id B12B76A9505; Fri, 4 Oct 2024 21:43:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728070983; bh=0P2WxnUpd1AyHHvrMH196mT7Oa6TA2+VCu5CwDH3EHo=; h=From:Subject:Date; b=kW2VDnhyQwQOcey/bOFd8nuhVmqF4pPrrWOb+529WlA4B03S04luBlvT25Vsw+5am SdBBNQqYv00mWnqBdKYTdBQGR+T+CGmKqlznKkzQY3RO3uclHwWLvilRrgcjjm+edN Fyk1iuOtJrkGbX5L7z8FYEW/6kUsFL7lepogRp50VmY3L6+nRcfS8+CpsaAW+JfFhl 1eRzEt81NPArvex3FE34l3fBg9mq8QTkicc8TXi1LGu44uBKJ+rOw91zKf+yZF0QOd 2+1VxYrWxDN4gPOjbog7l0yoO/Qscxdz2FTwtR6sGWHCKmRx2EbZmZilPfRqfO/6OS C69C2uhFUyvGw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 09/12] thermal: core: Update thermal zones after cooling device binding Date: Fri, 04 Oct 2024 21:33:28 +0200 Message-ID: <2226302.Icojqenx9y@rjwysocki.net> In-Reply-To: <2215082.irdbgypaU6@rjwysocki.net> References: <2215082.irdbgypaU6@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvfedgudegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdi X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki If a new cooling device is registered and it is bound to at least one trip point in a given thermal zone, that thermal zone needs to be updated via __thermal_zone_device_update(). Instead of doing this with the help of the need_update atomic field in struct thermal_zone_device, which is not particularly straightforward, make __thermal_zone_cdev_bind() return a bool value indicating whether or not the given thermal zone needs to be updated because a new cooling device has been bound to it and update thermal_zone_cdev_bind() to call __thermal_zone_device_update() when this value is "true". No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/3603909.iIbC2pHGDl@rjwysocki.net/ v1 -> v2: Rebase. --- drivers/thermal/thermal_core.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -933,13 +933,14 @@ void print_bind_err_msg(struct thermal_z cdev->type, thermal_zone_trip_id(tz, trip), ret); } -static void __thermal_zone_cdev_bind(struct thermal_zone_device *tz, +static bool __thermal_zone_cdev_bind(struct thermal_zone_device *tz, struct thermal_cooling_device *cdev) { struct thermal_trip_desc *td; + bool update_tz = false; if (!tz->ops.should_bind) - return; + return false; for_each_trip_desc(tz, td) { struct thermal_trip *trip = &td->trip; @@ -954,9 +955,15 @@ static void __thermal_zone_cdev_bind(str continue; ret = thermal_bind_cdev_to_trip(tz, trip, cdev, &c); - if (ret) + if (ret) { print_bind_err_msg(tz, trip, cdev, ret); + continue; + } + + update_tz = true; } + + return update_tz; } static void thermal_zone_cdev_bind(struct thermal_zone_device *tz, @@ -964,7 +971,8 @@ static void thermal_zone_cdev_bind(struc { mutex_lock(&tz->lock); - __thermal_zone_cdev_bind(tz, cdev); + if (__thermal_zone_cdev_bind(tz, cdev)) + __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); mutex_unlock(&tz->lock); } @@ -991,7 +999,7 @@ __thermal_cooling_device_register(struct const struct thermal_cooling_device_ops *ops) { struct thermal_cooling_device *cdev; - struct thermal_zone_device *pos = NULL; + struct thermal_zone_device *pos; unsigned long current_state; int id, ret; @@ -1067,11 +1075,6 @@ __thermal_cooling_device_register(struct list_for_each_entry(pos, &thermal_tz_list, node) thermal_zone_cdev_bind(pos, cdev); - list_for_each_entry(pos, &thermal_tz_list, node) - if (atomic_cmpxchg(&pos->need_update, 1, 0)) - thermal_zone_device_update(pos, - THERMAL_EVENT_UNSPECIFIED); - mutex_unlock(&thermal_list_lock); return cdev; From patchwork Fri Oct 4 19:35:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 832900 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A88791DFDBA; Fri, 4 Oct 2024 19:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070993; cv=none; b=EHRoJB7g2cY8hiPCzE4BA55xItermUlygUrmOOlEAJTn2dj5mBznwcQ3LkO9ASpFAlhwp7GUloUkVwZWBM/b2f5sMrNDlFh5tp0AOCnmYClUoHuBpq8csjqBmCe/nfNy6oUdAkkTLQ0aAc0ArSwRJkQ30D4B0P926FPxmL2e5G8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728070993; c=relaxed/simple; bh=2E7p4xDIjiqESb8HjztsoX4HPtZwOjx8IWDVhvI2xHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OYQbzHpK1lJ7heOfQCVZWbRtCyGRqeNEjh0m6TyhJ3RembVkzjSwIZPXXzvjbqVzY4xGhdh1WS9TBAFqQPAAyoW/yCIALBoU5xVxPQ/QqR+JLic8vkgopMO3x9OIPSeOJaPSIw+fosd2O1Tnjo6L2CYassw9OzUpCffyX4YtKLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=h9WBaLHd reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="h9WBaLHd" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.0) id ac159aa11a076184; Fri, 4 Oct 2024 21:43:03 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 2CD0E6A9505; Fri, 4 Oct 2024 21:43:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1728070983; bh=2E7p4xDIjiqESb8HjztsoX4HPtZwOjx8IWDVhvI2xHI=; h=From:Subject:Date; b=h9WBaLHdxIkBceiEZ3weXYNHdu/axLVNeNpU9VgHm2MseQ/3tPIQds3AAGFWquUyt fQAmCW/NLYsNqlI+ep1XU0YO1wa0ewvifY9IaJk65LwKuOuatHYkW1amh4VEoFQGo0 PKbRDirn/4DrX0/w/ARuTbHtGaR+WTEyZnQ6wOhdYVP/1SpmKlMY8VOySJQ7dAko5K Q08fJDfPzbj1buwjV87/LnhZbRIRHv9vc7Vq/rMOXwDPIanr2GGq949kr+3tmEbVz8 OKp+naZxIjghTEHQBNqvpaq3oOO0tdrWiEXtKS0CNF8tW2ew4xrX23dHqcCxZnBi7b SztEmxKUap21w== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v2 10/12] thermal: core: Drop need_update field from struct thermal_zone_device Date: Fri, 04 Oct 2024 21:35:16 +0200 Message-ID: <2495061.jE0xQCEvom@rjwysocki.net> In-Reply-To: <2215082.irdbgypaU6@rjwysocki.net> References: <2215082.irdbgypaU6@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvfedgudegtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohepiedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopehruhhirdi X-DCC--Metrics: v370.home.net.pl 0; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki After previous changes, the need_update field in struct thermal_zone_device is only set and never read, so drop it. No functional impact. Signed-off-by: Rafael J. Wysocki --- This is a new iteration of https://lore.kernel.org/linux-pm/3261209.5fSG56mABF@rjwysocki.net/ v1 -> v2: Rebase. --- drivers/thermal/thermal_core.c | 4 ---- drivers/thermal/thermal_core.h | 2 -- 2 files changed, 6 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -840,7 +840,6 @@ static int thermal_bind_cdev_to_trip(str if (!result) { list_add_tail(&dev->tz_node, &tz->thermal_instances); list_add_tail(&dev->cdev_node, &cdev->thermal_instances); - atomic_set(&tz->need_update, 1); thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV); } @@ -1505,9 +1504,6 @@ thermal_zone_device_register_with_trips( if (result) goto remove_id; - /* A new thermal zone needs to be updated anyway. */ - atomic_set(&tz->need_update, 1); - result = dev_set_name(&tz->device, "thermal_zone%d", tz->id); if (result) { thermal_zone_destroy_device_groups(tz); Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -95,7 +95,6 @@ struct thermal_governor { trip point. * @prev_high_trip: the above current temperature if you've crossed a passive trip point. - * @need_update: if equals 1, thermal_zone_device_update needs to be invoked. * @ops: operations this &thermal_zone_device supports * @tzp: thermal zone parameters * @governor: pointer to the governor for this thermal zone @@ -129,7 +128,6 @@ struct thermal_zone_device { int passive; int prev_low_trip; int prev_high_trip; - atomic_t need_update; struct thermal_zone_device_ops ops; struct thermal_zone_params *tzp; struct thermal_governor *governor;