Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8594585rwp; Wed, 19 Jul 2023 12:10:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlGN5eEjELadUge2C4D6V0nKJMZBVx181GmKwCsum26y4G/pfYQPiNmi/R/XbZYGSTvKD+Ri X-Received: by 2002:a17:902:bb94:b0:1b3:d6c8:7008 with SMTP id m20-20020a170902bb9400b001b3d6c87008mr3074405pls.57.1689793802340; Wed, 19 Jul 2023 12:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689793802; cv=none; d=google.com; s=arc-20160816; b=br6RM+08R1eMuENgazXQzqeGtznbZJQ0nD8Hfh+vbyPWDIvZtFbvWfQvomlt+Wm2bl wV/bPtnFrNZf6hVmW/X9mzhTjXXg9zn7N4AUyu2K8y4X+L+xavKqG8AeiE6KlfgZ6O7i pOL4AuC4rId+oidG22CuYd0eiaaeoRdzp8AWA9Ps0AKZyyCKzlIWeZwZh7iPT8HOmVLD +xTjnyF2UB2BHPz/8ESdD1tVoZlQ20GTRVB/yVVuwll5cmC8Lscp2bg1fbIek8alVIr9 ok7PevWCU8cyXkT1tUykt88Ih0b3Qb1uGa+fHSGXDc7/UrrbFkyp/bxBOEcxSImUjG+L Mvdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=OPpQztn8DN7aX3mKGS+49fCZUDIEgCNb4mqfp4qqRbE=; fh=IFTpSaAmIRgeolVe22kxER7pHD7XAJYXHtDUV/59mTQ=; b=bvaxh58Y/0ewBKqBbkdufAvoNrpH4rMySxCMDLVZii0ePzso5mvYoVkggiVnlikrLG ERUE+GBmmIX0NPTjXMan0Qww05kQJr3BjwLCDzI83vYXovLQVMotVXh61hn15BrOsXcD g35bMTxghT1dSbdtw5GCLIuhTKpfLLMjiryYi91wy6Y2eugSX+106XOG3e9nfV/DgMjb xRv75HSpmPp5nQvSwpCP7lCxuLNpw7Fl0YdkllKSPjLvbU12aTnccjVbXljhw544YsXJ Ix10nsqOnxHjSUbgVKCJ4x9KnXNz6uO1uFxwEv353h3S/WS+brr7hqipHVZay5TwgJLH WXVg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a170902650600b001b9d2982362si3936168plk.36.2023.07.19.12.09.49; Wed, 19 Jul 2023 12:10:02 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230124AbjGSSuQ convert rfc822-to-8bit (ORCPT + 99 others); Wed, 19 Jul 2023 14:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbjGSSuP (ORCPT ); Wed, 19 Jul 2023 14:50:15 -0400 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1218B6; Wed, 19 Jul 2023 11:50:14 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-98dfd15aae1so1078066b.0; Wed, 19 Jul 2023 11:50:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689792613; x=1690397413; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=04YX9R3mG7CuWz76OohlmuJRDoflU0LoC/zLXWiywQ0=; b=PAKwjSDjk1UTM7ukFkHNH7ZIRoiDhI7k8dwEjeG/V9q7vwqyH/xXFs3aWLlZQmD0Dq Wurr0ufblsyFoe0lssQ5LbGpM7b3vzuIgJ/nOtwhrEtjopvQZlhdfsfM6cnetjqfhuU/ fUXZBoGi143DpkEFoLCqC+9UZaOeU/4GF9bBAPi94lZ2SvFHib4DjATOEqBrhYWQaJox /v/sxAw4dt3yQHFynU01aUuW6tONJ2VXeC6CPuGXPbfpRSe5YD4JW4fwOTSoeV5+ulBb FZ8LpHOuCUAeAdch0+rirzS665B+DpTF71dxliagsU6/GcbknPVX9wNIbE6atb2NhkRJ HTPA== X-Gm-Message-State: ABy/qLZ+H/dPncKr9ySoEO1Qta1lSf1qzjdWKmIt2ADl0uGnGEFCkZgF pZTqGligaEyRDgKwM9znwJq7R/4RnKnofskm54iOIg0V X-Received: by 2002:a17:906:5192:b0:994:1808:176b with SMTP id y18-20020a170906519200b009941808176bmr318089ejk.6.1689792612991; Wed, 19 Jul 2023 11:50:12 -0700 (PDT) MIME-Version: 1.0 References: <13318886.uLZWGnKmhe@kreacher> <9147669.CDJkKcVGEf@kreacher> In-Reply-To: <9147669.CDJkKcVGEf@kreacher> From: "Rafael J. Wysocki" Date: Wed, 19 Jul 2023 20:50:01 +0200 Message-ID: Subject: Re: [PATCH v1 6/7] ACPI: thermal: Rework thermal_get_trend() To: "Rafael J. Wysocki" Cc: Linux ACPI , LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue, Jul 18, 2023 at 8:21 PM Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > Rework the ACPI thermal driver's .get_trend() callback function, > thermal_get_trend(), to use trip point data stored in the generic > trip structures instead of calling thermal_get_trip_type() and > thermal_get_trip_temp() and make it hold thermal_check_lock to > protect against possible races against trip point updates. > > Signed-off-by: Rafael J. Wysocki > --- > drivers/acpi/thermal.c | 107 +++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 78 insertions(+), 29 deletions(-) > > Index: linux-pm/drivers/acpi/thermal.c > =================================================================== > --- linux-pm.orig/drivers/acpi/thermal.c > +++ linux-pm/drivers/acpi/thermal.c > @@ -572,47 +572,96 @@ static int thermal_get_crit_temp(struct > return -EINVAL; > } > > +static struct thermal_trip *acpi_thermal_get_trip(struct acpi_thermal *tz, > + int trip_index) > +{ > + struct thermal_trip *trip; > + int i; > + > + if (!tz || trip_index < 0) > + return NULL; > + > + trip = tz->trips.critical.trip_ref.trip; > + if (trip) { > + if (!trip_index) > + return trip; > + > + 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, enum thermal_trend *trend) > + int trip_index, enum thermal_trend *trend) > { > struct acpi_thermal *tz = thermal_zone_device_priv(thermal); > - enum thermal_trip_type type; > - int i; > + struct thermal_trip *trip; > + int ret = 0; > > - if (thermal_get_trip_type(thermal, trip, &type)) > - return -EINVAL; > + mutex_lock(&tz->thermal_check_lock); > > - if (type == THERMAL_TRIP_ACTIVE) { > - int trip_temp; > + trip = acpi_thermal_get_trip(tz, trip_index); > + if (!trip) { This should also return an error for trips with invalid temperature. Moreover, an error should be returned for the critical and hot trips, because it doesn't make sense to deal with them here. It looks like a new version of this patch is needed. > + ret = -EINVAL; > + goto out; > + } > + if (trip->type == THERMAL_TRIP_ACTIVE) { > int temp = deci_kelvin_to_millicelsius_with_offset( > tz->temperature, tz->kelvin_offset); > - if (thermal_get_trip_temp(thermal, trip, &trip_temp)) > - return -EINVAL; > > - if (temp > trip_temp) { > + if (temp > trip->temperature) > *trend = THERMAL_TREND_RAISING; > - return 0; > - } else { > - /* Fall back on default trend */ > - return -EINVAL; > - } > + else /* Fall back on default trend */ > + ret = -EINVAL; > + } else { > + /* > + * tz->temperature has already been updated by generic thermal > + * layer, before this callback being invoked. > + */ > + int i = tz->trips.passive.tc1 * (tz->temperature - > + tz->last_temperature) + > + tz->trips.passive.tc2 * (tz->temperature - > + tz->trips.passive.temperature); > + > + if (i > 0) > + *trend = THERMAL_TREND_RAISING; > + else if (i < 0) > + *trend = THERMAL_TREND_DROPPING; > + else > + *trend = THERMAL_TREND_STABLE; > } > > - /* > - * tz->temperature has already been updated by generic thermal layer, > - * before this callback being invoked > - */ > - i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) + > - tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.temperature); > - > - if (i > 0) > - *trend = THERMAL_TREND_RAISING; > - else if (i < 0) > - *trend = THERMAL_TREND_DROPPING; > - else > - *trend = THERMAL_TREND_STABLE; > +out: > + mutex_unlock(&tz->thermal_check_lock); > > - return 0; > + return ret; > } > > static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal) > > >