[v1,4/4] ACPI: processor: thermal: Update CPU cooling devices on cpufreq policy changes
Message ID | 1936685.PYKUYFuaPT@kreacher |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp588832wrd; Fri, 3 Mar 2023 11:27:39 -0800 (PST) X-Google-Smtp-Source: AK7set9YZGofup93LBBZVH2TINs+YWKlJxrA04cfq0MpaFuob8QusVJKYO1ZvIfQynMxVjfaKskk X-Received: by 2002:a17:906:b097:b0:8af:1a8c:f13f with SMTP id x23-20020a170906b09700b008af1a8cf13fmr3347596ejy.71.1677871659579; Fri, 03 Mar 2023 11:27:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677871659; cv=none; d=google.com; s=arc-20160816; b=EMjKkVcf3Iq7eH6Ei74Rk+3C2ePJI5XLs67cxJ1bwxwuXANlNMK1dHdCYRYftENJ6e 9yTWYAOu/Pyb4jNmVzeie3NoHLyCSk4I9sBK2f0N1cy1ySZKjvO5x9DiZ6Tjjjp8TykQ IY0NObKSDUoLqjseVEl3umrFgP0ApwaAxESeDNcZVj5Isr/zFA9wqEC2HZ+P+3c/yFbX zokC+uOPWpO50Z4kNYG5tlu2C2jEYqYflTEcs3A2hs3HgxNosVbjMSPsMFsAEk5L3Dja 0/9zpLm1dG5W2GlhPjM1iiueVU0qaHwvRxN8YxqBBzstEa9kii2rZRx7TRZ0uBabacuE gZmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Q4Y3uZprhKVftKfB7D8521kVJLhsDmFBPkn7jw+vS0Y=; b=Uo+0HSBzHoIg2ddrKImvsN6RMb6O54YoJIKmEV/Z2xSiLGo/o3yvqxRVf1oOCoE9js YOdzNhonAmiU65dQzVNIdGWLVSr2UkqaXk34nsxEzIPAfOyBSC9y43axcoEQOyvpwFc/ bo1phbTAai9qmpfMABI5E7jmWB63uhYg0lQfitfvdWiIwmpUiW2ZYVdei0tUyY1tJE2t Hk5QGL3kDRMvpKAlbKLlCm0XQJLzjfxOFrFYGhQXbxNTQ0/wYyhtI3GsVlExWqsgtKwG s8/FCUxErEJWwyp3dY+KXX3zYanpxpLJq6A5nb5E6TW9HR3UFaxZASkO0eksYJP5ghjD Yqpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o25-20020aa7d3d9000000b004bc2794f642si3354670edr.407.2023.03.03.11.27.17; Fri, 03 Mar 2023 11:27:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbjCCTYN (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Fri, 3 Mar 2023 14:24:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231190AbjCCTYL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 3 Mar 2023 14:24:11 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBC510408; Fri, 3 Mar 2023 11:24:09 -0800 (PST) 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 5.1.0) id 45dcb4239fb6fbda; Fri, 3 Mar 2023 20:24:07 +0100 Received: from kreacher.localnet (unknown [213.134.183.41]) (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 v370.home.net.pl (Postfix) with ESMTPSA id CE9CC20619DE; Fri, 3 Mar 2023 20:24:06 +0100 (CET) From: "Rafael J. Wysocki" <rjw@rjwysocki.net> To: Linux PM <linux-pm@vger.kernel.org> Cc: Zhang Rui <rui.zhang@intel.com>, Linux ACPI <linux-acpi@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>, Daniel Lezcano <daniel.lezcano@linaro.org>, Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>, Viresh Kumar <viresh.kumar@linaro.org>, Quanxian Wang <quanxian.wang@intel.com> Subject: [PATCH v1 4/4] ACPI: processor: thermal: Update CPU cooling devices on cpufreq policy changes Date: Fri, 03 Mar 2023 20:23:58 +0100 Message-ID: <1936685.PYKUYFuaPT@kreacher> In-Reply-To: <2148907.irdbgypaU6@kreacher> References: <2148907.irdbgypaU6@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.183.41 X-CLIENT-HOSTNAME: 213.134.183.41 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrudelledguddukecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpeefudduuedtuefgleffudeigeeitdeufeelvdejgefftdethffhhfethfeljefgteenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppedvudefrddufeegrddukeefrdegudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrddukeefrdeguddphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgv rhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759375953394739506?= X-GMAIL-MSGID: =?utf-8?q?1759375953394739506?= |
Series |
thermal: core/ACPI: Fix processor cooling device regression
|
|
Commit Message
Rafael J. Wysocki
March 3, 2023, 7:23 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> When a cpufreq policy appears or goes away, the CPU cooling devices for the CPUs covered by that policy need to be updated so that the new processor_get_max_state() value is stored as max_state and the statistics in sysfs are rearranged for each of them. Do that accordingly in acpi_thermal_cpufreq_init() and acpi_thermal_cpufreq_exit(). Fixes: a365105c685c("thermal: sysfs: Reuse cdev->max_state") Reported-by: Wang, Quanxian <quanxian.wang@intel.com> Link: https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> --- drivers/acpi/processor_thermal.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
Comments
On Fri, 2023-03-03 at 20:23 +0100, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > When a cpufreq policy appears or goes away, the CPU cooling devices > for > the CPUs covered by that policy need to be updated so that the new > processor_get_max_state() value is stored as max_state and the > statistics in sysfs are rearranged for each of them. > > Do that accordingly in acpi_thermal_cpufreq_init() and > acpi_thermal_cpufreq_exit(). > > Fixes: a365105c685c("thermal: sysfs: Reuse cdev->max_state") > Reported-by: Wang, Quanxian <quanxian.wang@intel.com> > Link: > https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/ > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > --- > drivers/acpi/processor_thermal.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > Index: linux-pm/drivers/acpi/processor_thermal.c > =================================================================== > --- linux-pm.orig/drivers/acpi/processor_thermal.c > +++ linux-pm/drivers/acpi/processor_thermal.c > @@ -140,9 +140,14 @@ void acpi_thermal_cpufreq_init(struct cp > ret = freq_qos_add_request(&policy->constraints, > &pr->thermal_req, > FREQ_QOS_MAX, INT_MAX); > - if (ret < 0) > + if (ret < 0) { > pr_err("Failed to add freq constraint for CPU%d > (%d)\n", > cpu, ret); > + continue; > + } > + > + if (!IS_ERR(pr->cdev)) > + thermal_cooling_device_update(pr->cdev); Although thermal_cooling_device_update() handles "pr->cdev == NULL" case, I think it is better to use !IS_ERR_OR_NULL() here. thanks, rui > } > } > > @@ -153,8 +158,13 @@ void acpi_thermal_cpufreq_exit(struct cp > for_each_cpu(cpu, policy->related_cpus) { > struct acpi_processor *pr = per_cpu(processors, cpu); > > - if (pr) > - freq_qos_remove_request(&pr->thermal_req); > + if (!pr) > + continue; > + > + freq_qos_remove_request(&pr->thermal_req); > + > + if (!IS_ERR(pr->cdev)) > + thermal_cooling_device_update(pr->cdev); > } > } > #else /* ! CONFIG_CPU_FREQ */ > > >
On Tue, Mar 7, 2023 at 5:47 PM Zhang, Rui <rui.zhang@intel.com> wrote: > > On Fri, 2023-03-03 at 20:23 +0100, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > When a cpufreq policy appears or goes away, the CPU cooling devices > > for > > the CPUs covered by that policy need to be updated so that the new > > processor_get_max_state() value is stored as max_state and the > > statistics in sysfs are rearranged for each of them. > > > > Do that accordingly in acpi_thermal_cpufreq_init() and > > acpi_thermal_cpufreq_exit(). > > > > Fixes: a365105c685c("thermal: sysfs: Reuse cdev->max_state") > > Reported-by: Wang, Quanxian <quanxian.wang@intel.com> > > Link: > > https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/ > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > --- > > drivers/acpi/processor_thermal.c | 16 +++++++++++++--- > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > Index: linux-pm/drivers/acpi/processor_thermal.c > > =================================================================== > > --- linux-pm.orig/drivers/acpi/processor_thermal.c > > +++ linux-pm/drivers/acpi/processor_thermal.c > > @@ -140,9 +140,14 @@ void acpi_thermal_cpufreq_init(struct cp > > ret = freq_qos_add_request(&policy->constraints, > > &pr->thermal_req, > > FREQ_QOS_MAX, INT_MAX); > > - if (ret < 0) > > + if (ret < 0) { > > pr_err("Failed to add freq constraint for CPU%d > > (%d)\n", > > cpu, ret); > > + continue; > > + } > > + > > + if (!IS_ERR(pr->cdev)) > > + thermal_cooling_device_update(pr->cdev); > > Although thermal_cooling_device_update() handles "pr->cdev == NULL" > case, I think it is better to use !IS_ERR_OR_NULL() here. Why is it? I was thinking about doing that, but then I realized that the NULL case had been covered and that's why I went for the change above. If there is a particular reason to check for NULL here, I can do that, but I'm not sure what it is.
On Fri, 2023-03-10 at 19:29 +0100, Rafael J. Wysocki wrote: > On Tue, Mar 7, 2023 at 5:47 PM Zhang, Rui <rui.zhang@intel.com> > wrote: > > On Fri, 2023-03-03 at 20:23 +0100, Rafael J. Wysocki wrote: > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > > > When a cpufreq policy appears or goes away, the CPU cooling > > > devices > > > for > > > the CPUs covered by that policy need to be updated so that the > > > new > > > processor_get_max_state() value is stored as max_state and the > > > statistics in sysfs are rearranged for each of them. > > > > > > Do that accordingly in acpi_thermal_cpufreq_init() and > > > acpi_thermal_cpufreq_exit(). > > > > > > Fixes: a365105c685c("thermal: sysfs: Reuse cdev->max_state") > > > Reported-by: Wang, Quanxian <quanxian.wang@intel.com> > > > Link: > > > https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/ > > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > --- > > > drivers/acpi/processor_thermal.c | 16 +++++++++++++--- > > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > > > Index: linux-pm/drivers/acpi/processor_thermal.c > > > ================================================================= > > > == > > > --- linux-pm.orig/drivers/acpi/processor_thermal.c > > > +++ linux-pm/drivers/acpi/processor_thermal.c > > > @@ -140,9 +140,14 @@ void acpi_thermal_cpufreq_init(struct cp > > > ret = freq_qos_add_request(&policy->constraints, > > > &pr->thermal_req, > > > FREQ_QOS_MAX, INT_MAX); > > > - if (ret < 0) > > > + if (ret < 0) { > > > pr_err("Failed to add freq constraint for > > > CPU%d > > > (%d)\n", > > > cpu, ret); > > > + continue; > > > + } > > > + > > > + if (!IS_ERR(pr->cdev)) > > > + thermal_cooling_device_update(pr->cdev); > > > > Although thermal_cooling_device_update() handles "pr->cdev == NULL" > > case, I think it is better to use !IS_ERR_OR_NULL() here. > > Why is it? > > I was thinking about doing that, but then I realized that the NULL > case had been covered and that's why I went for the change above. If > there is a particular reason to check for NULL here, I can do that, > but I'm not sure what it is. I don't have a strong objection here. I thought this was a code bug at first glance, until I double checked t hermal_cooling_device_update(). So I think the latter would be more straight forward without introducing code complexity. thanks, rui
On Sun, Mar 12, 2023 at 3:44 PM Zhang, Rui <rui.zhang@intel.com> wrote: > > On Fri, 2023-03-10 at 19:29 +0100, Rafael J. Wysocki wrote: > > On Tue, Mar 7, 2023 at 5:47 PM Zhang, Rui <rui.zhang@intel.com> > > wrote: > > > On Fri, 2023-03-03 at 20:23 +0100, Rafael J. Wysocki wrote: > > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > > > > > When a cpufreq policy appears or goes away, the CPU cooling > > > > devices > > > > for > > > > the CPUs covered by that policy need to be updated so that the > > > > new > > > > processor_get_max_state() value is stored as max_state and the > > > > statistics in sysfs are rearranged for each of them. > > > > > > > > Do that accordingly in acpi_thermal_cpufreq_init() and > > > > acpi_thermal_cpufreq_exit(). > > > > > > > > Fixes: a365105c685c("thermal: sysfs: Reuse cdev->max_state") > > > > Reported-by: Wang, Quanxian <quanxian.wang@intel.com> > > > > Link: > > > > https://lore.kernel.org/linux-pm/53ec1f06f61c984100868926f282647e57ecfb2d.camel@intel.com/ > > > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > --- > > > > drivers/acpi/processor_thermal.c | 16 +++++++++++++--- > > > > 1 file changed, 13 insertions(+), 3 deletions(-) > > > > > > > > Index: linux-pm/drivers/acpi/processor_thermal.c > > > > ================================================================= > > > > == > > > > --- linux-pm.orig/drivers/acpi/processor_thermal.c > > > > +++ linux-pm/drivers/acpi/processor_thermal.c > > > > @@ -140,9 +140,14 @@ void acpi_thermal_cpufreq_init(struct cp > > > > ret = freq_qos_add_request(&policy->constraints, > > > > &pr->thermal_req, > > > > FREQ_QOS_MAX, INT_MAX); > > > > - if (ret < 0) > > > > + if (ret < 0) { > > > > pr_err("Failed to add freq constraint for > > > > CPU%d > > > > (%d)\n", > > > > cpu, ret); > > > > + continue; > > > > + } > > > > + > > > > + if (!IS_ERR(pr->cdev)) > > > > + thermal_cooling_device_update(pr->cdev); > > > > > > Although thermal_cooling_device_update() handles "pr->cdev == NULL" > > > case, I think it is better to use !IS_ERR_OR_NULL() here. > > > > Why is it? > > > > I was thinking about doing that, but then I realized that the NULL > > case had been covered and that's why I went for the change above. If > > there is a particular reason to check for NULL here, I can do that, > > but I'm not sure what it is. > > I don't have a strong objection here. > > I thought this was a code bug at first glance, until I double checked t > hermal_cooling_device_update(). > > So I think the latter would be more straight forward without > introducing code complexity. Alternatively, thermal_cooling_device_update() can be made to do the full check instead.
Index: linux-pm/drivers/acpi/processor_thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/processor_thermal.c +++ linux-pm/drivers/acpi/processor_thermal.c @@ -140,9 +140,14 @@ void acpi_thermal_cpufreq_init(struct cp ret = freq_qos_add_request(&policy->constraints, &pr->thermal_req, FREQ_QOS_MAX, INT_MAX); - if (ret < 0) + if (ret < 0) { pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu, ret); + continue; + } + + if (!IS_ERR(pr->cdev)) + thermal_cooling_device_update(pr->cdev); } } @@ -153,8 +158,13 @@ void acpi_thermal_cpufreq_exit(struct cp for_each_cpu(cpu, policy->related_cpus) { struct acpi_processor *pr = per_cpu(processors, cpu); - if (pr) - freq_qos_remove_request(&pr->thermal_req); + if (!pr) + continue; + + freq_qos_remove_request(&pr->thermal_req); + + if (!IS_ERR(pr->cdev)) + thermal_cooling_device_update(pr->cdev); } } #else /* ! CONFIG_CPU_FREQ */