From patchwork Mon Nov 27 16:08:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beata Michalska X-Patchwork-Id: 747764 Authentication-Results: smtp.subspace.kernel.org; dkim=none 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> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, From patchwork Mon Nov 27 16:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beata Michalska X-Patchwork-Id: 749736 Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 630F0EA; Mon, 27 Nov 2023 08:09:11 -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 D36971688; Mon, 27 Nov 2023 08:09:58 -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 947263F6C4; Mon, 27 Nov 2023 08:09:09 -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 Subject: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq Date: Mon, 27 Nov 2023 16:08:38 +0000 Message-Id: <20231127160838.1403404-3-beata.michalska@arm.com> In-Reply-To: <20231127160838.1403404-1-beata.michalska@arm.com> References: <20231127160838.1403404-1-beata.michalska@arm.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sumit Gupta When available, use arch_freq_get_on_cpu to obtain current frequency (usually an average reported over given period of time) to better align the cpufreq's view on the current state of affairs. This also automatically pulls in the update for cpuinfo_cur_freq sysfs attribute, aligning it with the scaling_cur_freq one, and thus providing consistent view on relevant platforms. Signed-off-by: Sumit Gupta [BM: Subject & commit msg] Signed-off-by: Beata Michalska --- drivers/cpufreq/cpufreq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 8c4f9c2f9c44..109559438f45 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b { unsigned int new_freq; - new_freq = cpufreq_driver->get(policy->cpu); + new_freq = arch_freq_get_on_cpu(policy->cpu); + new_freq = new_freq ?: cpufreq_driver->get(policy->cpu); if (!new_freq) return 0;