Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1480745rdb; Sat, 23 Dec 2023 08:10:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHijdg25QT2C2We2gBRiJKniVNV+8NqycLx4LWJ8g0YKENNtYTDlh00Jq21vy3XjAgLBXAV X-Received: by 2002:a17:90a:a787:b0:28b:e1dd:1d44 with SMTP id f7-20020a17090aa78700b0028be1dd1d44mr1749493pjq.33.1703347857984; Sat, 23 Dec 2023 08:10:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703347857; cv=none; d=google.com; s=arc-20160816; b=N3DeTyZCq1TDvY17hqAOU2nztil6c8iM2XDjrGbx2QICouvx2KhgBv/EuRWvmhKTjA uRrfWk06PUuSqPv/dZfPboIA/MU1Y5GtP3XdYub9NyvmHumrzUQvL6mWEl7V8zkU++uH Gmk0aEE8//ADQiUR1CJGr9ErmwvTHWv/y/v29OmsNHFvN53erIl4GlyhZGddkEc3vn9b CHmsYRUy0HVWcyo2csVQTOgj3bjJcJP7m48j/fEZdxh3Kz3evKJ7+9BeybdPB3YM+ROC kPWiWhnNwavvBxi+WBaIwaJexEALTjdeSy6565jMSaDL65TDRyR++v82lsIIjgnLKRCV /Wew== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10491-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id lr13-20020a17090b4b8d00b0028bec85dbbasi4935075pjb.149.2023.12.23.08.10.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 08:10:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10491-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10491-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7570C28314C for ; Sat, 23 Dec 2023 16:10:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41DF3199D1; Sat, 23 Dec 2023 16:10:02 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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_ */