From patchwork Sat Dec 23 16:09:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 182981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1752138dyi; Sat, 23 Dec 2023 08:11:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBCkxMT9mHhBFkD5AYi6AvtVYdnvppBYMdsUw+stVPYwDfrLQHvx3sQ1F59CKdCyqk4USM X-Received: by 2002:a17:906:518d:b0:a26:dc8e:effa with SMTP id y13-20020a170906518d00b00a26dc8eeffamr288836ejk.141.1703347915667; Sat, 23 Dec 2023 08:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703347915; cv=none; d=google.com; s=arc-20160816; b=zG78nALc9CzsEUhTIHmxzIAfiG8ZMqGfa6c10nEnMmB3DpQUiZGyii6fca/0LufSZx IEYBq3OdLm6+lZzE64hLCiQo465YFFUAAGO97KP5OeUCgb0V4UHcTh7QZFnttus3TNOz VGlpDKvQqZ29xS+utP6tFwFY91D8w/lLVn2ume2Ow0kChaWSrHHgZ0wllhQ8n5qt0DwY SVYuOWaaT2bq8NZtntFv2Txi/1dxntY94JNBDQMLLzyjpHB0xIh2R3VWXXykhN+fDlC6 uHEf6XapEkrpCZ+0ERf2KlJLv8vtJnptmiF5qSf6PcnN/csDhnSDSMW0taUJBaoQY0Wg VPCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=NwgA6LdUqAO3XVfytZbrjuE7sIziL0RwjlTrMLwIR6w=; fh=EEFTSBPQBZowE/8cmbl2wgNrzZpHJ8nkd4PrCb3LwiU=; b=Z89KKLbXQHVfj4VZNbblBkVpfmJ/IbwTVEr10c5uVy1wLvafbUXQeCTsWp+g3nZo7G LFEjB7jM4I66B/ciCFifymU07n99ErntE/FmDsDhWQ4MVcAGL42EekTHJuYK2nm8JQ5q j/0lqLQg2IITEvrbntabt6If9qouAIVzCSBvlz5SVfKED6k4Z0x4ukbc99D/13cy2kLj 3o6WZplxoOQttk5MfTJoipI9t4UaUNNJa9FdvxyQxXAQfJyurQGVAm1jzIu9KeQko8ao rAymGJRXewfHQt4XaUMmqc6nTYcchJhL+0LVBvWvxN3B4SFW5pHkcDhdcRvIWiaDQtZ8 X8Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="R2IpT6/n"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-10491-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10491-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o21-20020a17090637d500b00a2693064c33si2809578ejc.466.2023.12.23.08.11.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 08:11:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10491-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="R2IpT6/n"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-10491-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10491-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1719B1F223B1 for ; Sat, 23 Dec 2023 16:11:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 365BE224E3; Sat, 23 Dec 2023 16:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="R2IpT6/n"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qT4zZPFc" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C4F011CA3; Sat, 23 Dec 2023 16:09:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Sat, 23 Dec 2023 16:09:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1703347791; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NwgA6LdUqAO3XVfytZbrjuE7sIziL0RwjlTrMLwIR6w=; b=R2IpT6/nOIgu8teYJIo587WExji0zq2g6kWyrIldLrMSbv1Yw6DGBBHKyoSh7egcWaFxXN BX0PoyzXr2n+766A93BaWsmRQfk3MrN4j4NxLWEc89LXutUFyCaokspEloTzWSk7br+Hv7 NWQ9qJCL5RrlzOx6mYNs/YLG7b6ud6PmbrsVKXVs4HpdK4BWtSfYIybohGRkv8uERsv/7i bENv9wSt7aeUV6+3HmzRVQYpEn6nUD3jjUBzUS/lmkGzLYUMdvCsquXacCXCFZzoSnmUxn jx8rVSKMAHZqsCdgSVcPQOi5ftaRONF9GGP8geS8lFHBv3wobIHHSdCgzcM7qg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1703347791; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NwgA6LdUqAO3XVfytZbrjuE7sIziL0RwjlTrMLwIR6w=; b=qT4zZPFcjGbP6a6CgxbSsBugejfH+dql0SJAa8um2nohod809m5Fb2uQveigbj6n5RR8jv LLTJQAwFskQtljDw== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] arm64/amu: Use capacity_ref_freq() to set AMU ratio Cc: Vincent Guittot , Ingo Molnar , Sudeep Holla , Will Deacon , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231211104855.558096-8-vincent.guittot@linaro.org> References: <20231211104855.558096-8-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170334779091.398.13322969154683634281.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786089744101191610 X-GMAIL-MSGID: 1786089744101191610 The following commit has been merged into the sched/core branch of tip: Commit-ID: 1f023007f5e782bda19ad9104830c404fd622c5d Gitweb: https://git.kernel.org/tip/1f023007f5e782bda19ad9104830c404fd622c5d Author: Vincent Guittot AuthorDate: Mon, 11 Dec 2023 11:48:55 +01:00 Committer: Ingo Molnar CommitterDate: Sat, 23 Dec 2023 15:52:36 +01:00 arm64/amu: Use capacity_ref_freq() to set AMU ratio Use the new capacity_ref_freq() method to set the ratio that is used by AMU for computing the arch_scale_freq_capacity(). This helps to keep everything aligned using the same reference for computing CPUs capacity. The default value of the ratio (stored in per_cpu(arch_max_freq_scale)) ensures that arch_scale_freq_capacity() returns max capacity until it is set to its correct value with the cpu capacity and capacity_ref_freq(). Signed-off-by: Vincent Guittot Signed-off-by: Ingo Molnar Acked-by: Sudeep Holla Acked-by: Will Deacon Link: https://lore.kernel.org/r/20231211104855.558096-8-vincent.guittot@linaro.org --- arch/arm64/kernel/topology.c | 26 +++++++++++++------------- drivers/base/arch_topology.c | 12 +++++++++++- include/linux/arch_topology.h | 1 + 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 817d788..1a2c72f 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -82,7 +82,12 @@ int __init parse_acpi_topology(void) #undef pr_fmt #define pr_fmt(fmt) "AMU: " fmt -static DEFINE_PER_CPU_READ_MOSTLY(unsigned long, arch_max_freq_scale); +/* + * Ensure that amu_scale_freq_tick() will return SCHED_CAPACITY_SCALE until + * the CPU capacity and its associated frequency have been correctly + * initialized. + */ +static DEFINE_PER_CPU_READ_MOSTLY(unsigned long, arch_max_freq_scale) = 1UL << (2 * SCHED_CAPACITY_SHIFT); static DEFINE_PER_CPU(u64, arch_const_cycles_prev); static DEFINE_PER_CPU(u64, arch_core_cycles_prev); static cpumask_var_t amu_fie_cpus; @@ -112,14 +117,14 @@ static inline bool freq_counters_valid(int cpu) return true; } -static int freq_inv_set_max_ratio(int cpu, u64 max_rate, u64 ref_rate) +void freq_inv_set_max_ratio(int cpu, u64 max_rate) { - u64 ratio; + u64 ratio, ref_rate = arch_timer_get_rate(); if (unlikely(!max_rate || !ref_rate)) { - pr_debug("CPU%d: invalid maximum or reference frequency.\n", + WARN_ONCE(1, "CPU%d: invalid maximum or reference frequency.\n", cpu); - return -EINVAL; + return; } /* @@ -139,12 +144,10 @@ static int freq_inv_set_max_ratio(int cpu, u64 max_rate, u64 ref_rate) ratio = div64_u64(ratio, max_rate); if (!ratio) { WARN_ONCE(1, "Reference frequency too low.\n"); - return -EINVAL; + return; } - per_cpu(arch_max_freq_scale, cpu) = (unsigned long)ratio; - - return 0; + WRITE_ONCE(per_cpu(arch_max_freq_scale, cpu), (unsigned long)ratio); } static void amu_scale_freq_tick(void) @@ -195,10 +198,7 @@ static void amu_fie_setup(const struct cpumask *cpus) return; for_each_cpu(cpu, cpus) { - if (!freq_counters_valid(cpu) || - freq_inv_set_max_ratio(cpu, - cpufreq_get_hw_max_freq(cpu) * 1000ULL, - arch_timer_get_rate())) + if (!freq_counters_valid(cpu)) return; } diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 1aa76b5..5aaa086 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -344,6 +344,10 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) return !ret; } +void __weak freq_inv_set_max_ratio(int cpu, u64 max_rate) +{ +} + #ifdef CONFIG_ACPI_CPPC_LIB #include @@ -381,6 +385,9 @@ void topology_init_cpu_capacity_cppc(void) } for_each_possible_cpu(cpu) { + freq_inv_set_max_ratio(cpu, + per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); + capacity = raw_capacity[cpu]; capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT, capacity_scale); @@ -422,8 +429,11 @@ init_cpu_capacity_callback(struct notifier_block *nb, cpumask_andnot(cpus_to_visit, cpus_to_visit, policy->related_cpus); - for_each_cpu(cpu, policy->related_cpus) + for_each_cpu(cpu, policy->related_cpus) { per_cpu(capacity_freq_ref, cpu) = policy->cpuinfo.max_freq; + freq_inv_set_max_ratio(cpu, + per_cpu(capacity_freq_ref, cpu) * HZ_PER_KHZ); + } if (cpumask_empty(cpus_to_visit)) { topology_normalize_cpu_scale(); diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index 32c24ff..a63d61c 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -99,6 +99,7 @@ void update_siblings_masks(unsigned int cpu); void remove_cpu_topology(unsigned int cpuid); void reset_cpu_topology(void); int parse_acpi_topology(void); +void freq_inv_set_max_ratio(int cpu, u64 max_rate); #endif #endif /* _LINUX_ARCH_TOPOLOGY_H_ */