From patchwork Fri Jul 21 15:08:48 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: 123933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp294926vqg; Fri, 21 Jul 2023 08:46:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZhd6soLK2c+oKxjurst29tgyiBQZQ/rNVblRR0ffThpF6O0W5w4Biyq4HzgYlEPFt3EhH X-Received: by 2002:a9d:63cb:0:b0:6b8:7cdf:c2f3 with SMTP id e11-20020a9d63cb000000b006b87cdfc2f3mr449932otl.31.1689954401742; Fri, 21 Jul 2023 08:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689954401; cv=none; d=google.com; s=arc-20160816; b=jZXaR705mVl+lpbpALg+20ogadEpoG96Z+CYydEq0XAq7nZXW+zq93ij99XxseeLBT 03/g+V4jGQy8Adh4oQ5NLi8S3MCFW731fcdaaO2qlCdN6wmtjyLATh3+Rw3DnDetD/Ly G1WjxJ+2+9anHsytePRU2qajQg+FUKpWXf+KNSnujlh6NbogXbdTjtUWb+VqBvpFDu7T kMMnadL+kzIwgQxYH0PfsZopd9VULSgdD2zE+gFwoREarUaJE544L+Sba1iqmR/ktICt 83LuGrgPooGd4pxbMGDPg4xKquaq7sE8QjuB3yrvucH7TEeuH4W9GNdz/hLb+nbb7m0q k0tQ== 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=BP0N+ZjrsSxgmoqYhnVRk5ydkJKbkQmjKBfGg7SItjk=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=npExmK1PhtgC/gFmqKlGc+VdQNfG8HubOgmWSZ8LEESVc7KOPzGTqCo/uHjnIqcAFJ ffHgwllHAKJrSM4OJOGdo4Y6K/O0wsZLd90T3TGm1gUHVwQ2xlPbUbtXXa2ux739zS0u ewDsYnmBuvdPTEJ4dbo9N/xnCuv3TL1ClA6yEmOqVtS91C8wereXgMp9xvyfXOxvU0FY Ca9bXfUT7IulrczXuh4ZOZTLSIpbkpFFdwaOqkIwWnAwB078h8gUEEiRRDW1xYVW6KXy gDOLDeg7DnUm25HTj0448+W19s3L/2gAth3IbXAVnByPJAbOIMxjQp8EssNRrxP+nyja A+Aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a654389000000b0056381977278si1940379pgp.667.2023.07.21.08.46.28; Fri, 21 Jul 2023 08:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbjGUPST (ORCPT + 99 others); Fri, 21 Jul 2023 11:18:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjGUPSP (ORCPT ); Fri, 21 Jul 2023 11:18:15 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F35930DD; Fri, 21 Jul 2023 08:18:13 -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 0a38bb1b8a5a6388; Fri, 21 Jul 2023 17:18:11 +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 32225661901; Fri, 21 Jul 2023 17:18:11 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v2 7/8] ACPI: thermal: Rework thermal_get_trend() Date: Fri, 21 Jul 2023 17:08:48 +0200 Message-ID: <1849104.atdPhlSkOF@kreacher> In-Reply-To: <5710197.DvuYhMxLoT@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <5710197.DvuYhMxLoT@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: gggruggvucftvghtrhhoucdtuddrgedviedrhedvgdekvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771784820687096789 X-GMAIL-MSGID: 1772045626576800250 From: Rafael J. Wysocki Rework the ACPI thermal driver's .get_trend() callback function, thermal_get_trend(), to use trip point data stored in the generic trip structures instead of calling thermal_get_trip_type() and thermal_get_trip_temp(). Signed-off-by: Rafael J. Wysocki --- v1 -> v2: * Do not acquire thermal_check_lock in thermal_get_trend() (lockdep would complain about this, because it is hold around thermal zone locking and .get_trend() runs under the thermal zone lock). The thermal zone locking added in the previous patches is sufficient to protect this code. * Check trips against invalid temperature values. * Return an error for trips other than passive and active. --- drivers/acpi/thermal.c | 106 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 28 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -577,47 +577,97 @@ static int thermal_get_crit_temp(struct return -EINVAL; } -static int thermal_get_trend(struct thermal_zone_device *thermal, - int trip, enum thermal_trend *trend) +static struct thermal_trip *acpi_thermal_get_trip(struct acpi_thermal *tz, + int trip_index) { - struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - enum thermal_trip_type type; + struct thermal_trip *trip; int i; - if (thermal_get_trip_type(thermal, trip, &type)) - return -EINVAL; + if (!tz || trip_index < 0) + return NULL; - if (type == THERMAL_TRIP_ACTIVE) { - int trip_temp; - int temp = deci_kelvin_to_millicelsius_with_offset( - tz->temperature, tz->kelvin_offset); - if (thermal_get_trip_temp(thermal, trip, &trip_temp)) - return -EINVAL; + trip = tz->trips.critical.trip_ref.trip; + if (trip) { + if (!trip_index) + return trip; - if (temp > trip_temp) { - *trend = THERMAL_TREND_RAISING; - return 0; - } else { - /* Fall back on default trend */ - return -EINVAL; + trip_index--; + } + + trip = tz->trips.hot.trip_ref.trip; + if (trip) { + if (!trip_index) + return trip; + + trip_index--; + } + + trip = tz->trips.passive.trip_ref.trip; + if (trip) { + if (!trip_index) + return trip; + + trip_index--; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + trip = tz->trips.active[i].trip_ref.trip; + if (trip) { + if (!trip_index) + return trip; + + trip_index--; } } + return NULL; +} + +static int thermal_get_trend(struct thermal_zone_device *thermal, + int trip_index, enum thermal_trend *trend) +{ + struct acpi_thermal *tz = thermal_zone_device_priv(thermal); + struct thermal_trip *trip; + long t; + + trip = acpi_thermal_get_trip(tz, trip_index); + if (!trip || trip->temperature == THERMAL_TEMP_INVALID) + return -EINVAL; + /* * tz->temperature has already been updated by generic thermal layer, - * before this callback being invoked + * before this callback being invoked. */ - i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) + - tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.temperature); + switch (trip->type) { + case THERMAL_TRIP_PASSIVE: + t = tz->trips.passive.tc1 * (tz->temperature - + tz->last_temperature) + + tz->trips.passive.tc2 * (tz->temperature - + tz->trips.passive.temperature); + if (t > 0) + *trend = THERMAL_TREND_RAISING; + else if (t < 0) + *trend = THERMAL_TREND_DROPPING; + else + *trend = THERMAL_TREND_STABLE; + + return 0; + + case THERMAL_TRIP_ACTIVE: + t = deci_kelvin_to_millicelsius_with_offset(tz->temperature, + tz->kelvin_offset); + if (t > trip->temperature) { + *trend = THERMAL_TREND_RAISING; + return 0; + } - if (i > 0) - *trend = THERMAL_TREND_RAISING; - else if (i < 0) - *trend = THERMAL_TREND_DROPPING; - else - *trend = THERMAL_TREND_STABLE; + fallthrough; - return 0; + default: + break; + } + + return -EINVAL; } static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)