Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4647131rdb; Tue, 12 Dec 2023 05:48:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyewnv8hJG/iIdvXvG+ecnh1zNxVIiZpuc3pHiBDD0PFqkT6IaSNO9JswPYQaAiIpNBzqO X-Received: by 2002:a05:6a20:85a7:b0:191:309:1646 with SMTP id s39-20020a056a2085a700b0019103091646mr2841505pzd.20.1702388923983; Tue, 12 Dec 2023 05:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702388923; cv=none; d=google.com; s=arc-20160816; b=SEZtBwvTxqxvvoxEka3vnQVnbNqrlJmeQtmkulpCpDm9UWajC2gj0FIRKjrQfQrrgY /WBRYuWQnO8TBNh1x44jE957wspkk94IZ+6CT7xICbD5KS/oUazKyd4jIx9astfiQOFm 9oDGp24kDbI/OzHdKxdkSIQjuw+DKHCM93UAwQ0xQRx3jdFXE5UfQ48/kpFnxSiQLXXe XDYaJR5Dc+WCmneRqemYH9AE02s/NikPMcBbeDNVAZj+X11+l9MrG6VMU/Xbb+fLL4yY iKY63L2X90a+WGMoNWD9XSbGB73TJJIQ7Pmte/rQPiPCeepFsiat5OF8rkVmhfIyjYUj tTmw== 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=u+8SkwCW6q+/pPESNmKM83u351nZH1VNnqpbxkEhte4=; fh=8IgpUQ2T6XGOjA/qDosxdUSIIBz0a6nQ23NA8pgv1Tg=; b=ygjQ97/a7WL2jI3CWSGXpiyR+4ABOD+4Ouhfm527t/s63QWc0teUFJpoV1vcGCi5Jv 5pvCZLo/CxdXiNSjybeLmmkInO9kiI/D8XP2ktf6TgH+IlWn7cpPIhWwl/wUZyIYy/jN iT/OprKX7NonHFJNf2h/zjDZ6M+oCAAhvazfgEmfiswhjPkx+x7csQpELW5aMGggIuxh xlPERM7ahMbSve8BIKbCPNHf2cGkiy/2U3MED1QD5PnpzTl5T8A83eDgQwIah2/F6O+9 ltgLOkOGmwTWTQmgJR7VYgwT2nXzg/g0/abECSjNWd0Lx8QxoXHE+yeInpnY5usPiNSN IF4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id t6-20020a170902b20600b001d0bf9348e7si7608244plr.63.2023.12.12.05.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:48:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 74652803EBB0; Tue, 12 Dec 2023 05:48:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376374AbjLLNsM (ORCPT + 99 others); Tue, 12 Dec 2023 08:48:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376365AbjLLNr6 (ORCPT ); Tue, 12 Dec 2023 08:47:58 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 51FE2FD; Tue, 12 Dec 2023 05:48:04 -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 7A7C3143D; Tue, 12 Dec 2023 05:48:50 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.82.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EB1E03F738; Tue, 12 Dec 2023 05:48:02 -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 v2 5/8] thermal: gov_power_allocator: Refactor checks in divvy_up_power() Date: Tue, 12 Dec 2023 13:48:41 +0000 Message-Id: <20231212134844.1213381-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231212134844.1213381-1-lukasz.luba@arm.com> References: <20231212134844.1213381-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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:48:41 -0800 (PST) Simplify the code and remove one extra 'if' block. No intentional functional impact. Signed-off-by: Lukasz Luba --- drivers/thermal/gov_power_allocator.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 1a605fd9c8c6..574aa5822112 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -349,7 +349,8 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, u32 total_req_power, u32 power_range, u32 *granted_power, u32 *extra_actor_power) { - u32 extra_power, capped_extra_power; + u32 capped_extra_power = 0; + u32 extra_power = 0; int i; /* @@ -358,8 +359,6 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, if (!total_req_power) total_req_power = 1; - capped_extra_power = 0; - extra_power = 0; for (i = 0; i < num_actors; i++) { u64 req_range = (u64)req_power[i] * power_range; @@ -375,7 +374,7 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, capped_extra_power += extra_actor_power[i]; } - if (!extra_power) + if (!extra_power || !capped_extra_power) return; /* @@ -383,12 +382,13 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, * how far they are from the max */ extra_power = min(extra_power, capped_extra_power); - if (capped_extra_power > 0) - for (i = 0; i < num_actors; i++) { - u64 extra_range = (u64)extra_actor_power[i] * extra_power; - granted_power[i] += DIV_ROUND_CLOSEST_ULL(extra_range, - capped_extra_power); - } + + for (i = 0; i < num_actors; i++) { + u64 extra_range = (u64)extra_actor_power[i] * extra_power; + + granted_power[i] += DIV_ROUND_CLOSEST_ULL(extra_range, + capped_extra_power); + } } static int allocate_power(struct thermal_zone_device *tz, int control_temp) -- 2.25.1