Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3498385ybl; Sun, 12 Jan 2020 19:49:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwvo4RNiTWxe2LVOfk/kbVOjPqgRQ35T3DTXe/rCMzCeHtzMU4Xe577as9h5EMpAaJrRgu5 X-Received: by 2002:aca:c0c5:: with SMTP id q188mr10543951oif.169.1578887386163; Sun, 12 Jan 2020 19:49:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578887386; cv=none; d=google.com; s=arc-20160816; b=eD5UeNIcZhLIshgLBR7Blv6y50L30kgUWF40G9b0Mmeghfq0Gwa3KnuUiayUA3xclk qosgtnfpcOJk9sEQO2uJmGAz6KzZx7R9llHjIywRxdL+DoSGwFgFnEeFuJCYXhW3Enjw Gcpn46gF91SzEXVF2rtedC7Se5/UCarQg6hVGOYj+Xl/LXGN0Lbylckbc+Vpj55JLVy/ doFKtOZlR7hJcYZ16DIOpCpSbg54st+TlnpYrdBjVY8L1QSz6LPnDNdi8ajDcZUwpRHK j6oGz23ARJ8WvYFpLFDnR8S60BaUMQlYufOIZQs8rU2T0W+AyWweEqpknBeNl+uzoBmi dpUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=VRfrNdDqgdfcWVRsp3C58o/LxIyFFBdPRoHuikMsGXc=; b=VgTXOt3tZgalCTE3dWKB6/VmMO7zK+Oh5gc9lOs1eMFcUavMhAHaR5y5RR5j+AT6/+ 2nr8eO4Re0GCVrM7wd1kxXzRCPuNb95cyiT7t+36Pw+vgAY3ThXc0JdxngZWJH38taHj N2fyt+kxj//hO69KJLkwdziu59g8N7a2PaHP9yOG1n16YGgB11R6oFX7qPP1bAh6KEw8 ltH/k6QhBYs7nu2nNQTPzQTKOY19+qfWdGZ6tLq2G9N01lTojPAKZzCZwX4i1kcW9yeC 4O0oD7p+auTVbyxsr7a+oa8CyysIGqOGhRwW0Foc/hj/viqLqDmTAmAR6rSZocxCbpDp LOLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si5105210oic.251.2020.01.12.19.49.34; Sun, 12 Jan 2020 19:49:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387475AbgAMDsf (ORCPT + 99 others); Sun, 12 Jan 2020 22:48:35 -0500 Received: from lucky1.263xmail.com ([211.157.147.133]:38606 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387415AbgAMDse (ORCPT ); Sun, 12 Jan 2020 22:48:34 -0500 Received: from localhost (unknown [192.168.167.235]) by lucky1.263xmail.com (Postfix) with ESMTP id CD0458AA05; Mon, 13 Jan 2020 11:48:28 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (postfix) whith ESMTP id P25811T139966185199360S1578887298528581_; Mon, 13 Jan 2020 11:48:28 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: jeffy.chen@rock-chips.com X-SENDER: cjf@rock-chips.com X-LOGIN-NAME: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Jeffy Chen To: linux-kernel@vger.kernel.org Cc: Heiko Stuebner , Brian Norris , Robin Murphy , Douglas Anderson , sudeep.holla@arm.com, Marc Zyngier , dietmar.eggemann@arm.com, Jeffy Chen , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH v2] arch_topology: Adjust initial CPU capacities with current freq Date: Mon, 13 Jan 2020 11:48:15 +0800 Message-Id: <20200113034815.25924-1-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The CPU freqs are not supposed to change before cpufreq policies properly registered, meaning that they should be used to calculate the initial CPU capacities. Doing this helps choosing the best CPU during early boot, especially for the initramfs decompressing. There's no functional changes for non-clk CPU DVFS mechanism. Signed-off-by: Jeffy Chen --- Changes in v2: Fix u64 div compile error on 32-bit platforms, and be compatible with non-clk CPU DVFS mechanism. drivers/base/arch_topology.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 1eb81f113786..54a48dfafd2f 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -94,7 +94,7 @@ static void update_topology_flags_workfn(struct work_struct *work) update_topology = 0; } -static u32 capacity_scale; +static DEFINE_PER_CPU(u32, freq_factor) = 1; static u32 *raw_capacity; static int free_raw_capacity(void) @@ -108,17 +108,23 @@ static int free_raw_capacity(void) void topology_normalize_cpu_scale(void) { u64 capacity; + u64 capacity_scale; int cpu; if (!raw_capacity) return; - pr_debug("cpu_capacity: capacity_scale=%u\n", capacity_scale); + capacity_scale = 1; for_each_possible_cpu(cpu) { - pr_debug("cpu_capacity: cpu=%d raw_capacity=%u\n", - cpu, raw_capacity[cpu]); - capacity = (raw_capacity[cpu] << SCHED_CAPACITY_SHIFT) - / capacity_scale; + capacity = raw_capacity[cpu] * per_cpu(freq_factor, cpu); + 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(freq_factor, cpu); + capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT, + capacity_scale); topology_set_cpu_scale(cpu, capacity); pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n", cpu, topology_get_cpu_scale(cpu)); @@ -127,6 +133,7 @@ void topology_normalize_cpu_scale(void) bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) { + struct clk *cpu_clk; static bool cap_parsing_failed; int ret; u32 cpu_capacity; @@ -146,10 +153,22 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) return false; } } - capacity_scale = max(cpu_capacity, capacity_scale); raw_capacity[cpu] = cpu_capacity; pr_debug("cpu_capacity: %pOF cpu_capacity=%u (raw)\n", cpu_node, raw_capacity[cpu]); + + /* + * Update freq_factor for calculating early boot cpu capacities. + * For non-clk CPU DVFS mechanism, there's no way to get the + * frequency value now, assuming they are running at the same + * frequency (by keeping the initial freq_factor value). + */ + cpu_clk = of_clk_get(cpu_node, 0); + if (!PTR_ERR_OR_ZERO(cpu_clk)) + per_cpu(freq_factor, cpu) = + clk_get_rate(cpu_clk) / 1000; + + clk_put(cpu_clk); } else { if (raw_capacity) { pr_err("cpu_capacity: missing %pOF raw capacity\n", @@ -188,11 +207,8 @@ 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) { - raw_capacity[cpu] = topology_get_cpu_scale(cpu) * - policy->cpuinfo.max_freq / 1000UL; - capacity_scale = max(raw_capacity[cpu], capacity_scale); - } + for_each_cpu(cpu, policy->related_cpus) + per_cpu(freq_factor, cpu) = policy->cpuinfo.max_freq / 1000; if (cpumask_empty(cpus_to_visit)) { topology_normalize_cpu_scale(); -- 2.11.0