Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7578499rwd; Tue, 20 Jun 2023 03:21:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VH6WQ9RXTWeHfN+AvgBirv3oG8QJwgO6xdXUfpXMAOpihl4OSP0CuQrPKlFRbbjeLO7KA X-Received: by 2002:a17:903:2284:b0:1b6:6a5c:2c76 with SMTP id b4-20020a170903228400b001b66a5c2c76mr3083746plh.15.1687256512645; Tue, 20 Jun 2023 03:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687256512; cv=none; d=google.com; s=arc-20160816; b=Ef4sUh73d5B+7Lbd7vvfbfblpSBJrPqdEj+iPkoOSFtEQyFOwjwbI1h3kPUzVo8Bgw NmFA96GkrZupErporfATAKALSzr+25Tzp94KASm6v6fgnlCsoHV6nJm7JqMzwT0Fb9F8 8DI6BOt2ZZli9guOcWWWgXPj3SLYznxig80rpzxspUOxNxbTZT77LUz/lwdDqAdpjsYg LxRi1R3wxmjeVypc1R4HaNMTX6am5sTOqW+luJ3Ufi7CoIIXdHMdJay66pAiSKvveXSc 5d++aF962mKToAbl/qmd2MQqLLXLqw+x87+OHjqibnOox6UPr3lzSTsmi4Y+7e+/FLaO y/JQ== 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=zN90iPZtE4ZLZfMi9rzAzA97Fe3x0V/5mJNozTUoRjc=; b=wBoVB50uhmx6zA22EA6nti+bOyr9xwDOd88pLRKm2e1YH66YALrW+EF4CYErI+7a8V Aj3lTo3WRlxh0eVd7BCSBjDZWGSmt4LKL7QCYmp7zvRdgDoK0svlXDC6utWind0IFLYZ auI6s3q+FwrGtgszWU59jAr2UpYbwhbVIpPIuejHw9bFFLIQEs67bt3amPSwkR1JQFJU EhPG2oxPmBP37qwAznqSctSIIoJuUvt4+4W9+uJIppxCsFbg9dGoNf7syTwU/wbvqKYJ FqePEgqy3Vwb/4D1kTgu9cku/8zn7JlBi27DrQEPkVZznm5UShvSL2c4bOL2HvqmAojL QyHA== 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 q5-20020a170902eb8500b001b3f35a694esi1610533plg.83.2023.06.20.03.21.38; Tue, 20 Jun 2023 03:21:52 -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 S231366AbjFTKIL convert rfc822-to-8bit (ORCPT + 99 others); Tue, 20 Jun 2023 06:08:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjFTKID (ORCPT ); Tue, 20 Jun 2023 06:08:03 -0400 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D19CF1; Tue, 20 Jun 2023 03:08:02 -0700 (PDT) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2b07762d292so13101911fa.0; Tue, 20 Jun 2023 03:08:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687255677; x=1689847677; 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=wjQW/g2eOU+G17oTPsY0Hzgvd7Db2fUoFqshufHaJLQ=; b=eeYsEVYyWgENbPkq49/6zGTWJ3Zb0O+7fMziZ+Uo55bDXW7raMZCc9/P4Jj2xRWozt AdQgPMrKVwhGNOaJe81FY052UZbiOxWlPOLgU8NPdknD+h+VUyzkNz+QYJvXaHEZyNvF tMCuMELiLgTrXwQx+63YHSZYG+5u59CBlLHRVnx6f4muFqyqRDCJXifp91jnB5VhiM9G WWQYUj/mjOye3+3LFwu8U48CJCpnZbIx0mhzkwSLKavkRABSwIYj1vXaNnuVlTyorjuG 4V3GveW0u+ErwZOwGvff4s0I71xVCex0VMPQTq2NlSIaSBn6FT4TxJSdWvlYGZdo7Q3Z Br1A== X-Gm-Message-State: AC+VfDzaUIiECOFxBOzmwykuwrMRTUTqEeT1T25yA1CgfGZ1GU7o4G4x WCGgg2kCaRKdyF3zMOZzk0naFR3CuJEGE87rmuTEmig7 X-Received: by 2002:a2e:8e2f:0:b0:2b4:60c0:1ac9 with SMTP id r15-20020a2e8e2f000000b002b460c01ac9mr4548586ljk.2.1687255676656; Tue, 20 Jun 2023 03:07:56 -0700 (PDT) MIME-Version: 1.0 References: <6aad180f-410c-5b11-b30b-c7bc02cbe054@linaro.org> <20230619063534.12831-1-di.shen@unisoc.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 20 Jun 2023 12:07:39 +0200 Message-ID: Subject: Re: [PATCH V4] thermal/core/power_allocator: reset thermal governor when trip point is changed To: Di Shen Cc: lukasz.luba@arm.com, daniel.lezcano@linaro.org, rafael@kernel.org, rui.zhang@intel.com, amitk@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, xuewen.yan@unisoc.com, jeson.gao@unisoc.com, zhanglyra@gmail.com, orsonzhai@gmail.com 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_NONE,RCVD_IN_MSPIKE_H2,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, Jun 20, 2023 at 11:46 AM Rafael J. Wysocki wrote: > > On Mon, Jun 19, 2023 at 8:36 AM Di Shen wrote: > > > > When the thermal trip point is changed, the governor should > > be reset so that the policy algorithm be updated to adapt to the > > new trip point. > > > > This patch adds an ops for thermal the governor structure to reset > > the governor. The ops is called when the trip point is changed. > > For power allocator, the parameters of pid controller and the states > > of power cooling devices can be reset when the passive trip point > > is changed. > > > > Signed-off-by: Di Shen > > > > --- > > V4: > > - Compared to V3, handle it in thermal core instead of in governor. > > > > - Add an ops to the governor structure, and call it when a trip > > point is changed. > > > > - Define reset ops for power allocator. > > > > V3: > > - Add fix tag. > > > > V2: > > - Compared to v1, do not revert. > > > > - Add a variable(last_switch_on_temp) in power_allocator_params > > to record the last switch_on_temp value. > > > > - Adds a function to renew the update flag and update the > > last_switch_on_temp when thermal trips are writable. > > > > V1: > > - Revert commit 0952177f2a1f. > > --- > > --- > > drivers/thermal/gov_power_allocator.c | 21 +++++++++++++++++++++ > > drivers/thermal/thermal_trip.c | 6 ++++++ > > include/linux/thermal.h | 1 + > > 3 files changed, 28 insertions(+) > > > > diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c > > index 8642f1096b91..41d155adc616 100644 > > --- a/drivers/thermal/gov_power_allocator.c > > +++ b/drivers/thermal/gov_power_allocator.c > > @@ -729,10 +729,31 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id) > > return allocate_power(tz, trip.temperature); > > } > > > > +static int power_allocator_reset(struct thermal_zone_device *tz, int trip_id) > > +{ > > + int ret = 0; > > + struct thermal_trip trip; > > + struct power_allocator_params *params = tz->governor_data; > > + > > + ret = __thermal_zone_get_trip(tz, trip_id, &trip); > > + if (ret) > > + return ret; > > + > > + /* Only need reset for passive trips */ > > + if (trip.type != THERMAL_TRIP_PASSIVE) > > + return -EINVAL; > > + > > + reset_pid_controller(params); > > + allow_maximum_power(tz, true); > > + > > + return ret; > > +} > > + > > static struct thermal_governor thermal_gov_power_allocator = { > > .name = "power_allocator", > > .bind_to_tz = power_allocator_bind, > > .unbind_from_tz = power_allocator_unbind, > > .throttle = power_allocator_throttle, > > + .reset = power_allocator_reset, > > }; > > THERMAL_GOVERNOR_DECLARE(thermal_gov_power_allocator); > > diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c > > index 907f3a4d7bc8..52eb768fada8 100644 > > --- a/drivers/thermal/thermal_trip.c > > +++ b/drivers/thermal/thermal_trip.c > > @@ -173,6 +173,12 @@ int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, > > if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) > > tz->trips[trip_id] = *trip; > > > > + if (t.temperature != trip->temperature && tz->governor && tz->governor->reset) { > > + ret = tz->governor->reset(tz, trip_id); > > + if (ret) > > + pr_warn_once("Failed to reset thermal governor\n"); > > I'm not really sure if it is useful to print this message here. > > First off, the governors may print more precise diagnostic messages if > they care. > > Second, what is the sysadmin supposed to do in response to this message? In addition to the above, trip point temperatures may be updated in other places too, for instance in response to notifications from platform firmware and IMV this new callback should be also used in those cases. However, in those cases multiple trip points may change at a time and the critical/hot trip point temperatures may be updated too AFAICS.