From patchwork Fri Oct 9 13:58:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 11825859 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49F8A14D5 for ; Fri, 9 Oct 2020 13:59:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37A07222C3 for ; Fri, 9 Oct 2020 13:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387871AbgJIN7H (ORCPT ); Fri, 9 Oct 2020 09:59:07 -0400 Received: from foss.arm.com ([217.140.110.172]:51824 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgJIN7E (ORCPT ); Fri, 9 Oct 2020 09:59:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 724091063; Fri, 9 Oct 2020 06:59:03 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.51.133]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id ACF2C3F70D; Fri, 9 Oct 2020 06:59:01 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: daniel.lezcano@linaro.org, amitk@kernel.org, Dietmar.Eggemann@arm.com, lukasz.luba@arm.com, ionela.voinescu@arm.com Subject: [PATCH v3 1/2] thermal: power allocator: change the 'k_i' coefficient estimation Date: Fri, 9 Oct 2020 14:58:49 +0100 Message-Id: <20201009135850.14727-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201009135850.14727-1-lukasz.luba@arm.com> References: <20201009135850.14727-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Intelligent Power Allocation (IPA) is built around the PID controller concept. The initialization code tries to setup the environment based on the information available in DT or estimate the value based on minimum power reported by each of the cooling device. The estimation will have an impact on the PID controller behaviour via the related 'k_po', 'k_pu', 'k_i' coefficients and also on the power budget calculation. This change prevents the situation when 'k_i' is relatively big compared to 'k_po' and 'k_pu' values. This might happen when the estimation for 'sustainable_power' returned small value, thus 'k_po' and 'k_pu' are small. Reviewed-by: Ionela Voinescu Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index e566806f1550..aa35aa6c561c 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -132,6 +132,7 @@ static void estimate_pid_constants(struct thermal_zone_device *tz, int ret; int switch_on_temp; u32 temperature_threshold; + s32 k_i; ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp); if (ret) @@ -157,8 +158,11 @@ static void estimate_pid_constants(struct thermal_zone_device *tz, tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / temperature_threshold; - if (!tz->tzp->k_i || force) - tz->tzp->k_i = int_to_frac(10) / 1000; + 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 * leave them as they are. From patchwork Fri Oct 9 13:58:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 11825861 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62E7B1744 for ; Fri, 9 Oct 2020 13:59:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46BEF222D5 for ; Fri, 9 Oct 2020 13:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387889AbgJIN7H (ORCPT ); Fri, 9 Oct 2020 09:59:07 -0400 Received: from foss.arm.com ([217.140.110.172]:51832 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387861AbgJIN7G (ORCPT ); Fri, 9 Oct 2020 09:59:06 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B00C011B3; Fri, 9 Oct 2020 06:59:05 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.51.133]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CD8EF3F70D; Fri, 9 Oct 2020 06:59:03 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: daniel.lezcano@linaro.org, amitk@kernel.org, Dietmar.Eggemann@arm.com, lukasz.luba@arm.com, ionela.voinescu@arm.com Subject: [PATCH v3 2/2] thermal: power allocator: change how estimation code is called Date: Fri, 9 Oct 2020 14:58:50 +0100 Message-Id: <20201009135850.14727-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201009135850.14727-1-lukasz.luba@arm.com> References: <20201009135850.14727-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The sustainable power value might come from the Device Tree or can be estimated in run time. There is no need to estimate every time when the governor is called and temperature is high. Instead, store the estimated value and make it available via standard sysfs interface so it can be checked from the user-space. Re-invoke the estimation only in case the sustainable power was set to 0. Apart from that the PID coefficients are not going to be force updated thus can better handle sysfs settings. Signed-off-by: Lukasz Luba Reviewed-by: Ionela Voinescu --- v3: - changed estimate_pid_constants to estimate_tzp_constants and related comments - estimate the PID coefficients always together with sust. power - added print indicating that we are estimating sust. power and PID const. - don't use local variable 'sustainable_power' drivers/thermal/gov_power_allocator.c | 65 ++++++++++++--------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index aa35aa6c561c..e92a8d3ca5d4 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -96,6 +96,9 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz) if (instance->trip != params->trip_max_desired_temperature) continue; + if (!cdev_is_power_actor(cdev)) + continue; + if (cdev->ops->state2power(cdev, tz, instance->upper, &min_power)) continue; @@ -107,40 +110,37 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz) } /** - * estimate_pid_constants() - Estimate the constants for the PID controller + * estimate_tzp_constants() - Estimate sustainable power and PID constants * @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 * @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. - * Sustainable power is provided in case it was estimated. The - * estimated sustainable_power should not be stored in the - * thermal_zone_parameters so it has to be passed explicitly to this - * function. - * - * 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. + * This function is used to estimate the sustainable power and PID controller + * constants in struct thermal_zone_parameters. These estimations will then be + * available in the sysfs. */ -static void estimate_pid_constants(struct thermal_zone_device *tz, - u32 sustainable_power, int trip_switch_on, - int control_temp, bool force) +static void estimate_tzp_constants(struct thermal_zone_device *tz, + int trip_switch_on, int control_temp) { - int ret; - int switch_on_temp; u32 temperature_threshold; + int switch_on_temp; + bool force = false; + int ret; s32 k_i; + if (!tz->tzp->sustainable_power) { + tz->tzp->sustainable_power = estimate_sustainable_power(tz); + force = true; + dev_info(&tz->device, "power_allocator: estimating sust. power and PID constants\n"); + } + ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp); if (ret) switch_on_temp = 0; temperature_threshold = control_temp - switch_on_temp; /* - * estimate_pid_constants() tries to find appropriate default + * estimate_tzp_constants() tries to find appropriate default * values for thermal zones that don't provide them. If a * system integrator has configured a thermal zone with two * passive trip points at the same temperature, that person @@ -151,11 +151,11 @@ static void estimate_pid_constants(struct thermal_zone_device *tz, return; if (!tz->tzp->k_po || force) - tz->tzp->k_po = int_to_frac(sustainable_power) / + tz->tzp->k_po = int_to_frac(tz->tzp->sustainable_power) / temperature_threshold; if (!tz->tzp->k_pu || force) - tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / + tz->tzp->k_pu = int_to_frac(2 * tz->tzp->sustainable_power) / temperature_threshold; if (!tz->tzp->k_i || force) { @@ -193,19 +193,13 @@ static u32 pid_controller(struct thermal_zone_device *tz, { s64 p, i, d, power_range; s32 err, max_power_frac; - u32 sustainable_power; struct power_allocator_params *params = tz->governor_data; max_power_frac = int_to_frac(max_allocatable_power); - if (tz->tzp->sustainable_power) { - sustainable_power = tz->tzp->sustainable_power; - } else { - sustainable_power = estimate_sustainable_power(tz); - estimate_pid_constants(tz, sustainable_power, - params->trip_switch_on, control_temp, - true); - } + if (!tz->tzp->sustainable_power) + estimate_tzp_constants(tz, params->trip_switch_on, + control_temp); err = control_temp - tz->temperature; err = int_to_frac(err); @@ -244,7 +238,7 @@ static u32 pid_controller(struct thermal_zone_device *tz, power_range = p + i + d; /* feed-forward the known sustainable dissipatable power */ - power_range = sustainable_power + frac_to_int(power_range); + power_range = tz->tzp->sustainable_power + frac_to_int(power_range); power_range = clamp(power_range, (s64)0, (s64)max_allocatable_power); @@ -603,20 +597,19 @@ static int power_allocator_bind(struct thermal_zone_device *tz) get_governor_trips(tz, params); + tz->governor_data = params; + if (tz->trips > 0) { ret = tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature, &control_temp); if (!ret) - estimate_pid_constants(tz, tz->tzp->sustainable_power, - params->trip_switch_on, - control_temp, false); + estimate_tzp_constants(tz, params->trip_switch_on, + control_temp); } reset_pid_controller(params); - tz->governor_data = params; - return 0; free_params: