From patchwork Mon Aug 7 18:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 711457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2D4DC04A94 for ; Mon, 7 Aug 2023 18:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbjHGSVQ (ORCPT ); Mon, 7 Aug 2023 14:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231222AbjHGSVG (ORCPT ); Mon, 7 Aug 2023 14:21:06 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4665010FF; Mon, 7 Aug 2023 11:21:03 -0700 (PDT) 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.2.0) id ece2375058cdbf73; Mon, 7 Aug 2023 20:21:01 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id DE75E6625B2; Mon, 7 Aug 2023 20:21:00 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 01/11] thermal: core: Do not handle trip points with invalid temperature Date: Mon, 07 Aug 2023 20:01:24 +0200 Message-ID: <4824219.GXAFRqVoOG@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Trip points with temperature set to THERMAL_TEMP_INVALID are as good as disabled, so make handle_thermal_trip() ignore them. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- v4 -> v5: ACK from Daniel. v3 -> v4: No changes. v2 -> v3: No changes. v1 -> v2: No changes. --- drivers/thermal/thermal_core.c | 3 ++- 1 file changed, 2 insertions(+), 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 @@ -348,7 +348,8 @@ static void handle_thermal_trip(struct t struct thermal_trip trip; /* Ignore disabled trip points */ - if (test_bit(trip_id, &tz->trips_disabled)) + if (test_bit(trip_id, &tz->trips_disabled) || + trip.temperature == THERMAL_TEMP_INVALID) return; __thermal_zone_get_trip(tz, trip_id, &trip); From patchwork Mon Aug 7 18:02:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 711458 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22C89C05051 for ; Mon, 7 Aug 2023 18:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231567AbjHGSVO (ORCPT ); Mon, 7 Aug 2023 14:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbjHGSVF (ORCPT ); Mon, 7 Aug 2023 14:21:05 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A7A0E5B; Mon, 7 Aug 2023 11:21:02 -0700 (PDT) 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.2.0) id 9ce1ce9819c4cc9e; Mon, 7 Aug 2023 20:21:00 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 1ADD46625B2; Mon, 7 Aug 2023 20:21:00 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 02/11] thermal: core: Introduce thermal_zone_device_adjust() Date: Mon, 07 Aug 2023 20:02:57 +0200 Message-ID: <2154540.irdbgypaU6@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Introduce a new thermal zone device operation called .update() for modifying thermal zone components such as trip point and a new helper function, thermal_zone_device_adjust(), that can be used by drivers providing the new thermal zone device operation to invoke it under the zone lock. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: No changes. New patch in v4. --- drivers/thermal/thermal_core.c | 20 ++++++++++++++++++++ include/linux/thermal.h | 2 ++ 2 files changed, 22 insertions(+) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -74,6 +74,7 @@ struct thermal_zone_device_ops { enum thermal_trend *); void (*hot)(struct thermal_zone_device *); void (*critical)(struct thermal_zone_device *); + void (*update)(struct thermal_zone_device *, unsigned long); }; /** @@ -323,6 +324,7 @@ int thermal_zone_unbind_cooling_device(s struct thermal_cooling_device *); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); +void thermal_zone_device_adjust(struct thermal_zone_device *tz, unsigned long data); struct thermal_cooling_device *thermal_cooling_device_register(const char *, void *, const struct thermal_cooling_device_ops *); Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -497,6 +497,26 @@ void thermal_zone_device_update(struct t } EXPORT_SYMBOL_GPL(thermal_zone_device_update); +/** + * thermal_zone_device_adjust - Adjust a thermal zone. + * @tz: Thermal zone. + * @data: Data to pass to the zone's .update() callback. + * + * Modify components of a thermal zone (for example, trip points) via + * its .update() callback (for example, after a platform configuration + * change). + */ +void thermal_zone_device_adjust(struct thermal_zone_device *tz, unsigned long data) +{ + mutex_lock(&tz->lock); + + if (device_is_registered(&tz->device) && tz->ops->update) + tz->ops->update(tz, data); + + mutex_unlock(&tz->lock); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_adjust); + static void thermal_zone_device_check(struct work_struct *work) { struct thermal_zone_device *tz = container_of(work, struct From patchwork Mon Aug 7 18:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 712233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 805A7C04FE1 for ; Mon, 7 Aug 2023 18:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbjHGSVN (ORCPT ); Mon, 7 Aug 2023 14:21:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbjHGSVD (ORCPT ); Mon, 7 Aug 2023 14:21:03 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7C02194; Mon, 7 Aug 2023 11:21:01 -0700 (PDT) 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.2.0) id 5eb1f2393699e2aa; Mon, 7 Aug 2023 20:20:59 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 510F86625B2; Mon, 7 Aug 2023 20:20:59 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 03/11] thermal: core: Add priv pointer to struct thermal_trip Date: Mon, 07 Aug 2023 20:04:47 +0200 Message-ID: <2896662.e9J7NaK4W3@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Add a new field called priv to struct thermal_trip to allow thermal drivers to store pointers to their local data associated with trip points. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- v4 -> v5: ACK from Daniel. New patch in v4. --- include/linux/thermal.h | 2 ++ 1 file changed, 2 insertions(+) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -82,11 +82,13 @@ struct thermal_zone_device_ops { * @temperature: temperature value in miliCelsius * @hysteresis: relative hysteresis in miliCelsius * @type: trip point type + * @priv: pointer to driver data associated with this trip */ struct thermal_trip { int temperature; int hysteresis; enum thermal_trip_type type; + void *priv; }; struct thermal_cooling_device_ops { From patchwork Mon Aug 7 18:06:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 712232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B73BC001DE for ; Mon, 7 Aug 2023 18:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbjHGSVP (ORCPT ); Mon, 7 Aug 2023 14:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjHGSVC (ORCPT ); Mon, 7 Aug 2023 14:21:02 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA48CFD; Mon, 7 Aug 2023 11:21:00 -0700 (PDT) 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.2.0) id 3af2a06c4c8e8b76; Mon, 7 Aug 2023 20:20:59 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 7DB6F6625B2; Mon, 7 Aug 2023 20:20:58 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 04/11] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Date: Mon, 07 Aug 2023 20:06:13 +0200 Message-ID: <3251836.44csPzL39Z@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Rename the trips variable in acpi_thermal_register_thermal_zone() to trip_count so its name better reflects the purpose, rearrange white space in the loop over active trips for clarity and reduce code duplication related to calling thermal_zone_device_register() by using an extra local variable to store the passive delay value. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: No changes. v3 -> v4: No changes. v2 -> v3: No changes. v1 -> v2: No changes. --- drivers/acpi/thermal.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -740,34 +740,30 @@ static void acpi_thermal_zone_sysfs_remo static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { - int trips = 0; + int passive_delay = 0; + int trip_count = 0; int result; acpi_status status; int i; if (tz->trips.critical.valid) - trips++; + trip_count++; if (tz->trips.hot.valid) - trips++; - - if (tz->trips.passive.valid) - trips++; - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; - i++, trips++); - - if (tz->trips.passive.valid) - tz->thermal_zone = thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - tz->trips.passive.tsp * 100, - tz->polling_frequency * 100); - else - tz->thermal_zone = - thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - 0, tz->polling_frequency * 100); + trip_count++; + if (tz->trips.passive.valid) { + trip_count++; + passive_delay = tz->trips.passive.tsp * 100; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++) + trip_count++; + + tz->thermal_zone = thermal_zone_device_register("acpitz", trip_count, 0, + tz, &acpi_thermal_zone_ops, + NULL, passive_delay, + tz->polling_frequency * 100); if (IS_ERR(tz->thermal_zone)) return -ENODEV; From patchwork Mon Aug 7 18:08:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 712234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AC76C001DE for ; Mon, 7 Aug 2023 18:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbjHGSVM (ORCPT ); Mon, 7 Aug 2023 14:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjHGSVB (ORCPT ); Mon, 7 Aug 2023 14:21:01 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E1E58F; Mon, 7 Aug 2023 11:20:59 -0700 (PDT) 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.2.0) id dd494a809452f723; Mon, 7 Aug 2023 20:20:58 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id B2A3A6625B2; Mon, 7 Aug 2023 20:20:57 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 05/11] ACPI: thermal: Carry out trip point updates under zone lock Date: Mon, 07 Aug 2023 20:08:26 +0200 Message-ID: <2236767.iZASKD2KPV@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki There is a race condition between acpi_thermal_trips_update() and acpi_thermal_check_fn(), because the trip points may get updated while the latter is running which in theory may lead to inconsistent results. For example, if two trips are updated together, using the temperature value of one of them from before the update and the temperature value of the other one from after the update may not lead to the expected outcome. Moreover, if thermal_get_trend() runs when a trip points update is in progress, it may end up using stale trip point temperatures. To address this, make acpi_thermal_trips_update() call thermal_zone_device_adjust() to carry out the trip points update and provide a new acpi_thermal_adjust_thermal_zone() wrapper around __acpi_thermal_trips_update() as the callback function for the latter. While at it, change the acpi_thermal_trips_update() return data type to void as that function always returns 0 anyway. Signed-off-by: Rafael J. Wysocki Signed-off-by: Rafael J. Wysocki --- v4 -> v5: No changes. v3 -> v4: * Rework to use thermal_zone_device_adjust() and the .update() callback instead of using the (exported) zone lock directly. * Call acpi_queue_thermal_check() from acpi_thermal_trips_update() which allows code duplication in acpi_thermal_notify() to be reduced. v2 -> v3: No changes. v1 -> v2: * Hold the thermal zone lock instead of thermal_check_lock around trip point updates (this also helps to protect thermal_get_trend() from using stale trip temperatures). * Add a comment documenting the purpose of the locking. * Make acpi_thermal_trips_update() void. --- drivers/acpi/thermal.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -185,7 +185,7 @@ static int acpi_thermal_get_polling_freq return 0; } -static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) { acpi_status status; unsigned long long tmp; @@ -393,17 +393,39 @@ static int acpi_thermal_trips_update(str ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } +} - return 0; +static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal, + unsigned long data) +{ + __acpi_thermal_trips_update(thermal_zone_device_priv(thermal), data); +} + +static void acpi_queue_thermal_check(struct acpi_thermal *tz) +{ + if (!work_pending(&tz->thermal_check_work)) + queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); +} + +static void acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +{ + /* + * Use thermal_zone_device_adjust() to carry out the trip points + * update, so as to protect thermal_get_trend() from getting stale + * trip point temperatures and to prevent thermal_zone_device_update() + * invoked from acpi_thermal_check_fn() from producing inconsistent + * results. + */ + thermal_zone_device_adjust(tz->thermal_zone, flag); + acpi_queue_thermal_check(tz); } static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - int i, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); bool valid; + int i; - if (ret) - return ret; + __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); valid = tz->trips.critical.valid | tz->trips.hot.valid | @@ -710,6 +732,7 @@ static struct thermal_zone_device_ops ac .get_trend = thermal_get_trend, .hot = acpi_thermal_zone_device_hot, .critical = acpi_thermal_zone_device_critical, + .update = acpi_thermal_adjust_thermal_zone, }; static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) @@ -810,12 +833,6 @@ static void acpi_thermal_unregister_ther Driver Interface -------------------------------------------------------------------------- */ -static void acpi_queue_thermal_check(struct acpi_thermal *tz) -{ - if (!work_pending(&tz->thermal_check_work)) - queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); -} - static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) { struct acpi_device *device = data; @@ -830,13 +847,11 @@ static void acpi_thermal_notify(acpi_han break; case ACPI_THERMAL_NOTIFY_THRESHOLDS: acpi_thermal_trips_update(tz, ACPI_TRIPS_THRESHOLDS); - acpi_queue_thermal_check(tz); acpi_bus_generate_netlink_event(device->pnp.device_class, dev_name(&device->dev), event, 0); break; case ACPI_THERMAL_NOTIFY_DEVICES: acpi_thermal_trips_update(tz, ACPI_TRIPS_DEVICES); - acpi_queue_thermal_check(tz); acpi_bus_generate_netlink_event(device->pnp.device_class, dev_name(&device->dev), event, 0); break; From patchwork Mon Aug 7 18:10:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 711460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26953C04A6A for ; Mon, 7 Aug 2023 18:21:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbjHGSVH (ORCPT ); Mon, 7 Aug 2023 14:21:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230497AbjHGSVB (ORCPT ); Mon, 7 Aug 2023 14:21:01 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D9AEDE; Mon, 7 Aug 2023 11:20:59 -0700 (PDT) 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.2.0) id efd8927cb8f9f9b8; Mon, 7 Aug 2023 20:20:57 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 07F096625B2; Mon, 7 Aug 2023 20:20:57 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 06/11] ACPI: thermal: Introduce struct acpi_thermal_trip Date: Mon, 07 Aug 2023 20:10:06 +0200 Message-ID: <21971973.EfDdHjke4D@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Add struct acpi_thermal_trip to contain the temperature and valid flag of each trip point in the driver's local data structures. This helps to make the subsequent changes more straightforward. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- New patch in v5. --- drivers/acpi/thermal.c | 96 ++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 51 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -92,34 +92,27 @@ MODULE_PARM_DESC(psv, "Disable or overri static struct workqueue_struct *acpi_thermal_pm_queue; -struct acpi_thermal_critical { - unsigned long temperature; - bool valid; -}; - -struct acpi_thermal_hot { +struct acpi_thermal_trip { unsigned long temperature; bool valid; }; struct acpi_thermal_passive { + struct acpi_thermal_trip trip; struct acpi_handle_list devices; - unsigned long temperature; unsigned long tc1; unsigned long tc2; unsigned long tsp; - bool valid; }; struct acpi_thermal_active { + struct acpi_thermal_trip trip; struct acpi_handle_list devices; - unsigned long temperature; - bool valid; }; struct acpi_thermal_trips { - struct acpi_thermal_critical critical; - struct acpi_thermal_hot hot; + struct acpi_thermal_trip critical; + struct acpi_thermal_trip hot; struct acpi_thermal_passive passive; struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; }; @@ -250,9 +243,9 @@ static void __acpi_thermal_trips_update( } /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.valid) || + if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) || flag == ACPI_TRIPS_INIT) { - valid = tz->trips.passive.valid; + valid = tz->trips.passive.trip.valid; if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { @@ -264,44 +257,44 @@ static void __acpi_thermal_trips_update( } if (ACPI_FAILURE(status)) { - tz->trips.passive.valid = false; + tz->trips.passive.trip.valid = false; } else { - tz->trips.passive.temperature = tmp; - tz->trips.passive.valid = true; + tz->trips.passive.trip.temperature = tmp; + tz->trips.passive.trip.valid = true; if (flag == ACPI_TRIPS_INIT) { status = acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.valid = false; + tz->trips.passive.trip.valid = false; else tz->trips.passive.tc1 = tmp; status = acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.valid = false; + tz->trips.passive.trip.valid = false; else tz->trips.passive.tc2 = tmp; status = acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.valid = false; + tz->trips.passive.trip.valid = false; else tz->trips.passive.tsp = tmp; } } } - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.valid) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.trip.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid passive threshold\n"); - tz->trips.passive.valid = false; + tz->trips.passive.trip.valid = false; } else { - tz->trips.passive.valid = true; + tz->trips.passive.trip.valid = true; } if (memcmp(&tz->trips.passive.devices, &devices, @@ -312,24 +305,24 @@ static void __acpi_thermal_trips_update( } } if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { - if (valid != tz->trips.passive.valid) + if (valid != tz->trips.passive.trip.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } /* Active (optional) */ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; - valid = tz->trips.active[i].valid; + valid = tz->trips.active[i].trip.valid; if (act == -1) break; /* disable all active trip points */ if (flag == ACPI_TRIPS_INIT || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips.active[i].valid)) { + tz->trips.active[i].trip.valid)) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.active[i].valid = false; + tz->trips.active[i].trip.valid = false; if (i == 0) break; @@ -337,35 +330,36 @@ static void __acpi_thermal_trips_update( break; if (i == 1) - tz->trips.active[0].temperature = celsius_to_deci_kelvin(act); + tz->trips.active[0].trip.temperature = + celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->trips.active[i-1].temperature = + tz->trips.active[i-1].trip.temperature = min_t(unsigned long, - tz->trips.active[i-2].temperature, + tz->trips.active[i-2].trip.temperature, celsius_to_deci_kelvin(act)); break; } else { - tz->trips.active[i].temperature = tmp; - tz->trips.active[i].valid = true; + tz->trips.active[i].trip.temperature = tmp; + tz->trips.active[i].trip.valid = true; } } name[2] = 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].valid) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].trip.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, name, NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid active%d threshold\n", i); - tz->trips.active[i].valid = false; + tz->trips.active[i].trip.valid = false; } else { - tz->trips.active[i].valid = true; + tz->trips.active[i].trip.valid = true; } if (memcmp(&tz->trips.active[i].devices, &devices, @@ -376,10 +370,10 @@ static void __acpi_thermal_trips_update( } } if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) - if (valid != tz->trips.active[i].valid) + if (valid != tz->trips.active[i].trip.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); - if (!tz->trips.active[i].valid) + if (!tz->trips.active[i].trip.valid) break; } @@ -429,10 +423,10 @@ static int acpi_thermal_get_trip_points( valid = tz->trips.critical.valid | tz->trips.hot.valid | - tz->trips.passive.valid; + tz->trips.passive.trip.valid; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid = valid || tz->trips.active[i].valid; + valid = valid || tz->trips.active[i].trip.valid; if (!valid) { pr_warn(FW_BUG "No valid trip found\n"); @@ -485,7 +479,7 @@ static int thermal_get_trip_type(struct trip--; } - if (tz->trips.passive.valid) { + if (tz->trips.passive.trip.valid) { if (!trip) { *type = THERMAL_TRIP_PASSIVE; return 0; @@ -493,7 +487,7 @@ static int thermal_get_trip_type(struct trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++) { + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) { if (!trip) { *type = THERMAL_TRIP_ACTIVE; return 0; @@ -533,10 +527,10 @@ static int thermal_get_trip_temp(struct trip--; } - if (tz->trips.passive.valid) { + if (tz->trips.passive.trip.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.passive.temperature, + tz->trips.passive.trip.temperature, tz->kelvin_offset); return 0; } @@ -544,10 +538,10 @@ static int thermal_get_trip_temp(struct } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].valid; i++) { + tz->trips.active[i].trip.valid; i++) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.active[i].temperature, + tz->trips.active[i].trip.temperature, tz->kelvin_offset); return 0; } @@ -603,7 +597,7 @@ static int thermal_get_trend(struct ther * before this callback being invoked */ i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) + - tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.temperature); + tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.trip.temperature); if (i > 0) *trend = THERMAL_TREND_RAISING; @@ -654,7 +648,7 @@ static int acpi_thermal_cooling_device_c if (tz->trips.hot.valid) trip++; - if (tz->trips.passive.valid) { + if (tz->trips.passive.trip.valid) { trip++; for (i = 0; i < tz->trips.passive.devices.count; i++) { handle = tz->trips.passive.devices.handles[i]; @@ -679,7 +673,7 @@ static int acpi_thermal_cooling_device_c } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].valid) + if (!tz->trips.active[i].trip.valid) break; trip++; @@ -775,12 +769,12 @@ static int acpi_thermal_register_thermal if (tz->trips.hot.valid) trip_count++; - if (tz->trips.passive.valid) { + if (tz->trips.passive.trip.valid) { trip_count++; passive_delay = tz->trips.passive.tsp * 100; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++) + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) trip_count++; tz->thermal_zone = thermal_zone_device_register("acpitz", trip_count, 0, @@ -1060,7 +1054,7 @@ static int acpi_thermal_resume(struct de return -EINVAL; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].valid) + if (!tz->trips.active[i].trip.valid) break; for (j = 0; j < tz->trips.active[i].devices.count; j++) { From patchwork Mon Aug 7 18:11:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 712235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F71C001DE for ; Mon, 7 Aug 2023 18:21:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbjHGSVG (ORCPT ); Mon, 7 Aug 2023 14:21:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbjHGSVA (ORCPT ); Mon, 7 Aug 2023 14:21:00 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A7DFE50; Mon, 7 Aug 2023 11:20:58 -0700 (PDT) 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.2.0) id 150a4115505eee88; Mon, 7 Aug 2023 20:20:56 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 46A036625B2; Mon, 7 Aug 2023 20:20:56 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 07/11] thermal: core: Rework and rename __for_each_thermal_trip() Date: Mon, 07 Aug 2023 20:11:07 +0200 Message-ID: <3755730.kQq0lBPeGt@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Rework the currently unused __for_each_thermal_trip() to pass original pointers to struct thermal_trip objects to the callback, so it can be used for updating trip data (e.g. temperatures), rename it to for_each_thermal_trip() and make it available to modular drivers. Suggested-by: Daniel Lezcano Signed-off-by: Rafael J. Wysocki --- New patch in v5. --- drivers/thermal/thermal_core.h | 4 ---- drivers/thermal/thermal_trip.c | 18 ++++++++---------- include/linux/thermal.h | 3 +++ 3 files changed, 11 insertions(+), 14 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -54,10 +54,6 @@ int for_each_thermal_cooling_device(int int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *), void *thermal_governor); -int __for_each_thermal_trip(struct thermal_zone_device *, - int (*cb)(struct thermal_trip *, void *), - void *); - struct thermal_zone_device *thermal_zone_get_by_id(int id); struct thermal_attr { Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -9,28 +9,26 @@ */ #include "thermal_core.h" -int __for_each_thermal_trip(struct thermal_zone_device *tz, - int (*cb)(struct thermal_trip *, void *), - void *data) +int for_each_thermal_trip(struct thermal_zone_device *tz, + int (*cb)(struct thermal_trip *, void *), + void *data) { int i, ret; - struct thermal_trip trip; lockdep_assert_held(&tz->lock); - for (i = 0; i < tz->num_trips; i++) { + if (!tz->trips) + return -ENODATA; - ret = __thermal_zone_get_trip(tz, i, &trip); - if (ret) - return ret; - - ret = cb(&trip, data); + for (i = 0; i < tz->num_trips; i++) { + ret = cb(&tz->trips[i], data); if (ret) return ret; } return 0; } +EXPORT_SYMBOL_GPL(for_each_thermal_trip); int thermal_zone_get_num_trips(struct thermal_zone_device *tz) { Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -290,6 +290,9 @@ int thermal_zone_get_trip(struct thermal int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, const struct thermal_trip *trip); +int for_each_thermal_trip(struct thermal_zone_device *tz, + int (*cb)(struct thermal_trip *, void *), + void *data); int thermal_zone_get_num_trips(struct thermal_zone_device *tz); int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp); From patchwork Mon Aug 7 18:14:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 711461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06058C04FE0 for ; Mon, 7 Aug 2023 18:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbjHGSVB (ORCPT ); Mon, 7 Aug 2023 14:21:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbjHGSU7 (ORCPT ); Mon, 7 Aug 2023 14:20:59 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E26BC1B7; Mon, 7 Aug 2023 11:20:57 -0700 (PDT) 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.2.0) id b9c9405b2b992c1f; Mon, 7 Aug 2023 20:20:56 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 7D4EE6625B2; Mon, 7 Aug 2023 20:20:55 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 08/11] ACPI: thermal: Use trip point table to register thermal zones Date: Mon, 07 Aug 2023 20:14:43 +0200 Message-ID: <3178745.5fSG56mABF@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Make the ACPI thermal driver use thermal_zone_device_register_with_trips() to register its thermal zones. For this purpose, make it create a trip point table that will be passed to thermal_zone_device_register_with_trips() as an argument. Also use the thermal_zone_update_trip_temp() helper introduced previously to update temperatures of the passive and active trip points after a trip points change notification from the platform firmware. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: * Use for_each_thermal_trip() introduced previously to update trip temperatures with the help of a new trip callback function. * Drop a function that has no users after the above change. * Rebase on top of patch [07/11]. v3 -> v4: * Rework to use thermal_zone_update_trip_temp() for updating trip point temperatures. * Rebase on top of the new version of the previous patch. v2 -> v3: * Fix error code path memory leak in acpi_thermal_register_thermal_zone(). * Notice that the critical and hot trips never change after initialization, so don't add struct thermal_trip_ref to any of them. v1 -> v2: * Use thermal_zone_device_lock()/thermal_zone_device_unlock() in acpi_thermal_check_fn() explicitly and call __thermal_zone_device_update() from there without unlocking the thermal zone. * Export __thermal_zone_device_update() to modules (so it can be called by the ACPI thermal code). --- drivers/acpi/thermal.c | 93 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 7 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -125,6 +125,7 @@ struct acpi_thermal { unsigned long polling_frequency; volatile u8 zombie; struct acpi_thermal_trips trips; + struct thermal_trip *trip_table; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ @@ -178,6 +179,15 @@ static int acpi_thermal_get_polling_freq return 0; } +static int acpi_thermal_temp(struct acpi_thermal *tz, int temp_deci_k) +{ + if (temp_deci_k == THERMAL_TEMP_INVALID) + return THERMAL_TEMP_INVALID; + + return deci_kelvin_to_millicelsius_with_offset(temp_deci_k, + tz->kelvin_offset); +} + static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) { acpi_status status; @@ -389,10 +399,30 @@ static void __acpi_thermal_trips_update( } } +static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data) +{ + struct acpi_thermal_trip *acpi_trip = trip->priv; + struct acpi_thermal *tz = data; + + if (!acpi_trip) + return 0; + + if (acpi_trip->valid) + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + else + trip->temperature = THERMAL_TEMP_INVALID; + + return 0; +} + static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal, unsigned long data) { - __acpi_thermal_trips_update(thermal_zone_device_priv(thermal), data); + struct acpi_thermal *tz = thermal_zone_device_priv(thermal); + + __acpi_thermal_trips_update(tz, data); + + for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz); } static void acpi_queue_thermal_check(struct acpi_thermal *tz) @@ -757,6 +787,8 @@ static void acpi_thermal_zone_sysfs_remo static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { + struct acpi_thermal_trip *acpi_trip; + struct thermal_trip *trip; int passive_delay = 0; int trip_count = 0; int result; @@ -777,12 +809,56 @@ static int acpi_thermal_register_thermal for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) trip_count++; - tz->thermal_zone = thermal_zone_device_register("acpitz", trip_count, 0, - tz, &acpi_thermal_zone_ops, - NULL, passive_delay, - tz->polling_frequency * 100); - if (IS_ERR(tz->thermal_zone)) - return -ENODEV; + trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); + if (!trip) + return -ENOMEM; + + tz->trip_table = trip; + + if (tz->trips.critical.valid) { + trip->type = THERMAL_TRIP_CRITICAL; + trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature); + trip++; + } + + if (tz->trips.hot.valid) { + trip->type = THERMAL_TRIP_HOT; + trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature); + trip++; + } + + acpi_trip = &tz->trips.passive.trip; + if (acpi_trip->valid) { + trip->type = THERMAL_TRIP_PASSIVE; + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->priv = &tz->trips.passive.trip; + trip++; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + acpi_trip = &tz->trips.active[i].trip; + + if (!acpi_trip->valid) + continue; + + trip->type = THERMAL_TRIP_ACTIVE; + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->priv = &tz->trips.active[i].trip; + trip++; + } + + tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz", + tz->trip_table, + trip_count, + 0, tz, + &acpi_thermal_zone_ops, + NULL, + passive_delay, + tz->polling_frequency * 100); + if (IS_ERR(tz->thermal_zone)) { + result = PTR_ERR(tz->thermal_zone); + goto free_trip_table; + } result = acpi_thermal_zone_sysfs_add(tz); if (result) @@ -810,6 +886,8 @@ remove_links: acpi_thermal_zone_sysfs_remove(tz); unregister_tzd: thermal_zone_device_unregister(tz->thermal_zone); +free_trip_table: + kfree(tz->trip_table); return result; } @@ -818,6 +896,7 @@ static void acpi_thermal_unregister_ther { acpi_thermal_zone_sysfs_remove(tz); thermal_zone_device_unregister(tz->thermal_zone); + kfree(tz->trip_table); tz->thermal_zone = NULL; acpi_bus_detach_private_data(tz->device->handle); } From patchwork Mon Aug 7 18:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 712236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32A19C04FDF for ; Mon, 7 Aug 2023 18:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbjHGSVA (ORCPT ); Mon, 7 Aug 2023 14:21:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjHGSU6 (ORCPT ); Mon, 7 Aug 2023 14:20:58 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194A3194; Mon, 7 Aug 2023 11:20:56 -0700 (PDT) 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.2.0) id e153a7dfbe3fa879; Mon, 7 Aug 2023 20:20:55 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id B19566625B2; Mon, 7 Aug 2023 20:20:54 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 09/11] ACPI: thermal: Rework thermal_get_trend() Date: Mon, 07 Aug 2023 20:17:07 +0200 Message-ID: <8296661.NyiUUSuA9g@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Rework the ACPI thermal driver's .get_trend() callback function, thermal_get_trend(), so that it does not call thermal_get_trip_type() and thermal_get_trip_temp() which are going to be dropped. This reduces the overhead of the function too, because it will always carry out a trip point lookup once after the change. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: * Rebase on top of patches [07-08/11]. v3 -> v4: * Adjust for the lack of a direct way to get from the local trip point representations to trips[i]. v2 -> v3: Rebase on top of the v2 of the previous patch. v1 -> v2: * Do not acquire thermal_check_lock in thermal_get_trend() (lockdep would complain about this, because it is hold around thermal zone locking and .get_trend() runs under the thermal zone lock). The thermal zone locking added in the previous patches is sufficient to protect this code. * Check trips against invalid temperature values. * Return an error for trips other than passive and active. --- drivers/acpi/thermal.c | 68 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 30 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -597,46 +597,54 @@ static int thermal_get_crit_temp(struct } static int thermal_get_trend(struct thermal_zone_device *thermal, - int trip, enum thermal_trend *trend) + int trip_index, enum thermal_trend *trend) { struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - enum thermal_trip_type type; - int i; + struct acpi_thermal_trip *acpi_trip; + int t, i; - if (thermal_get_trip_type(thermal, trip, &type)) + if (!tz || trip_index < 0) return -EINVAL; - if (type == THERMAL_TRIP_ACTIVE) { - int trip_temp; - int temp = deci_kelvin_to_millicelsius_with_offset( - tz->temperature, tz->kelvin_offset); - if (thermal_get_trip_temp(thermal, trip, &trip_temp)) - return -EINVAL; + if (tz->trips.critical.valid) + trip_index--; - if (temp > trip_temp) { + if (tz->trips.hot.valid) + trip_index--; + + if (trip_index < 0) + return -EINVAL; + + acpi_trip = &tz->trips.passive.trip; + if (acpi_trip->valid && !trip_index--) { + t = tz->trips.passive.tc1 * (tz->temperature - + tz->last_temperature) + + tz->trips.passive.tc2 * (tz->temperature - + acpi_trip->temperature); + if (t > 0) *trend = THERMAL_TREND_RAISING; - return 0; - } else { - /* Fall back on default trend */ - return -EINVAL; - } + else if (t < 0) + *trend = THERMAL_TREND_DROPPING; + else + *trend = THERMAL_TREND_STABLE; + + return 0; } - /* - * tz->temperature has already been updated by generic thermal layer, - * before this callback being invoked - */ - i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) + - tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.trip.temperature); - - if (i > 0) - *trend = THERMAL_TREND_RAISING; - else if (i < 0) - *trend = THERMAL_TREND_DROPPING; - else - *trend = THERMAL_TREND_STABLE; + t = acpi_thermal_temp(tz, tz->temperature); + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + acpi_trip = &tz->trips.active[i].trip; + if (acpi_trip->valid && !trip_index--) { + if (t > acpi_thermal_temp(tz, acpi_trip->temperature)) { + *trend = THERMAL_TREND_RAISING; + return 0; + } + break; + } + } - return 0; + return -EINVAL; } static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal) From patchwork Mon Aug 7 18:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 711462 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76A57C001DE for ; Mon, 7 Aug 2023 18:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230405AbjHGSU7 (ORCPT ); Mon, 7 Aug 2023 14:20:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbjHGSU6 (ORCPT ); Mon, 7 Aug 2023 14:20:58 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49610DE; Mon, 7 Aug 2023 11:20:56 -0700 (PDT) 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.2.0) id 8cfedfee9a03d93a; Mon, 7 Aug 2023 20:20:54 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id EBE836625B2; Mon, 7 Aug 2023 20:20:53 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 10/11] ACPI: thermal: Drop unnecessary thermal zone callbacks Date: Mon, 07 Aug 2023 20:18:49 +0200 Message-ID: <3436224.QJadu78ljV@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Drop the .get_trip_type(), .get_trip_temp() and .get_crit_temp() thermal zone callbacks that are not necessary any more from the ACPI thermal driver along with the corresponding callback functions. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: Rebase. v3 -> v4: No changes. v2 -> v3: Rebase on top of the v2 of the previous patch. v1 -> v2: No changes. --- drivers/acpi/thermal.c | 115 ------------------------------------------------- 1 file changed, 115 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -484,118 +484,6 @@ static int thermal_get_temp(struct therm return 0; } -static int thermal_get_trip_type(struct thermal_zone_device *thermal, - int trip, enum thermal_trip_type *type) -{ - struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - int i; - - if (!tz || trip < 0) - return -EINVAL; - - if (tz->trips.critical.valid) { - if (!trip) { - *type = THERMAL_TRIP_CRITICAL; - return 0; - } - trip--; - } - - if (tz->trips.hot.valid) { - if (!trip) { - *type = THERMAL_TRIP_HOT; - return 0; - } - trip--; - } - - if (tz->trips.passive.trip.valid) { - if (!trip) { - *type = THERMAL_TRIP_PASSIVE; - return 0; - } - trip--; - } - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) { - if (!trip) { - *type = THERMAL_TRIP_ACTIVE; - return 0; - } - trip--; - } - - return -EINVAL; -} - -static int thermal_get_trip_temp(struct thermal_zone_device *thermal, - int trip, int *temp) -{ - struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - int i; - - if (!tz || trip < 0) - return -EINVAL; - - if (tz->trips.critical.valid) { - if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, - tz->kelvin_offset); - return 0; - } - trip--; - } - - if (tz->trips.hot.valid) { - if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.hot.temperature, - tz->kelvin_offset); - return 0; - } - trip--; - } - - if (tz->trips.passive.trip.valid) { - if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.passive.trip.temperature, - tz->kelvin_offset); - return 0; - } - trip--; - } - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].trip.valid; i++) { - if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.active[i].trip.temperature, - tz->kelvin_offset); - return 0; - } - trip--; - } - - return -EINVAL; -} - -static int thermal_get_crit_temp(struct thermal_zone_device *thermal, - int *temperature) -{ - struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - - if (tz->trips.critical.valid) { - *temperature = deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, - tz->kelvin_offset); - return 0; - } - - return -EINVAL; -} - static int thermal_get_trend(struct thermal_zone_device *thermal, int trip_index, enum thermal_trend *trend) { @@ -758,9 +646,6 @@ static struct thermal_zone_device_ops ac .bind = acpi_thermal_bind_cooling_device, .unbind = acpi_thermal_unbind_cooling_device, .get_temp = thermal_get_temp, - .get_trip_type = thermal_get_trip_type, - .get_trip_temp = thermal_get_trip_temp, - .get_crit_temp = thermal_get_crit_temp, .get_trend = thermal_get_trend, .hot = acpi_thermal_zone_device_hot, .critical = acpi_thermal_zone_device_critical, From patchwork Mon Aug 7 18:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 712237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 308F1C41513 for ; Mon, 7 Aug 2023 18:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229968AbjHGSU7 (ORCPT ); Mon, 7 Aug 2023 14:20:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjHGSU5 (ORCPT ); Mon, 7 Aug 2023 14:20:57 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D38B78F; Mon, 7 Aug 2023 11:20:55 -0700 (PDT) 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.2.0) id 94dc6781b6e2d306; Mon, 7 Aug 2023 20:20:53 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 095486625B2; Mon, 7 Aug 2023 20:20:53 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v5 11/11] thermal: core: Eliminate code duplication from acpi_thermal_notify() Date: Mon, 07 Aug 2023 20:20:18 +0200 Message-ID: <23175634.6Emhk5qWAg@kreacher> In-Reply-To: <4503814.LvFx2qVVIh@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4503814.LvFx2qVVIh@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrledtgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Rafael J. Wysocki Move the acpi_bus_generate_netlink_event() invocation into acpi_thermal_trips_update() which allows the code duplication in acpi_thermal_notify() to be cleaned up, but for this purpose the event value needs to be passed to acpi_thermal_trips_update() and from there to acpi_thermal_adjust_thermal_zone() which has to determine the flag value for __acpi_thermal_trips_update() by itself. Signed-off-by: Rafael J. Wysocki --- v4 -> v5: Rebase. New patch in v4. --- drivers/acpi/thermal.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -419,8 +419,10 @@ static void acpi_thermal_adjust_thermal_ unsigned long data) { struct acpi_thermal *tz = thermal_zone_device_priv(thermal); + int flag = data == ACPI_THERMAL_NOTIFY_THRESHOLDS ? + ACPI_TRIPS_THRESHOLDS : ACPI_TRIPS_DEVICES; - __acpi_thermal_trips_update(tz, data); + __acpi_thermal_trips_update(tz, flag); for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz); } @@ -431,8 +433,10 @@ static void acpi_queue_thermal_check(str queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); } -static void acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event) { + struct acpi_device *adev = tz->device; + /* * Use thermal_zone_device_adjust() to carry out the trip points * update, so as to protect thermal_get_trend() from getting stale @@ -440,8 +444,10 @@ static void acpi_thermal_trips_update(st * invoked from acpi_thermal_check_fn() from producing inconsistent * results. */ - thermal_zone_device_adjust(tz->thermal_zone, flag); + thermal_zone_device_adjust(tz->thermal_zone, event); acpi_queue_thermal_check(tz); + acpi_bus_generate_netlink_event(adev->pnp.device_class, + dev_name(&adev->dev), event, 0); } static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) @@ -812,14 +818,8 @@ static void acpi_thermal_notify(acpi_han acpi_queue_thermal_check(tz); break; case ACPI_THERMAL_NOTIFY_THRESHOLDS: - acpi_thermal_trips_update(tz, ACPI_TRIPS_THRESHOLDS); - acpi_bus_generate_netlink_event(device->pnp.device_class, - dev_name(&device->dev), event, 0); - break; case ACPI_THERMAL_NOTIFY_DEVICES: - acpi_thermal_trips_update(tz, ACPI_TRIPS_DEVICES); - acpi_bus_generate_netlink_event(device->pnp.device_class, - dev_name(&device->dev), event, 0); + acpi_thermal_trips_update(tz, event); break; default: acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n",