From patchwork Tue Jul 25 12: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: 125605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2444858vqg; Tue, 25 Jul 2023 05:52:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEKcG6qNC9GCThEMYOW6fIC8x8VwknAWcm3aaFzAeytz//dMQQ7gD3nrmz1IrbSn30us+CN X-Received: by 2002:a2e:96d1:0:b0:2b5:81bc:43a8 with SMTP id d17-20020a2e96d1000000b002b581bc43a8mr7687966ljj.0.1690289538083; Tue, 25 Jul 2023 05:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690289538; cv=none; d=google.com; s=arc-20160816; b=KT0647t9RWeB+IOj3OMOyJYVDw/YvIPIsZ8Y1QWWDg0BsZ7799ksaD5tZczfsflsHq 3udsGJ3il3HZDOTtfHEm36cPd5pdm+eoFWjTksncR1M6L1xtQ1ch/qICdIeiojEzQ6r2 ZPEyRNPTH0VmWNm2BNKkFhpdwkSfSTTm5fDDVB1hRe8vaTjM9ab9X6OF6ZUmuO+IewRJ OYZQ2QsAd+7JA3QSPz2VzGQDKgyfYwYRZyYW0Gd6E/efjaYdk+8AjTBxHCt2WwkcH3Ux ec7E1qysEn4+/N+SlUqruD4msB7UFoI1JyMy6I4k4+cJXEbGa75GRdz2GTV7JpcP9X1g HdQA== 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=xidGRlxWDNK/99Z3UlBOuNPDIc6EBhW8AS20Dp39fd0=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=dRQpi0ypRw1jsS4Nt462286cdinUWhfMS/15lJuGESuvWdzyyBHhf8jQbY37Fh3noS XSJexo08beJ+1x2qYdhhwSznNw0lSEm3d2PCHME4rzncQ3tgdy2sxC8myeeh1sOXonUl SbftKdFKPl3z/tkl2GYESCYHnaBHfXDV19rB1Jl0Ep73U0nFwPTSN9F+aP0R+T66cSzc E3a7RmyFVJlBVPvxF0wNW0dqXkVl7Hbf1jK5Zt8uQZggm9iPOCHIsuX7A7mfOGKn/8Qa cxL5+08D7kOQR16IAtFMcJvGApVZNqdN6dSDq4xX4J3wQHI1ogQ1Brd+iwyD0m7KD25K rJ4w== 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 r22-20020a17090638d600b00992bd9701f9si8386480ejd.798.2023.07.25.05.51.46; Tue, 25 Jul 2023 05: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 S233412AbjGYMZx (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233524AbjGYMZg (ORCPT ); Tue, 25 Jul 2023 08:25:36 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AC4F172A; Tue, 25 Jul 2023 05:25:34 -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 ba941fb0d1fb1fc1; Tue, 25 Jul 2023 14:25:32 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 51406661B0E; Tue, 25 Jul 2023 14:25:32 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 1/8] thermal: core: Add mechanism for connecting trips with driver data Date: Tue, 25 Jul 2023 14:04:53 +0200 Message-ID: <4501957.LvFx2qVVIh@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh 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,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1771785116040472389 X-GMAIL-MSGID: 1772397042223567616 From: Rafael J. Wysocki Some drivers need to update trip point data (temperature and/or hysteresis) upon notifications from the platform firmware or they may need to reprogram hardware when trip point parameters are changed via sysfs. For those purposes, they need to connect struct thermal_trip to a private data set associated with the trip or the other way around and using a trip point index for that may not always work, because the core may need to reorder the trips during thermal zone registration (in particular, they may need to be sorted). To allow that to be done without using a trip point index, introduce a new field in struct thermal_trip that can be pointed by the driver to its own data structure containing a trip pointer to be initialized by the core during thermal zone registration. That pointer will then have to be updated by the core every time the location of the given trip point object in memory changes. Signed-off-by: Rafael J. Wysocki --- v2 -> v3: No changes. v1 -> v2: No changes. --- drivers/thermal/thermal_core.c | 20 +++++++++++++++++--- include/linux/thermal.h | 13 +++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -76,16 +76,29 @@ struct thermal_zone_device_ops { void (*critical)(struct thermal_zone_device *); }; +struct thermal_trip_ref { + struct thermal_trip *trip; +}; + /** * struct thermal_trip - representation of a point in temperature domain * @temperature: temperature value in miliCelsius * @hysteresis: relative hysteresis in miliCelsius * @type: trip point type + * @driver_ref: driver's reference to this trip point + * + * If @driver_ref is not NULL, the trip pointer in the object pointed to by it + * will be initialized by the core during thermal zone registration and updated + * whenever the location of the given trip object changes. This allows the + * driver to access the trip point data without knowing the relative ordering + * of trips within the trip table used by the core and, given a trip pointer, + * to get back to its private data associated with the given trip. */ struct thermal_trip { int temperature; int hysteresis; enum thermal_trip_type type; + struct thermal_trip_ref *driver_ref; }; 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 @@ -1306,14 +1306,28 @@ thermal_zone_device_register_with_trips( if (result) goto release_device; + mutex_lock(&tz->lock); + for (count = 0; count < num_trips; count++) { - struct thermal_trip trip; + int temperature = 0; + + if (trips) { + temperature = trips[count].temperature; + if (trips[count].driver_ref) + trips[count].driver_ref->trip = &trips[count]; + } else { + struct thermal_trip trip; - result = thermal_zone_get_trip(tz, count, &trip); - if (result || !trip.temperature) + result = __thermal_zone_get_trip(tz, count, &trip); + if (!result) + temperature = trip.temperature; + } + if (!temperature) set_bit(count, &tz->trips_disabled); } + mutex_unlock(&tz->lock); + /* Update 'this' zone's governor information */ mutex_lock(&thermal_governor_lock); From patchwork Tue Jul 25 12: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: 125596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2437915vqg; Tue, 25 Jul 2023 05:38:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+uyp/sB+LKyX2H3Z5Jbw/lMpEHJR41CSXayUOP5ULeVsrqJ9jjM+dBYKFaNFTc9J8JX1G X-Received: by 2002:a17:906:53cd:b0:992:4250:545b with SMTP id p13-20020a17090653cd00b009924250545bmr11798404ejo.47.1690288695987; Tue, 25 Jul 2023 05:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288695; cv=none; d=google.com; s=arc-20160816; b=PL3LhBGK/djqYHM218htXqgKHhu+KMb2yQfeZ4hNIHtT3QddbNEDFB5hNdMSVoX8E1 jkZYPMyqAm/SzkEXsTWDv34YiK7Eqhv2KB0R7F9HGl7tRVNPdUQdib4kVbc3O2V31Wrd 83CyZthBuWUw3dv42HGFi3prYQRbKv49vE9LNMa4oEJYNGx8S/Mx/wXYC6tMlGqQtQgQ b9hwu9tQWFOteYCKObJt6LnPbXMNzhLXHl6Smy/Rxa9yL3GFumEPFeEZXKJIr5DPpRCZ 97yYoroGAbsiK9Ww5Kus+RIbQV3DdhYR+3zc85OMAk6ffdD1eZaV/Y5fEuiqdLVvXvub 77TA== 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=UlzE9h2FJjGQdsrK13CUt8ylwMOnv1m1WHR8T55ZYTc=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=IFFv9UxGLMMO9fDXJJGIIwb1AjCoC8NLNKC0HXDZ/3fecJXejsYRT3AJkFzNQgrZgY O606ZDowL1rO5K0xJ2wRXC4ZsXksj1MEdRt7l7OdX5iXaUGeDT7MzQKx+Uk+R6Zxis82 tMPod3nk8UqvTAByLBZI3IANEDtTHvprkeMPkpP1LfWMMUrlfJlEMRIKK5bW4Hj6LopA XiXnmWzTS/y3REE5roLxddN5xba6W9irXvLyV5zADO7a5V+TNCFEN2zHnha+AAp0ubAf NzWa0TvOczj1VkQVK2cScVL8PfAOcU+aY5wP2dxV/bEs0SzhsvU4QoZUsUHOPsY0Y6R9 HWEw== 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 e12-20020a1709067e0c00b00992acfd27fesi7511861ejr.503.2023.07.25.05.37.51; Tue, 25 Jul 2023 05:38:15 -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 S233740AbjGYMZv (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233506AbjGYMZe (ORCPT ); Tue, 25 Jul 2023 08:25:34 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CB6710FA; Tue, 25 Jul 2023 05:25:33 -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 1d287a6242350abc; Tue, 25 Jul 2023 14:25:32 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 804B1661B0E; Tue, 25 Jul 2023 14:25:31 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 2/8] thermal: core: Do not handle trip points with invalid temperature Date: Tue, 25 Jul 2023 14:06:13 +0200 Message-ID: <4822145.GXAFRqVoOG@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh 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,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772396159803547296 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 --- 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 Tue Jul 25 12:08:02 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: 125595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2434967vqg; Tue, 25 Jul 2023 05:32:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVg4UxSDSL9YJNvnASagGLALoH4rugzLi8teT90rp+Tk2DrjUHj8IpE/es0V6AoBiBsAuS X-Received: by 2002:a17:903:2282:b0:1bb:c69b:6f6b with SMTP id b2-20020a170903228200b001bbc69b6f6bmr197196plh.6.1690288350369; Tue, 25 Jul 2023 05:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288350; cv=none; d=google.com; s=arc-20160816; b=hs61XHE07fg3ubrCXDn5RibkZE8zhfnRdrF4WCXA2nUtNAc1Zg8mHI11hZq241HjQ6 /POU3SB9SQz68RZnO8L0DR2RTKMmEXaeSY738sXpaERPrjaCb9rkYIQyKFSvbZPSnRMz fw7YdVNzq2uyH5EcSUhwbCg5zqwb5IAEwBTKqvDcMjEdYSM1hAnJ3OIYVNBYpCBiGt50 W2kOhiA6h+RvCRpyTIvf21x0kxzaQLZUSxrKPN5tofVUvzZL3DgJTxwC0I+9CYRtB8Ku 2RQ12f1HqkUz1C1fgxLdhoj3Amo6m0udksm2D89zAbnqZtx0wU0QYH/ALEC7DP0cr7ol SuhA== 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=alSq7BdOaSsBYMfAPzfpgZZ7ZOKbiiZNSa0ZsR49irw=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=TZ+h70DiXDx6yaWDw1Wvw6dWONKmuYKQu3e/pZdj471aNAv9pJgMe7T2G6YUwniyAq mRBgtpw+b+kMbidLB8g9bjrm95rnxOoBLGF8bIXCHZJRdUQKeVPBVqJW/iNzVf/cuPV6 LtAO6DYgvPVtlAIFZJi8C54LgalHKote+EFKbHAGpfRGxgA3Zo3hgA0OuaCalmAYUMXH 97LEkjfMSkwIngTc5oIMHSxwjwD8oJbvHnvLLIZZw+fPK9hN+XNlxIlMVR91i2aZ4XKD tMPfH39hRhR2boEwssgCKzZVElDN35XLFanDekjnd8DqW6cmnEks06wOmPWaK17xpLqP QVPQ== 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 d16-20020a170902ced000b001bbbbb61c71si1670428plg.399.2023.07.25.05.32.15; Tue, 25 Jul 2023 05:32:30 -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 S233718AbjGYMZs (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230424AbjGYMZe (ORCPT ); Tue, 25 Jul 2023 08:25:34 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C181E7E; Tue, 25 Jul 2023 05:25:32 -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 a9f50b1ffa9a852c; Tue, 25 Jul 2023 14:25:31 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id BD62E661B0F; Tue, 25 Jul 2023 14:25:30 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 3/8] thermal: core: Add routines for locking and unlocking thermal zones Date: Tue, 25 Jul 2023 14:08:02 +0200 Message-ID: <2154273.irdbgypaU6@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh 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,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772040673538566700 X-GMAIL-MSGID: 1772395797126516167 From: Rafael J. Wysocki Add thermal_zone_device_lock() and thermal_zone_device_unlock() for acquiring and releasing the thermal zone lock, respectively. They will be used by the ACPI thermal driver to protect trip point temperature updates against races with accesses from elsewhere. Signed-off-by: Rafael J. Wysocki --- v2 -> v3: No changes. v1 -> v2: New patch. --- drivers/thermal/thermal_core.c | 13 +++++++++++++ include/linux/thermal.h | 2 ++ 2 files changed, 15 insertions(+) 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 +498,18 @@ void thermal_zone_device_update(struct t } EXPORT_SYMBOL_GPL(thermal_zone_device_update); +void thermal_zone_device_lock(struct thermal_zone_device *tz) +{ + mutex_lock(&tz->lock); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_lock); + +void thermal_zone_device_unlock(struct thermal_zone_device *tz) +{ + mutex_unlock(&tz->lock); +} +EXPORT_SYMBOL_GPL(thermal_zone_device_unlock); + static void thermal_zone_device_check(struct work_struct *work) { struct thermal_zone_device *tz = container_of(work, struct Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -336,6 +336,8 @@ 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_lock(struct thermal_zone_device *tz); +void thermal_zone_device_unlock(struct thermal_zone_device *tz); struct thermal_cooling_device *thermal_cooling_device_register(const char *, void *, const struct thermal_cooling_device_ops *); From patchwork Tue Jul 25 12:09:16 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: 125600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2442373vqg; Tue, 25 Jul 2023 05:47:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlFLiG8Dsawmn8GvtUhlg4mdlgUHD8oKQ3N+HSQGeg0VUKFNvDwMMhlTuDOSXiaDBZ56zslU X-Received: by 2002:a05:6830:19ce:b0:6b9:b985:2892 with SMTP id p14-20020a05683019ce00b006b9b9852892mr10791396otp.17.1690289225690; Tue, 25 Jul 2023 05:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690289225; cv=none; d=google.com; s=arc-20160816; b=VdC5vidWGV+Tn/O/dqs58mEPr1LQZf4plGs/rK8nLrjop8kkFym41OnYv4sxZwgXnh L4l9vJMofbSBck0OCo/ykVYpnnjmxYpGkH1Xn9gz+O9h/4dKC/NF3yQ+WMIsupydSn+M 9vI1DZwG1NgwDuin4o/qoo4iNbEJO4bbf+Yx9VmhwtHvFOSo/eAQQgAKawM+lpwG3XOZ RPq8VizuUqCVUjsguhe48A3ApKzzcPnoSCKgt8K7BqBrDBpoGEgG73ht5RznLQYTgQlG ItqqkYevk1P+k6u176TsVtPIV+2Wgi9sSsXc8890V5llecUlKx9hwRRfg1PprHdefuze fDgw== 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=eH9J+NBTpK7aRsLHJ/qXBl06yQGHUI8Ynru9hlTVoVQ=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=KyaMgtBvpOO6ra9KWJeBkw/pivnE2JcmyyY2gFb+C7c6/6eGIfbH/9nbgAm4E4pQXa AEbwnho/cKhsyQZq3Cfa2o5xszXi0NKE1zkwsO5umFf42yIwQTlBduQPeHTTWU/0Cq7k QmH4KqDxSVaBD3FRI6dBDA2fsE+ASmMT+ygu0u/ftNRb6Xiv/tZinyVyaAM3wZGuhc9u cknaGFWAXgAv373tQx7sBBMkPZppQmCGln3oU7ExAOVOIas5GxpJ8G8NSI98vQiMEKLJ lcCUBeS+oLxBeOfWyYLQq5dXk8y7kJ7KVdp6wch25cBiUTRDAHZO9eQjltv2VQjccaf6 JDaA== 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 t6-20020a63d246000000b0055c9d23b482si10999605pgi.314.2023.07.25.05.46.51; Tue, 25 Jul 2023 05:47:05 -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 S233625AbjGYMZp (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233485AbjGYMZd (ORCPT ); Tue, 25 Jul 2023 08:25:33 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24F46A7; Tue, 25 Jul 2023 05:25:31 -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 7b78a6bf7a2a48f1; Tue, 25 Jul 2023 14:25:30 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 0E3B6661B0F; Tue, 25 Jul 2023 14:25:30 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 4/8] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Date: Tue, 25 Jul 2023 14:09:16 +0200 Message-ID: <2895893.e9J7NaK4W3@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh 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,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772396714688598064 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 --- 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 Tue Jul 25 12:16:33 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: 125594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2434767vqg; Tue, 25 Jul 2023 05:32:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlHztf71mG36+02x38yhg3Uw3VQe77HcOXEo1HnKxnq9WDeZGohMN/ndVPU9NJQb/bsJJXxg X-Received: by 2002:a05:6870:f148:b0:1b7:4870:9075 with SMTP id l8-20020a056870f14800b001b748709075mr14030220oac.6.1690288330525; Tue, 25 Jul 2023 05:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288330; cv=none; d=google.com; s=arc-20160816; b=xmpqoJ1+TEsuN3Go9inVmN6u3SkUpMhXfUdVm+I49zPO2XD+rAwBzGe4+DL5SDT+dH qmOgUoWWmFrYG7EsbveuoFsvYxzQ46zE0pjgwijU0Ls8u/3uOunWhvsaGZqn0PfzaWGB obnGFum8NTreK1SVtm5ZJpeOAyE6sX8z7cSUA52pZ1I9KakXvlre5/Zpu/67Ok65+Tcj dTQmksKo0yGNcGjpO/s7Uy8VaTh7psT409iPDFwWXTEB6Wqove57VW3QBOwNreU/Ghdd XJRKXs1A5ZYYcP7MOBIzd4o7OBxZznKFH+At/KE9OMndSi9WSPu++w9EkbzM/rgYAozq iRfw== 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=GXCL8lMvPjm5oxw9qCQ5PkWHOcol1z4dRjZG6zSxLO8=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=wJr/r25q447xYQNg5JviRgliIw6K0op671aF8TCVKbX9d9vMqaPQc0J0Ku2EQhMmam JB3k2HGiecMLMeED+fb6CQRv2YZGOGoQ47jUDJCY+wlDUxayuN99Sxy/NHzRQKQmKkio 9Noy9xFNZBMimO+FJYWtg97aA//laoj075EX7sujHqUgKMezUIPLtUaZeuvCLjfhSFIJ xvZi/v8WfPfZ81LetEDbBwc6o1DlCuxPfLzFt8lp9H82J0TqMKGcdyBO0Zha5kt9Y/xY NeHCKxXiy7HHX6CRI+QWm5Z21etpoJ03n99pf16yb0VWVdOFVjuknJ08URk4ieKpsY7o hD3g== 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 q68-20020a632a47000000b0055c868268f9si11870793pgq.462.2023.07.25.05.31.49; Tue, 25 Jul 2023 05:32:10 -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 S233559AbjGYMZk (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233410AbjGYMZc (ORCPT ); Tue, 25 Jul 2023 08:25:32 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66976172A; Tue, 25 Jul 2023 05:25:31 -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 3810275855d39208; Tue, 25 Jul 2023 14:25:29 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 5404B661B0E; Tue, 25 Jul 2023 14:25:29 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 5/8] ACPI: thermal: Hold thermal zone lock around trip updates Date: Tue, 25 Jul 2023 14:16:33 +0200 Message-ID: <7552439.EvYhyI6sBW@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh 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,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772044269368069758 X-GMAIL-MSGID: 1772395776492306885 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. To address this, make acpi_thermal_trips_update() hold the thermal zone lock across the entire update of trip points. 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 --- 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 | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 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,28 @@ static int acpi_thermal_trips_update(str ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } +} - return 0; +static void acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +{ + /* + * The locking is needed here to protect thermal_get_trend() from using + * a stale passive trip temperature and to synchronize with the trip + * temperature updates in acpi_thermal_check_fn(). + */ + thermal_zone_device_lock(tz->thermal_zone); + + __acpi_thermal_trips_update(tz, flag); + + thermal_zone_device_unlock(tz->thermal_zone); } 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 | From patchwork Tue Jul 25 12:20: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: 125593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2434629vqg; Tue, 25 Jul 2023 05:31:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlG+YimoXxFHYjtv/b8WSLWb26Zb5k7DkNRvr9FiDPzPmo4+42/rWf/vUBZvu+BROxiv9e8r X-Received: by 2002:a05:6e02:f44:b0:347:fd0d:2ba1 with SMTP id y4-20020a056e020f4400b00347fd0d2ba1mr2464739ilj.28.1690288315747; Tue, 25 Jul 2023 05:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288315; cv=none; d=google.com; s=arc-20160816; b=AKB9KXLIsVtSbEocAT+uca2DukEJiRd5Dr/+JuiEvbFGt7+uZNnvMtcuNyvRl55cZz CN9TVHGDZHctcnOc8qe6HELQnqSqD8jN7xR/QPdw569wbKMrDH3vK/eMnm+BPGUK8Hu2 ew6YA+H3atonldDbDY82SxNviTaC/nDhYmoqc5rf9CR01k0fwHOLZFpZxHD32t2ubBwA m9ojyoNErKOlsdDLlPxywHI7waoe8IIfRwtDwkPCI7foImO+BgoxchZzK+YttR3XnCKZ b+7I6+OU1gdlunTlyMvuuvzE7w3kHae6yklninKhEdwinjmKaeoc57WO1HVDVq0HdLu0 M/rg== 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=Kabmk+TBOC1vDjU990preTTtXo8lI3g7OFV5Bqijx+c=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=MZ2tUudA4MMCrfy3EsSgVH11/0K2W9YmgPohH9YjHrUMUk35r1AXpQ1D9us1/fZ5uB 2cWzgXu0fk8PruC9eibkPmD3y7/kKEvRz/ThiibIpcnVLcXmt6rJFBff3e5+DTCyKD79 NQq+jt9l24uLdzB+bdQFWqtf91mBZogvlZwb4CCbmiL1QQFe6qnt/evn1v+RmA8tew9t s9GbcwkqGaMJfCu46eDdKhfeIwbGruuWtBERYPTl6jVdS3VY0cXtHZ9bTZ7iI4yHrMbT fweAsfQKP3iBh8VnqycOCicuCSTJ+18evLBb1Pfhy19deVPgyMIyzKi68yapdDA+giCx Xrew== 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 s1-20020a63dc01000000b0053490e8df50si11643257pgg.223.2023.07.25.05.31.41; Tue, 25 Jul 2023 05:31:55 -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 S233562AbjGYMZm (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233418AbjGYMZc (ORCPT ); Tue, 25 Jul 2023 08:25:32 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A889D1718; Tue, 25 Jul 2023 05:25:30 -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 b8c0db411b4055ad; Tue, 25 Jul 2023 14:25:29 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 1D6AF661B0E; Tue, 25 Jul 2023 14:25:28 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 6/8] ACPI: thermal: Use trip point table to register thermal zones Date: Tue, 25 Jul 2023 14:20:57 +0200 Message-ID: <3177785.5fSG56mABF@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=14 Fuz1=14 Fuz2=14 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772395761052369885 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 and pass it to thermal_zone_device_register_with_trips() as an argument and use the struct thermal_trip_ref introduced previously to connect the generic thermal trip structures to the internal data structures representing trip points in the driver. Signed-off-by: Rafael J. Wysocki --- 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 | 106 ++++++++++++++++++++++++++++++++++++++--- drivers/thermal/thermal_core.c | 1 include/linux/thermal.h | 2 3 files changed, 102 insertions(+), 7 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -107,6 +107,7 @@ struct acpi_thermal_hot { }; struct acpi_thermal_passive { + struct thermal_trip_ref trip_ref; struct acpi_handle_list devices; unsigned long temperature; unsigned long tc1; @@ -116,6 +117,7 @@ struct acpi_thermal_passive { }; struct acpi_thermal_active { + struct thermal_trip_ref trip_ref; struct acpi_handle_list devices; unsigned long temperature; bool valid; @@ -137,6 +139,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 +193,14 @@ static int acpi_thermal_get_polling_freq return 0; } +static void acpi_thermal_trip_update_temp(struct acpi_thermal *tz, + struct thermal_trip *trip, + long temperature) +{ + trip->temperature = deci_kelvin_to_millicelsius_with_offset(temperature, + tz->kelvin_offset); +} + static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) { acpi_status status; @@ -756,6 +767,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; @@ -776,12 +788,54 @@ 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; + acpi_thermal_trip_update_temp(tz, trip, + tz->trips.critical.temperature); + trip++; + } + + if (tz->trips.hot.valid) { + trip->type = THERMAL_TRIP_HOT; + acpi_thermal_trip_update_temp(tz, trip, + tz->trips.hot.temperature); + trip++; + } + + if (tz->trips.passive.valid) { + trip->type = THERMAL_TRIP_PASSIVE; + acpi_thermal_trip_update_temp(tz, trip, + tz->trips.passive.temperature); + trip->driver_ref = &tz->trips.passive.trip_ref; + trip++; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++) { + trip->type = THERMAL_TRIP_ACTIVE; + acpi_thermal_trip_update_temp(tz, trip, + tz->trips.active[i].temperature); + trip->driver_ref = &tz->trips.active[i].trip_ref; + 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) @@ -809,6 +863,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; } @@ -817,6 +873,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); } @@ -950,6 +1007,9 @@ static void acpi_thermal_check_fn(struct { struct acpi_thermal *tz = container_of(work, struct acpi_thermal, thermal_check_work); + struct thermal_trip *trip; + long temperature; + int i; /* * In general, it is not sufficient to check the pending bit, because @@ -964,7 +1024,39 @@ static void acpi_thermal_check_fn(struct mutex_lock(&tz->thermal_check_lock); - thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED); + thermal_zone_device_lock(tz->thermal_zone); + + trip = tz->trips.passive.trip_ref.trip; + if (trip) { + /* + * This means that the passive trip was valid initially, so + * update its temperature in case it has changed or the trip + * has become invalid. + */ + temperature = tz->trips.passive.valid ? + tz->trips.passive.temperature : + THERMAL_TEMP_INVALID; + acpi_thermal_trip_update_temp(tz, trip, temperature); + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + trip = tz->trips.active[i].trip_ref.trip; + if (trip) { + /* + * This means that the active trip #i was valid + * initially, so update its temperature in case it has + * changed or the trip has become invalid. + */ + temperature = tz->trips.active[i].valid ? + tz->trips.active[i].temperature : + THERMAL_TEMP_INVALID; + acpi_thermal_trip_update_temp(tz, trip, temperature); + } + } + + __thermal_zone_device_update(tz->thermal_zone, THERMAL_EVENT_UNSPECIFIED); + + thermal_zone_device_unlock(tz->thermal_zone); refcount_inc(&tz->thermal_check_count); Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -429,6 +429,7 @@ void __thermal_zone_device_update(struct monitor_thermal_zone(tz); } +EXPORT_SYMBOL_GPL(__thermal_zone_device_update); static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, enum thermal_device_mode mode) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -334,6 +334,8 @@ int thermal_zone_bind_cooling_device(str unsigned int); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); +void __thermal_zone_device_update(struct thermal_zone_device *, + enum thermal_notify_event); void thermal_zone_device_update(struct thermal_zone_device *, enum thermal_notify_event); void thermal_zone_device_lock(struct thermal_zone_device *tz); From patchwork Tue Jul 25 12:22:54 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: 125592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2434457vqg; Tue, 25 Jul 2023 05:31:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlHzq+qAMi25zkf3eja2nEwLcB1YEIi2ew6wx3B2fCxn/czOXN7jB0yQ28tYm6WG+IGe0Oxg X-Received: by 2002:a05:6358:e486:b0:135:9281:3542 with SMTP id by6-20020a056358e48600b0013592813542mr6257265rwb.9.1690288301629; Tue, 25 Jul 2023 05:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288301; cv=none; d=google.com; s=arc-20160816; b=xLRg47trSk+3jeJjI+CSIiR6s0yWWIf8Lp33qhZKSl/s5lu0ej4la66MA2srPdIg2Z +Hybg6gPukLR9PAI6gxRrWEG3vZU/7sEHoY6larl+nstwUKtnlp7zm71BCd1io2jleKY YQX4gtORhmTV2TMjfSGsf9psVympv2zWzeMhxymZYR/lfGx2eRKZM0eHcCDdD1QVm9vS 0wt8v9QbkibqByjYlGS6AruIRvuPiV2BoH1strRdHL5Yoqz9oohkkjfxd3EAij03gzje KGatAhXFM1OraTWNPT3WU8nVBwCwnYn6P7EcW7rQq1SmvcTu4A5DSbH+0nfUkbEG+DXD nbOQ== 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=MJxDszMU+45M5U0iCTxhTMfQBE7Z1X/gdf4MOyapmvo=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=JxaRl8LOXU9FIhYXv//SOQTjChxDwNr0ZwUF6qUFg/LCQjQWyhPxL64zgRVKWg4CzP LEXYHtNxj+o6l+OE3mmEBSNcZgSr45ZqCLjEKTCjwZ3ld9Oo9gcmYSb0MuHfcWXZzW8o vqkW/jF2ZlwWa4fAy47XXlI0PbC8EXmC7GLVEDG13mCIwo6DX3QAvmUDtsK6Hbqydvoe jMGUuD75Dut1TPKd3sYZq++8KNGEz4IP6NFji4pVGfTvmnwUR2LOwxofuZJPEjjLIdLz fiP8Ped8VurDxA443f4Kc6yKr9fdc+klyBwIThdnKKxqE5/29zfv3px5KOSzX9/OEv2p rI8A== 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 18-20020a630112000000b005638262c542si9798781pgb.840.2023.07.25.05.31.28; Tue, 25 Jul 2023 05:31: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 S232050AbjGYMZf (ORCPT + 99 others); Tue, 25 Jul 2023 08:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231584AbjGYMZc (ORCPT ); Tue, 25 Jul 2023 08:25:32 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9220AE7E; Tue, 25 Jul 2023 05:25:29 -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 00bb790ef557508e; Tue, 25 Jul 2023 14:25:27 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 646D9661B0E; Tue, 25 Jul 2023 14:25:27 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v3 7/8] ACPI: thermal: Rework thermal_get_trend() Date: Tue, 25 Jul 2023 14:22:54 +0200 Message-ID: <1769066.VLH7GnMWUR@kreacher> In-Reply-To: <12254967.O9o76ZdvQC@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@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: gggruggvucftvghtrhhoucdtuddrgedviedriedtgdehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh 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,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1772395746385137103 From: Rafael J. Wysocki Rework the ACPI thermal driver's .get_trend() callback function, thermal_get_trend(), to use trip point data stored in the generic trip structures instead of calling thermal_get_trip_type() and thermal_get_trip_temp() and make it hold thermal_check_lock to protect against possible races with trip point updates. Signed-off-by: Rafael J. Wysocki --- 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 | 98 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 28 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -577,47 +577,89 @@ static int thermal_get_crit_temp(struct return -EINVAL; } -static int thermal_get_trend(struct thermal_zone_device *thermal, - int trip, enum thermal_trend *trend) +static struct thermal_trip *get_thermal_trip(struct acpi_thermal *tz, int trip_index) { - struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - enum thermal_trip_type type; + struct thermal_trip *trip; int i; - if (thermal_get_trip_type(thermal, trip, &type)) - return -EINVAL; + if (!tz || trip_index < 0) + return NULL; - 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) { - *trend = THERMAL_TREND_RAISING; - return 0; - } else { - /* Fall back on default trend */ - return -EINVAL; + if (tz->trips.hot.valid) + trip_index--; + + if (trip_index < 0) + return NULL; + + trip = tz->trips.passive.trip_ref.trip; + if (trip) { + if (!trip_index) + return trip; + + trip_index--; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + trip = tz->trips.active[i].trip_ref.trip; + if (trip) { + if (!trip_index) + return trip; + + trip_index--; } } + return NULL; +} + +static int thermal_get_trend(struct thermal_zone_device *thermal, + int trip_index, enum thermal_trend *trend) +{ + struct acpi_thermal *tz = thermal_zone_device_priv(thermal); + struct thermal_trip *trip; + long t; + + trip = get_thermal_trip(tz, trip_index); + if (!trip || trip->temperature == THERMAL_TEMP_INVALID) + return -EINVAL; + /* * tz->temperature has already been updated by generic thermal layer, - * before this callback being invoked + * 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); + switch (trip->type) { + case THERMAL_TRIP_PASSIVE: + 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; + else if (t < 0) + *trend = THERMAL_TREND_DROPPING; + else + *trend = THERMAL_TREND_STABLE; + + return 0; + + case THERMAL_TRIP_ACTIVE: + t = deci_kelvin_to_millicelsius_with_offset(tz->temperature, + tz->kelvin_offset); + if (t > trip->temperature) { + *trend = THERMAL_TREND_RAISING; + return 0; + } - if (i > 0) - *trend = THERMAL_TREND_RAISING; - else if (i < 0) - *trend = THERMAL_TREND_DROPPING; - else - *trend = THERMAL_TREND_STABLE; + fallthrough; - return 0; + default: + break; + } + + return -EINVAL; } static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)