From patchwork Thu Sep 21 17:48: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: 142965 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5183787vqi; Thu, 21 Sep 2023 15:40:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHE+/mi7JDOb/+TeOv+q3x+vUWlImat0nPWHVOM53de8nRiDinvjgb5KkR9gV5T0Rj6AwJ X-Received: by 2002:a05:6870:be9a:b0:1dc:7e71:d475 with SMTP id nx26-20020a056870be9a00b001dc7e71d475mr2717390oab.4.1695336020602; Thu, 21 Sep 2023 15:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336020; cv=none; d=google.com; s=arc-20160816; b=KjxGXO//keeWyMECPTnjT79buChg4Iu1n9WeKQabfBmYkUrTLm+L9PJpo6Ti6i2q8z V6RNIqsMAHQHuuZKHCwADQtiA6gY311I8ehWO8ycB07Cl4Roy+wBNx8p1xkr+NP+oHoh SQUXDEU27Bd65exFrtPty/elf1oAeHaQfB32AXsvVgQBAZ+P7h987jMmDaSVKG+aju15 3sL8Wp3iOAibbSZEftEtGLERscuXSG8N0rRNDMUQ+xYSTpMRZ4+vmfuHNr4vCBfGYSoc ZKOt6QslPUzu+mf3Dio8Su2xRZUUeYVDyRo3Tob0lblyaE7Sk+3K/75Y+XR1gSeV3pDQ VEGA== 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=NBpF/GQSltjPmoIrlzu3PfGAjeDVmtr35+hezRYHKvU=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=D0GTDf9Jf5HrDiUfN1oPGBeJ0bKBW74QLTuLE3VzgAsK0ZPgLRqvoKUjhtGLOC7kAB cWGVGAKPgKA4bN4m03IEp2yHx8Phgx9nfj/jAvWDj4U6M6Gs8Lc/HHXiL5WvE/bvl2an A6P4wY+vpe0q6QpWNbNZDa0sYThh0yqR4tuxLJy+qzoyOLT8udvqr+jYGC1r4XfMiWfG 3hLY6uyNZbTEYGX6NkpY4niZ4Uglx6ckZuK/HZK2yMQDxbuocxr3wZfLnEbWzpeqGL34 Z5chLeetgoOHNkP4RejGmJeVu1BKEDff/1DaxJSLJ6JXUJt8E2aX9Iqs23CWKtLjFFwu qvPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id l9-20020a654c49000000b00553800fe4dcsi2453667pgr.583.2023.09.21.15.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 18BD78373A03; Thu, 21 Sep 2023 13:58:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbjIUU6I (ORCPT + 29 others); Thu, 21 Sep 2023 16:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbjIUU5v (ORCPT ); Thu, 21 Sep 2023 16:57:51 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46816AF962; Thu, 21 Sep 2023 11:07: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 107c9b7d8d95f1f5; Thu, 21 Sep 2023 20:07: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 40739664EBE; Thu, 21 Sep 2023 20:07:32 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 01/13] ACPI: thermal: Add device list to struct acpi_thermal_trip Date: Thu, 21 Sep 2023 19:48:33 +0200 Message-ID: <7586104.EvYhyI6sBW@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:58:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777688663331723538 X-GMAIL-MSGID: 1777688663331723538 From: Rafael J. Wysocki The device lists present in struct acpi_thermal_passive and struct acpi_thermal_active can be located in struct acpi_thermal_trip which then will allow the same code to be used for handling both the passive and active trip points, so make that change. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -81,11 +81,11 @@ static struct workqueue_struct *acpi_the struct acpi_thermal_trip { unsigned long temperature; + struct acpi_handle_list devices; }; struct acpi_thermal_passive { struct acpi_thermal_trip trip; - struct acpi_handle_list devices; unsigned long tc1; unsigned long tc2; unsigned long tsp; @@ -93,7 +93,6 @@ struct acpi_thermal_passive { struct acpi_thermal_active { struct acpi_thermal_trip trip; - struct acpi_handle_list devices; }; struct acpi_thermal_trips { @@ -205,6 +204,7 @@ static void acpi_thermal_update_passive_ static bool update_passive_devices(struct acpi_thermal *tz, bool compare) { + struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; struct acpi_handle_list devices; acpi_status status; @@ -217,10 +217,10 @@ static bool update_passive_devices(struc return false; } - if (compare && memcmp(&tz->trips.passive.devices, &devices, sizeof(devices))) + if (compare && memcmp(&acpi_trip->devices, &devices, sizeof(devices))) ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device"); - memcpy(&tz->trips.passive.devices, &devices, sizeof(devices)); + memcpy(&acpi_trip->devices, &devices, sizeof(devices)); return true; } @@ -276,6 +276,7 @@ static void acpi_thermal_update_active_t static bool update_active_devices(struct acpi_thermal *tz, int index, bool compare) { char method[] = { '_', 'A', 'L', '0' + index, '\0' }; + struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; struct acpi_handle_list devices; acpi_status status; @@ -289,10 +290,10 @@ static bool update_active_devices(struct return false; } - if (compare && memcmp(&tz->trips.active[index].devices, &devices, sizeof(devices))) + if (compare && memcmp(&acpi_trip->devices, &devices, sizeof(devices))) ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device"); - memcpy(&tz->trips.active[index].devices, &devices, sizeof(devices)); + memcpy(&acpi_trip->devices, &devices, sizeof(devices)); return true; } @@ -602,6 +603,7 @@ static int acpi_thermal_cooling_device_c { struct acpi_device *device = cdev->devdata; struct acpi_thermal *tz = thermal_zone_device_priv(thermal); + struct acpi_thermal_trip *acpi_trip; struct acpi_device *dev; acpi_handle handle; int i; @@ -615,10 +617,11 @@ static int acpi_thermal_cooling_device_c if (tz->trips.hot_valid) trip++; - if (acpi_thermal_trip_valid(&tz->trips.passive.trip)) { + acpi_trip = &tz->trips.passive.trip; + if (acpi_thermal_trip_valid(acpi_trip)) { trip++; - for (i = 0; i < tz->trips.passive.devices.count; i++) { - handle = tz->trips.passive.devices.handles[i]; + for (i = 0; i < acpi_trip->devices.count; i++) { + handle = acpi_trip->devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -640,12 +643,13 @@ static int acpi_thermal_cooling_device_c } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!acpi_thermal_trip_valid(&tz->trips.active[i].trip)) + acpi_trip = &tz->trips.active[i].trip; + if (!acpi_thermal_trip_valid(acpi_trip)) break; trip++; - for (j = 0; j < tz->trips.active[i].devices.count; j++) { - handle = tz->trips.active[i].devices.handles[j]; + for (j = 0; j < acpi_trip->devices.count; j++) { + handle = acpi_trip->devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -1035,11 +1039,13 @@ static int acpi_thermal_resume(struct de return -EINVAL; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!acpi_thermal_trip_valid(&tz->trips.active[i].trip)) + struct acpi_thermal_trip *acpi_trip = &tz->trips.active[i].trip; + + if (!acpi_thermal_trip_valid(acpi_trip)) break; - for (j = 0; j < tz->trips.active[i].devices.count; j++) { - acpi_bus_update_power(tz->trips.active[i].devices.handles[j], + for (j = 0; j < acpi_trip->devices.count; j++) { + acpi_bus_update_power(acpi_trip->devices.handles[j], &power_state); } } From patchwork Thu Sep 21 17:49:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 142911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5139638vqi; Thu, 21 Sep 2023 14:07:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4BrqS9LbtJIOd180tIfRBBMp9LivuejsrXP3CzZGOQlivhJxgBwbz4djkwfKHDKUtON0P X-Received: by 2002:a05:6870:891a:b0:1d6:53e6:7c8a with SMTP id i26-20020a056870891a00b001d653e67c8amr7838511oao.14.1695330476735; Thu, 21 Sep 2023 14:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695330476; cv=none; d=google.com; s=arc-20160816; b=q4jCJJvZ80euIub9DQLPGQBn5IyCoVESVO3AMrb+mloowpGdDIYFPtYBMoZaIOay2b i4KxK91Vyu3AzbIsedR0dGDt7Y9pOKdMBi9v6TboA7ergEKFC04YlZtnPPTfY4zHmj6E 3J2brIdLkCNRQ4nReCgHm9tGRmkGGUyR9txc3TYjKYi40zxlbh2c7ZDBxRClscipiHU6 g4/cdUDKG8y1csXScfj+m+C+sN/DHLVv7nU65nN0FIYMlKOnrE303HYrEQJ2z+1mpu/b wpUhryYqaEBWU8BCVn3XkoHg1npHCVPQMctocpbDbwpCJtyZL6ryuWMp3QUzbfeq8U/D chYg== 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=wSDttAIQgobA5UE3gRXZydfsV8LyXUxFCofSqtQ2HhI=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=dEwGObhGwjR8bImCkfRaHGq4TN0RiPB+650Z1Vpgort9z6k1vrei2hxEhAbh9XY5Jz QpfhxCzIs6eVGhYiLB+cZZF3eg7WgkhPhXfsxfqkL0YLrwgqwQQBAgGIKBC6eZ8+TdHG oA4eTsobLc7xrQiGzAyzxaSWXkWR1B+LHJMSXIF3uJAS9gxpGezZoPjJa7KuOCElfpWp bmwIXqJPCr9je17X+TE8HJD++XLvabZjlx22krtSxzm+PJVxIQCPwWd4A47DioZouglb r6t13RY+jqZmP1M0fZQNBFQ9LOHNy3fIwSoLsywDxAOeEVFQltMHHEg5kIF7A/TU+bPP fVIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p20-20020a639514000000b0057745b2d018si2181168pgd.390.2023.09.21.14.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:07:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C427E82CD6DB; Thu, 21 Sep 2023 13:58:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232272AbjIUU5h (ORCPT + 29 others); Thu, 21 Sep 2023 16:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232259AbjIUU5W (ORCPT ); Thu, 21 Sep 2023 16:57:22 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ADACAF95D; Thu, 21 Sep 2023 11:07: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 120831ec96c186fd; Thu, 21 Sep 2023 20:07: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 3665E664EBE; Thu, 21 Sep 2023 20:07:31 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 02/13] ACPI: thermal: Collapse trip devices update functions Date: Thu, 21 Sep 2023 19:49:24 +0200 Message-ID: <3534976.iIbC2pHGDl@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:58:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777682849928446187 X-GMAIL-MSGID: 1777682849928446187 From: Rafael J. Wysocki In order to reduce code duplication, merge update_passive_devices() and update_active_devices() into one function called update_trip_devices() that will be used for updating both the passive and active trip points. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 53 ++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -43,6 +43,8 @@ #define ACPI_THERMAL_MAX_ACTIVE 10 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 +#define ACPI_THERMAL_TRIP_PASSIVE (-1) + /* * This exception is thrown out in two cases: * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid @@ -202,18 +204,25 @@ static void acpi_thermal_update_passive_ ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } -static bool update_passive_devices(struct acpi_thermal *tz, bool compare) +static bool update_trip_devices(struct acpi_thermal *tz, + struct acpi_thermal_trip *acpi_trip, + int index, bool compare) { - struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; struct acpi_handle_list devices; + char method[] = "_PSL"; acpi_status status; + if (index != ACPI_THERMAL_TRIP_PASSIVE) { + method[1] = 'A'; + method[2] = 'L'; + method[3] = '0' + index; + } + memset(&devices, 0, sizeof(devices)); - status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); + status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices); if (ACPI_FAILURE(status)) { - acpi_handle_info(tz->device->handle, - "Missing device list for passive threshold\n"); + acpi_handle_info(tz->device->handle, "%s evaluation failure\n", method); return false; } @@ -231,8 +240,9 @@ static void acpi_thermal_update_passive_ if (!acpi_thermal_trip_valid(acpi_trip)) return; - if (update_passive_devices(tz, true)) + if (update_trip_devices(tz, acpi_trip, ACPI_THERMAL_TRIP_PASSIVE, true)) { return; + } acpi_trip->temperature = THERMAL_TEMP_INVALID; ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); @@ -273,30 +283,6 @@ static void acpi_thermal_update_active_t ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } -static bool update_active_devices(struct acpi_thermal *tz, int index, bool compare) -{ - char method[] = { '_', 'A', 'L', '0' + index, '\0' }; - struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; - struct acpi_handle_list devices; - acpi_status status; - - memset(&devices, 0, sizeof(devices)); - - status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices); - if (ACPI_FAILURE(status)) { - acpi_handle_info(tz->device->handle, - "Missing device list for active threshold %d\n", - index); - return false; - } - - if (compare && memcmp(&acpi_trip->devices, &devices, sizeof(devices))) - ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device"); - - memcpy(&acpi_trip->devices, &devices, sizeof(devices)); - return true; -} - static void acpi_thermal_update_active_devices(struct acpi_thermal *tz, int index) { struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; @@ -304,7 +290,7 @@ static void acpi_thermal_update_active_d if (!acpi_thermal_trip_valid(acpi_trip)) return; - if (update_active_devices(tz, index, true)) + if (update_trip_devices(tz, acpi_trip, index, true)) return; acpi_trip->temperature = THERMAL_TEMP_INVALID; @@ -460,7 +446,8 @@ static bool acpi_thermal_init_passive_tr tz->trips.passive.tsp = tmp; - if (!update_passive_devices(tz, false)) + if (!update_trip_devices(tz, &tz->trips.passive.trip, + ACPI_THERMAL_TRIP_PASSIVE, false)) goto fail; tz->trips.passive.trip.temperature = temp; @@ -482,7 +469,7 @@ static bool acpi_thermal_init_active_tri if (temp == THERMAL_TEMP_INVALID) goto fail; - if (!update_active_devices(tz, index, false)) + if (!update_trip_devices(tz, &tz->trips.active[index].trip, index, false)) goto fail; tz->trips.active[index].trip.temperature = temp; From patchwork Thu Sep 21 17:50: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: 142968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5186323vqi; Thu, 21 Sep 2023 15:46:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHILOi/f7UvCBVUdIzCZMZMV0l9Ky+oJvlYdgZj2U4QEtMn9sRBILNhssxEq52ZKxByhABs X-Received: by 2002:a17:902:ea0f:b0:1bf:557c:5a2c with SMTP id s15-20020a170902ea0f00b001bf557c5a2cmr7464358plg.44.1695336368792; Thu, 21 Sep 2023 15:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695336368; cv=none; d=google.com; s=arc-20160816; b=AlT6RzRMSLoS8Ad1GGqncx4aI4deQRcZrGIijWIcrW1fBM32Gv8S4vH3SI7lLqJg0P e+mYnVFOwscSOU8ASHOvZi3IqkPrMJxnuj/+17h1XekKYDoPfWv9DbboR9BBN8N+fJzU Rw1EmGZQhe71E3/hTtQK0sMds+SsVjij+J2fOkdk/xKkP+nlzt4qDx4MzfLr5JVkG34h YjW77TJk/MgBzzfvAmjWIRRNTQQK3NepmNM0Gwl2KceBcDzfJG1B/Hn3DdtSkPijhHSO ZTIbLNOvEDgOT3tG4KmH7nf80y2J0niDoTgqjdm9MPWdPfabYXYsJR192E7h6yXWdYO4 wc5A== 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=P6HOP+eKk467rzNGwCQzpmBpBX5+/nitfU4sBMqppnM=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=zWHPGvZb9zAdtYdFCJ2nSc3G3vr7L/IPOpexx9trimyARZJbmdawEyvuezTT1Bi14s MglB3qSl737M4+g8XHqCEiwUvTqrxxZ1Utgk4STyuSDln+PQ2pIXnfSiztJPqy5lstSV r8VZYmXWUw0y5HoyHzeS3gk4n3yTlDhfsI/sRDVkYpVTfc529bkJFOPECwSTRkhMsjVA TGTkbpXTmFWGsdSpYR2P4fWif90WdsVpmixx4kYbiQ0oW170g8Oaoub+N1DCl3ACtCQZ nhvi8MChP+rFxMWj8y441gDc6Y6nJvSq+cCqaWpq5fGZGxmI1GcwZ40PJhC60NcpZYH+ 459w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id u16-20020a170903125000b001bda57935fasi2534098plh.64.2023.09.21.15.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:46:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 44A638086835; Thu, 21 Sep 2023 14:00:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbjIUVAQ (ORCPT + 29 others); Thu, 21 Sep 2023 17:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232439AbjIUU7o (ORCPT ); Thu, 21 Sep 2023 16:59:44 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72A72AF957; Thu, 21 Sep 2023 11:07: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 bfbd3e583f736223; Thu, 21 Sep 2023 20:07: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 2DCAD664EBE; Thu, 21 Sep 2023 20:07:30 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 03/13] ACPI: thermal: Collapse trip devices update function wrappers Date: Thu, 21 Sep 2023 19:50:08 +0200 Message-ID: <3198428.5fSG56mABF@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:00:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777689028175857442 X-GMAIL-MSGID: 1777689028175857442 From: Rafael J. Wysocki In order to reduce code duplicationeve further, merge acpi_thermal_update_passive/active_devices() into one function called acpi_thermal_update_trip_devices() that will be used for updating both the passive and active trip points. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -233,14 +233,16 @@ static bool update_trip_devices(struct a return true; } -static void acpi_thermal_update_passive_devices(struct acpi_thermal *tz) +static void acpi_thermal_update_trip_devices(struct acpi_thermal *tz, int index) { - struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; + struct acpi_thermal_trip *acpi_trip; + acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ? + &tz->trips.passive.trip : &tz->trips.active[index].trip; if (!acpi_thermal_trip_valid(acpi_trip)) return; - if (update_trip_devices(tz, acpi_trip, ACPI_THERMAL_TRIP_PASSIVE, true)) { + if (update_trip_devices(tz, acpi_trip, index, true)) { return; } @@ -283,20 +285,6 @@ static void acpi_thermal_update_active_t ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } -static void acpi_thermal_update_active_devices(struct acpi_thermal *tz, int index) -{ - struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; - - if (!acpi_thermal_trip_valid(acpi_trip)) - return; - - if (update_trip_devices(tz, acpi_trip, index, true)) - return; - - acpi_trip->temperature = THERMAL_TEMP_INVALID; - ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); -} - static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data) { struct acpi_thermal_trip *acpi_trip = trip->priv; @@ -324,9 +312,9 @@ static void acpi_thermal_adjust_thermal_ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) acpi_thermal_update_active_trip(tz, i); } else { - acpi_thermal_update_passive_devices(tz); + acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE); for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - acpi_thermal_update_active_devices(tz, i); + acpi_thermal_update_trip_devices(tz, i); } for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz); From patchwork Thu Sep 21 17:51:19 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: 142896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5129428vqi; Thu, 21 Sep 2023 13:48:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjQXNL7cfko1VtUva9ZLK9NNOGPYvYAffZl1M1Mm30MElZb7+8sB53ZmETCa2S68jZcKBm X-Received: by 2002:a05:6a20:4303:b0:15c:8555:a21c with SMTP id h3-20020a056a20430300b0015c8555a21cmr1113394pzk.8.1695329304155; Thu, 21 Sep 2023 13:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695329304; cv=none; d=google.com; s=arc-20160816; b=IIUXmeEDPn2HHAYp4uOVfxMfyfRVJmAf6XmuiuNKApbprEYhjAUYxYdCrwOIGgLXOx 8K+ZvU2feQQLK4Sutv5h3kE/yGpAEioYsus9Ou09JlsjwOqjZvvm5AALCCTn5wFpEdXr wHYc5dPBO2NSJ5cPO5n1Gbqw5NBg5ODh4qv1Wt0RcBlMgOish4GskQqTiAf7ziPaKZhp ppgg/2kZcMnqFEpxl1kgFZbSuFKuPTA3XL+ye46ty6A8RJlq6hC3rTWVVevk92fQ9PRD H+W0LJhQ3KBDzty64bJzaEoxxNawPDndiV5mCcIMFStXFEWtw7DGaxTJhUM1LSyCHrNN oWvg== 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=N7bh3QqM+2DuacGqAGtAqnACiKdpmKXRDKshPAJWMHI=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=JAGc1Jlz4oMWF8RBGI/57kOxazM6wh0vrXerkMR1taUclFYO8IVe43/rIEVafTYzP4 9e8gnC+d9Slrbbri5i3UZjap01jBNCbrz99nHrW7v6MQ1zmK1x6j9hWOxEq4xOP5LHKm EwcIw87DuJtUcwdiFiNLSdJOgm4jJr/RzE4Y4/GCwPFgMVPySnFSvB5Bdib2pUz1hSju +APuhgtCXB9zmwdb4IxLcs3G2ukUgTvk5NZb7NZ32mZDayZztg+UeRBHHo+OsBMdn6mx zhojB67rK4+gS3GijnPgFYjEttncAdwteEiE/ixv7LpeSjrI3jFkjr1g9qyY8IqZX6tS 3D+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id h2-20020a631202000000b0056546b5fef5si2050433pgl.561.2023.09.21.13.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2ABE781CA3C8; Thu, 21 Sep 2023 13:32:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbjIUUcW (ORCPT + 29 others); Thu, 21 Sep 2023 16:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbjIUUcA (ORCPT ); Thu, 21 Sep 2023 16:32:00 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DCA1AF94C; Thu, 21 Sep 2023 11:07: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 c8dfa8de6a80f189; Thu, 21 Sep 2023 20:07: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 1A650664EBE; Thu, 21 Sep 2023 20:07:28 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 04/13] ACPI: thermal: Merge trip initialization functions Date: Thu, 21 Sep 2023 19:51:19 +0200 Message-ID: <1785516.VLH7GnMWUR@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:32:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777681620534294103 X-GMAIL-MSGID: 1777681620534294103 From: Rafael J. Wysocki In order to reduce code duplicationeve further, merge acpi_thermal_init_passive/active_trip() into one function called acpi_thermal_init_trip() that will be used for initializing both the passive and active trip points. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 64 ++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -399,72 +399,68 @@ static long acpi_thermal_get_hot_trip(st return tmp; } -static bool acpi_thermal_init_passive_trip(struct acpi_thermal *tz) +static bool passive_trip_params_init(struct acpi_thermal *tz) { unsigned long long tmp; acpi_status status; - int temp; - - if (psv == -1) - goto fail; - - if (psv > 0) { - temp = celsius_to_deci_kelvin(psv); - } else { - temp = get_passive_temp(tz); - if (temp == THERMAL_TEMP_INVALID) - goto fail; - } status = acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - goto fail; + return false; tz->trips.passive.tc1 = tmp; status = acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - goto fail; + return false; tz->trips.passive.tc2 = tmp; status = acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - goto fail; + return false; tz->trips.passive.tsp = tmp; - if (!update_trip_devices(tz, &tz->trips.passive.trip, - ACPI_THERMAL_TRIP_PASSIVE, false)) - goto fail; - - tz->trips.passive.trip.temperature = temp; return true; - -fail: - tz->trips.passive.trip.temperature = THERMAL_TEMP_INVALID; - return false; } -static bool acpi_thermal_init_active_trip(struct acpi_thermal *tz, int index) +static bool acpi_thermal_init_trip(struct acpi_thermal *tz, int index) { + struct acpi_thermal_trip *acpi_trip; long temp; - if (act == -1) - goto fail; + if (index == ACPI_THERMAL_TRIP_PASSIVE) { + acpi_trip = &tz->trips.passive.trip; + + if (psv == -1) + goto fail; + + if (!passive_trip_params_init(tz)) + goto fail; + + temp = psv > 0 ? celsius_to_deci_kelvin(psv) : + get_passive_temp(tz); + } else { + acpi_trip = &tz->trips.active[index].trip; + + if (act == -1) + goto fail; + + temp = get_active_temp(tz, index); + } - temp = get_active_temp(tz, index); if (temp == THERMAL_TEMP_INVALID) goto fail; - if (!update_trip_devices(tz, &tz->trips.active[index].trip, index, false)) + if (!update_trip_devices(tz, acpi_trip, index, false)) goto fail; - tz->trips.active[index].trip.temperature = temp; + acpi_trip->temperature = temp; return true; fail: - tz->trips.active[index].trip.temperature = THERMAL_TEMP_INVALID; + acpi_trip->temperature = THERMAL_TEMP_INVALID; return false; } @@ -473,11 +469,11 @@ static int acpi_thermal_get_trip_points( unsigned int count = 0; int i; - if (acpi_thermal_init_passive_trip(tz)) + if (acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE)) count++; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (acpi_thermal_init_active_trip(tz, i)) + if (acpi_thermal_init_trip(tz, i)) count++; else break; From patchwork Thu Sep 21 17:52:44 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: 142953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5172170vqi; Thu, 21 Sep 2023 15:14:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyGdFZYVYwziHsZ+ZDX80q1FIJRkSMUXik5K6Oc/vz9Z5X4dMEy0/PvB6qZXD78HjUVTRG X-Received: by 2002:a05:6808:1820:b0:3a8:43d5:878b with SMTP id bh32-20020a056808182000b003a843d5878bmr7668666oib.2.1695334488059; Thu, 21 Sep 2023 15:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695334488; cv=none; d=google.com; s=arc-20160816; b=FbV8QR1nEdHt/ObzfQCn20Kh9A0RRXHTZpxS7YdrGeFCE7Kx0XN/UI1cxCJek1CBbQ fXg3iRFszLIEwCBL//IwXjWyhsLSzT1/9lRAj4MxxzUsUcsacO9H/PhEOIgka8/L/SGR wnqeNnObwEeBIs9/a6sjHFEYS+j5lCujTLk4r3bwcaY3hfS0VFrckMfyAqRBMBKcnTux lsPWjXPOabS06NQRlKwVIvEhunQ7BjlEni8eG20/qWtJCSCpqQHQ1bau2c8BYirBYxN+ dvtj31LaT9RbKjjDoRAqzNxVzIq6rrFMD+527uDXwm7HZmpiSftwNQJayPKmAGelYZGf Z/sA== 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=NMOArhbTedrpDyrwyCBB/Zjqqtxn7xvNSXH2ojbZqKg=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=xn4tJ0+JkKpLtKsH3C2rp+btzgvy5LZQfkvZoYTu7dnscrtz6egWu9h2qfYRHDNe2R vk011pTeMP2+scvZvkmotArdJcPiVKPI+6fmiKAkix8f0TVfZsjNEC+R4VnI9ZShVxxu dpjLu4+CdyMR+aFroqvDcVFSkBorXR175VV63dDqlCj8BR27rUNCRov9MqM5PJ/ETP9z eCglKA97aXjK22SxgugwuQhFc4x3y7Yj1aMzzscDJOKJlfS3U0RfMkBvtIM+gbdDqxqb l06N8WAC5GXsSMBm5rID10rB1IlhrKLzx9oN6Bv168OvRfyubgcGJ21Bh5BSm7wejKnu FLdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t22-20020a056a0021d600b0068bf645ac9bsi2464617pfj.238.2023.09.21.15.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:14:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 66C0882DDFA9; Thu, 21 Sep 2023 14:04:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232330AbjIUU7W (ORCPT + 29 others); Thu, 21 Sep 2023 16:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232090AbjIUU65 (ORCPT ); Thu, 21 Sep 2023 16:58:57 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68ED7AF947; Thu, 21 Sep 2023 11:07: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 6e5678acd76eb7ac; Thu, 21 Sep 2023 20:07:28 +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 0322B664EC0; Thu, 21 Sep 2023 20:07:28 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 05/13] thermal: core: Store trip pointer in struct thermal_instance Date: Thu, 21 Sep 2023 19:52:44 +0200 Message-ID: <1977624.usQuhbGJ8B@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:04:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777687055983669325 X-GMAIL-MSGID: 1777687055983669325 From: Rafael J. Wysocki Replace the integer trip number stored in struct thermal_instance with a pointer to the relevant trip and adjust the code using the structure in question accordingly. The main reason for making this change is to allow the trip point to cooling device binding code more straightforward, as illustrated by subsequent modifications of the ACPI thermal driver, but it also helps to clarify the overall design and allows the governor code overhead to be reduced (through subsequent modifications). The only case in which it adds complexity is trip_point_show() that needs to walk the trips[] table to find the index of the given trip point, but this is not a critical path and the interface that trip_point_show() belongs to is problematic anyway (for instance, it doesn't cover the case when the same cooling devices is associated with multiple trip points). This is a preliminary change and the affected code will be refined by a series of subsequent modifications of thermal governors, the core and the ACPI thermal driver. The general functionality is not expected to be affected by this change. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/thermal/gov_bang_bang.c | 23 ++++++++--------------- drivers/thermal/gov_fair_share.c | 5 +++-- drivers/thermal/gov_power_allocator.c | 11 ++++++++--- drivers/thermal/gov_step_wise.c | 16 +++++++--------- drivers/thermal/thermal_core.c | 15 ++++++++++----- drivers/thermal/thermal_core.h | 4 +++- drivers/thermal/thermal_helpers.c | 5 ++++- drivers/thermal/thermal_sysfs.c | 3 ++- drivers/thermal/thermal_trip.c | 15 +++++++++++++++ 9 files changed, 60 insertions(+), 37 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -87,7 +87,7 @@ struct thermal_instance { char name[THERMAL_NAME_LENGTH]; struct thermal_zone_device *tz; struct thermal_cooling_device *cdev; - int trip; + const struct thermal_trip *trip; bool initialized; unsigned long upper; /* Highest cooling state for this trip point */ unsigned long lower; /* Lowest cooling state for this trip point */ @@ -119,6 +119,8 @@ void __thermal_zone_device_update(struct void __thermal_zone_set_trips(struct thermal_zone_device *tz); int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); +int thermal_zone_trip_id(struct thermal_zone_device *tz, + const struct thermal_trip *trip); int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); /* sysfs I/F */ Index: linux-pm/drivers/thermal/thermal_helpers.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_helpers.c +++ linux-pm/drivers/thermal/thermal_helpers.c @@ -42,14 +42,17 @@ int get_tz_trend(struct thermal_zone_dev struct thermal_instance * get_thermal_instance(struct thermal_zone_device *tz, - struct thermal_cooling_device *cdev, int trip) + struct thermal_cooling_device *cdev, int trip_index) { struct thermal_instance *pos = NULL; struct thermal_instance *target_instance = NULL; + const struct thermal_trip *trip; mutex_lock(&tz->lock); mutex_lock(&cdev->lock); + trip = &tz->trips[trip_index]; + list_for_each_entry(pos, &tz->thermal_instances, tz_node) { if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { target_instance = pos; Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -602,7 +602,7 @@ struct thermal_zone_device *thermal_zone /** * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone * @tz: pointer to struct thermal_zone_device - * @trip: indicates which trip point the cooling devices is + * @trip_index: indicates which trip point the cooling devices is * associated with in this thermal zone. * @cdev: pointer to struct thermal_cooling_device * @upper: the Maximum cooling state for this trip point. @@ -622,7 +622,7 @@ struct thermal_zone_device *thermal_zone * Return: 0 on success, the proper error value otherwise. */ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, - int trip, + int trip_index, struct thermal_cooling_device *cdev, unsigned long upper, unsigned long lower, unsigned int weight) @@ -631,12 +631,15 @@ int thermal_zone_bind_cooling_device(str struct thermal_instance *pos; struct thermal_zone_device *pos1; struct thermal_cooling_device *pos2; + const struct thermal_trip *trip; bool upper_no_limit; int result; - if (trip >= tz->num_trips || trip < 0) + if (trip_index >= tz->num_trips || trip_index < 0) return -EINVAL; + trip = &tz->trips[trip_index]; + list_for_each_entry(pos1, &thermal_tz_list, node) { if (pos1 == tz) break; @@ -739,7 +742,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_bind_cool * thermal_zone_unbind_cooling_device() - unbind a cooling device from a * thermal zone. * @tz: pointer to a struct thermal_zone_device. - * @trip: indicates which trip point the cooling devices is + * @trip_index: indicates which trip point the cooling devices is * associated with in this thermal zone. * @cdev: pointer to a struct thermal_cooling_device. * @@ -750,13 +753,15 @@ EXPORT_SYMBOL_GPL(thermal_zone_bind_cool * Return: 0 on success, the proper error value otherwise. */ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, - int trip, + int trip_index, struct thermal_cooling_device *cdev) { struct thermal_instance *pos, *next; + const struct thermal_trip *trip; mutex_lock(&tz->lock); mutex_lock(&cdev->lock); + trip = &tz->trips[trip_index]; list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { list_del(&pos->tz_node); Index: linux-pm/drivers/thermal/gov_bang_bang.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_bang_bang.c +++ linux-pm/drivers/thermal/gov_bang_bang.c @@ -13,28 +13,21 @@ #include "thermal_core.h" -static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) +static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index) { - struct thermal_trip trip; + const struct thermal_trip *trip = &tz->trips[trip_index]; struct thermal_instance *instance; - int ret; - ret = __thermal_zone_get_trip(tz, trip_id, &trip); - if (ret) { - pr_warn_once("Failed to retrieve trip point %d\n", trip_id); - return ret; - } - - if (!trip.hysteresis) + if (!trip->hysteresis) dev_info_once(&tz->device, "Zero hysteresis value for thermal zone %s\n", tz->type); dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n", - trip_id, trip.temperature, tz->temperature, - trip.hysteresis); + trip_index, trip->temperature, tz->temperature, + trip->hysteresis); list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if (instance->trip != trip_id) + if (instance->trip != trip) continue; /* in case fan is in initial state, switch the fan off */ @@ -52,10 +45,10 @@ static int thermal_zone_trip_update(stru * enable fan when temperature exceeds trip_temp and disable * the fan in case it falls below trip_temp minus hysteresis */ - if (instance->target == 0 && tz->temperature >= trip.temperature) + if (instance->target == 0 && tz->temperature >= trip->temperature) instance->target = 1; else if (instance->target == 1 && - tz->temperature <= trip.temperature - trip.hysteresis) + tz->temperature <= trip->temperature - trip->hysteresis) instance->target = 0; dev_dbg(&instance->cdev->device, "target=%d\n", Index: linux-pm/drivers/thermal/gov_fair_share.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_fair_share.c +++ linux-pm/drivers/thermal/gov_fair_share.c @@ -49,7 +49,7 @@ static long get_target_state(struct ther /** * fair_share_throttle - throttles devices associated with the given zone * @tz: thermal_zone_device - * @trip: trip point index + * @trip_index: trip point index * * Throttling Logic: This uses three parameters to calculate the new * throttle state of the cooling devices associated with the given zone. @@ -65,8 +65,9 @@ static long get_target_state(struct ther * (Heavily assumes the trip points are in ascending order) * new_state of cooling device = P3 * P2 * P1 */ -static int fair_share_throttle(struct thermal_zone_device *tz, int trip) +static int fair_share_throttle(struct thermal_zone_device *tz, int trip_index) { + const struct thermal_trip *trip = &tz->trips[trip_index]; struct thermal_instance *instance; int total_weight = 0; int total_instance = 0; Index: linux-pm/drivers/thermal/gov_step_wise.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_step_wise.c +++ linux-pm/drivers/thermal/gov_step_wise.c @@ -81,26 +81,24 @@ static void update_passive_instance(stru static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) { + const struct thermal_trip *trip = &tz->trips[trip_id]; enum thermal_trend trend; struct thermal_instance *instance; - struct thermal_trip trip; bool throttle = false; int old_target; - __thermal_zone_get_trip(tz, trip_id, &trip); - trend = get_tz_trend(tz, trip_id); - if (tz->temperature >= trip.temperature) { + if (tz->temperature >= trip->temperature) { throttle = true; - trace_thermal_zone_trip(tz, trip_id, trip.type); + trace_thermal_zone_trip(tz, trip_id, trip->type); } dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n", - trip_id, trip.type, trip.temperature, trend, throttle); + trip_id, trip->type, trip->temperature, trend, throttle); list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if (instance->trip != trip_id) + if (instance->trip != trip) continue; old_target = instance->target; @@ -114,11 +112,11 @@ static void thermal_zone_trip_update(str /* Activate a passive thermal instance */ if (old_target == THERMAL_NO_TARGET && instance->target != THERMAL_NO_TARGET) - update_passive_instance(tz, trip.type, 1); + update_passive_instance(tz, trip->type, 1); /* Deactivate a passive thermal instance */ else if (old_target != THERMAL_NO_TARGET && instance->target == THERMAL_NO_TARGET) - update_passive_instance(tz, trip.type, -1); + update_passive_instance(tz, trip->type, -1); instance->initialized = true; mutex_lock(&instance->cdev->lock); Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -943,7 +943,8 @@ trip_point_show(struct device *dev, stru instance = container_of(attr, struct thermal_instance, attr); - return sprintf(buf, "%d\n", instance->trip); + return sprintf(buf, "%d\n", + thermal_zone_trip_id(instance->tz, instance->trip)); } ssize_t Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -157,3 +157,18 @@ int thermal_zone_set_trip(struct thermal return 0; } + +int thermal_zone_trip_id(struct thermal_zone_device *tz, + const struct thermal_trip *trip) +{ + int i; + + lockdep_assert_held(&tz->lock); + + for (i = 0; i < tz->num_trips; i++) { + if (&tz->trips[i] == trip) + return i; + } + + return -ENODATA; +} Index: linux-pm/drivers/thermal/gov_power_allocator.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_power_allocator.c +++ linux-pm/drivers/thermal/gov_power_allocator.c @@ -90,12 +90,14 @@ static u32 estimate_sustainable_power(st u32 sustainable_power = 0; struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; + const struct thermal_trip *trip_max_desired_temperature = + &tz->trips[params->trip_max_desired_temperature]; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; u32 min_power; - if (instance->trip != params->trip_max_desired_temperature) + if (instance->trip != trip_max_desired_temperature) continue; if (!cdev_is_power_actor(cdev)) @@ -383,12 +385,13 @@ static int allocate_power(struct thermal { struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; + const struct thermal_trip *trip_max_desired_temperature = + &tz->trips[params->trip_max_desired_temperature]; u32 *req_power, *max_power, *granted_power, *extra_actor_power; u32 *weighted_req_power; u32 total_req_power, max_allocatable_power, total_weighted_req_power; u32 total_granted_power, power_range; int i, num_actors, total_weight, ret = 0; - int trip_max_desired_temperature = params->trip_max_desired_temperature; num_actors = 0; total_weight = 0; @@ -564,12 +567,14 @@ static void allow_maximum_power(struct t { struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; + const struct thermal_trip *trip_max_desired_temperature = + &tz->trips[params->trip_max_desired_temperature]; u32 req_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; - if ((instance->trip != params->trip_max_desired_temperature) || + if ((instance->trip != trip_max_desired_temperature) || (!cdev_is_power_actor(instance->cdev))) continue; From patchwork Thu Sep 21 17:54: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: 142955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5173949vqi; Thu, 21 Sep 2023 15:18:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2F9FORCuJbg8/gNafB6u54I2hWqfelPWMsERkreCFvCj2hPUw0pZSqXJLmv0/xXCmejrM X-Received: by 2002:a05:6830:22d1:b0:6b8:7d12:423d with SMTP id q17-20020a05683022d100b006b87d12423dmr6672919otc.18.1695334697742; Thu, 21 Sep 2023 15:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695334697; cv=none; d=google.com; s=arc-20160816; b=k3QxCcz0OpmZd8WyVLIRQe9BMnLStdihxby+XNcnNAGBuRLdsex/48znIvmlWB0SVJ Y9C3weQvUsiBJO+ygTj0olhbj06vP6rv7TOG3Jt8m/ajE/2jfdl79tmNiNLOJ7hGCbSZ SH+JJPDUrdZRGpXJ4ANaf6PeKHlpWV6mCXrhvW18Ws5CEEyf9MGV/e8uCL+kz9t7SqtW c9xk0/pwHGQFAfCJ2FgfniBEYG+wsOk1ir84bKoR0/BOf6dfJNgW87jNlzXaRXd7JAfk Ku8keAvbBpJSujVs8QFP+IRuVVPC/Wg2pUYGCxr+Vwby6pgtbXcQ/dU1YPH66Y+vk6vE djcQ== 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=ixFOR+3Lq0zpp/fWaiAdnOe96pHHdhfyMAtnK+akSEY=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=TNr0X9hCOpKhGx0AAbCR98a37GePwwx4y1rfcqELpFHAtFAm8vtLLEKurbTZ+jkw6P AcscFc1WLrQhYvlj4Hy0Zmlmk0MZXzOHzVdXe7Qy1Fy3tjxpwuzfXWykSF+qa9T0sxk/ Ljx7u0yZ5OOy0Te5Yz7snr3Z9nGfAOCW535B+PrXd2Zvm7Av2qpp5NvdEQzEZJUsMMHI MNs5KJLXV99n1sv/T9m0mYX/hHeXBs5ltqhL7vM60NCDIwTK8qCgqYfk4BBdjC2zF/r6 ffDqvoZoTTdcxtIZ2bVMDPLMAI8a04E8M9EIKIwotNBnCNtIkGI/vQ4I/gWkKf9mLFwL CBdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ea22-20020a056a004c1600b00690f8dfb431si2385925pfb.253.2023.09.21.15.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:18:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A03D782289BF; Thu, 21 Sep 2023 15:07:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232244AbjIUWGh (ORCPT + 29 others); Thu, 21 Sep 2023 18:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjIUWGV (ORCPT ); Thu, 21 Sep 2023 18:06:21 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A345AF941; Thu, 21 Sep 2023 11:07: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 27ba5ac5cc524f47; Thu, 21 Sep 2023 20:07: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 3400F664EC0; Thu, 21 Sep 2023 20:07:27 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 06/13] thermal: gov_fair_share: Rearrange get_trip_level() Date: Thu, 21 Sep 2023 19:54:02 +0200 Message-ID: <1882755.CQOukoFCf9@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:07:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777687275843441234 X-GMAIL-MSGID: 1777687275843441234 From: Rafael J. Wysocki Make get_trip_level() access the thermal zone's trip table directly instead of using __thermal_zone_get_trip() which adds overhead related to the unnecessary bounds checking and copying the trip point data. Also rearrange the code in it to make it somewhat easier to follow. The general functionality is not expected to be changed. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_fair_share.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) Index: linux-pm/drivers/thermal/gov_fair_share.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_fair_share.c +++ linux-pm/drivers/thermal/gov_fair_share.c @@ -21,23 +21,21 @@ */ static int get_trip_level(struct thermal_zone_device *tz) { - struct thermal_trip trip; - int count; + const struct thermal_trip *trip = tz->trips; + int i; - for (count = 0; count < tz->num_trips; count++) { - __thermal_zone_get_trip(tz, count, &trip); - if (tz->temperature < trip.temperature) + if (tz->temperature < trip->temperature) + return 0; + + for (i = 0; i < tz->num_trips - 1; i++) { + trip++; + if (tz->temperature < trip->temperature) break; } - /* - * count > 0 only if temperature is greater than first trip - * point, in which case, trip_point = count - 1 - */ - if (count > 0) - trace_thermal_zone_trip(tz, count - 1, trip.type); + trace_thermal_zone_trip(tz, i, tz->trips[i].type); - return count; + return i; } static long get_target_state(struct thermal_zone_device *tz, From patchwork Thu Sep 21 17:55:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 143021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5222247vqi; Thu, 21 Sep 2023 17:08:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQFL14o484jpSzIrAp55e8xw7BZ18Fkcsl4+HY8jVjmeeMLnRkROhu/x2AhWsGeHbwn3b+ X-Received: by 2002:a05:6808:189f:b0:3ae:126b:8bfc with SMTP id bi31-20020a056808189f00b003ae126b8bfcmr2315621oib.4.1695341329600; Thu, 21 Sep 2023 17:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695341329; cv=none; d=google.com; s=arc-20160816; b=f9ZBGpmUcr9Khb8wD/i8LAxMNDP/vldUmBr1RuvewLnZ7NcT/bquIfVUFy1myMaYjM duI6BShdcboK7w5+0VjMoxQMBs95Vod4Z2IUokbG60nBmDKdJ+vO+m5taxjWwWtsSb+D K0Z4TKR1t7GtngxLAQUTRH6KfJabAsw9U46Qaf/o4rS5gOolv7A3pdGBhlHfza/+RUDr 9CKMPaL4tYRv+kL+MSy6OVpJcb9kMiL/NXBnzM5v49HtC0xRbVyiR9RrqSrnHEkMLWI7 BFrEPhoMItkDoe/cmOLvGUHwCLs9bxntHXwXf1dLjgqk8u8gZGbyGfSsvsi/EK+iCT4N wChA== 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=k8aukUEXFaQjPvSN+EEgCASXKuXnub/8NB1Ug7zE+z8=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=i2j6+KwP+PHPXqE3x7DkK+SJ0zF6Oh6ID7urHK2cogm07b0NYtAULcZtehfF8a8Efo OF94jVYnG4jdhqg2UCyNFQFLNofX1gXA1rC1Bk904Bu1mRga3tYtx521rOlAyxHFm5K+ AQ6wZI7xIXZzzoLef5xS9OJ+tPpLtduQP/2q/EFjhNENpO1vgEsA24GKUVpvVbqGMeI7 CmEKsIVObDWpHSpjU0nkS1sk+HLgPToqjsgGfMdSeMdgOSnMbreMvEcn86DGuzGpZOJ3 a4VbnxYIAQyyQ/V+3cb6wNuZ9GeHgJtgwvzYAy6TDwU310sxoXqNJXXRRVdllubmSXAB T8HA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id f20-20020a637554000000b00578cc8d2599si2603782pgn.211.2023.09.21.17.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:08:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id F1EDF8332577; Thu, 21 Sep 2023 16:20:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbjIUXUW (ORCPT + 29 others); Thu, 21 Sep 2023 19:20:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjIUXUU (ORCPT ); Thu, 21 Sep 2023 19:20:20 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BAA2AF6BB; Thu, 21 Sep 2023 11:07:28 -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 4759fab77295fb91; Thu, 21 Sep 2023 20:07:26 +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 4C8CC664EBE; Thu, 21 Sep 2023 20:07:26 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 07/13] thermal: gov_power_allocator: Use trip pointers instead of trip indices Date: Thu, 21 Sep 2023 19:55:26 +0200 Message-ID: <2590280.Lt9SDvczpP@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 16:20:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777694229902828654 X-GMAIL-MSGID: 1777694229902828654 From: Rafael J. Wysocki Eliminate the __thermal_zone_get_trip() usage that adds unnecessary overhead (due to pointless bounds checking and copying of trip point data) from the power allocator thermal governor and generally make it use trip pointers instead of trip indices where applicable. The general functionality is not expected to be changed. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_power_allocator.c | 102 ++++++++++++---------------------- 1 file changed, 38 insertions(+), 64 deletions(-) Index: linux-pm/drivers/thermal/gov_power_allocator.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_power_allocator.c +++ linux-pm/drivers/thermal/gov_power_allocator.c @@ -16,8 +16,6 @@ #include "thermal_core.h" -#define INVALID_TRIP -1 - #define FRAC_BITS 10 #define int_to_frac(x) ((x) << FRAC_BITS) #define frac_to_int(x) ((x) >> FRAC_BITS) @@ -55,23 +53,23 @@ static inline s64 div_frac(s64 x, s64 y) * @err_integral: accumulated error in the PID controller. * @prev_err: error in the previous iteration of the PID controller. * Used to calculate the derivative term. + * @sustainable_power: Sustainable power (heat) that this thermal zone can + * dissipate * @trip_switch_on: first passive trip point of the thermal zone. The * governor switches on when this trip point is crossed. * If the thermal zone only has one passive trip point, - * @trip_switch_on should be INVALID_TRIP. + * @trip_switch_on should be NULL. * @trip_max_desired_temperature: last passive trip point of the thermal * zone. The temperature we are * controlling for. - * @sustainable_power: Sustainable power (heat) that this thermal zone can - * dissipate */ struct power_allocator_params { bool allocated_tzp; s64 err_integral; s32 prev_err; - int trip_switch_on; - int trip_max_desired_temperature; u32 sustainable_power; + const struct thermal_trip *trip_switch_on; + const struct thermal_trip *trip_max_desired_temperature; }; /** @@ -90,14 +88,12 @@ static u32 estimate_sustainable_power(st u32 sustainable_power = 0; struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip_max_desired_temperature = - &tz->trips[params->trip_max_desired_temperature]; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; u32 min_power; - if (instance->trip != trip_max_desired_temperature) + if (instance->trip != params->trip_max_desired_temperature) continue; if (!cdev_is_power_actor(cdev)) @@ -116,24 +112,23 @@ static u32 estimate_sustainable_power(st * estimate_pid_constants() - Estimate the constants for the PID controller * @tz: thermal zone for which to estimate the constants * @sustainable_power: sustainable power for the thermal zone - * @trip_switch_on: trip point number for the switch on temperature + * @trip_switch_on: trip point for the switch on temperature * @control_temp: target temperature for the power allocator governor * * This function is used to update the estimation of the PID * controller constants in struct thermal_zone_parameters. */ static void estimate_pid_constants(struct thermal_zone_device *tz, - u32 sustainable_power, int trip_switch_on, + u32 sustainable_power, + const struct thermal_trip *trip_switch_on, int control_temp) { - struct thermal_trip trip; u32 temperature_threshold = control_temp; int ret; s32 k_i; - ret = __thermal_zone_get_trip(tz, trip_switch_on, &trip); - if (!ret) - temperature_threshold -= trip.temperature; + if (trip_switch_on) + temperature_threshold -= trip_switch_on->temperature; /* * estimate_pid_constants() tries to find appropriate default @@ -386,7 +381,7 @@ static int allocate_power(struct thermal struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; const struct thermal_trip *trip_max_desired_temperature = - &tz->trips[params->trip_max_desired_temperature]; + params->trip_max_desired_temperature; u32 *req_power, *max_power, *granted_power, *extra_actor_power; u32 *weighted_req_power; u32 total_req_power, max_allocatable_power, total_weighted_req_power; @@ -513,46 +508,35 @@ static int allocate_power(struct thermal static void get_governor_trips(struct thermal_zone_device *tz, struct power_allocator_params *params) { - int i, last_active, last_passive; - bool found_first_passive; - - found_first_passive = false; - last_active = INVALID_TRIP; - last_passive = INVALID_TRIP; + const struct thermal_trip *last_active = NULL: + const struct thermal_trip *last_passive = NULL; + bool found_first_passive = false; + int i; for (i = 0; i < tz->num_trips; i++) { - struct thermal_trip trip; - int ret; + const struct thermal_trip *trip = &tz->trips[i]; - ret = __thermal_zone_get_trip(tz, i, &trip); - if (ret) { - dev_warn(&tz->device, - "Failed to get trip point %d type: %d\n", i, - ret); - continue; - } - - if (trip.type == THERMAL_TRIP_PASSIVE) { + if (trip->type == THERMAL_TRIP_PASSIVE) { if (!found_first_passive) { - params->trip_switch_on = i; + params->trip_switch_on = trip; found_first_passive = true; } else { - last_passive = i; + last_passive = trip; } - } else if (trip.type == THERMAL_TRIP_ACTIVE) { - last_active = i; + } else if (trip->type == THERMAL_TRIP_ACTIVE) { + last_active = trip; } else { break; } } - if (last_passive != INVALID_TRIP) { + if (last_passive) { params->trip_max_desired_temperature = last_passive; } else if (found_first_passive) { params->trip_max_desired_temperature = params->trip_switch_on; - params->trip_switch_on = INVALID_TRIP; + params->trip_switch_on = NULL; } else { - params->trip_switch_on = INVALID_TRIP; + params->trip_switch_on = NULL; params->trip_max_desired_temperature = last_active; } } @@ -567,14 +551,12 @@ static void allow_maximum_power(struct t { struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip_max_desired_temperature = - &tz->trips[params->trip_max_desired_temperature]; u32 req_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; - if ((instance->trip != trip_max_desired_temperature) || + if (instance->trip != params->trip_max_desired_temperature || (!cdev_is_power_actor(instance->cdev))) continue; @@ -636,7 +618,6 @@ static int power_allocator_bind(struct t { int ret; struct power_allocator_params *params; - struct thermal_trip trip; ret = check_power_actors(tz); if (ret) @@ -662,12 +643,13 @@ static int power_allocator_bind(struct t get_governor_trips(tz, params); if (tz->num_trips > 0) { - ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, - &trip); - if (!ret) + const struct thermal_trip *trip; + + trip = params->trip_max_desired_temperature; + if (trip) estimate_pid_constants(tz, tz->tzp->sustainable_power, params->trip_switch_on, - trip.temperature); + trip->temperature); } reset_pid_controller(params); @@ -697,11 +679,10 @@ static void power_allocator_unbind(struc tz->governor_data = NULL; } -static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id) +static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_index) { struct power_allocator_params *params = tz->governor_data; - struct thermal_trip trip; - int ret; + const struct thermal_trip *trip = &tz->trips[trip_index]; bool update; lockdep_assert_held(&tz->lock); @@ -710,12 +691,12 @@ static int power_allocator_throttle(stru * We get called for every trip point but we only need to do * our calculations once */ - if (trip_id != params->trip_max_desired_temperature) + if (trip != params->trip_max_desired_temperature) return 0; - ret = __thermal_zone_get_trip(tz, params->trip_switch_on, &trip); - if (!ret && (tz->temperature < trip.temperature)) { - update = (tz->last_temperature >= trip.temperature); + trip = params->trip_switch_on; + if (trip && tz->temperature < trip->temperature) { + update = tz->last_temperature >= trip->temperature; tz->passive = 0; reset_pid_controller(params); allow_maximum_power(tz, update); @@ -724,14 +705,7 @@ static int power_allocator_throttle(stru tz->passive = 1; - ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, &trip); - if (ret) { - dev_warn(&tz->device, "Failed to get the maximum desired temperature: %d\n", - ret); - return ret; - } - - return allocate_power(tz, trip.temperature); + return allocate_power(tz, params->trip_max_desired_temperature->temperature); } static struct thermal_governor thermal_gov_power_allocator = { From patchwork Thu Sep 21 17:56:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 142961 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5177194vqi; Thu, 21 Sep 2023 15:25:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHal7kNmUoNR9p7C0EyNwNm+pTuJjYm31dCGLgVhhPr5nakzRvJrAX6IJsNjAV0iA6sIitF X-Received: by 2002:a25:494:0:b0:d84:ce15:8336 with SMTP id 142-20020a250494000000b00d84ce158336mr6757294ybe.18.1695335144652; Thu, 21 Sep 2023 15:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695335144; cv=none; d=google.com; s=arc-20160816; b=YZPTwFFomgBDPgXIAQrQ/HoZ5EJmipJlSHpXj8MZnvG9lnDSmX0GO+tNGatlywrdeg J2eZldEJ5IugsrksPdY2qoOYCJmVoP2cZX+aVWAfai0WGpoIa0J22QGLFmeaYMDWlqo9 QNyanhlia27Tf8A0kwL4GDRH81lYBAmokSKFCWrIbhth7YtNlnFIJ/ppFA85qejrxMlm SyMXfhqXdT90KkL8iBBufDXJmlMvb8RyoY3AX59vDvOKctMRUho3/aK8tymkRgVkm32W cXTDS+M86mZtv7Wx4HuOr3RGhCVvvQqgmF2dqxai1C2kZTbGdp1c7peP/oQkQ5tvizjp XCxg== 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=f7LmQP0UmruflYMCMM6WI92ijpnDS5T1M98XwguGSbs=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=GK94TzPl+LmqBTUBrTdMa9ppEcFE5oxqrvVEtRePQwfEnd2llol+pMRwk2vI7rQdD+ 7v6/oPZIBQTdVefquBbnGVRYXh058UsDtDTt451M4K290ufzlPeXkBG/Zxavhas4vlrn VsggukQue5QNwpp0n7uoD/xaIDdr6vRKMRn6zmMb0JuVLRso6uWRYbqQR6MPECAN7gaH xRoD0+FL7PD54r7Bv47GZ+PM8CHLS6V2YMIggovik0RFbcQHSeaJyO5Y/knyIuuyVj2q i3u2srEJegXLLikllUTUJLte1M2UTlHTi0F7rJMNyOTmd/kNR0J6JN29Wme8+vj97Wi1 xm4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u21-20020a63b555000000b0056417c8a310si2378181pgo.204.2023.09.21.15.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:25:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 21CD9837B5E1; Thu, 21 Sep 2023 15:11:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232848AbjIUWLD (ORCPT + 29 others); Thu, 21 Sep 2023 18:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232852AbjIUWKu (ORCPT ); Thu, 21 Sep 2023 18:10:50 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C361AF6B6; Thu, 21 Sep 2023 11:07:27 -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 c196ef04c16d75e5; Thu, 21 Sep 2023 20:07:25 +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 66D16664EBE; Thu, 21 Sep 2023 20:07:25 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 08/13] thermal: gov_step_wise: Fold update_passive_instance() into its caller Date: Thu, 21 Sep 2023 19:56:47 +0200 Message-ID: <2180114.Mh6RI2rZIc@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:11:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777687744957906733 X-GMAIL-MSGID: 1777687744957906733 From: Rafael J. Wysocki Fold update_passive_instance() into thermal_zone_trip_update() that is its only caller so as to make the code in question easeir to follow. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_step_wise.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) Index: linux-pm/drivers/thermal/gov_step_wise.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_step_wise.c +++ linux-pm/drivers/thermal/gov_step_wise.c @@ -68,17 +68,6 @@ static unsigned long get_target_state(st return next_target; } -static void update_passive_instance(struct thermal_zone_device *tz, - enum thermal_trip_type type, int value) -{ - /* - * If value is +1, activate a passive instance. - * If value is -1, deactivate a passive instance. - */ - if (type == THERMAL_TRIP_PASSIVE) - tz->passive += value; -} - static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) { const struct thermal_trip *trip = &tz->trips[trip_id]; @@ -109,14 +98,17 @@ static void thermal_zone_trip_update(str if (instance->initialized && old_target == instance->target) continue; - /* Activate a passive thermal instance */ if (old_target == THERMAL_NO_TARGET && - instance->target != THERMAL_NO_TARGET) - update_passive_instance(tz, trip->type, 1); - /* Deactivate a passive thermal instance */ - else if (old_target != THERMAL_NO_TARGET && - instance->target == THERMAL_NO_TARGET) - update_passive_instance(tz, trip->type, -1); + instance->target != THERMAL_NO_TARGET) { + /* Activate a passive thermal instance */ + if (trip->type == THERMAL_TRIP_PASSIVE) + tz->passive++; + } else if (old_target != THERMAL_NO_TARGET && + instance->target == THERMAL_NO_TARGET) { + /* Deactivate a passive thermal instance */ + if (trip->type == THERMAL_TRIP_PASSIVE) + tz->passive--; + } instance->initialized = true; mutex_lock(&instance->cdev->lock); From patchwork Thu Sep 21 17:58:32 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: 142957 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5176267vqi; Thu, 21 Sep 2023 15:23:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJOhlMd+nuXX9M8wRYcZfT2r68TfjOhZspT9nHm8JXgCaYSh00ouDz+58tGrIMdhfiA7T6 X-Received: by 2002:a05:6e02:1190:b0:345:79eb:e001 with SMTP id y16-20020a056e02119000b0034579ebe001mr6619068ili.19.1695335012113; Thu, 21 Sep 2023 15:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695335012; cv=none; d=google.com; s=arc-20160816; b=FA3JH3Aj5jdKswy1KIsni9dd2nqgcIrKTqG2uu7sEvkt3yiYFB7sEnMgMP0NajqTxM o/S3nETfiJarZ00APC2Zuhwbx2kvQ0/mtS8m2Bf2SSvxEe4EjirVpJBtjRc1Yo0dh/0a EHSJlvfTd29xHHzv05OeveIKLfxQkAlc+UKe+JF0XEKY0qjhk7mNsxdAE0lWlVZb+CNZ 8MBW2KyvM4IjCQrjOkWBxxMCQONzXgpglEwD8HL5IIFO2XBDiIXxWhtJ8P7+U3E6mdnS u0TbEQ6sXJbq7mPEtryqsen2TmuFt1i4NZidAPnfsGChhQitt0a2LI30QEhcKWVVXLGf zaLQ== 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=wQLsZzP7HfqaU9mX9RXdT30rY+Ags3V1ra5Ey9pbd6s=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=qlpgd8u62WHMCU4Gs1N1CHPgmF6FuIVNNVdKzD+ga3HTOErAcBU7Qlh7sFNPQIkXqO qP9XPrUeyqYW8Vru/V9xe812h/BLhOHS15+TnnhwS8vDxm+zyy74s7E4U4fF22Z4ZDaz RIsS8O7lHeXn6aJqf9hnxNCGmXGtbu/1TJYmR1htgqxyIWyh76xWh596RaatI2RWGfbp Cl0PBj78XB/MS7QDOwUk3xE/n3Mv8hiaJgQO3oCYFFO6CVPGU5HYdv7L1FabFowR9xuw I5frR6DRcHSpD9OATfXijVTl4rYy0m3rUJWK06E37uuUJlpQHSDYe/Fj55aJPvpvg+eR jd3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o15-20020a656a4f000000b00565eedb1cf8si2647092pgu.825.2023.09.21.15.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 15:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9041A8198C66; Thu, 21 Sep 2023 15:11:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232500AbjIUWLn (ORCPT + 29 others); Thu, 21 Sep 2023 18:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232056AbjIUWLZ (ORCPT ); Thu, 21 Sep 2023 18:11:25 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A8A5AF6B1; Thu, 21 Sep 2023 11:07:26 -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 f5571a811c8c5fc5; Thu, 21 Sep 2023 20:07:25 +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 85623664EBE; Thu, 21 Sep 2023 20:07:24 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 09/13] thermal: core: Rename trip point index function arguments in governors Date: Thu, 21 Sep 2023 19:58:32 +0200 Message-ID: <3719288.MHq7AAxBmi@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:11:53 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777687605847962742 X-GMAIL-MSGID: 1777687605847962742 From: Rafael J. Wysocki Rename function argumets used for passing trip point indices in thermal governors and in the .throttle() callback to "trip_index" to avoid confusion with trip pointer names. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_bang_bang.c | 4 ++-- drivers/thermal/gov_step_wise.c | 16 ++++++++-------- drivers/thermal/gov_user_space.c | 6 +++--- include/linux/thermal.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -199,7 +199,7 @@ struct thermal_governor { char name[THERMAL_NAME_LENGTH]; int (*bind_to_tz)(struct thermal_zone_device *tz); void (*unbind_from_tz)(struct thermal_zone_device *tz); - int (*throttle)(struct thermal_zone_device *tz, int trip); + int (*throttle)(struct thermal_zone_device *tz, int trip_index); struct list_head governor_list; }; Index: linux-pm/drivers/thermal/gov_user_space.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_user_space.c +++ linux-pm/drivers/thermal/gov_user_space.c @@ -25,11 +25,11 @@ static int user_space_bind(struct therma /** * notify_user_space - Notifies user space about thermal events * @tz: thermal_zone_device - * @trip: trip point index + * @trip_index: trip point index * * This function notifies the user space through UEvents. */ -static int notify_user_space(struct thermal_zone_device *tz, int trip) +static int notify_user_space(struct thermal_zone_device *tz, int trip_index) { char *thermal_prop[5]; int i; @@ -38,7 +38,7 @@ static int notify_user_space(struct ther thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type); thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature); - thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip); + thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip_index); thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event); thermal_prop[4] = NULL; kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop); Index: linux-pm/drivers/thermal/gov_bang_bang.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_bang_bang.c +++ linux-pm/drivers/thermal/gov_bang_bang.c @@ -89,14 +89,14 @@ static int thermal_zone_trip_update(stru * (trip_temp - hyst) so that the fan gets turned off again. * */ -static int bang_bang_control(struct thermal_zone_device *tz, int trip) +static int bang_bang_control(struct thermal_zone_device *tz, int trip_index) { struct thermal_instance *instance; int ret; lockdep_assert_held(&tz->lock); - ret = thermal_zone_trip_update(tz, trip); + ret = thermal_zone_trip_update(tz, trip_index); if (ret) return ret; Index: linux-pm/drivers/thermal/gov_step_wise.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_step_wise.c +++ linux-pm/drivers/thermal/gov_step_wise.c @@ -68,23 +68,23 @@ static unsigned long get_target_state(st return next_target; } -static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id) +static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index) { - const struct thermal_trip *trip = &tz->trips[trip_id]; + const struct thermal_trip *trip = &tz->trips[trip_index]; enum thermal_trend trend; struct thermal_instance *instance; bool throttle = false; int old_target; - trend = get_tz_trend(tz, trip_id); + trend = get_tz_trend(tz, trip_index); if (tz->temperature >= trip->temperature) { throttle = true; - trace_thermal_zone_trip(tz, trip_id, trip->type); + trace_thermal_zone_trip(tz, trip_index, trip->type); } dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n", - trip_id, trip->type, trip->temperature, trend, throttle); + trip_index, trip->type, trip->temperature, trend, throttle); list_for_each_entry(instance, &tz->thermal_instances, tz_node) { if (instance->trip != trip) @@ -120,7 +120,7 @@ static void thermal_zone_trip_update(str /** * step_wise_throttle - throttles devices associated with the given zone * @tz: thermal_zone_device - * @trip: trip point index + * @trip_index: trip point index * * Throttling Logic: This uses the trend of the thermal zone to throttle. * If the thermal zone is 'heating up' this throttles all the cooling @@ -128,13 +128,13 @@ static void thermal_zone_trip_update(str * step. If the zone is 'cooling down' it brings back the performance of * the devices by one step. */ -static int step_wise_throttle(struct thermal_zone_device *tz, int trip) +static int step_wise_throttle(struct thermal_zone_device *tz, int trip_index) { struct thermal_instance *instance; lockdep_assert_held(&tz->lock); - thermal_zone_trip_update(tz, trip); + thermal_zone_trip_update(tz, trip_index); list_for_each_entry(instance, &tz->thermal_instances, tz_node) thermal_cdev_update(instance->cdev); From patchwork Thu Sep 21 18:01:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 142919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5145762vqi; Thu, 21 Sep 2023 14:20:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/4cii6o57HaO+pItWM7jDBclYRDO85cZBT2ea2Agfg4aGBmboM4aW7H48WOJh/ahP33CI X-Received: by 2002:a17:903:244d:b0:1c3:a814:a12b with SMTP id l13-20020a170903244d00b001c3a814a12bmr1285574pls.16.1695331225783; Thu, 21 Sep 2023 14:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695331225; cv=none; d=google.com; s=arc-20160816; b=08z0g1gfi2mC/2iNeulbvjGAQFRN0jYLSVOX8mtKKIxJn3BBaaa8svzlrx6B7NEoQO kvCFi4YnOUUueXYMwAW5KC4AEQu+7D0b4G5kk6Cd6J25JXbEmCrE6MIdBjnLTU6ZxYYl gIsSag0wEyUhWTsQEEdoZ+29n2M8P9LxAm2keMBPVMUCMOWG7pRWJd0UfdarRUZwQ4a9 rS4rwz1EFValZkD+RTfXi2nEQ05HRS/LJod7j1YoX1eGy+TTuwyCRq/KZ4XIcrNf68kq 6Z8I4eIno74fjHiuOVc/MlJ0IndBmlLnVG0xc8OJ/au+v35E/8g48JizWYxwiTQTaO8x NUoQ== 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=C4MjTpDyjEf6zYS58+QBDE0XaOtUTmB0pOvj1FEYLsA=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=KuxMrii2RdfJomxtQIXuG2oU0NROZczUr34yDwCQQTN1DNY2CwuIWyi7n9k42/7o3U UOlrxj9lsGHzdmRtVIGW5ojQrFY2iiNWoXfXvhQ1zTXHA5y0642y3FDH5iZIbAyLjU54 uY0lwm/Ptz/gjfgAHYnaDDkkLXaBi/7Ew8EjpXHXgqIP766k2LmlSEfzsPcD1/p1oysr qhZnxY3vJmqeI66iYkU+P8ct5uqzH3yHVDTUELYZJ/y5I62NdCqxk/w0OJN54xSUyZag EJ/z1reT21i5oImT6kIBPHhqlZieBzUwV06EAJPLrZZIveO++umaxwmBJ8hAYa3KNQwT Sa7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i17-20020a17090332d100b001b8b437b01esi2551183plr.350.2023.09.21.14.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:20:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2CEC7831C828; Thu, 21 Sep 2023 14:04:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231974AbjIUVEM (ORCPT + 29 others); Thu, 21 Sep 2023 17:04:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230237AbjIUVDf (ORCPT ); Thu, 21 Sep 2023 17:03:35 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE22AF6AC; Thu, 21 Sep 2023 11:07:25 -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 7e05a53f9afe0d47; Thu, 21 Sep 2023 20:07:24 +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 B6180664EBE; Thu, 21 Sep 2023 20:07:23 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 10/13] thermal: core: Allow trip pointers to be used for cooling device binding Date: Thu, 21 Sep 2023 20:01:43 +0200 Message-ID: <45837158.fMDQidcC6G@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:04:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777683635689117555 X-GMAIL-MSGID: 1777683635689117555 From: Rafael J. Wysocki Add new helper functions, thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip(), to allow a trip pointer to be used for binding a cooling device to a trip point and unbinding it, respectively, and redefine the existing helpers, thermal_zone_bind_cooling_device() and thermal_zone_unbind_cooling_device(), as wrappers around the new ones, respectively. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 54 +++++++++++++++++++++++++---------------- include/linux/thermal.h | 8 ++++++ 2 files changed, 42 insertions(+), 20 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -600,10 +600,9 @@ struct thermal_zone_device *thermal_zone */ /** - * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone + * thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone * @tz: pointer to struct thermal_zone_device - * @trip_index: indicates which trip point the cooling devices is - * associated with in this thermal zone. + * @trip: trip point the cooling devices is associated with in this zone. * @cdev: pointer to struct thermal_cooling_device * @upper: the Maximum cooling state for this trip point. * THERMAL_NO_LIMIT means no upper limit, @@ -621,8 +620,8 @@ struct thermal_zone_device *thermal_zone * * Return: 0 on success, the proper error value otherwise. */ -int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, - int trip_index, +int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, + const struct thermal_trip *trip, struct thermal_cooling_device *cdev, unsigned long upper, unsigned long lower, unsigned int weight) @@ -631,15 +630,9 @@ int thermal_zone_bind_cooling_device(str struct thermal_instance *pos; struct thermal_zone_device *pos1; struct thermal_cooling_device *pos2; - const struct thermal_trip *trip; bool upper_no_limit; int result; - if (trip_index >= tz->num_trips || trip_index < 0) - return -EINVAL; - - trip = &tz->trips[trip_index]; - list_for_each_entry(pos1, &thermal_tz_list, node) { if (pos1 == tz) break; @@ -736,14 +729,26 @@ free_mem: kfree(dev); return result; } +EXPORT_SYMBOL_GPL(thermal_bind_cdev_to_trip); + +int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, + int trip_index, + struct thermal_cooling_device *cdev, + unsigned long upper, unsigned long lower, + unsigned int weight) +{ + if (trip_index < 0 || trip_index >= tz->num_trips) + return -EINVAL; + + return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev, + upper, lower, weight); +} EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device); /** - * thermal_zone_unbind_cooling_device() - unbind a cooling device from a - * thermal zone. + * thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone. * @tz: pointer to a struct thermal_zone_device. - * @trip_index: indicates which trip point the cooling devices is - * associated with in this thermal zone. + * @trip: trip point the cooling devices is associated with in this zone. * @cdev: pointer to a struct thermal_cooling_device. * * This interface function unbind a thermal cooling device from the certain @@ -752,16 +757,14 @@ EXPORT_SYMBOL_GPL(thermal_zone_bind_cool * * Return: 0 on success, the proper error value otherwise. */ -int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, - int trip_index, - struct thermal_cooling_device *cdev) +int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz, + const struct thermal_trip *trip, + struct thermal_cooling_device *cdev) { struct thermal_instance *pos, *next; - const struct thermal_trip *trip; mutex_lock(&tz->lock); mutex_lock(&cdev->lock); - trip = &tz->trips[trip_index]; list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { list_del(&pos->tz_node); @@ -784,6 +787,17 @@ unbind: kfree(pos); return 0; } +EXPORT_SYMBOL_GPL(thermal_unbind_cdev_from_trip); + +int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, + int trip_index, + struct thermal_cooling_device *cdev) +{ + if (trip_index < 0 || trip_index >= tz->num_trips) + return -EINVAL; + + return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev); +} EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device); static void thermal_release(struct device *dev) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -320,10 +320,18 @@ const char *thermal_zone_device_type(str int thermal_zone_device_id(struct thermal_zone_device *tzd); struct device *thermal_zone_device(struct thermal_zone_device *tzd); +int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, + const struct thermal_trip *trip, + struct thermal_cooling_device *cdev, + unsigned long upper, unsigned long lower, + unsigned int weight); int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *, unsigned long, unsigned long, unsigned int); +int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz, + const struct thermal_trip *trip, + struct thermal_cooling_device *cdev); int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, struct thermal_cooling_device *); void thermal_zone_device_update(struct thermal_zone_device *, From patchwork Thu Sep 21 18:02:59 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: 142920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5145892vqi; Thu, 21 Sep 2023 14:20:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG57pPwNZOMOH3Gg8XdKUXAHrsRWFJj+EcxXKbAgjsrb545861oAARlo9eIeRbtJrVdRYeS X-Received: by 2002:a05:6358:281d:b0:140:ecf2:4c69 with SMTP id k29-20020a056358281d00b00140ecf24c69mr6878190rwb.3.1695331240872; Thu, 21 Sep 2023 14:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695331240; cv=none; d=google.com; s=arc-20160816; b=rhwrZCx35K4ToWlmcP0QzToXAFZtTdxE3HUx4Sf+1vzg7fpyGFI2/ByXGwzNdDisp/ l+ex062SLscqbEXeI94ClScT1pvYzDUp55nYr1G9opGmrhSRbf5Qji5SToxta4NSs1nm zNCIGBPwZJzjJTNR+zxhPMK9UQLL3fAOmEYuDyYOZ9XM9xiYtfC8BdstkbNwD6IG57jn DJNJFusm7Z2HepeTGmiyKkc+wNuMn9KjFkocBpbHF/bNCpNeyXk6qY0Czog+KL6cpFaA pQQ8bspYqzQ/xDenE0z8X6GlsiQYgnP2O1TttR7EoIFIBnsQoIF7Oka2EsZ18sBkuhc+ CMHA== 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=G5/7WJJgfNGSv2liyz0SY1ZFbvHEls3NXduwEImLQO8=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=fy/Z+JDifOpaM5OOSvSbg7tnVjFZlM3mOxAsOo7vEpLALRaXN6+6w/dm2uw027lIBo t3k+PezaKzNa9TvDUr5Qcw7CB3Ap/NrRXCMLtNA1QbN9hCznzGOQheoylW1ekPHe06ry ytqzXZOGFQAScod2vMrvfuCFx3VanCUIlqpD9mqMn5s6JEdbxtcDJ9zilGIEPqz+hy5g znA6ayzxr+4SSrF7KlQzDmu9JtzNGA3aUdrdXdqIVmNTiA7RB9LXyx5OHbkrP8HCKmXQ Q5LLnWkhFaA9xWsETNL2kT+u/Sh1vbj53YhzHPQ6AS0CiXoezs1jnwUi46bO0PhcoLQD cl1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id h11-20020a65480b000000b00577dd005706si2193968pgs.779.2023.09.21.14.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 981FB8048E53; Thu, 21 Sep 2023 14:06:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232568AbjIUVEj (ORCPT + 29 others); Thu, 21 Sep 2023 17:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232375AbjIUVEJ (ORCPT ); Thu, 21 Sep 2023 17:04:09 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B555DAF6A9; Thu, 21 Sep 2023 11:07:24 -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 8de49c409fbac1fc; Thu, 21 Sep 2023 20:07:23 +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 B0ABA664EBE; Thu, 21 Sep 2023 20:07:22 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 11/13] ACPI: thermal: Do not use trip indices for cooling device binding Date: Thu, 21 Sep 2023 20:02:59 +0200 Message-ID: <113039009.nniJfEyVGO@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:06:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777683651285243694 X-GMAIL-MSGID: 1777683651285243694 From: Rafael J. Wysocki Rearrange the ACPI thermal driver's callback functions used for cooling device binding and unbinding, acpi_thermal_bind_cooling_device() and acpi_thermal_unbind_cooling_device(), respectively, so that they use trip pointers instead of trip indices which is more straightforward and allows the driver to become independent of the ordering of trips in the thermal zone structure. The general functionality is not expected to be changed. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 114 +++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 68 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -568,94 +568,72 @@ static void acpi_thermal_zone_device_cri thermal_zone_device_critical(thermal); } -static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, - struct thermal_cooling_device *cdev, - bool bind) +struct acpi_thermal_bind_data { + struct thermal_zone_device *thermal; + struct thermal_cooling_device *cdev; + bool bind; +}; + +static int bind_unbind_cdev_cb(struct thermal_trip *trip, void *arg) { - struct acpi_device *device = cdev->devdata; - struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - struct acpi_thermal_trip *acpi_trip; - struct acpi_device *dev; - acpi_handle handle; + struct acpi_thermal_trip *acpi_trip = trip->priv; + struct acpi_thermal_bind_data *bd = arg; + struct thermal_zone_device *thermal = bd->thermal; + struct thermal_cooling_device *cdev = bd->cdev; + struct acpi_device *cdev_adev = cdev->devdata; int i; - int j; - int trip = -1; - int result = 0; - - if (tz->trips.critical_valid) - trip++; - - if (tz->trips.hot_valid) - trip++; - - acpi_trip = &tz->trips.passive.trip; - if (acpi_thermal_trip_valid(acpi_trip)) { - trip++; - for (i = 0; i < acpi_trip->devices.count; i++) { - handle = acpi_trip->devices.handles[i]; - dev = acpi_fetch_acpi_dev(handle); - if (dev != device) - continue; - - if (bind) - result = thermal_zone_bind_cooling_device( - thermal, trip, cdev, - THERMAL_NO_LIMIT, - THERMAL_NO_LIMIT, - THERMAL_WEIGHT_DEFAULT); - else - result = - thermal_zone_unbind_cooling_device( - thermal, trip, cdev); - if (result) - goto failed; + /* Skip critical and hot trips. */ + if (!acpi_trip) + return 0; + + for (i = 0; i < acpi_trip->devices.count; i++) { + acpi_handle handle = acpi_trip->devices.handles[i]; + struct acpi_device *adev = acpi_fetch_acpi_dev(handle); + + if (adev != cdev_adev) + continue; + + if (bd->bind) { + int ret; + + ret = thermal_bind_cdev_to_trip(thermal, trip, cdev, + THERMAL_NO_LIMIT, + THERMAL_NO_LIMIT, + THERMAL_WEIGHT_DEFAULT); + if (ret) + return ret; + } else { + thermal_unbind_cdev_from_trip(thermal, trip, cdev); } } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - acpi_trip = &tz->trips.active[i].trip; - if (!acpi_thermal_trip_valid(acpi_trip)) - break; - - trip++; - for (j = 0; j < acpi_trip->devices.count; j++) { - handle = acpi_trip->devices.handles[j]; - dev = acpi_fetch_acpi_dev(handle); - if (dev != device) - continue; - - if (bind) - result = thermal_zone_bind_cooling_device( - thermal, trip, cdev, - THERMAL_NO_LIMIT, - THERMAL_NO_LIMIT, - THERMAL_WEIGHT_DEFAULT); - else - result = thermal_zone_unbind_cooling_device( - thermal, trip, cdev); + return 0; +} - if (result) - goto failed; - } - } +static int acpi_thermal_bind_unbind_cdev(struct thermal_zone_device *thermal, + struct thermal_cooling_device *cdev, + bool bind) +{ + struct acpi_thermal_bind_data bd = { + .thermal = thermal, .cdev = cdev, .bind = bind + }; -failed: - return result; + return for_each_thermal_trip(thermal, bind_unbind_cdev_cb, &bd); } static int acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) { - return acpi_thermal_cooling_device_cb(thermal, cdev, true); + return acpi_thermal_bind_unbind_cdev(thermal, cdev, true); } static int acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev) { - return acpi_thermal_cooling_device_cb(thermal, cdev, false); + return acpi_thermal_bind_unbind_cdev(thermal, cdev, false); } static struct thermal_zone_device_ops acpi_thermal_zone_ops = { From patchwork Thu Sep 21 18:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 142923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5146574vqi; Thu, 21 Sep 2023 14:22:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4kR+GoKdDwX1cxV6zoHMdA5mqPcandkMZK8I2/P/Sjf6ZXWkOSDTLgCKTGTWxAy5c/ilY X-Received: by 2002:a05:6870:a691:b0:1bf:df47:7b5e with SMTP id i17-20020a056870a69100b001bfdf477b5emr7829926oam.16.1695331327685; Thu, 21 Sep 2023 14:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695331327; cv=none; d=google.com; s=arc-20160816; b=Ml9+NvmjMz5yztIkxfdzc0dufxkjhV6o6gP+YH+DOkMEKOw/wJ2+mEnZ5BVoZT+td1 bdD0ZBKrNyvkzPd4daVJasSyNE3ZiQrvugBk34YyeKqj92pCWwJXSWzjssA2WXMX+RBi S9GuO162oj0SRZolRjC8IZs+T4TQ5YS0gY24KyialnvdI6LVXoK7xNKoT7IFQ17QXSLO ebt2CR9b300cNGqEuMo2KW9y4547h87AXJ0k0LiHFgvcJVVYoeWYIBAgkWPYxut+NsS/ OzjgzufF2NB4Wjw3cFp+3fjpMQwZV/5CjObe0ctmc2is/W+ex5FqKIODhj9rlhZ1lgjg zdeg== 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=uAnJ7xLeSPzNFUY9aHPIIV1U4zr8LnczFH9Zz9YXAHU=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=anuh4LcXZ6MLWRka4YwztxYR/VyJfc0I5ekWrpvepPJouNWntqzAstI22BHsmSW7iX Vp2HCJkuqsxnikxZtub68gXCJDZRM6hkzXRB1MaCf4ZWGerbwmb05IuAectKaBRsBmLQ gH5HV92LwxHQjd1Rh7xgPs8z3iqyWPCyM0VvoUgcXjeziK2zIlblQXC75txKB6ecARXn MbpCdxQektSkiXWl5C/mBzWJ0tnvOpIZ/z4ryGD3OjQUvR9nZ4Y+1IquVO5mZ6Xu2EId BSn1/6MMt+zETfVidyvVM2GtWaS6Xu4vuhTKm0gcEpZKt9Lzy4cVogr1raMm5o8SBR7K +JaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id a35-20020a631a63000000b00578ea9a0b93si2176913pgm.890.2023.09.21.14.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:22:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id C77918158E8B; Thu, 21 Sep 2023 14:06:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232641AbjIUVGb (ORCPT + 29 others); Thu, 21 Sep 2023 17:06:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233042AbjIUVFU (ORCPT ); Thu, 21 Sep 2023 17:05:20 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA2A1AF69F; Thu, 21 Sep 2023 11:07:23 -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 36cbd7be29a8bf2c; Thu, 21 Sep 2023 20:07:22 +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 D268B664EBE; Thu, 21 Sep 2023 20:07:21 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 12/13] ACPI: thermal: Drop critical_valid and hot_valid trip flags Date: Thu, 21 Sep 2023 20:04:49 +0200 Message-ID: <2375603.NG923GbCHz@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:06:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777683742324686366 X-GMAIL-MSGID: 1777683742324686366 From: Rafael J. Wysocki The critical_valid and hot_valid flags in struct acpi_thermal_trips are only used during initialization and they are only false if the corresponding trip temperatures are equal to THERMAL_TEMP_INVALID, so drop them and use THERMAL_TEMP_INVALID checks instead of them where applicable. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -100,8 +100,6 @@ struct acpi_thermal_active { struct acpi_thermal_trips { struct acpi_thermal_passive passive; struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; - bool critical_valid; - bool hot_valid; }; struct acpi_thermal { @@ -355,13 +353,13 @@ static long acpi_thermal_get_critical_tr } if (crt == -1) { acpi_handle_debug(tz->device->handle, "Critical threshold disabled\n"); - goto fail; + return THERMAL_TEMP_INVALID; } status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); if (ACPI_FAILURE(status)) { acpi_handle_debug(tz->device->handle, "No critical threshold\n"); - goto fail; + return THERMAL_TEMP_INVALID; } if (tmp <= 2732) { /* @@ -369,17 +367,12 @@ static long acpi_thermal_get_critical_tr * so discard them as invalid. */ pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); - goto fail; + return THERMAL_TEMP_INVALID; } set: - tz->trips.critical_valid = true; acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp); return tmp; - -fail: - tz->trips.critical_valid = false; - return THERMAL_TEMP_INVALID; } static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz) @@ -389,12 +382,10 @@ static long acpi_thermal_get_hot_trip(st status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.hot_valid = false; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); return THERMAL_TEMP_INVALID; } - tz->trips.hot_valid = true; acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp); return tmp; } @@ -789,7 +780,7 @@ static void acpi_thermal_aml_dependency_ */ static void acpi_thermal_guess_offset(struct acpi_thermal *tz, long crit_temp) { - if (tz->trips.critical_valid && crit_temp % 5 == 1) + if (crit_temp != THERMAL_TEMP_INVALID && crit_temp % 5 == 1) tz->kelvin_offset = 273100; else tz->kelvin_offset = 273200; @@ -850,11 +841,11 @@ static int acpi_thermal_add(struct acpi_ trip_count = acpi_thermal_get_trip_points(tz); crit_temp = acpi_thermal_get_critical_trip(tz); - if (tz->trips.critical_valid) + if (crit_temp != THERMAL_TEMP_INVALID) trip_count++; hot_temp = acpi_thermal_get_hot_trip(tz); - if (tz->trips.hot_valid) + if (hot_temp != THERMAL_TEMP_INVALID) trip_count++; if (!trip_count) { @@ -886,13 +877,13 @@ static int acpi_thermal_add(struct acpi_ tz->trip_table = trip; - if (tz->trips.critical_valid) { + if (crit_temp != THERMAL_TEMP_INVALID) { trip->type = THERMAL_TRIP_CRITICAL; trip->temperature = acpi_thermal_temp(tz, crit_temp); trip++; } - if (tz->trips.hot_valid) { + if (hot_temp != THERMAL_TEMP_INVALID) { trip->type = THERMAL_TRIP_HOT; trip->temperature = acpi_thermal_temp(tz, hot_temp); trip++; From patchwork Thu Sep 21 18:06:58 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: 142834 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5059188vqi; Thu, 21 Sep 2023 11:38:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEv7Im8SxZr753VTDj/A8fc7Jle4xiuu+6FzBwE4AugqLjS7uTLh33hLxVQxxFs0Dh4h4/g X-Received: by 2002:a05:6300:808b:b0:14c:4deb:7189 with SMTP id ap11-20020a056300808b00b0014c4deb7189mr5555218pzc.26.1695321538699; Thu, 21 Sep 2023 11:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695321538; cv=none; d=google.com; s=arc-20160816; b=YLPNfgyAMWkaY96XmYODjscNjUEIL35Sy3Ggaz/EXJdz286spnmteSQBF8yYkWkQvQ t0y42bjwHxF/TkZH5x5q5xxwlth3+6PKNgCKM7EIixU/6Yj6+q4dCyxz5kSCEdNXmR8T iTUYc9S8ZczmP7njLVSxTO9MzHlzDm5fvovnwBb1+Pl44W7UIMSIKUuNIWoZf9R5uuEj ft+oqkSqbI9AKpL76M+qtYbytwE60WGrU5JbanZi9WS6R6uD6V5LNgSJznluUIgvz4Zt bhhFnfXQxAQFcEmFNuXza8rNHYNlTIz5pLZ59WcM7E9XUKadaVLSysQ6XEndlji1tegW DJAA== 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=YxxbWkUeeE9us7vZDXuPmdRNs0DyT1A2hQfeE3JZf+g=; fh=M3Xj0cy8L+JeZSSd0Q6EHM9/xVzlLsbYrLkDMv02gfM=; b=p4a+K+vYax7s5tHvVN9LxG6yqW15mi+CWgqCLF3wRi8+STTTA2/1YrH70aIAM16IV5 U/e/tfe1NUTn7EeJVyGevhfj2ArzgXRVc7Za66Zfds0zpyZgul7PnqGdG9kPQMvwIqul fXa9W1AaZ17g/tQ5IiyRuux2s6vJ4Y7u8r5xYDausqP39dPcCaYtYtzL1iJBlPsOF6a5 8WXWWSbpzGN4eAZ2+mqWRUMwShN6bxnVTXHYQQHpL+8vfMHia9Oi7ENfdX1+LORWyAwR 1IeOUDpDsTo9f8uZEqjBbdE0lOswpJEcmv2eNdFwIYEkqRoP1O9WLXNmpNm0GmKKLI8l IB9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id by14-20020a056a00400e00b006901a8f5dadsi1947567pfb.289.2023.09.21.11.38.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 11:38:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A335F837E999; Thu, 21 Sep 2023 11:36:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbjIUSgx (ORCPT + 29 others); Thu, 21 Sep 2023 14:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjIUSg1 (ORCPT ); Thu, 21 Sep 2023 14:36:27 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17704AF69C; Thu, 21 Sep 2023 11:07:22 -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 2fecdf3dfb7fb0c9; Thu, 21 Sep 2023 20:07:21 +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 0973A664EBE; Thu, 21 Sep 2023 20:07:21 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Linux ACPI , Srinivas Pandruvada , Zhang Rui , Daniel Lezcano , Lukasz Luba , "Rafael J. Wysocki" Subject: [PATCH v1 13/13] ACPI: thermal: Rename structure fields holding temperature in deci-Kelvin Date: Thu, 21 Sep 2023 20:06:58 +0200 Message-ID: <1968603.yKVeVyVuyW@kreacher> In-Reply-To: <1957441.PYKUYFuaPT@kreacher> References: <1957441.PYKUYFuaPT@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: gggruggvucftvghtrhhoucdtuddrgedviedrudekiedguddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeekpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhn thgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:36:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777673478003704292 X-GMAIL-MSGID: 1777673478003704292 From: Rafael J. Wysocki Subject: [PATCH v1] Rename structure fields holding temperature values in deci-Kelvin so as to avoid temperature units confusion. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- drivers/acpi/thermal.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -82,7 +82,7 @@ MODULE_PARM_DESC(psv, "Disable or overri static struct workqueue_struct *acpi_thermal_pm_queue; struct acpi_thermal_trip { - unsigned long temperature; + unsigned long temp_dk; struct acpi_handle_list devices; }; @@ -105,8 +105,8 @@ struct acpi_thermal_trips { struct acpi_thermal { struct acpi_device *device; acpi_bus_id name; - unsigned long temperature; - unsigned long last_temperature; + unsigned long temp_dk; + unsigned long last_temp_dk; unsigned long polling_frequency; volatile u8 zombie; struct acpi_thermal_trips trips; @@ -131,16 +131,16 @@ static int acpi_thermal_get_temperature( if (!tz) return -EINVAL; - tz->last_temperature = tz->temperature; + tz->last_temp_dk = tz->temp_dk; status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); if (ACPI_FAILURE(status)) return -ENODEV; - tz->temperature = tmp; + tz->temp_dk = tmp; acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n", - tz->temperature); + tz->temp_dk); return 0; } @@ -175,7 +175,7 @@ static int acpi_thermal_temp(struct acpi static bool acpi_thermal_trip_valid(struct acpi_thermal_trip *acpi_trip) { - return acpi_trip->temperature != THERMAL_TEMP_INVALID; + return acpi_trip->temp_dk != THERMAL_TEMP_INVALID; } static long get_passive_temp(struct acpi_thermal *tz) @@ -197,7 +197,7 @@ static void acpi_thermal_update_passive_ if (!acpi_thermal_trip_valid(acpi_trip) || psv > 0) return; - acpi_trip->temperature = get_passive_temp(tz); + acpi_trip->temp_dk = get_passive_temp(tz); if (!acpi_thermal_trip_valid(acpi_trip)) ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -244,7 +244,7 @@ static void acpi_thermal_update_trip_dev return; } - acpi_trip->temperature = THERMAL_TEMP_INVALID; + acpi_trip->temp_dk = THERMAL_TEMP_INVALID; ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -278,7 +278,7 @@ static void acpi_thermal_update_active_t if (!acpi_thermal_trip_valid(acpi_trip)) return; - acpi_trip->temperature = get_active_temp(tz, index); + acpi_trip->temp_dk = get_active_temp(tz, index); if (!acpi_thermal_trip_valid(acpi_trip)) ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -292,7 +292,7 @@ static int acpi_thermal_adjust_trip(stru return 0; if (acpi_thermal_trip_valid(acpi_trip)) - trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk); else trip->temperature = THERMAL_TEMP_INVALID; @@ -447,11 +447,11 @@ static bool acpi_thermal_init_trip(struc if (!update_trip_devices(tz, acpi_trip, index, false)) goto fail; - acpi_trip->temperature = temp; + acpi_trip->temp_dk = temp; return true; fail: - acpi_trip->temperature = THERMAL_TEMP_INVALID; + acpi_trip->temp_dk = THERMAL_TEMP_INVALID; return false; } @@ -488,7 +488,7 @@ static int thermal_get_temp(struct therm if (result) return result; - *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature, + *temp = deci_kelvin_to_millicelsius_with_offset(tz->temp_dk, tz->kelvin_offset); return 0; } @@ -510,10 +510,10 @@ static int thermal_get_trend(struct ther switch (trip->type) { case THERMAL_TRIP_PASSIVE: - t = tz->trips.passive.tc1 * (tz->temperature - - tz->last_temperature) + - tz->trips.passive.tc2 * (tz->temperature - - acpi_trip->temperature); + t = tz->trips.passive.tc1 * (tz->temp_dk - + tz->last_temp_dk) + + tz->trips.passive.tc2 * (tz->temp_dk - + acpi_trip->temp_dk); if (t > 0) *trend = THERMAL_TREND_RAISING; else if (t < 0) @@ -524,7 +524,7 @@ static int thermal_get_trend(struct ther return 0; case THERMAL_TRIP_ACTIVE: - t = acpi_thermal_temp(tz, tz->temperature); + t = acpi_thermal_temp(tz, tz->temp_dk); if (t <= trip->temperature) break; @@ -894,7 +894,7 @@ static int acpi_thermal_add(struct acpi_ passive_delay = tz->trips.passive.tsp * 100; trip->type = THERMAL_TRIP_PASSIVE; - trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk); trip->priv = acpi_trip; trip++; } @@ -906,7 +906,7 @@ static int acpi_thermal_add(struct acpi_ break; trip->type = THERMAL_TRIP_ACTIVE; - trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk); trip->priv = acpi_trip; trip++; } @@ -920,7 +920,7 @@ static int acpi_thermal_add(struct acpi_ INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); pr_info("%s [%s] (%ld C)\n", acpi_device_name(device), - acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature)); + acpi_device_bid(device), deci_kelvin_to_celsius(tz->temp_dk)); result = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, acpi_thermal_notify);