Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3184927rdh; Mon, 27 Nov 2023 08:09:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnFY9aQa1gtpOphuF75LJ2yLRX9bsICzVcumE5CACq/KeqFoj8PzpKlEVucLJ45ccnnz+G X-Received: by 2002:a17:90b:1a8e:b0:285:9893:b31a with SMTP id ng14-20020a17090b1a8e00b002859893b31amr8961993pjb.44.1701101363860; Mon, 27 Nov 2023 08:09:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701101363; cv=none; d=google.com; s=arc-20160816; b=NwlxJQ5ug4PbV/R7E9de6/Pu+kyOmeNlFTrPCwAsGi6EFT9PeGzvaCZUlwdke712Oo JrZjbToYrkTpsXJ9f+Benb2YMhTn1xh4chvfRCnxScmxz/K5div9UEDnWc0KcOAVHzMO 17TuONL7J8isNz9rQND4mxaL6zkKJRutTYzXxLjKUXxhe/KiHz3CKxvZ9VgSH2vJn0UN psOHgz9iJEPK04M89xfAEjQi7QkWRjcfxuJLqFcObLXmwVjfrXFFfVWtOKRGu0lyG8vA KflboFyLHlPQUgMqdXFAqj2aqwkIEyCUsfh6Mu31+Hb7SwQL8vWZGxbfUF7jYqaHhK3D Jx8A== 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=dZztWQ+uLXxw7B4x8zsdYupCBTws0iIRbymEKsEbv/I=; fh=p2JojXIkIJFr7BPcA5U5CLvPHM4tWxDZCp1Aam8B/LU=; b=UgmsEPIBrb7MyjA+dJEOSXeuBSJWMXq4fwLlWfxWwx9dCZNCG0x7D0cIxcg9Dl2xKo 89jjxHNB4Vx2tibt1SqUd7NeV79OOB7jRfXq+TQi5fQ/zZOzrkJ/HcGaH6jeLfMQXiWC sQpeXYtGIiboEpKdaKeqHBGfIAcpfTreM6w0q9dLAkWx8VyYJUcu6SAqIAtOYjCv6SnB d1wclN6pyG+fg1/ToNs085RQB4a3SrEnPUeJKpXKZtCycWgWOp507KbaXKAGeJiCpk6U Sf1NQvz2BdcnNnkSBe3NEedFwF5w4Jqe0bbnrdnYqljxXqraP/bgVupRBja1/H5ZXsUo 1zHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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. [23.128.96.36]) by mx.google.com with ESMTPS id j12-20020a17090a840c00b002850fa45ad1si9649755pjn.95.2023.11.27.08.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 08:09:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 966CE8145575; Mon, 27 Nov 2023 08:09:20 -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 S234333AbjK0QJB (ORCPT + 99 others); Mon, 27 Nov 2023 11:09:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234305AbjK0QJA (ORCPT ); Mon, 27 Nov 2023 11:09:00 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 091F599; Mon, 27 Nov 2023 08:09:07 -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 77779165C; Mon, 27 Nov 2023 08:09:54 -0800 (PST) Received: from e125905.cambridge.arm.com (e125905.cambridge.arm.com [10.1.194.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 26D123F6C4; Mon, 27 Nov 2023 08:09:05 -0800 (PST) From: Beata Michalska To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, sumitg@nvidia.com Cc: sudeep.holla@arm.covm, will@kernel.org, catalin.marinas@arm.com, viresh.kumar@linaro.org, rafael@kernel.org, ionela.voinescu@arm.com, yang@os.amperecomputing.com, linux-tegra@vger.kernel.org, Sudeep Holla Subject: [PATCH v2 1/2] arm64: Provide an AMU-based version of arch_freq_get_on_cpu Date: Mon, 27 Nov 2023 16:08:37 +0000 Message-Id: <20231127160838.1403404-2-beata.michalska@arm.com> In-Reply-To: <20231127160838.1403404-1-beata.michalska@arm.com> References: <20231127160838.1403404-1-beata.michalska@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]); Mon, 27 Nov 2023 08:09:20 -0800 (PST) With the Frequency Invariance Engine (FIE) being already wired up with sched tick and making use of relevant (core counter and constant counter) AMU counters, getting the current frequency for a given CPU on supported platforms, can be achieved by utilizing the frequency scale factor which reflects an average CPU frequency for the last tick period length. Suggested-by: Ionela Voinescu Signed-off-by: Beata Michalska Reviewed-by: Sudeep Holla --- Notes: Due to [1], if merged, there might be a need to modify the patch to accommodate changes [1] introduces: freq = cpufreq_get_hw_max_freq(cpu) >> SCHED_CAPACITY_SHIFT to freq = per_cpu(capacity_freq_ref, cpu); >> SCHED_CAPACITY_SHIFT [1] https://lore.kernel.org/linux-arm-kernel/20231121154349.GA1938@willie-the-truck/T/#mcb018d076dbce6f60ed2779634a9b6ffe622641e arch/arm64/kernel/topology.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 615c1a20129f..ae2445f6e7da 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -186,6 +187,44 @@ static void amu_scale_freq_tick(void) this_cpu_write(arch_freq_scale, (unsigned long)scale); } +unsigned int arch_freq_get_on_cpu(int cpu) +{ + unsigned int freq; + u64 scale; + + if (!cpumask_test_cpu(cpu, amu_fie_cpus)) + return 0; + + /* + * For those CPUs that are in full dynticks mode, try an alternative + * source for the counters (and thus freq scale), + * if available for given policy + */ + if (!housekeeping_cpu(cpu, HK_TYPE_TICK)) { + struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); + int ref_cpu = nr_cpu_ids; + + if (cpumask_intersects(housekeeping_cpumask(HK_TYPE_TICK), + policy->cpus)) + ref_cpu = cpumask_nth_and(cpu, policy->cpus, + housekeeping_cpumask(HK_TYPE_TICK)); + cpufreq_cpu_put(policy); + if (ref_cpu >= nr_cpu_ids) + return 0; + cpu = ref_cpu; + } + + /* + * Reversed computation to the one used to determine + * the arch_freq_scale value + * (see amu_scale_freq_tick for details) + */ + scale = per_cpu(arch_freq_scale, cpu); + freq = cpufreq_get_hw_max_freq(cpu) >> SCHED_CAPACITY_SHIFT; + freq *= scale; + return freq; +} + static struct scale_freq_data amu_sfd = { .source = SCALE_FREQ_SOURCE_ARCH, .set_freq_scale = amu_scale_freq_tick, -- 2.25.1