From patchwork Tue Aug 27 15:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ionela Voinescu X-Patchwork-Id: 13779757 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C1C9C5472F for ; Tue, 27 Aug 2024 15:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=wO8Pdqf6O1c2oEKd7rhuSrSVyfxnZy72W7ho9pQA8kQ=; b=3AbTK3ipNhy9PVONZlGc6Ngzye grDcWIa8hBObq43Qerb2wH9o/Pz2IhPnC8KSIvKNCOgA9GlnvKuo+vq80+7MhvZx0bGkyz53pgsQ2 k0/FbQxf+eZpGcNZ4QwCoiCoq6QLggMIi3QtB3w71ZnI5dNQ/qTfK4BSWZZGz5I19YlkqYL+l2qFP 6p9Jq38JGsAhvoD/Ss+QTanRsQisTArGmNxrcq33ALG8tVPF36GjiXPsPd8sfPPLe+k0MGxXWZNxW iuLIh5kRVdtOkv9gAiZJTCjcj6mi2DSGkPCwWR3/yS0m9TlPfFFvhpwY/nr2db1B/D7KASuYer2pf 3elP5tIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siyS3-0000000Bx9S-1n0S; Tue, 27 Aug 2024 15:49:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siyRE-0000000Bx0Z-1neo for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 15:48:57 +0000 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 26E13DA7; Tue, 27 Aug 2024 08:49:20 -0700 (PDT) Received: from ionvoi01-desktop.cambridge.arm.com (ionvoi01-desktop.cambridge.arm.com [10.2.80.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6D65D3F762; Tue, 27 Aug 2024 08:48:52 -0700 (PDT) From: Ionela Voinescu To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com, catalin.marinas@arm.com, vincent.guittot@linaro.org, beata.michalska@arm.com Cc: rafael@kernel.org, viresh.kumar@linaro.org, dietmar.eggemann@arm.com, pierre.gondois@arm.com Subject: [PATCH] arch_topology: init capacity_freq_ref to 0 Date: Tue, 27 Aug 2024 16:48:18 +0100 Message-Id: <20240827154818.1195849-1-ionela.voinescu@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_084856_538038_143117C2 X-CRM114-Status: GOOD ( 11.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It's useful to have capacity_freq_ref initialized to 0 for users of arch_scale_freq_ref() to detect when capacity_freq_ref was not yet set. The only scenario affected by this change in the init value is when a cpufreq driver is never loaded. As a result, the only setter of a cpu scale factor remains the call of topology_normalize_cpu_scale() from parse_dt_topology(). There we cannot use the value 0 of capacity_freq_ref so we have to compensate for its uninitialized state. Signed-off-by: Ionela Voinescu Signed-off-by: Beata Michalska Reviewed-by: Vincent Guittot Reviewed-by: Sudeep Holla --- Hi, This patch was previously part of the patch-set at [1], but we thought it's best to separate the standalone patches in that set to make further review easier on the remaining topics. Based on v6.11-rc5 and tested on Juno with and without a cpufreq driver. [1] https://lore.kernel.org/lkml/20240603082154.3830591-2-beata.michalska@arm.com/ Thanks, Ionela. drivers/base/arch_topology.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 75fcb75d5515..c49ef1a712f4 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -28,7 +28,7 @@ static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data); static struct cpumask scale_freq_counters_mask; static bool scale_freq_invariant; -DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 1; +DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 0; EXPORT_PER_CPU_SYMBOL_GPL(capacity_freq_ref); static bool supports_scale_freq_counters(const struct cpumask *cpus) @@ -293,13 +293,15 @@ void topology_normalize_cpu_scale(void) capacity_scale = 1; for_each_possible_cpu(cpu) { - capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu); + capacity = raw_capacity[cpu] * + (per_cpu(capacity_freq_ref, cpu) ?: 1); capacity_scale = max(capacity, capacity_scale); } pr_debug("cpu_capacity: capacity_scale=%llu\n", capacity_scale); for_each_possible_cpu(cpu) { - capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu); + capacity = raw_capacity[cpu] * + (per_cpu(capacity_freq_ref, cpu) ?: 1); capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT, capacity_scale); topology_set_cpu_scale(cpu, capacity);