From patchwork Fri Aug 4 21:00:22 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: 131376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp119184vqr; Fri, 4 Aug 2023 14:52:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+lzZx5GYijrRU6qX3FOBZg/+upIb0PUKtD4LB7+0GU6Z2+RHF+SQtwQb6odMw2lGqM3Eb X-Received: by 2002:a17:906:3052:b0:99c:5056:4e31 with SMTP id d18-20020a170906305200b0099c50564e31mr922370ejd.15.1691185938995; Fri, 04 Aug 2023 14:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691185938; cv=none; d=google.com; s=arc-20160816; b=rf6oAbBt4TQnI0Myc6YFRoDK5f3aMqLAwx+cEodixz0NQsdH/TNRprfDI3lM9wrH20 mEahmb7T1Tl7Wrwvh/5LZvuWzuTjFrnAXwxgjPHNWSlPJR3bvSj0o6ZM4EfkHNknKKoi T8mUfu1O6bSQUunxCnJdtXB6an+9nxolbixLpmwvK77vcK++JGAE4WOXoQ89ggoCnvE3 INX7GPf2T/AfE55DIUUg2s9jGWG7E0HLoHELFsOuJdaKkfvSpjPvN9lKG6dfcX3uu6Yc vSoDSsJ/VeWoeSsc+X2q5LXksI1fs7ZNEUlypTEqMfTpE+m16oNNT8z9v4H4fc3oGk5t S+Wg== 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=T0xvm0KE0jwiBvoXLCFCeB7sa2tOPqhijyN43fdkY4c=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=ndEgRmoAn6/0OtvQciyF64PRDGuneyHIFBezvq+knD7sseFv6iau4Yg1FGp7Zh82Dz AvXhWKC2+fSUDl3hD7y0jhyV3pK7H9z5kclabwwSEheZzCrA9+/Zkl0O3PBEkO8maSNo uzxVO3Lzm/LCdwwI+SFK3w8D7i/0ZMKfmcwlOsUlY3uuHF5NuhEMDGatyOxWwMog8CD2 X/0Ck4FYHkL0G+lBVb1Bxq6prccwUcUO6PkIYgjCTWBr1h1L0IoFMlsvrfJO5LvOUzhG BOECTfoek0/uuaHE2cLQAXSANbVYQbOa8dsnsWA7yjCp9qB2JtPtjwEXM+lZrhTThZB8 vaUA== 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 t26-20020a170906a11a00b0099b633adf35si508487ejy.454.2023.08.04.14.51.55; Fri, 04 Aug 2023 14:52:18 -0700 (PDT) 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 S229671AbjHDV0g (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbjHDV0Q (ORCPT ); Fri, 4 Aug 2023 17:26:16 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D2514C3B; Fri, 4 Aug 2023 14:26:12 -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 a6286e61ff4363f4; Fri, 4 Aug 2023 23:26:11 +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 BAA3D6624B9; Fri, 4 Aug 2023 23:26:10 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 01/10] thermal: core: Do not handle trip points with invalid temperature Date: Fri, 04 Aug 2023 23:00:22 +0200 Message-ID: <4850902.GXAFRqVoOG@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771784336627630697 X-GMAIL-MSGID: 1773336987627947779 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 --- 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 Fri Aug 4 21:03:23 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: 131381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp132531vqr; Fri, 4 Aug 2023 15:21:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoyxGyZzm334e4DzVZrpO9aZBPImDzeQEVeREZA9o9CT+gE7Bwxw9JtYQ2sDV7QCT1Zh8w X-Received: by 2002:a17:906:5a45:b0:99b:5e5f:1667 with SMTP id my5-20020a1709065a4500b0099b5e5f1667mr2588496ejc.15.1691187701224; Fri, 04 Aug 2023 15:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691187701; cv=none; d=google.com; s=arc-20160816; b=RSGiH6nTYgQL3Cy+LofV14SZH+MTLLDRrDKTWf0n0kduUYKE2mNEUIqDjxauPl7bmT EMJ9sBdLeDv/XhcTqe2uj6eqkeHSJhY4bsauAeoxXdnqWK2NIL0DeeyqoGW2RfJ8YkIw XZOZ5gOHl2L+IDnIomYJQDjLDBCYt+6oRV6L6Vcf1ymEDKxGJjGhVBH3YHSNTpLmfUXj udvfDm9mM0YiG4zMuQe0P40fmGMHA+bMOEoDCmlccBQp8E48hpwaLoJjol+eWzhojG4W MJ6Y9ZMZ5QXeKpfFHL3zcnNd1Bqy8C7coZ70MzSykA6i34IoiQJDVwqYOsXjosOspJ1n mNsw== 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=49NjO7N2nIIvi9T9PEqVZ7EtDl6kTERa6N1iIGLQ0L8=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=Mh6wQ4h24fA0XM6bcP209kKehbEkmEItDBEnYUQe2WebBzaheSzVvJk4EmfuXjdVMC JkZD5BaSUQ28A22bc/kTuKHMJ0ywSxyO/5jcJQer7/D5+zN0A/Zm6o0s2N08UGuO38sy RmRyetmFf8Ojf3lDhJL2+LJd+Wpdmjn6AHubncIJaIgs94HlSc9cpBHEDTZI6OEwu20J uBEGNwsoyiGIWUmzhowzwV2m6o3kZF7PtWkfNZGxkGK1OvRS27irXBLgOMcQmqFxnZ7S MUB27zvGAWBy0wsJbSQ0awnEBPgp+ynR4MNwEmZyrLUuv9vjC/DJH4sBa7PidjvQoFO+ sJgQ== 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 q9-20020a1709064c8900b0099b46fc04f6si2311519eju.1006.2023.08.04.15.21.07; Fri, 04 Aug 2023 15:21:41 -0700 (PDT) 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 S231302AbjHDV0i (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbjHDV0Q (ORCPT ); Fri, 4 Aug 2023 17:26:16 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46987E43; Fri, 4 Aug 2023 14:26:12 -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 2e134a16b4b32ce9; Fri, 4 Aug 2023 23:26:10 +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 F29F1661680; Fri, 4 Aug 2023 23:26:09 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 02/10] thermal: core: Introduce thermal_zone_device_adjust() Date: Fri, 04 Aug 2023 23:03:23 +0200 Message-ID: <3272532.aeNJFYEL58@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773338834769154865 X-GMAIL-MSGID: 1773338834769154865 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 --- 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 Fri Aug 4 21:04:53 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: 131375 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp118822vqr; Fri, 4 Aug 2023 14:51:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdFVhKNzhF8/4oxDqJBP7iWuPLvM1e0B5DJ153I6raxrXWlHVehc3UAhR0hD8N1T3R1yVW X-Received: by 2002:a17:902:7883:b0:1bb:c7c6:3454 with SMTP id q3-20020a170902788300b001bbc7c63454mr2796359pll.48.1691185877388; Fri, 04 Aug 2023 14:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691185877; cv=none; d=google.com; s=arc-20160816; b=hx/J3KxysUbwBKkdbcv2YCOzA0Ar/GPI7BwmqD9FI4as8QzM5qZyag1+hz2lTAQOPO 78JCncwo1JqcOKBY5zDxu1Sp5OP2kTwHspEKLBgxSjQnHuTyf+PVvaYJ4K4MSUDhYGyw o+xyYfBhl0TrQGq09l2Ef6be1TE28JDzQIwVrFaCxpptI4B0YygqSKo6nIx4ktZmYQOr fnIxHOTep4T0NRZRuqCum7dLyGuLVMe083UHVn+2Wt2jMEMBKCWnfeq1lklsehnRjHt7 6JrX8SQbkeW9qa14oh/9xPbspq4LScy2bzy2kUbMUDeaMGHeKlVo08dh1a6Zl/YVd5LR g/VA== 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=ex8ATw85Z0vRp/Ys9DOd5sAhBbnyk8Rj1+rB7gv2tDg=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=E5vxAXSJ/eZ2c9xhXpvauyAGom0ar+M639tug4tpOr9qiMjaQWAYP1sToolgYBr1fK PoAQEqxm6FCJlMIEg2RPVNjvFPwpraST5efyndI+o8xi3ApvuVg1t/V7g/rI9vt2IfEH y7KQaVV5HYLLvSw65GiLCXYj58aIBvboOAcePKasNcuVwVuqWWK61b2rNCFvhTqRFqzh E8JSk9DBFtk1H3SNdcdOHZ3qlhDAcScqzAzF9T+/NKCwHoRUXvmwlcYWW2Tt8dVJOd3b fXxGsMaoC9UZchW5UyX4zrSGj80N5HoNmHXgj0mSXlrJ8drXjNZl9zWUpzfmmGwfjUsa B6Gg== 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 w3-20020a170902e88300b001b829a32f2dsi2359478plg.457.2023.08.04.14.51.03; Fri, 04 Aug 2023 14:51:17 -0700 (PDT) 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 S231140AbjHDV0c (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjHDV0N (ORCPT ); Fri, 4 Aug 2023 17:26:13 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6704C2D7E; Fri, 4 Aug 2023 14:26:11 -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 dec5b0a88e15fbd9; Fri, 4 Aug 2023 23:26:09 +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 38F00661680; Fri, 4 Aug 2023 23:26:09 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 03/10] thermal: core: Add priv pointer to struct thermal_trip Date: Fri, 04 Aug 2023 23:04:53 +0200 Message-ID: <10344810.nUPlyArG6x@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773336922437496432 X-GMAIL-MSGID: 1773336922437496432 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 --- 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 Fri Aug 4 21:05:40 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: 131374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp118408vqr; Fri, 4 Aug 2023 14:50:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEYCbqzeRoCwawp2aT0uu5NIDmWLxbIH2Sdt5aNsA6/84Ei8rP2H9ProO0/kOL6qeof+Tt X-Received: by 2002:a17:907:75f5:b0:997:eae6:9350 with SMTP id jz21-20020a17090775f500b00997eae69350mr2318999ejc.51.1691185809424; Fri, 04 Aug 2023 14:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691185809; cv=none; d=google.com; s=arc-20160816; b=DNJAv9kFGBilQxRk/o4a2zJNu5CBKFCPmuV/nAXznXeYr/C59vlALb4SWYpyiigjU4 90y/ydiOKGUHQ7dzvKH5oOk5DWBQ+95dVw8nlIMDMLKebgzVVnsGLjbClBSgzUXKvI04 2bu/pwTqbzq+89/9MWq4C9AB/U8ZUf64VYkNy3/UFptCMXG9DDCM9SCPaYCXty7BbpnN 6hfpOLnlFEcYcqjMzqxCKR9n//+NccKwx1Fcx6Yq3qf5s9dYjsqBdfo5hlUuPKpy7Euf ugMGQEpfVgpI61GyWUmg2ADmQi/B4iq+TKdKzPwZ1/r6GjOA+Eg9+ggfX8SK+QhRm8UV zu0w== 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=QdM/khr6HnLK0AdU6MnTD2VJG7D4tGKXoR/zpyL6EVc=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=1HpHB3cGnD4zpAbL4r6sO67P+ByBkoE54hCS5lcSgoZvMc+oOo5Csidg3SZBPhhu9d /2lE/oyK6yGQ+PdhQo4+zdQoTYos5LLIWNofWxXvNGv1tQjAMJ66AYe0Ap84EwRWHaNB 2evPizZ5uyJ01w9riHlOeQZrz7t8b2bXurIsQlASAoj0AhwtjCxLM01z9CHxV00QGati IP9VE39S3yjTRNQ/Hoioy3oOidEgmzPi+/GHCcvoRuYOSwKjJPk4bTzvZHoATYm870+y 9ZuoFywjixzxwynYWfTnBcmH1RTnuBuSB2ncmTXZ81sOJsmc/NvtTKF0XteB0VE3TEMj EA4g== 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 jt18-20020a170906dfd200b0099c9e68e3b4si963263ejc.325.2023.08.04.14.49.45; Fri, 04 Aug 2023 14:50:09 -0700 (PDT) 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 S229615AbjHDV03 (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbjHDV0M (ORCPT ); Fri, 4 Aug 2023 17:26:12 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AED66E46; Fri, 4 Aug 2023 14:26:10 -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 cae361074099a2a1; Fri, 4 Aug 2023 23:26:09 +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 7A7AB661680; Fri, 4 Aug 2023 23:26:08 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 04/10] thermal: core: Add thermal_zone_update_trip_temp() helper routine Date: Fri, 04 Aug 2023 23:05:40 +0200 Message-ID: <1967710.PYKUYFuaPT@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773336851811481558 X-GMAIL-MSGID: 1773336851811481558 From: Rafael J. Wysocki Introduce a helper routine called thermal_zone_update_trip_temp() that can be used to update a trip point's temperature with the help of a pointer to local data associated with that trip point provided by the thermal driver that created it. Signed-off-by: Rafael J. Wysocki --- New patch in v4. --- drivers/thermal/thermal_trip.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 4 ++++ 2 files changed, 41 insertions(+) Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -180,3 +180,40 @@ int thermal_zone_set_trip(struct thermal return 0; } + +/** + * thermal_zone_update_trip_temp - Update the trip point temperature. + * @tz: Thermal zone. + * @trip_priv: Trip tag. + * @temp: New trip temperature. + * + * This only works for thermal zones using trip tables and its caller must + * ensure that the zone lock is held before using it. + * + * @trip_priv is expected to be the value that has been stored by the driver + * in the struct thermal_trip representing the trip point in question, so it + * can be matched against the value of the priv field in that structure. + * + * If @trip_priv does not match any trip point in the trip table of @tz, + * nothing happens. + */ +void thermal_zone_update_trip_temp(struct thermal_zone_device *tz, + void *trip_priv, int temperature) +{ + int i; + + lockdep_assert_held(&tz->lock); + + if (!tz->trips || !trip_priv) + return; + + for (i = 0; i < tz->num_trips; i++) { + struct thermal_trip *trip = &tz->trips[i]; + + if (trip->priv == trip_priv) { + trip->temperature = temperature; + return; + } + } +} +EXPORT_SYMBOL_GPL(thermal_zone_update_trip_temp); Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -286,9 +286,13 @@ int __thermal_zone_get_trip(struct therm struct thermal_trip *trip); int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); +void thermal_zone_update_trip_temp(struct thermal_zone_device *tz, + void *trip_priv, int temperature); int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, const struct thermal_trip *trip); +void thermal_zone_update_trip_temp(struct thermal_zone_device *tz, + void *trip_priv, int temperature); int thermal_zone_get_num_trips(struct thermal_zone_device *tz); From patchwork Fri Aug 4 21:07: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: 131373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp118355vqr; Fri, 4 Aug 2023 14:50:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJqOA1/NTj8HwdYHwGHYFilkFsrEeyLZ+hLpFxsyjBwVTq2SOuMNttte2Rn5AvizRom2f/ X-Received: by 2002:a17:906:41:b0:99c:47a:8bcd with SMTP id 1-20020a170906004100b0099c047a8bcdmr2464597ejg.67.1691185801334; Fri, 04 Aug 2023 14:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691185801; cv=none; d=google.com; s=arc-20160816; b=mtyNvx/v5Flu0PJABOZ+tEmILi/yhykp7A5LsTAKNSB5W1eD9GdyINVZ4rkl8LpSiq a8YTZ6kuKOm0LSr85WnB45+hXI5nLw1vaT3odJFsKcC6CfXQzwkH8GzYqCzGKSYEQbkj Ezm7/xDqL//AeE43Q20I5bMw4nmWwpNmynfuYNtDlOiTpxB57eifmy8E7bQfbOW8ZgDy R6lulEIyoBr/dDe5eGj0t4NCtDbNV4ypRb19EpU48E8VFzfRxjRPCFhvbFstj1ASweTL oHdfgdf49SF79dNdASZb9aUF+HArC2hVaFu8lgwvwdQ5sL7nDOarcrDo0w5mXXs8Ty5v 5C+Q== 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=5VYgHSwcGsra1K2Z+t53gFTqDnnro+xqr2rVQChsDQQ=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=hGUOZhWvQkLHsJg5tmPI8/rZTiNgzFE20kCL6Nc+2p4lY9uSfAab0kU+ZdN4Tz9fLb k2mCZjutGyg7wtI8zYJs5KSMiPJO5lmKN8TTtgxLPrCava3vdNI0XpQ2Yn9ipBqS6lHN V1fsQ90pVB8K53TsFJd4Nijeyqpo/9jo02vs5dGhbm7c1yaTljoj38xVtdEESVvidz67 dKRhzR7QGUti6oMCrFNSzae1d313WwBmEbSebKwSNk6DIQLB2VaTsJDgMoRnfMhuLQVw KRKAqrANUGUV+jwvjSwFOWxxjx3GqYHfAYFFXNqZqVFRGE1fjn+mCxztO4NJM2iXHgdx isLw== 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 pw28-20020a17090720bc00b0098882d02831si2039377ejb.710.2023.08.04.14.49.38; Fri, 04 Aug 2023 14:50:01 -0700 (PDT) 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 S231202AbjHDV0X (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbjHDV0L (ORCPT ); Fri, 4 Aug 2023 17:26:11 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DADA8E43; Fri, 4 Aug 2023 14:26:09 -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 22f7f0f302ddf991; Fri, 4 Aug 2023 23:26:08 +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 B344C661680; Fri, 4 Aug 2023 23:26:07 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 05/10] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Date: Fri, 04 Aug 2023 23:07:18 +0200 Message-ID: <7582643.EvYhyI6sBW@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771784737878457592 X-GMAIL-MSGID: 1773336843086331988 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 --- 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 @@ -745,34 +745,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 Fri Aug 4 21:13:08 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: 131390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp141120vqr; Fri, 4 Aug 2023 15:42:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2cFNryB4EMkvhTyVgCgpetqPX5iYmmublEk/YTnFj/c4rvZAQ/ppMI6lejhWfUj1c2H8g X-Received: by 2002:a05:6402:51d2:b0:521:ef0f:8ef9 with SMTP id r18-20020a05640251d200b00521ef0f8ef9mr1140384edd.19.1691188964101; Fri, 04 Aug 2023 15:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691188964; cv=none; d=google.com; s=arc-20160816; b=x7bXPi3ykwaHY/yV4NL4yp2UWe3lDNQMo5kom+ZQhw7L5xlIctLMBAE8DgRZSmvw+d IFHMFUU1huTdux+/uwUr58HVAstMztBrpHIufxuR0UQhP8IERiEFKIW+Uhq2j1+ELdM1 /t5j2jY88BbvaPInrvVGSjeudfm2FXQVgtGni42U12fIwH8JY0Pj7gEUu9LRYYPNuS/E 3PE2MvMTMAge1ktuo9vlL4iPyN44Zwtsj8uVcACLSVztzEWEi/jN0soaEb+OceBcEaWV 1raqVZOlVfix4k1dMNVkK1+e6o9YhIDLeGkv4v98yxzbe8M0LVpxB0eP/vG3b0a3FJqC hY3w== 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=7WNaqtBS2qanpG1e5cEO/9dl0kdiGiGEH/6soZ9q/hE=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=U/BM0ecgjI3O4TK6/Zte41zuYoUcXdvg7B/pfeReKOKEncm0yIU+Hx4tPvujxivd+p vWUiK10jW0Iod/MRqJqzbMpwHJp1LsZImEyQrFfTHfhBoHRXumc+IQcOnjcsmXkkTtlT RnTwSLRD2Kgae0AmRq1jrmz8Z+oEAB8tNUdF1F7ZXrKAKs97B3KILvUBPE8Crq1ksBjt HZN+GM1BLPRO9G14asvpK/zMEAz65FW8FbIOKXXmsU3/1MUDOTH0GaFl7O9EnvGH1GdG N9sp6E4xKSPNjp/hHV5FHQni+dV781a79keKlOjR+TKUdqkxcSF/kJhGaY0nO5jn2LRp G3Vg== 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 m14-20020a50ef0e000000b0052246fca042si2234818eds.342.2023.08.04.15.42.21; Fri, 04 Aug 2023 15:42:44 -0700 (PDT) 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 S231234AbjHDV0U (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230488AbjHDV0K (ORCPT ); Fri, 4 Aug 2023 17:26:10 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23EC8B1; Fri, 4 Aug 2023 14:26:08 -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 6d6d931799418004; Fri, 4 Aug 2023 23:26:07 +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 F0C4C661680; Fri, 4 Aug 2023 23:26:06 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 06/10] ACPI: thermal: Carry out trip point updates under zone lock Date: Fri, 04 Aug 2023 23:13:08 +0200 Message-ID: <3205670.5fSG56mABF@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773340159455863293 X-GMAIL-MSGID: 1773340159455863293 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 --- 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 @@ -190,7 +190,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; @@ -398,17 +398,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 | @@ -715,6 +737,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) @@ -815,12 +838,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; @@ -835,13 +852,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 Fri Aug 4 21:18:10 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: 131371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp118018vqr; Fri, 4 Aug 2023 14:49:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2D7va8l4lNzvX/t4dHA5vLvyrFxWaUmLiqFfaZeI43u7nZ1sdpAuw3HQdPULs6vOjMV3+ X-Received: by 2002:a05:6808:1b0e:b0:3a3:fa64:bb8d with SMTP id bx14-20020a0568081b0e00b003a3fa64bb8dmr3881120oib.10.1691185747543; Fri, 04 Aug 2023 14:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691185747; cv=none; d=google.com; s=arc-20160816; b=Ah9ojNCeSN8cQRxBwYf81ULlNaJYPU7ZhHgtKTl6EaKbhXjkbw9AjyIaSPzJDmqlux BBX6CfNAiHUEydeGv105NCnfp3J2CxSb3bZg2jEEbEWNgOfS67U9H7oqIEciNmbHOP6k o+oQmUQHu/9+26KuEvFbObRiZW/o0uSOzgBUIarMstTL7leR4ngMMz1kRJeHVHyQGtHd jOtcSf4L54JK2WIkrko47Gjb31pqU//gm589x3xz4jH9jNO/3VhXUPry6s1AXU6DXF3V i0HKBAuT+hDhaq/ltGwek5go8GfQyhMNSMy6Zu0C/xeITRmIYVum2WthtXmJrw68DbbB SVmw== 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=xG544WZG5oF0OWEMEqpSYe/C5CZ83c297+M1hA4YMMU=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=FEndYkfHFM+EMkqqsT2BbtS0lgQHWE2eCgghEYrID2/zBvyNAogFZJOE6KZEn8JW8v G+19t2EOcaDRTbefLs5K5426G8OEOw7N7eRHOwrcHgYlrIfsPwlRQBUCGDmvIxVgUQsL 6bUctoyhzAoZlVR1Kh7xHJ6MJpQQ3kYMgyuSjfqQ/ytNrIdzwUweqdrTctW0+N874uJQ 6jwIjNlGPEAr5i9zy1T34nPSUUK7Xeev8EM9jTPx9lwb4y8J/oExUKH1/kCIPWXQEwAN Qc4hlPxK63EzbOqhqDom2789Pdn9IW22cTKAW/ytm/moCJ+mf3rrYDKnzOHn0pVNy48u /7YQ== 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 t70-20020a638149000000b00563fe7f89e0si682388pgd.769.2023.08.04.14.48.54; Fri, 04 Aug 2023 14:49:07 -0700 (PDT) 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 S231226AbjHDV0S (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjHDV0K (ORCPT ); Fri, 4 Aug 2023 17:26:10 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 751A2E60; Fri, 4 Aug 2023 14:26:08 -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 3627b7821fbcc242; Fri, 4 Aug 2023 23:26:06 +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 4E705661680; Fri, 4 Aug 2023 23:26:06 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 07/10] ACPI: thermal: Use trip point table to register thermal zones Date: Fri, 04 Aug 2023 23:18:10 +0200 Message-ID: <1987843.usQuhbGJ8B@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771784738121547230 X-GMAIL-MSGID: 1773336786714833429 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 --- 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 | 95 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 8 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -137,6 +137,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 */ @@ -190,6 +191,22 @@ 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_update_trip_temp(struct acpi_thermal *tz, + void *trip_priv, int temp_deci_k) +{ + thermal_zone_update_trip_temp(tz->thermal_zone, trip_priv, + acpi_thermal_temp(tz, temp_deci_k)); +} + static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) { acpi_status status; @@ -403,7 +420,28 @@ static void __acpi_thermal_trips_update( 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); + int i; + + __acpi_thermal_trips_update(tz, data); + + if (tz->trips.passive.valid) + acpi_thermal_update_trip_temp(tz, &tz->trips.passive, + tz->trips.passive.temperature); + else + thermal_zone_update_trip_temp(tz->thermal_zone, + &tz->trips.passive, + THERMAL_TEMP_INVALID); + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (tz->trips.active[i].valid) + acpi_thermal_update_trip_temp(tz, &tz->trips.active[i], + tz->trips.active[i].temperature); + else + thermal_zone_update_trip_temp(tz->thermal_zone, + &tz->trips.active[i], + THERMAL_TEMP_INVALID); + } } static void acpi_queue_thermal_check(struct acpi_thermal *tz) @@ -768,6 +806,7 @@ static void acpi_thermal_zone_sysfs_remo static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { + struct thermal_trip *trip; int passive_delay = 0; int trip_count = 0; int result; @@ -788,12 +827,50 @@ static int acpi_thermal_register_thermal 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; + 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++; + } + + if (tz->trips.passive.valid) { + trip->type = THERMAL_TRIP_PASSIVE; + trip->temperature = acpi_thermal_temp(tz, tz->trips.passive.temperature); + trip->priv = &tz->trips.passive; + trip++; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++) { + trip->type = THERMAL_TRIP_ACTIVE; + trip->temperature = acpi_thermal_temp(tz, tz->trips.active[i].temperature); + trip->priv = &tz->trips.active[i]; + 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) @@ -821,6 +898,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; } @@ -829,6 +908,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 Fri Aug 4 21:22: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: 131370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp117979vqr; Fri, 4 Aug 2023 14:49:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELk4r6Lvj/7tTP089SjsNuoq/pAyJ6lkaxdZsS5heXNEBmosu3XpZ3GrzYSLWBVxI6ifhM X-Received: by 2002:a17:907:2ce9:b0:99b:4956:e4e3 with SMTP id hz9-20020a1709072ce900b0099b4956e4e3mr2336314ejc.8.1691185741959; Fri, 04 Aug 2023 14:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691185741; cv=none; d=google.com; s=arc-20160816; b=pLWEwCaaCclRoe03n7wq66I522X/GZgwr4ReH9H8H0VNlniZbqefbZ2oznzdJNoAK2 GcHViwVbg6ylfKZaOmIJebF2j7b7mcdpx3QFk504DjcgBTH2Bx5xKcnD1JCJwgRL91K2 enAYb0saQegoxgbCSr0xMehWuIIK7zsuGzzkXRthlQ4uBIdiigcJ0/zEceyP3MhzvItd Bh3SJN2VoqZqMyQiuBw2PV3s8i8Isd4jaICquQIkmdO9VTqJddGImO/o9NJVqA1vdy9R mwiknPQJGyQCwwkpUjFWQV3wL8fKZkbL1W05QCWf8HE6uQX7er8+q1nnDKe1yFJb43av u3rQ== 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=zWLlXOvv0e2JWeU2G6g7UpRLP0vkGhLn9IvaF/jIMmo=; fh=jABj5v2rHKw019HO9Ag6891M+lPZ6d+O4eAkd8el8mQ=; b=xXBBK+GfkLbspNApHWYVkOFlDNYqgkfO3WnNXObJ49A2ifaznsI15t+AxtYE1Nmt8F y5epiCBof0vGJIJ0gM7h1zfSh4ARLMyTqL316cYCto9VnFaxY3n3RODFapfQQupslkAb cXLrGRXaNyTosvSeHZsB3iFkjA2IZia0YK+5axKh/n9kWF9gFaEu3EzFHUty8X1gkSqK hlSy9P8F6bfG92kwJ3/vf+WP3IuB1FXDc5cz0r82iF68qi9o7piRDf+DpoUh4s/bQFAB qKKN1NBe7xJf7WFyte3ngz0tbvjUM55ak7b7U+X8Qz5eyyuydB928ke3eyAFFVkS++p4 JAdg== 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 pw28-20020a17090720bc00b0098882d02831si2039377ejb.710.2023.08.04.14.48.38; Fri, 04 Aug 2023 14:49:01 -0700 (PDT) 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 S229916AbjHDV0O (ORCPT + 99 others); Fri, 4 Aug 2023 17:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjHDV0J (ORCPT ); Fri, 4 Aug 2023 17:26:09 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1052E46; Fri, 4 Aug 2023 14:26:07 -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 82f67363ccf29e27; Fri, 4 Aug 2023 23:26:06 +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 8B747661680; Fri, 4 Aug 2023 23:26:05 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Daniel Lezcano Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Subject: [PATCH v4 08/10] ACPI: thermal: Rework thermal_get_trend() Date: Fri, 04 Aug 2023 23:22:57 +0200 Message-ID: <23199624.6Emhk5qWAg@kreacher> In-Reply-To: <4878513.31r3eYUQgx@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <4878513.31r3eYUQgx@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: gggruggvucftvghtrhhoucdtuddrgedviedrkeeggdduheelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771784820687096789 X-GMAIL-MSGID: 1773336780759486560 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 --- 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 @@ -616,46 +616,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; + 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; + + if (tz->trips.passive.valid && !trip_index--) { + t = tz->trips.passive.tc1 * (tz->temperature - + tz->last_temperature) + + tz->trips.passive.tc2 * (tz->temperature - + tz->trips.passive.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.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++) { + if (tz->trips.active[i].valid && !trip_index--) { + int trip_temp; + + trip_temp = acpi_thermal_temp(tz, tz->trips.active[i].temperature); + if (t > trip_temp) { + *trend = THERMAL_TREND_RAISING; + return 0; + } + break; + } + } - return 0; + return -EINVAL; } static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)