From patchwork Wed Jul 12 08:48:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Di Shen X-Patchwork-Id: 118969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1009599vqm; Wed, 12 Jul 2023 02:00:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlFQq7e1n4YOLy2diGNBLQIhOZRV3D1ozySYCROpOF0KFK/KduEMBrHZwd4jUSckHokJ2TRf X-Received: by 2002:a17:906:5308:b0:994:9ed:300b with SMTP id h8-20020a170906530800b0099409ed300bmr7977196ejo.16.1689152418572; Wed, 12 Jul 2023 02:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689152418; cv=none; d=google.com; s=arc-20160816; b=aVfkqoiGQIu0KV/CLTNLUlJeOVy0JAqEcO3eA8XeH1pkr+5pZfmAAXIikDnncVzEuy ToSXa8rTmcNbG6rSEmwTOCXHJYYrXUccP0HctVwEZacHokVFQfJhA3+axlOGnEAIs0KC mGvQS3UcaiSEdihaGgrNYKkKWgVUgXw/IGx2aDOrDQxGct/GBo03vWFsTOoKEwyO1Sew VN1xcQfWeF8ye31HD+yXZoiKEVqP6w17vzuyRLOJYV7vzadix9JOzJGim1Z+CTP9Myc3 JEPC6YcWsZgBbyoSAa1/iibFenMBf1ORliNNyRc5aKz+XdYqwzUSW2wGblti55FDFvMM DowA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=42C7i8rwu50AQn8f91dB+6O8x7/9Uo0bFuOz0iJm9wI=; fh=IyHBZ7/A4ppI799TuEdXtq6AOIpBKO6W7BnA6Y7gwQ4=; b=YWyNMWSGvz5XPohmd+S5X6Rw4OGZeGAdz0ny7wf8lmHoPUU9PE5QL4GiTx+tdTMYtP Wy9Z+kAnoXs78wRdEtGlfoBAwADauyw/yA/WX9zwcKxN3o+2GwAET8iCDnAqECFTGmiY 7C39XXjLJWJpmFVXA19rQ8AGABsZepH3zbWaeAwmFIlk4eumZ9MmsQOOpyRHyy9EjrXJ c3c4pefdPcOP38XWEk5s2bvwl4AB6NOiWMbzrCZKFJ47ctJtn87jT32uuQdqdzerTkIO XKzZUsSC64VNI7ao+w6S9bsGmycyeAFjJu/sxb8Dh4a0A4CrDugckGlS3HtI4druPlQp SBLA== 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 w25-20020a17090633d900b009929c39d5c5si3799112eja.367.2023.07.12.01.59.54; Wed, 12 Jul 2023 02:00:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231989AbjGLItv (ORCPT + 99 others); Wed, 12 Jul 2023 04:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231856AbjGLIts (ORCPT ); Wed, 12 Jul 2023 04:49:48 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22FDFB1; Wed, 12 Jul 2023 01:49:44 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 36C8mjdd097455; Wed, 12 Jul 2023 16:48:45 +0800 (+08) (envelope-from Di.Shen@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4R1BFq1lLMz2MK44l; Wed, 12 Jul 2023 16:47:43 +0800 (CST) Received: from bj10906pcu1.spreadtrum.com (10.0.73.63) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 12 Jul 2023 16:48:43 +0800 From: Di Shen To: , , , , CC: , , , , , , Subject: [PATCH] Revert "thermal: power allocator: change the 'k_*' always in estimate_pid_constants()" Date: Wed, 12 Jul 2023 16:48:40 +0800 Message-ID: <20230712084840.3594-1-di.shen@unisoc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.63] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 36C8mjdd097455 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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: 1771204686441668716 X-GMAIL-MSGID: 1771204686441668716 This reverts commit 90a996544946d1d4834ec2ec8add586edd905779. The commit ensures that the pid constants are updated when sustainable_power changes, but it makes it impossible for the driver to set the pid constants when the sustainable_power is not changed. When the driver tries to register a thermal zone device by thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask, void *devdata, struct thermal_zone_device_ops *ops, struct thermal_zone_params *tzp, int passive_delay, int polling_delay) and passes the private thermal_zone_params structure data, thermal_zone_devcice_register_with_trips | thermal_set_governor | bind_to_tz | power_allocator_bind | estimate_pid_constants the tzp->k_* will not be the data that driver have given, but the data estimated by sustainable_power. To make it possible for driver to add its own pid constants, the 'force' flag is needed to indicate whether the tzp->k_* should be estimated by sustainable_power or not. Signed-off-by: Di Shen --- drivers/thermal/gov_power_allocator.c | 28 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 8642f1096b91..f1753291b827 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -116,13 +116,18 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz) * @sustainable_power: sustainable power for the thermal zone * @trip_switch_on: trip point number for the switch on temperature * @control_temp: target temperature for the power allocator governor + * @force: whether to force the update of the constants * * This function is used to update the estimation of the PID * controller constants in struct thermal_zone_parameters. + * + * If @force is not set, the values in the thermal zone's parameters + * are preserved if they are not zero. If @force is set, the values + * in thermal zone's parameters are overwritten. */ static void estimate_pid_constants(struct thermal_zone_device *tz, u32 sustainable_power, int trip_switch_on, - int control_temp) + int control_temp, bool force) { struct thermal_trip trip; u32 temperature_threshold = control_temp; @@ -144,14 +149,18 @@ static void estimate_pid_constants(struct thermal_zone_device *tz, if (!temperature_threshold) return; - tz->tzp->k_po = int_to_frac(sustainable_power) / - temperature_threshold; + if (!tz->tzp->k_po || force) + tz->tzp->k_po = int_to_frac(sustainable_power) / + temperature_threshold; - tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / - temperature_threshold; + if (!tz->tzp->k_pu || force) + tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / + temperature_threshold; - k_i = tz->tzp->k_pu / 10; - tz->tzp->k_i = k_i > 0 ? k_i : 1; + if (!tz->tzp->k_i || force) { + k_i = tz->tzp->k_pu / 10; + tz->tzp->k_i = k_i > 0 ? k_i : 1; + } /* * The default for k_d and integral_cutoff is 0, so we can @@ -184,7 +193,8 @@ static u32 get_sustainable_power(struct thermal_zone_device *tz, /* Check if it's init value 0 or there was update via sysfs */ if (sustainable_power != params->sustainable_power) { estimate_pid_constants(tz, sustainable_power, - params->trip_switch_on, control_temp); + params->trip_switch_on, control_temp, + true); /* Do the estimation only once and make available in sysfs */ tz->tzp->sustainable_power = sustainable_power; @@ -662,7 +672,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz) if (!ret) estimate_pid_constants(tz, tz->tzp->sustainable_power, params->trip_switch_on, - trip.temperature); + trip.temperature, false); } reset_pid_controller(params);