Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp907134rdb; Wed, 6 Dec 2023 03:31:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyW4HI6CQj9nJ7bPRjdKkQNNkyRes/+dHZediQRS6g//lVQlHHRkyjNyC2GNiYWtuo7a7T X-Received: by 2002:a05:6a20:2449:b0:18f:97c:824f with SMTP id t9-20020a056a20244900b0018f097c824fmr562420pzc.89.1701862282828; Wed, 06 Dec 2023 03:31:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701862282; cv=none; d=google.com; s=arc-20160816; b=X5v7NfL2ZDPI01JwupcPM5gpO/Ut51MpV4VjWfmLtQmC5mPOUAEr8N8AjLNbyfkBps GaJs5Qy9piZ6W21BYgCXzh/2Aiupl2VNLi1bftIrmertgwEu1YZxYlkWjcnZhMDiyVSw zRZzGan6Gpr9ztG2QtZjnB6AkzpAZiyJqOFVU6Aedf/vkyl9vYggSJu/aAz4q+8NqUYv gh90f7mFhAZKOBTGB6RzMeJuUF6+c/CHzVal6l+ZPbD0e6rmiTf2hIG4upEjAfWXDUxD sJknDZ5AGcZ3Q/q2YtFCED4CYodQKS9f0UiEpy6+BAQijP6bob/9DQB2qNgCc45FAdck /nzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LsN4aPG3Pf89eb6LgMAFkb+QZnSDjkYbzk/bHRl+RW4=; fh=8IgpUQ2T6XGOjA/qDosxdUSIIBz0a6nQ23NA8pgv1Tg=; b=dO49vIVQJzUpUoNp9lqGp8XCl0V0ftXvKmPgOApv4j57IbWytJ4QuHcHbN62knh+Ql C7EbJ1SC8ANteJQrmBT7zHsgAIRH5bG9XfoznupMPD8nFWV6kCemhW+nj7DvnxHSSmch sVnSKuogE9SEIzHGaJNfnn3SXWxfkXJa6Igl4dvMH/NZhkMAxzXi4Y4h+SXvVJnLRJco BozHywUYUXRbxncMvTRiFEfqAAnIVkjoQEAaWiPx6L5H9mb9Wc5b4XnJaTwDaZ+D5QrB R8pfj/IU3uYuz7lZEs/u0BMPIIABL80BbVuWQTu0inJTLB7V+vE5mBykVr5TWjuRLdYp NAwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id v5-20020a17090a458500b002867c645d4bsi6818470pjg.13.2023.12.06.03.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:31:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id CC95B81A8A8F; Wed, 6 Dec 2023 03:31:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377705AbjLFLa5 (ORCPT + 99 others); Wed, 6 Dec 2023 06:30:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377585AbjLFLao (ORCPT ); Wed, 6 Dec 2023 06:30:44 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62AE7D42; Wed, 6 Dec 2023 03:30:50 -0800 (PST) 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 2B402C15; Wed, 6 Dec 2023 03:31:36 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.1.114]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E01B03F5A1; Wed, 6 Dec 2023 03:30:48 -0800 (PST) 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/5] thermal: gov_power_allocator: Simplify checks for valid power actor Date: Wed, 6 Dec 2023 11:31:37 +0000 Message-Id: <20231206113138.3576492-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206113138.3576492-1-lukasz.luba@arm.com> References: <20231206113138.3576492-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 03:31:20 -0800 (PST) There is a need to check if the cooling device in the thermal zone supports IPA callback and is set for control trip point. Refactor the code which validates the power actor capabilities and make it more consistent in all places. No intentional functional impact. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 41 +++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 1b55d00fc12b..8f2d2ee3def0 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -85,6 +85,13 @@ struct power_allocator_params { u32 *weighted_req_power; }; +static bool power_actor_is_valid(struct power_allocator_params *params, + struct thermal_instance *instance) +{ + return ((instance->trip == params->trip_max) && + cdev_is_power_actor(instance->cdev)); +} + /** * estimate_sustainable_power() - Estimate the sustainable power of a thermal zone * @tz: thermal zone we are operating in @@ -105,14 +112,10 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz) u32 min_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - cdev = instance->cdev; - - if (instance->trip != params->trip_max) - continue; - - if (!cdev_is_power_actor(cdev)) + if (!power_actor_is_valid(params, instance)) continue; + cdev = instance->cdev; if (cdev->ops->state2power(cdev, instance->upper, &min_power)) continue; @@ -407,8 +410,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) return -ENODEV; list_for_each_entry(instance, &tz->thermal_instances, tz_node) - if ((instance->trip == params->trip_max) && - cdev_is_power_actor(instance->cdev)) + if (power_actor_is_valid(params, instance)) total_weight += instance->weight; /* Clean all buffers for new power estimations */ @@ -421,14 +423,10 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) weighted_req_power = params->weighted_req_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - cdev = instance->cdev; - - if (instance->trip != params->trip_max) - continue; - - if (!cdev_is_power_actor(cdev)) + if (!power_actor_is_valid(params, instance)) continue; + cdev = instance->cdev; if (cdev->ops->get_requested_power(cdev, &req_power[i])) continue; @@ -458,10 +456,7 @@ static int allocate_power(struct thermal_zone_device *tz, int control_temp) i = 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)) + if (!power_actor_is_valid(params, instance)) continue; power_actor_set_power(instance->cdev, instance, @@ -546,12 +541,11 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update) u32 req_power; list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - cdev = instance->cdev; - - if (instance->trip != params->trip_max || - !cdev_is_power_actor(instance->cdev)) + if (!power_actor_is_valid(params, instance)) continue; + cdev = instance->cdev; + instance->target = 0; mutex_lock(&cdev->lock); /* @@ -661,8 +655,7 @@ static void power_allocator_instances_update(struct thermal_zone_device *tz) int num_actors = 0; list_for_each_entry(instance, &tz->thermal_instances, tz_node) - if ((instance->trip == params->trip_max) && - cdev_is_power_actor(instance->cdev)) + if (power_actor_is_valid(params, instance)) num_actors++; if (num_actors == params->num_actors) -- 2.25.1