From patchwork Wed Oct 25 19:22:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB6D2C25B6B for ; Wed, 25 Oct 2023 19:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbjJYTVp (ORCPT ); Wed, 25 Oct 2023 15:21:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjJYTVo (ORCPT ); Wed, 25 Oct 2023 15:21:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E4BC137; Wed, 25 Oct 2023 12:21:42 -0700 (PDT) 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 05D521424; Wed, 25 Oct 2023 12:22:24 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2FF523F738; Wed, 25 Oct 2023 12:21:41 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 1/7] thermal: gov_power_allocator: Rename trip_max_desired_temperature Date: Wed, 25 Oct 2023 20:22:19 +0100 Message-Id: <20231025192225.468228-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Refactor the code and drop the long name for the trip point. There is a comment describing the field properly. Use shorten variable name so that allow to make the code cleaner a bit. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 40 ++++++++++++--------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 83d4f451b1a97..97a8a6e4e1b0b 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -59,9 +59,8 @@ static inline s64 div_frac(s64 x, s64 y) * governor switches on when this trip point is crossed. * If the thermal zone only has one passive trip point, * @trip_switch_on should be NULL. - * @trip_max_desired_temperature: last passive trip point of the thermal - * zone. The temperature we are - * controlling for. + * @trip_max: last passive trip point of the thermal zone. The + * temperature we are controlling for. */ struct power_allocator_params { bool allocated_tzp; @@ -69,7 +68,7 @@ struct power_allocator_params { s32 prev_err; u32 sustainable_power; const struct thermal_trip *trip_switch_on; - const struct thermal_trip *trip_max_desired_temperature; + const struct thermal_trip *trip_max; }; /** @@ -93,7 +92,7 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz) struct thermal_cooling_device *cdev = instance->cdev; u32 min_power; - if (instance->trip != params->trip_max_desired_temperature) + if (instance->trip != params->trip_max) continue; if (!cdev_is_power_actor(cdev)) @@ -379,8 +378,7 @@ static int allocate_power(struct thermal_zone_device *tz, { struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip_max_desired_temperature = - params->trip_max_desired_temperature; + const struct thermal_trip *trip_max = params->trip_max; u32 *req_power, *max_power, *granted_power, *extra_actor_power; u32 *weighted_req_power; u32 total_req_power, max_allocatable_power, total_weighted_req_power; @@ -390,7 +388,7 @@ static int allocate_power(struct thermal_zone_device *tz, num_actors = 0; total_weight = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if ((instance->trip == trip_max_desired_temperature) && + if ((instance->trip == trip_max) && cdev_is_power_actor(instance->cdev)) { num_actors++; total_weight += instance->weight; @@ -429,7 +427,7 @@ static int allocate_power(struct thermal_zone_device *tz, int weight; struct thermal_cooling_device *cdev = instance->cdev; - if (instance->trip != trip_max_desired_temperature) + if (instance->trip != trip_max) continue; if (!cdev_is_power_actor(cdev)) @@ -465,7 +463,7 @@ static int allocate_power(struct thermal_zone_device *tz, total_granted_power = 0; i = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if (instance->trip != trip_max_desired_temperature) + if (instance->trip != trip_max) continue; if (!cdev_is_power_actor(instance->cdev)) @@ -531,13 +529,13 @@ static void get_governor_trips(struct thermal_zone_device *tz, if (last_passive) { params->trip_switch_on = first_passive; - params->trip_max_desired_temperature = last_passive; + params->trip_max = last_passive; } else if (first_passive) { params->trip_switch_on = NULL; - params->trip_max_desired_temperature = first_passive; + params->trip_max = first_passive; } else { params->trip_switch_on = NULL; - params->trip_max_desired_temperature = last_active; + params->trip_max = last_active; } } @@ -556,8 +554,8 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update) list_for_each_entry(instance, &tz->thermal_instances, tz_node) { struct thermal_cooling_device *cdev = instance->cdev; - if (instance->trip != params->trip_max_desired_temperature || - (!cdev_is_power_actor(instance->cdev))) + if (instance->trip != params->trip_max || + !cdev_is_power_actor(instance->cdev)) continue; instance->target = 0; @@ -642,12 +640,10 @@ static int power_allocator_bind(struct thermal_zone_device *tz) get_governor_trips(tz, params); - if (params->trip_max_desired_temperature) { - int temp = params->trip_max_desired_temperature->temperature; - + if (params->trip_max) estimate_pid_constants(tz, tz->tzp->sustainable_power, - params->trip_switch_on, temp); - } + params->trip_switch_on, + params->trip_max->temperature); reset_pid_controller(params); @@ -688,7 +684,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, * We get called for every trip point but we only need to do * our calculations once */ - if (trip != params->trip_max_desired_temperature) + if (trip != params->trip_max) return 0; trip = params->trip_switch_on; @@ -702,7 +698,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, tz->passive = 1; - return allocate_power(tz, params->trip_max_desired_temperature->temperature); + return allocate_power(tz, params->trip_max->temperature); } static struct thermal_governor thermal_gov_power_allocator = { From patchwork Wed Oct 25 19:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F054AC25B6E for ; Wed, 25 Oct 2023 19:21:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjJYTVr (ORCPT ); Wed, 25 Oct 2023 15:21:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjJYTVq (ORCPT ); Wed, 25 Oct 2023 15:21:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 00231137; Wed, 25 Oct 2023 12:21:43 -0700 (PDT) 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 70B181474; Wed, 25 Oct 2023 12:22:25 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9A9EB3F738; Wed, 25 Oct 2023 12:21:42 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 2/7] thermal: gov_power_allocator: Setup trip points earlier Date: Wed, 25 Oct 2023 20:22:20 +0100 Message-Id: <20231025192225.468228-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Setup the trip points at the beginning of the binding function. This simplifies the code a bit and allows further cleaning. Add also the check if the last passive trip point is found and fail binding if not. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 97a8a6e4e1b0b..0dfc5b5ab5235 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -617,14 +617,24 @@ static int power_allocator_bind(struct thermal_zone_device *tz) int ret; struct power_allocator_params *params; - ret = check_power_actors(tz); - if (ret) - return ret; - params = kzalloc(sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; + get_governor_trips(tz, params); + if (!params->trip_max) { + dev_warn(&tz->device, "power_allocator: missing trip_max\n"); + kfree(params); + return -EINVAL; + } + + ret = check_power_actors(tz); + if (ret) { + dev_warn(&tz->device, "power_allocator: binding failed\n"); + kfree(params); + return ret; + } + if (!tz->tzp) { tz->tzp = kzalloc(sizeof(*tz->tzp), GFP_KERNEL); if (!tz->tzp) { @@ -638,12 +648,9 @@ static int power_allocator_bind(struct thermal_zone_device *tz) if (!tz->tzp->sustainable_power) dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); - get_governor_trips(tz, params); - - if (params->trip_max) - estimate_pid_constants(tz, tz->tzp->sustainable_power, - params->trip_switch_on, - params->trip_max->temperature); + estimate_pid_constants(tz, tz->tzp->sustainable_power, + params->trip_switch_on, + params->trip_max->temperature); reset_pid_controller(params); From patchwork Wed Oct 25 19:22:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38769C25B70 for ; Wed, 25 Oct 2023 19:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbjJYTVs (ORCPT ); Wed, 25 Oct 2023 15:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbjJYTVr (ORCPT ); Wed, 25 Oct 2023 15:21:47 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6A46E13A; Wed, 25 Oct 2023 12:21:45 -0700 (PDT) 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 DB2DB2F4; Wed, 25 Oct 2023 12:22:26 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1143A3F738; Wed, 25 Oct 2023 12:21:43 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 3/7] thermal: gov_power_allocator: Check the cooling devices only for trip_max Date: Wed, 25 Oct 2023 20:22:21 +0100 Message-Id: <20231025192225.468228-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The throttling logic takes care only for the last passive trip point and attached cooling devices to it. Therefore, there is no need to bail out if other trip points have a cooling device which is not a supported by IPA. Check the cooling devices only for the 'trip_max' during the binding. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 0dfc5b5ab5235..4b9ef04577a9a 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -578,6 +578,7 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update) * check_power_actors() - Check all cooling devices and warn when they are * not power actors * @tz: thermal zone to operate on + * @params: power allocator private data * * Check all cooling devices in the @tz and warn every time they are missing * power actor API. The warning should help to investigate the issue, which @@ -586,12 +587,16 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update) * Return: 0 on success, -EINVAL if any cooling device does not implement * the power actor API. */ -static int check_power_actors(struct thermal_zone_device *tz) +static int check_power_actors(struct thermal_zone_device *tz, + struct power_allocator_params *params) { struct thermal_instance *instance; int ret = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { + if (instance->trip != params->trip_max) + continue; + if (!cdev_is_power_actor(instance->cdev)) { dev_warn(&tz->device, "power_allocator: %s is not a power actor\n", instance->cdev->type); @@ -628,7 +633,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz) return -EINVAL; } - ret = check_power_actors(tz); + ret = check_power_actors(tz, params); if (ret) { dev_warn(&tz->device, "power_allocator: binding failed\n"); kfree(params); From patchwork Wed Oct 25 19:22:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22CCBC0032E for ; Wed, 25 Oct 2023 19:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230007AbjJYTVv (ORCPT ); Wed, 25 Oct 2023 15:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230354AbjJYTVt (ORCPT ); Wed, 25 Oct 2023 15:21:49 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DB8E013D; Wed, 25 Oct 2023 12:21:46 -0700 (PDT) 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 50C091424; Wed, 25 Oct 2023 12:22:28 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7ABB43F738; Wed, 25 Oct 2023 12:21:45 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 4/7] thermal: gov_power_allocator: Rearrange the order of variables Date: Wed, 25 Oct 2023 20:22:22 +0100 Message-Id: <20231025192225.468228-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Rearrange the order of variables in function and make them aligned with the standard order for the kernel coding style. Also, move some variables defined in nested code into the top of the function, to improve visibility off all variables used. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 39 ++++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 4b9ef04577a9a..79621b42ead38 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -84,13 +84,14 @@ struct power_allocator_params { */ static u32 estimate_sustainable_power(struct thermal_zone_device *tz) { - u32 sustainable_power = 0; - struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; + struct thermal_cooling_device *cdev; + struct thermal_instance *instance; + u32 sustainable_power = 0; + u32 min_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - struct thermal_cooling_device *cdev = instance->cdev; - u32 min_power; + cdev = instance->cdev; if (instance->trip != params->trip_max) continue; @@ -211,10 +212,10 @@ static u32 pid_controller(struct thermal_zone_device *tz, int control_temp, u32 max_allocatable_power) { + struct power_allocator_params *params = tz->governor_data; 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); @@ -373,20 +374,20 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, } } -static int allocate_power(struct thermal_zone_device *tz, - int control_temp) +static int allocate_power(struct thermal_zone_device *tz, int control_temp) { - struct thermal_instance *instance; + u32 total_req_power, max_allocatable_power, total_weighted_req_power; + u32 *req_power, *max_power, *granted_power, *extra_actor_power; struct power_allocator_params *params = tz->governor_data; const struct thermal_trip *trip_max = params->trip_max; - u32 *req_power, *max_power, *granted_power, *extra_actor_power; - u32 *weighted_req_power; - u32 total_req_power, max_allocatable_power, total_weighted_req_power; u32 total_granted_power, power_range; - int i, num_actors, total_weight, ret = 0; + struct thermal_cooling_device *cdev; + struct thermal_instance *instance; + u32 *weighted_req_power; + int i, weight, ret = 0; + int total_weight = 0; + int num_actors = 0; - num_actors = 0; - total_weight = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { if ((instance->trip == trip_max) && cdev_is_power_actor(instance->cdev)) { @@ -424,8 +425,7 @@ static int allocate_power(struct thermal_zone_device *tz, max_allocatable_power = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - int weight; - struct thermal_cooling_device *cdev = instance->cdev; + cdev = instance->cdev; if (instance->trip != trip_max) continue; @@ -547,12 +547,13 @@ static void reset_pid_controller(struct power_allocator_params *params) static void allow_maximum_power(struct thermal_zone_device *tz, bool update) { - struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; + struct thermal_cooling_device *cdev; + struct thermal_instance *instance; u32 req_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - struct thermal_cooling_device *cdev = instance->cdev; + cdev = instance->cdev; if (instance->trip != params->trip_max || !cdev_is_power_actor(instance->cdev)) @@ -619,8 +620,8 @@ static int check_power_actors(struct thermal_zone_device *tz, */ static int power_allocator_bind(struct thermal_zone_device *tz) { - int ret; struct power_allocator_params *params; + int ret; params = kzalloc(sizeof(*params), GFP_KERNEL); if (!params) From patchwork Wed Oct 25 19:22:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F560C25B6B for ; Wed, 25 Oct 2023 19:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233130AbjJYTVw (ORCPT ); Wed, 25 Oct 2023 15:21:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232076AbjJYTVu (ORCPT ); Wed, 25 Oct 2023 15:21:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55750181; Wed, 25 Oct 2023 12:21:48 -0700 (PDT) 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 C77EA1474; Wed, 25 Oct 2023 12:22:29 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E62753F738; Wed, 25 Oct 2023 12:21:46 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 5/7] thermal: gov_power_allocator: Use shorter variable when possible Date: Wed, 25 Oct 2023 20:22:23 +0100 Message-Id: <20231025192225.468228-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The 'cdev' pointer is initialed, so there is no need to use 'instance->cdev'. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 79621b42ead38..0f7f8278eacc5 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -560,7 +560,7 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update) continue; instance->target = 0; - mutex_lock(&instance->cdev->lock); + mutex_lock(&cdev->lock); /* * Call for updating the cooling devices local stats and avoid * periods of dozen of seconds when those have not been @@ -569,9 +569,9 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update) cdev->ops->get_requested_power(cdev, &req_power); if (update) - __thermal_cdev_update(instance->cdev); + __thermal_cdev_update(cdev); - mutex_unlock(&instance->cdev->lock); + mutex_unlock(&cdev->lock); } } From patchwork Wed Oct 25 19:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE811C25B6E for ; Wed, 25 Oct 2023 19:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233973AbjJYTVy (ORCPT ); Wed, 25 Oct 2023 15:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbjJYTVv (ORCPT ); Wed, 25 Oct 2023 15:21:51 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE0E9183; Wed, 25 Oct 2023 12:21:49 -0700 (PDT) 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 3B7962F4; Wed, 25 Oct 2023 12:22:31 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 663653F7C5; Wed, 25 Oct 2023 12:21:48 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 6/7] thermal: gov_power_allocator: Remove unneeded local variables Date: Wed, 25 Oct 2023 20:22:24 +0100 Message-Id: <20231025192225.468228-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There is no need to keep some variables. We have a shorter name variables in the governor private structure 'trip_max'. Remove the local 'trip_max' and 'ret' variables from the allocate_power(). This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 0f7f8278eacc5..e6d2f0fe8d2fd 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -379,17 +379,16 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) u32 total_req_power, max_allocatable_power, total_weighted_req_power; u32 *req_power, *max_power, *granted_power, *extra_actor_power; struct power_allocator_params *params = tz->governor_data; - const struct thermal_trip *trip_max = params->trip_max; u32 total_granted_power, power_range; struct thermal_cooling_device *cdev; struct thermal_instance *instance; u32 *weighted_req_power; - int i, weight, ret = 0; int total_weight = 0; int num_actors = 0; + int i, weight; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if ((instance->trip == trip_max) && + if ((instance->trip == params->trip_max) && cdev_is_power_actor(instance->cdev)) { num_actors++; total_weight += instance->weight; @@ -427,7 +426,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) list_for_each_entry(instance, &tz->thermal_instances, tz_node) { cdev = instance->cdev; - if (instance->trip != trip_max) + if (instance->trip != params->trip_max) continue; if (!cdev_is_power_actor(cdev)) @@ -463,7 +462,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) total_granted_power = 0; i = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if (instance->trip != trip_max) + if (instance->trip != params->trip_max) continue; if (!cdev_is_power_actor(instance->cdev)) @@ -484,7 +483,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) kfree(req_power); - return ret; + return 0; } /** From patchwork Wed Oct 25 19:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 13436597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C11EC0032E for ; Wed, 25 Oct 2023 19:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbjJYTV5 (ORCPT ); Wed, 25 Oct 2023 15:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234337AbjJYTVy (ORCPT ); Wed, 25 Oct 2023 15:21:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 462E0187; Wed, 25 Oct 2023 12:21:51 -0700 (PDT) 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 A5C5D1424; Wed, 25 Oct 2023 12:22:32 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.81.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D02F13F7C5; Wed, 25 Oct 2023 12:21:49 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH 7/7] thermal: gov_power_allocator: Clean needed variables at the beginning Date: Wed, 25 Oct 2023 20:22:25 +0100 Message-Id: <20231025192225.468228-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231025192225.468228-1-lukasz.luba@arm.com> References: <20231025192225.468228-1-lukasz.luba@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Rearrange the local variables setup. This improves the reading of the code and allows to better see the initial values; This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index e6d2f0fe8d2fd..785fff14223d8 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -376,16 +376,19 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, static int allocate_power(struct thermal_zone_device *tz, int control_temp) { - u32 total_req_power, max_allocatable_power, total_weighted_req_power; u32 *req_power, *max_power, *granted_power, *extra_actor_power; struct power_allocator_params *params = tz->governor_data; - u32 total_granted_power, power_range; struct thermal_cooling_device *cdev; struct thermal_instance *instance; + u32 total_weighted_req_power = 0; + u32 max_allocatable_power = 0; + u32 total_granted_power = 0; + u32 total_req_power = 0; u32 *weighted_req_power; + u32 power_range, weight; int total_weight = 0; int num_actors = 0; - int i, weight; + int i = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { if ((instance->trip == params->trip_max) && @@ -418,11 +421,6 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) extra_actor_power = &req_power[3 * num_actors]; weighted_req_power = &req_power[4 * num_actors]; - i = 0; - total_weighted_req_power = 0; - total_req_power = 0; - max_allocatable_power = 0; - list_for_each_entry(instance, &tz->thermal_instances, tz_node) { cdev = instance->cdev; @@ -459,7 +457,6 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) total_weighted_req_power, power_range, granted_power, extra_actor_power); - total_granted_power = 0; i = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { if (instance->trip != params->trip_max)