From patchwork Fri Oct 27 08:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp436613vqb; Fri, 27 Oct 2023 01:04:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1gIQbqoNJIgTZNDdKK0W5cxWVtfPYQh6QkdA4UzCiOnLt9ogdNDQwbt9jBI6HQBLTY+oM X-Received: by 2002:a25:3c8:0:b0:d09:34f4:6698 with SMTP id 191-20020a2503c8000000b00d0934f46698mr1464339ybd.36.1698393882054; Fri, 27 Oct 2023 01:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698393882; cv=none; d=google.com; s=arc-20160816; b=fv0QbGRtV9XHCVmFCjfQEKuutbqCLZ340QncibT8pzl+AvK6FS4v9WO3Ebw7+OqVvT A3FyqVb91unjo2ohsO/4DjXHEiplYMEpREElbdSTwUgWLer03sI0cH5KH2Qe5/A2N5ZE LuZo8M3r2iW+gVKDj++579WkuinWyTsKDEhWAa87F/yHurFgEYbYG9wce+hmVxoVY0jp aeS5fhNVnvmXyxqBoI8GkJV9kiA6j2LJVTY9faUyLIKfAwsFykFl0tKti8cd2wfYx7j4 W56ia02+eApB2Oncux9SiUIxZ9RgBNUXoVcbYQ3Uw+GIq3zOPr6CecxMzn1YfLd+IaFq fVQA== 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 :dkim-signature; bh=YoGuGIrA5tCLXnggkowip+pd7ImH8hiKVp+aIFtuuzw=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=Eh34rpjLHXDxcOMjVv1yrc0UexZBv5UkfNjrX/2Sn0Rvxs3sltjVsRoXMK1bzQ9P7T m6za1tmOB3si2l5O1XX7TjimAwWGounTZh92qayhgAUnjAnUhBnvaJ+ofv22T1Dl5ztI m5N78JyVRpXNPRPCOP6u8WzTgU6N3cCbISRtbqpMLO7AuDLlN26kjhnq7JOUlhV16isW J5Fz00s8cSruj5giO14JJmOdjuYMBlHkn98QS9FjMEh5gkyroD4Yj14GdK/yarNwjaCu xbFWIgIG9YkXYaZupSh2oh/AzwGUEnE267f+w0oD4HbdlllU53rpw9bZN5Ba/blPBC9J SPwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yKfD5qis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id z130-20020a254c88000000b00da0419b31c3si1509444yba.77.2023.10.27.01.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yKfD5qis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5F8D8809AFE6; Fri, 27 Oct 2023 01:04:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235032AbjJ0IEN (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbjJ0IEM (ORCPT ); Fri, 27 Oct 2023 04:04:12 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE6A71BD for ; Fri, 27 Oct 2023 01:04:08 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c5210a1515so26558281fa.0 for ; Fri, 27 Oct 2023 01:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393847; x=1698998647; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YoGuGIrA5tCLXnggkowip+pd7ImH8hiKVp+aIFtuuzw=; b=yKfD5qisFx1wsuO34RKVaJz1cOeQeHmX5AuQ/GFmdpv2hVaHpNBrDDc/ndJdlxfGxG uBfP7wkvegT4SU72wzHvMhfYhbNkZzr8SxCdbXTUbZjmZWh6dDyFF/c+5S25j9CsykE7 yhAKz5QPobMYgyWIn3pkuAqMgsuoCSbX/t9tOvRQOFHyDQtU29fwucP7fhRy4Tw8d1mx 6jRBWi5e1X+NJwPp6WywvuNkd44ISLnDQ5YJTAjr8C2hOenkDWjhuDWX11cSn6XACmL7 rJFU2Xl2K4y0i8vFuu6Q/KzOnJF+xeCkpDXL5XlaPGp15C+6wUonryFm1WgXljpENpg+ yxFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393847; x=1698998647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YoGuGIrA5tCLXnggkowip+pd7ImH8hiKVp+aIFtuuzw=; b=cJbvgJcjRPsR9aYVrxxtwV937KFaXsRPdweGmlRaDkX4rlzh6hJnSXgv28IvUIrUOq DCFJ93Kp6aI19E/WYlLh4Y9VIi+B+pANecuvVRq1sBq7vT3W1OqSaoJ+pqqdMJTgN3gn 0bkk2biApwHpQX8lOmvsX6CrMMZ1Uae07ark5hQCrU8RKXQ8myw9QXyXHl9AKd+MaknJ L3T7s9kb7/FbRNODBTXt/wyEQxRtgy+u6ev9561TS+TVmf+9pnXXSwqz54CzAk1L0L9z +w7fCjVVebRmuksZhIUM9Y83pTNqsYPDcB6TMy72zlm1fbH/ZBYrqZdbvjx0srC5/NUh PhWA== X-Gm-Message-State: AOJu0Yw1rarxRmxY1kZMekMFbTz4D6qj7KjvJPdwGRYVLnp4UAgZvicm tGVncWSkizuG3ChC0gaXlSM7ig== X-Received: by 2002:a2e:9943:0:b0:2c5:21e3:f21a with SMTP id r3-20020a2e9943000000b002c521e3f21amr1406134ljj.53.1698393846645; Fri, 27 Oct 2023 01:04:06 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:05 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 1/7] topology: add a new arch_scale_freq_reference Date: Fri, 27 Oct 2023 10:03:54 +0200 Message-Id: <20231027080400.56703-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:04:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895063029631570 X-GMAIL-MSGID: 1780895063029631570 Create a new method to get a unique and fixed max frequency. Currently cpuinfo.max_freq or the highest (or last) state of performance domain are used as the max frequency when computing the frequency for a level of utilization but: - cpuinfo_max_freq can change at runtime. boost is one example of such change. - cpuinfo.max_freq and last item of the PD can be different leading to different results between cpufreq and energy model. We need to save the reference frequency that has been used when computing the CPUs capacity and use this fixed and coherent value to convert between frequency and CPU's capacity. In fact, we already save the frequency that has been used when computing the capacity of each CPU. We extend the precision to save khZ instead of Mhz currently and we modify the type to be aligned with other variables used when converting frequency to capacity and the other way. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba --- arch/arm/include/asm/topology.h | 1 + arch/arm64/include/asm/topology.h | 1 + arch/riscv/include/asm/topology.h | 1 + drivers/base/arch_topology.c | 29 ++++++++++++++--------------- include/linux/arch_topology.h | 7 +++++++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topology.h index c7d2510e5a78..853c4f81ba4a 100644 --- a/arch/arm/include/asm/topology.h +++ b/arch/arm/include/asm/topology.h @@ -13,6 +13,7 @@ #define arch_set_freq_scale topology_set_freq_scale #define arch_scale_freq_capacity topology_get_freq_scale #define arch_scale_freq_invariant topology_scale_freq_invariant +#define arch_scale_freq_ref topology_get_freq_ref #endif /* Replace task scheduler's default cpu-invariant accounting */ diff --git a/arch/arm64/include/asm/topology.h b/arch/arm64/include/asm/topology.h index 9fab663dd2de..a323b109b9c4 100644 --- a/arch/arm64/include/asm/topology.h +++ b/arch/arm64/include/asm/topology.h @@ -23,6 +23,7 @@ void update_freq_counters_refs(void); #define arch_set_freq_scale topology_set_freq_scale #define arch_scale_freq_capacity topology_get_freq_scale #define arch_scale_freq_invariant topology_scale_freq_invariant +#define arch_scale_freq_ref topology_get_freq_ref #ifdef CONFIG_ACPI_CPPC_LIB #define arch_init_invariance_cppc topology_init_cpu_capacity_cppc diff --git a/arch/riscv/include/asm/topology.h b/arch/riscv/include/asm/topology.h index e316ab3b77f3..61183688bdd5 100644 --- a/arch/riscv/include/asm/topology.h +++ b/arch/riscv/include/asm/topology.h @@ -9,6 +9,7 @@ #define arch_set_freq_scale topology_set_freq_scale #define arch_scale_freq_capacity topology_get_freq_scale #define arch_scale_freq_invariant topology_scale_freq_invariant +#define arch_scale_freq_ref topology_get_freq_ref /* Replace task scheduler's default cpu-invariant accounting */ #define arch_scale_cpu_capacity topology_get_cpu_scale diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index b741b5ba82bd..9a073c2d2086 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -19,6 +19,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -26,7 +27,8 @@ static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data); static struct cpumask scale_freq_counters_mask; static bool scale_freq_invariant; -static DEFINE_PER_CPU(u32, freq_factor) = 1; +DEFINE_PER_CPU(unsigned long, capacity_ref_freq) = 1; +EXPORT_PER_CPU_SYMBOL_GPL(capacity_ref_freq); static bool supports_scale_freq_counters(const struct cpumask *cpus) { @@ -170,9 +172,9 @@ DEFINE_PER_CPU(unsigned long, thermal_pressure); * operating on stale data when hot-plug is used for some CPUs. The * @capped_freq reflects the currently allowed max CPUs frequency due to * thermal capping. It might be also a boost frequency value, which is bigger - * than the internal 'freq_factor' max frequency. In such case the pressure - * value should simply be removed, since this is an indication that there is - * no thermal throttling. The @capped_freq must be provided in kHz. + * than the internal 'capacity_ref_freq' max frequency. In such case the + * pressure value should simply be removed, since this is an indication that + * there is no thermal throttling. The @capped_freq must be provided in kHz. */ void topology_update_thermal_pressure(const struct cpumask *cpus, unsigned long capped_freq) @@ -183,10 +185,7 @@ void topology_update_thermal_pressure(const struct cpumask *cpus, cpu = cpumask_first(cpus); max_capacity = arch_scale_cpu_capacity(cpu); - max_freq = per_cpu(freq_factor, cpu); - - /* Convert to MHz scale which is used in 'freq_factor' */ - capped_freq /= 1000; + max_freq = arch_scale_freq_ref(cpu); /* * Handle properly the boost frequencies, which should simply clean @@ -279,13 +278,13 @@ void topology_normalize_cpu_scale(void) capacity_scale = 1; for_each_possible_cpu(cpu) { - capacity = raw_capacity[cpu] * per_cpu(freq_factor, cpu); + capacity = raw_capacity[cpu] * per_cpu(capacity_ref_freq, 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 = raw_capacity[cpu] * per_cpu(capacity_ref_freq, cpu); capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT, capacity_scale); topology_set_cpu_scale(cpu, capacity); @@ -321,15 +320,15 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) cpu_node, raw_capacity[cpu]); /* - * Update freq_factor for calculating early boot cpu capacities. + * Update capacity_ref_freq 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). + * frequency (by keeping the initial capacity_ref_freq 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; + per_cpu(capacity_ref_freq, cpu) = + clk_get_rate(cpu_clk) / HZ_PER_KHZ; clk_put(cpu_clk); } } else { @@ -411,7 +410,7 @@ 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) - per_cpu(freq_factor, cpu) = policy->cpuinfo.max_freq / 1000; + per_cpu(capacity_ref_freq, cpu) = policy->cpuinfo.max_freq; 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 a07b510e7dc5..38ca6c76af56 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -27,6 +27,13 @@ static inline unsigned long topology_get_cpu_scale(int cpu) void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity); +DECLARE_PER_CPU(unsigned long, capacity_ref_freq); + +static inline unsigned long topology_get_freq_ref(int cpu) +{ + return per_cpu(capacity_ref_freq, cpu); +} + DECLARE_PER_CPU(unsigned long, arch_freq_scale); static inline unsigned long topology_get_freq_scale(int cpu) From patchwork Fri Oct 27 08:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp438304vqb; Fri, 27 Oct 2023 01:08:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGi7DAjOKHX2+lG6MVHWpK/5Ss2f51Ca80D28ZnPHWizMGKnRpzbxkKmY0Wp1Ag52xPFAeI X-Received: by 2002:a81:e20a:0:b0:5a7:b9b1:c0c5 with SMTP id p10-20020a81e20a000000b005a7b9b1c0c5mr1791350ywl.3.1698394081090; Fri, 27 Oct 2023 01:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698394081; cv=none; d=google.com; s=arc-20160816; b=S1zmrmrjkFjlFgklJqe3WwO1DDoA5o/GYf4cRisfoXycJhm3npGsJhfBLsy/ub/nyq 8QDEev4F0Yj+JrZsODAB51Zw0bqXcB1/vXjOMdF/0SKVKAw6UtdCPaubJKF1X1f3xY7d Bd0M7zZVnG+RB/a5xvPy+mblYgW441gpEGDovluwTW/tA827vt97ZcsO8pwJKMQW5mhP u2Yc8sZ+L2O67kU/PWrqlj4gRlHoIXUuKJZBciB6tXxdbKQ56M9aCMB/nRC1q1uP1XaL hbgzsJdBYa/ELs/sRqATf1acI5WOjNsL2gGRzovhGBYr8nGvNKgSjELMlpsXXcElzabT 5F5g== 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 :dkim-signature; bh=r/qdhwYexgC4eelalZMREFYWDVhGmAVpyIy4h5YJd+Y=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=fFK0wT901xzVFhIDbLUFS3gZ7l3iARNd8bZMENXmkMrJ0/PdOvc28s23F/sF9R2oP2 v01MqOxcxm9kABbZ1P1iU/Ya0Oxtzlla66Vo/kf0xui0JMC2cuNNmoXkfrcb4PGkyych qPozLyUEES3S5E6dOPsBqOYT71YzEub7w0PIeLRNwsai8WwRB5SzGHzHXhU7QKBIdfIp TN/7NLIyUE7zjdHEToElHY1m9lK3t/dWrgwWyaz77J2e0Dir+eesvRbmq7KNvaL/h614 me/YdV32JOcbCqVxQWXunRlGVlKA0dlLtvKyXqrapy4X7Nv0pPYSSyF8XQWPTCYkrbu1 GmbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UwG/4VS2"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id n204-20020a8172d5000000b00589c065b71csi1824784ywc.61.2023.10.27.01.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:08:01 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b="UwG/4VS2"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7328980B1E5F; Fri, 27 Oct 2023 01:05:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbjJ0IEU (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235073AbjJ0IEP (ORCPT ); Fri, 27 Oct 2023 04:04:15 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDB3AD45 for ; Fri, 27 Oct 2023 01:04:11 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2c4fdf94666so23442711fa.2 for ; Fri, 27 Oct 2023 01:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393849; x=1698998649; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r/qdhwYexgC4eelalZMREFYWDVhGmAVpyIy4h5YJd+Y=; b=UwG/4VS2MSxnkHtnsQpx9o/IPbZw1SxCBiaWXkPAhvhzizTMzCCoLnLGF4IHzjENat p41YfyeuOalrUJevD4TBvRf890ua3fFIJoTyZdQDjvv8D3qHL11Ntu/6ji8O9I0mp7zt anztlSB/tAGfuE/cy2m4NgHBbFDhm39MQhI8VLPBWD5W2qjTAfJNX3MP05Aj4SXC2SAS +dCFxr2+vbXfCASS4kYKZoZNlXyQU9TnhvA64gvJV3qmfKdLXvk+vaXI5ZjbAUWy5cMN DS/HtrOHsQ1DBTnsFgr4/qM8B1P5gFIn8msWC/ZrDXdhoMwFttPih9Gy5hZU7d19DQed Sgcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393849; x=1698998649; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r/qdhwYexgC4eelalZMREFYWDVhGmAVpyIy4h5YJd+Y=; b=BrJrTLOoOKTqm7LCz9o8c8QJKGiUI603f+7AvqeO8tY6sayLCP5d6x/CtUBc24LXWQ C/B14thDYmLZIWCN9OS22Tzefv/KKHknRkwSpgCX7BCmK9eu0jq8YjDpKM71DgGIAXAT wyq0EwqCUekX3+tDWGck0dDgOS3GcpYV7vpC0E8D1NUzHV07ud1qCVJltnOYIuX6PTiJ C8CXkZQub2zpyF4rv7dkvvC2d2VwXO+64aG39O7wE4TQFB8xSYw54ri026K56UMTXbtp 1mTsn2l94Tr5Gvzu9hhYM7/iDnftEhv7BOopqEzhW53xD4MCUAH7wLfF6cQsMzG4V52p 6YIQ== X-Gm-Message-State: AOJu0Yz4buJgLwVn/N5iBO5rSdRjeXJNDI6qRMwVUrF3gDyWRUtYn1Z3 bWmQMAIhw2hGlEDSZOjkWJJE/w== X-Received: by 2002:a2e:8217:0:b0:2c5:1eb6:bd1e with SMTP id w23-20020a2e8217000000b002c51eb6bd1emr1414040ljg.43.1698393849239; Fri, 27 Oct 2023 01:04:09 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:08 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v2 2/7] cpufreq: use the fixed and coherent frequency for scaling capacity Date: Fri, 27 Oct 2023 10:03:55 +0200 Message-Id: <20231027080400.56703-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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]); Fri, 27 Oct 2023 01:05:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895272005463526 X-GMAIL-MSGID: 1780895272005463526 cpuinfo.max_freq can change at runtime because of boost as an example. This implies that the value could be different from the frequency that has been used to compute the capacity of a CPU. The new arch_scale_freq_ref() returns a fixed and coherent frequency that can be used to compute the capacity for a given frequency. Signed-off-by: Vincent Guittot Acked-by: Viresh Kumar Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Acked-by: Rafael J. Wysocki --- drivers/cpufreq/cpufreq.c | 4 ++-- include/linux/cpufreq.h | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 60ed89000e82..8c4f9c2f9c44 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -454,7 +454,7 @@ void cpufreq_freq_transition_end(struct cpufreq_policy *policy, arch_set_freq_scale(policy->related_cpus, policy->cur, - policy->cpuinfo.max_freq); + arch_scale_freq_ref(policy->cpu)); spin_lock(&policy->transition_lock); policy->transition_ongoing = false; @@ -2174,7 +2174,7 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, policy->cur = freq; arch_set_freq_scale(policy->related_cpus, freq, - policy->cpuinfo.max_freq); + arch_scale_freq_ref(policy->cpu)); cpufreq_stats_record_transition(policy, freq); if (trace_cpu_frequency_enabled()) { diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 71d186d6933a..bbc483b4b6e5 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -1211,6 +1211,15 @@ void arch_set_freq_scale(const struct cpumask *cpus, { } #endif + +#ifndef arch_scale_freq_ref +static __always_inline +unsigned int arch_scale_freq_ref(int cpu) +{ + return 0; +} +#endif + /* the following are really really optional */ extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs; extern struct freq_attr cpufreq_freq_attr_scaling_boost_freqs; From patchwork Fri Oct 27 08:03:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp436544vqb; Fri, 27 Oct 2023 01:04:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPOgSbcCOhkLTZqiIpb6nTIsmbA2QUvltgzfMiNn2gFTfPXxKAYpjMSx8evlT92Wji/w6W X-Received: by 2002:a81:451e:0:b0:5a7:fc20:7848 with SMTP id s30-20020a81451e000000b005a7fc207848mr1833199ywa.1.1698393875307; Fri, 27 Oct 2023 01:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698393875; cv=none; d=google.com; s=arc-20160816; b=unflYId+GBQIYwK2JuTNFsOS2WEC7DX5oyr+l/wHAil9BAPfwx1PlTzkmXu5QSQrLY rAgr2DjPq1e8X/0YAA2xcSV+nHYNKXNAJgR0Kp90DBbXa2tmRj7KncDItwyqp8pn454v q1Li+tbSWKLvfn6zMIcrz1lh5h70zmB+pu63Qe0jdG40KifQGMMZzFFzvtkL3hbFZHsP GYr6Uqa15+8W7Rs6D4E/ooa5sYr0NPCN6q3gJTZZ6A4vwkaVfHPGNIo84gXgNN+EkcP5 SZy5nmoVxX9l1gjxjlWOMHe0w/jZmWeOJwsCPrDTpqzQvAxTQh1W1V7PvrwFT6lUjdFx Uvlg== 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 :dkim-signature; bh=l8u+U/9u4ohr5MnGNG/ipD+T+tLh/PNcKnY6Yu8ixWw=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=kTikxRI0NkQZ1WHkncf6fl4zBpEDwX48uugTKJ+vISm1U6qZSOxEW6Qnptl4kTIFMM 9pGW3rCf9rvmAUnfOqwFBeVUsVA5HS7NAq2pKmgq6Qvxk/0P9p4ZtVmMbuP0KPsKP8dQ VD3X0wCuecnOcv1YzsWc+cdL7qqclc/AJojZMZi2kUvknRN+QomHvPzqSUyzpku2NGF9 0iwXtwiF7x8LDg0ukYjOCAbBaN1MZbE413DRg/dhRX+J81qmbDyWH0AooOZXRu1M4Y6R rdM9OcrEOl0d8wtIbM69V6rGR/5jwJolmRRH/9urJVCA/u4YPy+TD4441NcUInfpb/22 KP+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L24RwGMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o184-20020a0de5c1000000b005a88b1c3dcasi1391042ywe.368.2023.10.27.01.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L24RwGMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2436182B484B; Fri, 27 Oct 2023 01:04:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235083AbjJ0IEZ (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbjJ0IEQ (ORCPT ); Fri, 27 Oct 2023 04:04:16 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13EF31B9 for ; Fri, 27 Oct 2023 01:04:13 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40859c46447so12255935e9.1 for ; Fri, 27 Oct 2023 01:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393851; x=1698998651; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l8u+U/9u4ohr5MnGNG/ipD+T+tLh/PNcKnY6Yu8ixWw=; b=L24RwGMHA181FTA5H2iJVIE6oJBGLqBWg85c0yDhYhDgZ9Ox9Hc1ORQ7rO0MXisXlL 0gDMH/x0sTlJQINhM/UOCAIxOmENsXtaySZKUDbDbWabcZqTlVqEmMywfmSRiuebHLwF 4yNZajeH7zjRYQArVx5+D+fHTOTrhCyNHlvarxz5n/o7CFvnPubPdSGuhWViWJ5BKugn E70mGdjeQx2nEWovHP81d3oULXEYupE9mopY2Kzx1YHA7B2EOaxPe8tyBEGLAzjIWmWE RerpeqIsAz94yMRTE3jbOEmJAU4Zz4D0A/lcE5xRtd9ITvtFNhUIFZa0z6W5vI7EWPLy cZTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393851; x=1698998651; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l8u+U/9u4ohr5MnGNG/ipD+T+tLh/PNcKnY6Yu8ixWw=; b=b8Vfzi6sYDTI/ahRc/6WiIMEPW8urF32NNYQLMKiYksWu0jjmvQy9dvQZiv8gRO9RV zN7W/rpZeMZb87IViJyW/ByTYR2zmQOPYQgZR3cxX1wqWswm7EnHMRHmgK/Ce22tizpa 2NQrbnMRpcdlcIfrh4SrE/1jFdjuTLA0wQxY1XQ2+iH/tjTHbbRRHxf7LfeuZ50MrinQ nv+UqbXZUyY6ePryOZfhwdoDre+FGnTopNztHgQLoNd3EBTeXQ+AJBw7hHfftgzywQ6V lI1I15QzFfvdD6qsLhmZA9AXpqC4Bi7VkFY+5hGosS+fHsRdx51hqcJjT5QegfH8rlIb iueA== X-Gm-Message-State: AOJu0YyGE/v6xhtK9fBVrEOsbjcLSk5u8BAR6F8dbNgezvVAkmx0QBwI CL6Ky1nLGpu9KXtOnBUBwAod+w== X-Received: by 2002:a05:600c:3594:b0:405:4daa:6e3d with SMTP id p20-20020a05600c359400b004054daa6e3dmr1555522wmq.39.1698393851126; Fri, 27 Oct 2023 01:04:11 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:10 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 3/7] cpufreq/schedutil: use a fixed reference frequency Date: Fri, 27 Oct 2023 10:03:56 +0200 Message-Id: <20231027080400.56703-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:04:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895056247050416 X-GMAIL-MSGID: 1780895056247050416 cpuinfo.max_freq can change at runtime because of boost as an example. This implies that the value could be different than the one that has been used when computing the capacity of a CPU. The new arch_scale_freq_ref() returns a fixed and coherent reference frequency that can be used when computing a frequency based on utilization. Use this arch_scale_freq_ref() when available and fallback to policy otherwise. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Acked-by: Rafael J. Wysocki Reviewed-by: Dietmar Eggemann --- kernel/sched/cpufreq_schedutil.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 458d359f5991..f3a87fa16332 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -114,6 +114,28 @@ static void sugov_deferred_update(struct sugov_policy *sg_policy) } } +/** + * get_capacity_ref_freq - get the reference frequency that has been used to + * correlate frequency and compute capacity for a given cpufreq policy. We use + * the CPU managing it for the arch_scale_freq_ref() call in the function. + * @policy: the cpufreq policy of the CPU in question. + * + * Return: the reference CPU frequency to compute a capacity. + */ +static __always_inline +unsigned long get_capacity_ref_freq(struct cpufreq_policy *policy) +{ + unsigned int freq = arch_scale_freq_ref(policy->cpu); + + if (freq) + return freq; + + if (arch_scale_freq_invariant()) + return policy->cpuinfo.max_freq; + + return policy->cur; +} + /** * get_next_freq - Compute a new frequency for a given cpufreq policy. * @sg_policy: schedutil policy object to compute the new frequency for. @@ -140,10 +162,10 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, unsigned long util, unsigned long max) { struct cpufreq_policy *policy = sg_policy->policy; - unsigned int freq = arch_scale_freq_invariant() ? - policy->cpuinfo.max_freq : policy->cur; + unsigned int freq; util = map_util_perf(util); + freq = get_capacity_ref_freq(policy); freq = map_util_freq(util, freq, max); if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) From patchwork Fri Oct 27 08:03:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp437000vqb; Fri, 27 Oct 2023 01:05:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEieIPgMkfaoS9bRUno5xVISZmLO2AfSWoI7I8K/Up8J3pWyKCdwGZ5RtfF4VAfFGeGpnLS X-Received: by 2002:a81:4413:0:b0:5a7:dbf4:6a1e with SMTP id r19-20020a814413000000b005a7dbf46a1emr1777018ywa.33.1698393922886; Fri, 27 Oct 2023 01:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698393922; cv=none; d=google.com; s=arc-20160816; b=gzKx008uGuI1W00wmEZZ1layADh04NbkqX8vvQlP2ykMguDT4RVcU28doHAvubAck4 Iv2Je7AE2IOdF3CL5uhIY1dyyQhrKc6Qp1E7/ZjA6xwUIZIh03OkkTPNxXTM1zhAOMDF sP/R0U/b9lRLeBq+uxaorpPpi3RUi5FvfjWGKcqbK9WxMCuC3gVDyZ4DECrLkcyMNtFH f5s21qsOBgACLTknO7kVEL5lqY9EOBUSmWOOLSYugMEfmicxjwaT5DaCsXqMJIZ5XZ4G OaVROSQoLk8JAnnXq3IUrFW8rVlT6QOQBmzXHB++vTSXGvNtFic2u+JA3CmALGc39Laj eZXg== 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 :dkim-signature; bh=HdB4lDzOqWgKx+jcR+6XZlgYVoJSXQa0m+FGwW4RKJM=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=QbyJTc9+FFmLMn1/D/VqT67FD6kfSAQv+5ikI8ygTGgBs9Jdy8f8EBhgK+jYTuYgeb vipo+M3/Lpew4D7OPA5x1+zDYGTEyMpTFh8m5FAgG5g8okTM4hIBshRRb1IuxSqlJqKc UzFs3pr/1bHUpBP4uu4zx8WP2V79QWPvKnNVM9HnX06n5GPzokzfEN31cgHigB0LGbC/ w8hLsUH9lAf0GbCBJaKh/LK3kcc+LcZ3f24WCBz+TlCWlIpUbsiJgtR8DxwE4QXlOYFb 2OeHjIg3G+AR7qqYMc9Ge5D/G9r+jw6XccLEi7j9FIwGbUEx/ft0HpTtjtHO2oSAjBFy B3qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IzKpjjvZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id l125-20020a0de283000000b00584562cb522si1847773ywe.98.2023.10.27.01.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:05:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IzKpjjvZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DA556809AFCC; Fri, 27 Oct 2023 01:05:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235081AbjJ0IEf (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235062AbjJ0IET (ORCPT ); Fri, 27 Oct 2023 04:04:19 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 655FF1B3 for ; Fri, 27 Oct 2023 01:04:14 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-407c3adef8eso14423105e9.2 for ; Fri, 27 Oct 2023 01:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393853; x=1698998653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HdB4lDzOqWgKx+jcR+6XZlgYVoJSXQa0m+FGwW4RKJM=; b=IzKpjjvZmme+Q2E2K/KLw818QjNRvAaVWMjvBKySUsICuQUL6IkhFw93MJa4p4fWyl Hc59EOrKePqLRZE/Ofy++YQZWbd3pz5yKcBu28X3Re123JwtNuJaRRv7A0ULd1ejSXX5 pMAGwLyvKrdzvOtqrERFEhzTKbe+f0WKNvFCKnWbHdBV9cb3SXt/0+yIb71cDxmHnrDK gpzqCRCMQBajZDsIOfsauNBwYMpuZFJIxfr4M8w+wK2fN0VDU6CwJHsvGuuO6hjeWnM+ XJY030HzckDsG2aW4LbS3wr1CUoZzmD3MfGQyMzADz4TbyjdnKlS9tJF7rbO9Hda8Bez r57g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393853; x=1698998653; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HdB4lDzOqWgKx+jcR+6XZlgYVoJSXQa0m+FGwW4RKJM=; b=GGSv8YeBzvs1IAsPFwLka65P74i4XoYHdxo3vtorkA5OnvdmKH83dXIAABCFNttRhH QuhH+Kwq80O0/wPnurRSFsYvfGTizAD45s7b93lMWeqfKaMmX7kiQaOa7fV8mw5swkcX V4FJkEvM1+JP4hgpZ+f5hcgcAS/dAybqUQJWTDSCy+6PXpBHl/ApiwHodtiXwBEfTaWm 0bqSo38niQ5d8ZRkKa+lBt8ZlLW+gkomJAI67qFf8MDF8sUQsOYdzaawJIFVFiZvc/ZV KLUAyLa2JBffdEneYfxMwNSY1QsKwjEuCGDk/4F0n5gKfK2dGXM4Z4zVjB0hnx+C8rrs f4+A== X-Gm-Message-State: AOJu0Ywag2AkoMO7OrazaPT1CctAbPTOLeqAQvA7vvNhvkZIZvy7P26n xNlXzP7muDg6p9sHltxh+tQAyg== X-Received: by 2002:a05:600c:2990:b0:402:ee71:29 with SMTP id r16-20020a05600c299000b00402ee710029mr1624044wmd.10.1698393852695; Fri, 27 Oct 2023 01:04:12 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:12 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 4/7] energy_model: use a fixed reference frequency Date: Fri, 27 Oct 2023 10:03:57 +0200 Message-Id: <20231027080400.56703-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:05:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895106260096049 X-GMAIL-MSGID: 1780895106260096049 The last item of a performance domain is not always the performance point that has been used to compute CPU's capacity. This can lead to different target frequency compared with other part of the system like schedutil and would result in wrong energy estimation. A new arch_scale_freq_ref() is available to return a fixed and coherent frequency reference that can be used when computing the CPU's frequency for an level of utilization. Use this function to get this reference frequency. Energy model is never used without defining arch_scale_freq_ref() but can be compiled. Define a default arch_scale_freq_ref() returning 0 in such case. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba --- include/linux/energy_model.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index b9caa01dfac4..1b0c8490d4bd 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -204,6 +204,14 @@ struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, return ps; } +#ifndef arch_scale_freq_ref +static __always_inline +unsigned int arch_scale_freq_ref(int cpu) +{ + return 0; +} +#endif + /** * em_cpu_energy() - Estimates the energy consumed by the CPUs of a * performance domain @@ -224,7 +232,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long max_util, unsigned long sum_util, unsigned long allowed_cpu_cap) { - unsigned long freq, scale_cpu; + unsigned long freq, ref_freq, scale_cpu; struct em_perf_state *ps; int cpu; @@ -241,11 +249,11 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, */ cpu = cpumask_first(to_cpumask(pd->cpus)); scale_cpu = arch_scale_cpu_capacity(cpu); - ps = &pd->table[pd->nr_perf_states - 1]; + ref_freq = arch_scale_freq_ref(cpu); max_util = map_util_perf(max_util); max_util = min(max_util, allowed_cpu_cap); - freq = map_util_freq(max_util, ps->frequency, scale_cpu); + freq = map_util_freq(max_util, ref_freq, scale_cpu); /* * Find the lowest performance state of the Energy Model above the From patchwork Fri Oct 27 08:03:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158807 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp438297vqb; Fri, 27 Oct 2023 01:07:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExiAM06ZDmTYVSx8PHI7IYLa6LDm/Md+lUbQgfYervCsf6c+YqldsoiAFiMVSqwpxp4Ox2 X-Received: by 2002:aca:2307:0:b0:3b2:ef4c:8405 with SMTP id e7-20020aca2307000000b003b2ef4c8405mr1887437oie.5.1698394079555; Fri, 27 Oct 2023 01:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698394079; cv=none; d=google.com; s=arc-20160816; b=hNG8ASVfJ9F7JgENMCSE6RdDhybYXJQWvY333tUL3tuW39IWaBMg6MnnVl3M428csp ZhFTgmYp9S9ewh/sQhfgOQ8qn47xThUiZMtVbfzAhgi/zHXHhs8ERuyGpGNauwkej5/B HH4yO1yUwzk0QqzTNwyHIJaKxai3/Jsfjd767IWMIvGIb84k6bTQZPlgnrv6/xPhsLN5 qAQEAnRUMY7GhC5wsffX1dHEJck9GJFxJ1CI00QOGSfGE2c/y9C+4uNcdqR9sLGnJXAr XHvTBxEabG17quOz9Ak8NPsUDyLE2kw43C7pJycb7bXvZ8ocGcO7DAkvza0bHN13w8iL iZ5Q== 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 :dkim-signature; bh=Q0ZVOcabbIlkq0uyCMsiFpmUhv/n2tV7abq7OTQEIzs=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=n5HfhhMpE8Zji7XjPscxirceAsBBXZ33HuwhaYDZpv8mNs7XynLZe+ecXNLMCJ7gPd 0FPUt049ZP7JXUCL4I6cyaECSFdmdgkgT2u1P6OMXPUjWwkFKosvjYXyPW1og61zLfD/ Mdr0OEiHexphaEeUOlNabU0PKLvz0gQzTlv0LIvDRNQPA1iwjfPalmbnKGiyHoJpkTkI oK1OVd+ukAFjZasd/Wf5yVvzVKD58ZEwdXSmxM/izSg1aa4zvvN7f5BBvLznPinHKSnN 8YUBWIsBhiRAjb3yCmkHm0PjWEu8MHd4NPDOo2YnMH0g9qU+vCzqcrViC9Oc1Mkd5GvR 05pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KVxbgnT+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a70-20020a25ca49000000b00d867e0791fcsi2011936ybg.402.2023.10.27.01.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:07:59 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=KVxbgnT+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C804E80AF256; Fri, 27 Oct 2023 01:05:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235131AbjJ0IEi (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235116AbjJ0IEd (ORCPT ); Fri, 27 Oct 2023 04:04:33 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 718F9D4E for ; Fri, 27 Oct 2023 01:04:16 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c50d1b9f22so23772561fa.0 for ; Fri, 27 Oct 2023 01:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393854; x=1698998654; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q0ZVOcabbIlkq0uyCMsiFpmUhv/n2tV7abq7OTQEIzs=; b=KVxbgnT+n/PrSRjrEeYZRduII/q89cLXZmxNqAvPNsZJbEy6WDlA8bNVBu8Zh0S3BR eBj3LFgwxfS2G0scBAlBQPPDVm/MccDS9t3tq0BD6/ngpYqvV772vOvSOKt4ft7NF8Xz y/Bc19PK/2XNJPMIPT1nDch3m+iEZagtp6OTkelxwRMJsv8a5bZLdSbXOrOBI06dHdDj rVEQ0hBJ1i+dcmNEFo8LmjoHiJx7yFLH1WVSEvP0K8Gfvi6N46/knZLayIxvq8XHvgK9 pzs82iqu4Ggl5icmr9MK+kQKeQUaEbOnD29uSd3H335fp5D3Zrw3QKXBdpBRYXOqFxy5 X+pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393854; x=1698998654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q0ZVOcabbIlkq0uyCMsiFpmUhv/n2tV7abq7OTQEIzs=; b=KfMezeYiQB6fHH94VAqwQTGoCQXyCx8ZwNNlz4+NC1EXrnhf5SiONmV8w/ClIiyufQ s0tOIYS39cFsOIY0o75Bc5POcrX5zcraHw+jjwY56WEDS6mZydU1eHX2y0r15R3LSpa5 wNnCq9G1CE5B2xQO3y538rPamn592FCzXJzwZF6lXrrqzJ6QZMXHQADjyKFcsI0bn8zL sY9/W8GnFGkFGoOnHoDuMhUIuQxIqwSeWcMy/WuS7hfNkMLQtg3AJEOPzkNIFqmJg2ie BnFabdwuNyuaPrUjzkV+lpUAsRqUL1AAAJ9xGxpdiLGNKnuUKy9wnhi6nItNU1Y4sbIM tY9A== X-Gm-Message-State: AOJu0YzLI64AcvJUi5Kk9b4DPdFt6VH0/IAvVoBtKczmi9+/2705E1Xa vb2GdQrCHWeyi7oCG1DQ3mE9EQ== X-Received: by 2002:a05:651c:b06:b0:2c5:1867:b0bc with SMTP id b6-20020a05651c0b0600b002c51867b0bcmr1472905ljr.51.1698393854268; Fri, 27 Oct 2023 01:04:14 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:13 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 5/7] cpufreq/cppc: move and rename cppc_cpufreq_{perf_to_khz|khz_to_perf} Date: Fri, 27 Oct 2023 10:03:58 +0200 Message-Id: <20231027080400.56703-6-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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]); Fri, 27 Oct 2023 01:05:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895270462257181 X-GMAIL-MSGID: 1780895270462257181 We move and rename cppc_cpufreq_perf_to_khz and cppc_cpufreq_khz_to_perf to use them outside cppc_cpufreq in topology_init_cpu_capacity_cppc(). Modify the interface to use struct cppc_perf_caps *caps instead of struct cppc_cpudata *cpu_data as we only use the field perf_caps. No functional change Signed-off-by: Vincent Guittot Acked-by: Rafael J. Wysocki --- Rafael, I have kept your Acked as the cppc_acpi.c part has moved in its own patch and I haven't change this code. Let me know if this is a problem. drivers/acpi/cppc_acpi.c | 93 +++++++++++++++++++++++ drivers/cpufreq/cppc_cpufreq.c | 134 +++++---------------------------- include/acpi/cppc_acpi.h | 2 + 3 files changed, 112 insertions(+), 117 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 7ff269a78c20..72aae5e87788 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include @@ -1760,3 +1762,94 @@ unsigned int cppc_get_transition_latency(int cpu_num) return latency_ns; } EXPORT_SYMBOL_GPL(cppc_get_transition_latency); + +/* Minimum struct length needed for the DMI processor entry we want */ +#define DMI_ENTRY_PROCESSOR_MIN_LENGTH 48 + +/* Offset in the DMI processor structure for the max frequency */ +#define DMI_PROCESSOR_MAX_SPEED 0x14 + +/* Callback function used to retrieve the max frequency from DMI */ +static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private) +{ + const u8 *dmi_data = (const u8 *)dm; + u16 *mhz = (u16 *)private; + + if (dm->type == DMI_ENTRY_PROCESSOR && + dm->length >= DMI_ENTRY_PROCESSOR_MIN_LENGTH) { + u16 val = (u16)get_unaligned((const u16 *) + (dmi_data + DMI_PROCESSOR_MAX_SPEED)); + *mhz = val > *mhz ? val : *mhz; + } +} + +/* Look up the max frequency in DMI */ +static u64 cppc_get_dmi_max_khz(void) +{ + u16 mhz = 0; + + dmi_walk(cppc_find_dmi_mhz, &mhz); + + /* + * Real stupid fallback value, just in case there is no + * actual value set. + */ + mhz = mhz ? mhz : 1; + + return (1000 * mhz); +} + +/* + * If CPPC lowest_freq and nominal_freq registers are exposed then we can + * use them to convert perf to freq and vice versa. The conversion is + * extrapolated as an affine function passing by the 2 points: + * - (Low perf, Low freq) + * - (Nominal perf, Nominal perf) + */ +unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf) +{ + s64 retval, offset = 0; + static u64 max_khz; + u64 mul, div; + + if (caps->lowest_freq && caps->nominal_freq) { + mul = caps->nominal_freq - caps->lowest_freq; + div = caps->nominal_perf - caps->lowest_perf; + offset = caps->nominal_freq - div64_u64(caps->nominal_perf * mul, div); + } else { + if (!max_khz) + max_khz = cppc_get_dmi_max_khz(); + mul = max_khz; + div = caps->highest_perf; + } + + retval = offset + div64_u64(perf * mul, div); + if (retval >= 0) + return retval; + return 0; +} +EXPORT_SYMBOL_GPL(cppc_perf_to_khz); + +unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq) +{ + s64 retval, offset = 0; + static u64 max_khz; + u64 mul, div; + + if (caps->lowest_freq && caps->nominal_freq) { + mul = caps->nominal_perf - caps->lowest_perf; + div = caps->nominal_freq - caps->lowest_freq; + offset = caps->nominal_perf - div64_u64(caps->nominal_freq * mul, div); + } else { + if (!max_khz) + max_khz = cppc_get_dmi_max_khz(); + mul = caps->highest_perf; + div = max_khz; + } + + retval = offset + div64_u64(freq * mul, div); + if (retval >= 0) + return retval; + return 0; +} +EXPORT_SYMBOL_GPL(cppc_khz_to_perf); diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index fe08ca419b3d..14457703cf00 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -27,12 +27,6 @@ #include -/* Minimum struct length needed for the DMI processor entry we want */ -#define DMI_ENTRY_PROCESSOR_MIN_LENGTH 48 - -/* Offset in the DMI processor structure for the max frequency */ -#define DMI_PROCESSOR_MAX_SPEED 0x14 - /* * This list contains information parsed from per CPU ACPI _CPC and _PSD * structures: e.g. the highest and lowest supported performance, capabilities, @@ -291,97 +285,9 @@ static inline void cppc_freq_invariance_exit(void) } #endif /* CONFIG_ACPI_CPPC_CPUFREQ_FIE */ -/* Callback function used to retrieve the max frequency from DMI */ -static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private) -{ - const u8 *dmi_data = (const u8 *)dm; - u16 *mhz = (u16 *)private; - - if (dm->type == DMI_ENTRY_PROCESSOR && - dm->length >= DMI_ENTRY_PROCESSOR_MIN_LENGTH) { - u16 val = (u16)get_unaligned((const u16 *) - (dmi_data + DMI_PROCESSOR_MAX_SPEED)); - *mhz = val > *mhz ? val : *mhz; - } -} - -/* Look up the max frequency in DMI */ -static u64 cppc_get_dmi_max_khz(void) -{ - u16 mhz = 0; - - dmi_walk(cppc_find_dmi_mhz, &mhz); - - /* - * Real stupid fallback value, just in case there is no - * actual value set. - */ - mhz = mhz ? mhz : 1; - - return (1000 * mhz); -} - -/* - * If CPPC lowest_freq and nominal_freq registers are exposed then we can - * use them to convert perf to freq and vice versa. The conversion is - * extrapolated as an affine function passing by the 2 points: - * - (Low perf, Low freq) - * - (Nominal perf, Nominal perf) - */ -static unsigned int cppc_cpufreq_perf_to_khz(struct cppc_cpudata *cpu_data, - unsigned int perf) -{ - struct cppc_perf_caps *caps = &cpu_data->perf_caps; - s64 retval, offset = 0; - static u64 max_khz; - u64 mul, div; - - if (caps->lowest_freq && caps->nominal_freq) { - mul = caps->nominal_freq - caps->lowest_freq; - div = caps->nominal_perf - caps->lowest_perf; - offset = caps->nominal_freq - div64_u64(caps->nominal_perf * mul, div); - } else { - if (!max_khz) - max_khz = cppc_get_dmi_max_khz(); - mul = max_khz; - div = caps->highest_perf; - } - - retval = offset + div64_u64(perf * mul, div); - if (retval >= 0) - return retval; - return 0; -} - -static unsigned int cppc_cpufreq_khz_to_perf(struct cppc_cpudata *cpu_data, - unsigned int freq) -{ - struct cppc_perf_caps *caps = &cpu_data->perf_caps; - s64 retval, offset = 0; - static u64 max_khz; - u64 mul, div; - - if (caps->lowest_freq && caps->nominal_freq) { - mul = caps->nominal_perf - caps->lowest_perf; - div = caps->nominal_freq - caps->lowest_freq; - offset = caps->nominal_perf - div64_u64(caps->nominal_freq * mul, div); - } else { - if (!max_khz) - max_khz = cppc_get_dmi_max_khz(); - mul = caps->highest_perf; - div = max_khz; - } - - retval = offset + div64_u64(freq * mul, div); - if (retval >= 0) - return retval; - return 0; -} - static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) - { struct cppc_cpudata *cpu_data = policy->driver_data; unsigned int cpu = policy->cpu; @@ -389,7 +295,7 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy, u32 desired_perf; int ret = 0; - desired_perf = cppc_cpufreq_khz_to_perf(cpu_data, target_freq); + desired_perf = cppc_khz_to_perf(&cpu_data->perf_caps, target_freq); /* Return if it is exactly the same perf */ if (desired_perf == cpu_data->perf_ctrls.desired_perf) return ret; @@ -417,7 +323,7 @@ static unsigned int cppc_cpufreq_fast_switch(struct cpufreq_policy *policy, u32 desired_perf; int ret; - desired_perf = cppc_cpufreq_khz_to_perf(cpu_data, target_freq); + desired_perf = cppc_khz_to_perf(&cpu_data->perf_caps, target_freq); cpu_data->perf_ctrls.desired_perf = desired_perf; ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); @@ -530,7 +436,7 @@ static int cppc_get_cpu_power(struct device *cpu_dev, min_step = min_cap / CPPC_EM_CAP_STEP; max_step = max_cap / CPPC_EM_CAP_STEP; - perf_prev = cppc_cpufreq_khz_to_perf(cpu_data, *KHz); + perf_prev = cppc_khz_to_perf(perf_caps, *KHz); step = perf_prev / perf_step; if (step > max_step) @@ -550,8 +456,8 @@ static int cppc_get_cpu_power(struct device *cpu_dev, perf = step * perf_step; } - *KHz = cppc_cpufreq_perf_to_khz(cpu_data, perf); - perf_check = cppc_cpufreq_khz_to_perf(cpu_data, *KHz); + *KHz = cppc_perf_to_khz(perf_caps, perf); + perf_check = cppc_khz_to_perf(perf_caps, *KHz); step_check = perf_check / perf_step; /* @@ -561,8 +467,8 @@ static int cppc_get_cpu_power(struct device *cpu_dev, */ while ((*KHz == prev_freq) || (step_check != step)) { perf++; - *KHz = cppc_cpufreq_perf_to_khz(cpu_data, perf); - perf_check = cppc_cpufreq_khz_to_perf(cpu_data, *KHz); + *KHz = cppc_perf_to_khz(perf_caps, perf); + perf_check = cppc_khz_to_perf(perf_caps, *KHz); step_check = perf_check / perf_step; } @@ -591,7 +497,7 @@ static int cppc_get_cpu_cost(struct device *cpu_dev, unsigned long KHz, perf_caps = &cpu_data->perf_caps; max_cap = arch_scale_cpu_capacity(cpu_dev->id); - perf_prev = cppc_cpufreq_khz_to_perf(cpu_data, KHz); + perf_prev = cppc_khz_to_perf(perf_caps, KHz); perf_step = CPPC_EM_CAP_STEP * perf_caps->highest_perf / max_cap; step = perf_prev / perf_step; @@ -724,20 +630,16 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) * Set min to lowest nonlinear perf to avoid any efficiency penalty (see * Section 8.4.7.1.1.5 of ACPI 6.1 spec) */ - policy->min = cppc_cpufreq_perf_to_khz(cpu_data, - caps->lowest_nonlinear_perf); - policy->max = cppc_cpufreq_perf_to_khz(cpu_data, - caps->nominal_perf); + policy->min = cppc_perf_to_khz(caps, caps->lowest_nonlinear_perf); + policy->max = cppc_perf_to_khz(caps, caps->nominal_perf); /* * Set cpuinfo.min_freq to Lowest to make the full range of performance * available if userspace wants to use any perf between lowest & lowest * nonlinear perf */ - policy->cpuinfo.min_freq = cppc_cpufreq_perf_to_khz(cpu_data, - caps->lowest_perf); - policy->cpuinfo.max_freq = cppc_cpufreq_perf_to_khz(cpu_data, - caps->nominal_perf); + policy->cpuinfo.min_freq = cppc_perf_to_khz(caps, caps->lowest_perf); + policy->cpuinfo.max_freq = cppc_perf_to_khz(caps, caps->nominal_perf); policy->transition_delay_us = cppc_cpufreq_get_transition_delay_us(cpu); policy->shared_type = cpu_data->shared_type; @@ -773,7 +675,7 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) boost_supported = true; /* Set policy->cur to max now. The governors will adjust later. */ - policy->cur = cppc_cpufreq_perf_to_khz(cpu_data, caps->highest_perf); + policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf; ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); @@ -863,7 +765,7 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0, &fb_ctrs_t1); - return cppc_cpufreq_perf_to_khz(cpu_data, delivered_perf); + return cppc_perf_to_khz(&cpu_data->perf_caps, delivered_perf); } static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) @@ -878,11 +780,9 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) } if (state) - policy->max = cppc_cpufreq_perf_to_khz(cpu_data, - caps->highest_perf); + policy->max = cppc_perf_to_khz(caps, caps->highest_perf); else - policy->max = cppc_cpufreq_perf_to_khz(cpu_data, - caps->nominal_perf); + policy->max = cppc_perf_to_khz(caps, caps->nominal_perf); policy->cpuinfo.max_freq = policy->max; ret = freq_qos_update_request(policy->max_freq_req, policy->max); @@ -937,7 +837,7 @@ static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpu) if (ret < 0) return -EIO; - return cppc_cpufreq_perf_to_khz(cpu_data, desired_perf); + return cppc_perf_to_khz(&cpu_data->perf_caps, desired_perf); } static void cppc_check_hisi_workaround(void) diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 6126c977ece0..3a0995f8bce8 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -144,6 +144,8 @@ extern int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls); extern int cppc_set_enable(int cpu, bool enable); extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps); extern bool cppc_perf_ctrs_in_pcc(void); +extern unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf); +extern unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq); extern bool acpi_cpc_valid(void); extern bool cppc_allow_fast_switch(void); extern int acpi_get_psd_map(unsigned int cpu, struct cppc_cpudata *cpu_data); From patchwork Fri Oct 27 08:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp438318vqb; Fri, 27 Oct 2023 01:08:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/AH5DuMh0SsdQ3tc77MvOv+QCLgniuutCccn5Y3TuPEJgvh63GtX0Nlazz3hiVuQnv78U X-Received: by 2002:a25:5f4d:0:b0:da0:44fa:6cb1 with SMTP id h13-20020a255f4d000000b00da044fa6cb1mr3483453ybm.6.1698394082243; Fri, 27 Oct 2023 01:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698394082; cv=none; d=google.com; s=arc-20160816; b=BG3Yp1CNxPjVQFPdXhHWw/Gw3cEP6rmP5LUOr+pPSiS9howrP2aVQibRE6igyTdLgB Qo4x7k4Tx96a/jrib3VotpNX0VPnX0f9te6axrnhTpf1Z1uu02+iMAZBct3l3ESQp91Z ARok+7FEELCH7HFBjk9OFMZ9NDoCc8HHuFsXi/592Qw6A5pV1RQDTOjqnTJACyfOEh1r mahGxW39FFCJL+9kZ5NMs7gGrZYS85uHet8KaCImti5aT7s+QcnJZLoaALsX78AwucbF FDULfIC6nYXe84rO9wXK7+qChr3gxUJDHs22Ngdn2xYE4TNy/zeLeCICfWMe8aFja0GS bEaA== 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 :dkim-signature; bh=c18WsKqkMLxlFb2kxy1TvqZw0mGllHhrI7E/VCZUkXM=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=vVTY18iTu4VKSBmAjZpmgHtvSLmmcmCZOFWyzJFykXlr+SAwMpbI5IpgpqcqKV4Ipq TfNDDVkdeoeX2wvjIFX7YdL3hgt6RYsNvPOVoi7zABaOAJbFDcON9oHXk9iLaHW+4uqb L2ME8BQrZrWu4TDo5rtAO+ey7Qe5Vn+8EBrn1GqpdboWQintu79oOgdX6SOY61rvjpI1 dO+dg0H4rn7MLKDe3gIYmj2mfERGK+6UKMzQH6AdCBLaG+2ktVzdolDX93JGOUcnCzfi 8qycX52FLM8udxuQKRYL9wKPcyMhqmwEe7v98QKso3ycQr5ovuliJT1W5+IUb/iyc6Kl qXKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="q/hXih+d"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id w9-20020a05690204e900b00da06fb44e62si1811700ybs.300.2023.10.27.01.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:08:02 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b="q/hXih+d"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A366D8042B79; Fri, 27 Oct 2023 01:05:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235149AbjJ0IEr (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235126AbjJ0IEe (ORCPT ); Fri, 27 Oct 2023 04:04:34 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3E1D1B9 for ; Fri, 27 Oct 2023 01:04:18 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-5079f9675c6so2745462e87.2 for ; Fri, 27 Oct 2023 01:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393857; x=1698998657; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c18WsKqkMLxlFb2kxy1TvqZw0mGllHhrI7E/VCZUkXM=; b=q/hXih+d/oCm2aSJa4q02OZKkW1RVmFrLh1IxuBe0NS8MK1lPFBQxs1qnKHV66sqWN ZohVFDk9Fy7SxPXr4CgkXE62CTCSwLokru99Ir7CgPg1eppEgeDjmVRGg57qR0t7CdxD gVcpsr1HauYsCItYCXmlsbJ7D5H1nEOp/MVFmjfoGGQKOwrZGle4tjNGKkb7R3EQPWAG h6re274P+wmBwUOxaZK97BKffAmFeLqeTlGgpC0jjUprR6itqqEUSzSFbCvoCa5aKc5K VuUOxt+HOWB/VeTQuNAfW5KqlVvqg8k4ADKMJOpNwkBAfUnW7AQcBE4LQPMAL4jNFqzo jGNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393857; x=1698998657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c18WsKqkMLxlFb2kxy1TvqZw0mGllHhrI7E/VCZUkXM=; b=bv0HBjPj6VhM5fidxKROeT/yoVkBa/GVlQ1LdiOga/HipyZKwYFJO3VXlrBIFWwfBO YHB3ix3u16w3A8fCkFYLR6lIf7WH1tBCDf289WghL3WI6Nzh2kMHvHFxmYDQ6ShAUVKL 24NsiPXZcC5jkXrF3L6Czfo8W2+SskSA5OjjqlGbGo/ZseDoCJsYaDkJv+4L90UMksaE uE3+OptIUsASNJyqKBLS8Jh2K4Xkni1C8JCktax7S8JlGpMDZh09J3E9daPXzfdnsrMt I2txzxzBJ7bN/x9iGKqI46dGIJVR0LcyKo0eMQmYG+9gLrnxvVXP0sd3PRcxQlTwHZHq G//A== X-Gm-Message-State: AOJu0Yz7wAaz3aJn3TlI/yd7otwK/odREmchSmn0Udm9lX64JIkmZfRo wFoS9Ztilzw3mimMCoi9fRlTYw== X-Received: by 2002:a05:6512:3287:b0:500:aed0:cb1b with SMTP id p7-20020a056512328700b00500aed0cb1bmr1288833lfe.24.1698393856230; Fri, 27 Oct 2023 01:04:16 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:15 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 6/7] cpufreq/cppc: set the frequency used for computing the capacity Date: Fri, 27 Oct 2023 10:03:59 +0200 Message-Id: <20231027080400.56703-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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]); Fri, 27 Oct 2023 01:05:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895273178142630 X-GMAIL-MSGID: 1780895273178142630 Save the frequency associated to the performance that has been used when initializing the capacity of CPUs. Also, cppc cpufreq driver can register an artificial energy model. In such case, it needs the frequency for this compute capacity. Signed-off-by: Vincent Guittot --- drivers/base/arch_topology.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 9a073c2d2086..d4bef370feb3 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -349,6 +349,7 @@ bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) void topology_init_cpu_capacity_cppc(void) { + u64 capacity, capacity_scale = 0; struct cppc_perf_caps perf_caps; int cpu; @@ -365,6 +366,10 @@ void topology_init_cpu_capacity_cppc(void) (perf_caps.highest_perf >= perf_caps.nominal_perf) && (perf_caps.highest_perf >= perf_caps.lowest_perf)) { raw_capacity[cpu] = perf_caps.highest_perf; + capacity_scale = max_t(u64, capacity_scale, raw_capacity[cpu]); + + per_cpu(capacity_ref_freq, cpu) = cppc_perf_to_khz(&perf_caps, raw_capacity[cpu]); + pr_debug("cpu_capacity: CPU%d cpu_capacity=%u (raw).\n", cpu, raw_capacity[cpu]); continue; @@ -375,7 +380,15 @@ void topology_init_cpu_capacity_cppc(void) goto exit; } - topology_normalize_cpu_scale(); + for_each_possible_cpu(cpu) { + capacity = raw_capacity[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)); + } + schedule_work(&update_topology_flags_work); pr_debug("cpu_capacity: cpu_capacity initialization done\n"); From patchwork Fri Oct 27 08:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 158806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp437627vqb; Fri, 27 Oct 2023 01:06:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtePVnKu+UilmvQ1+9g01W8e57iPuwybnhraYwiYXcHc2jnFEmfit+Fa6XMXVke1yycP0z X-Received: by 2002:a05:620a:1662:b0:777:7314:ee19 with SMTP id d2-20020a05620a166200b007777314ee19mr1727321qko.21.1698393991306; Fri, 27 Oct 2023 01:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698393991; cv=none; d=google.com; s=arc-20160816; b=JvJwY+f1xJDArPx/faVL8w5RfEB1gFL2Ra2GKn/eHlT04UUA4cHU8bwDI2syFMVkm5 5uhPuqByAyksDGQacWJyHVDT46PkXRGFSujJWn6qoKMqa3Y2SogUFoRt8Qk2IgGLsHen CLAVpqQRh0SUuIS8+vIgG0UwPs4gF1NJXQJaCa9tzcM/kJoA48zuTRd1IhSMGyBwxugy ar1yI7A7KCyn+elIV+3Slc580Zv3pXDnF48wOOgA1EB3c/iIeUJ8/IzCAAi5TV0nxWtr Y+5Sp0p202fTwhNJfenqa3qV6bGBCVu/1hTc8cR1LgZoxInbGspOoOn5Whjo53ExS4Vq R5Eg== 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 :dkim-signature; bh=/IF1VOPdi0K4kIRvpjz08HAORhp3LmbyMbIJ+gO1rNg=; fh=aqXlZKEuqBn32GiqXwfBTBEPXMVE+dzbtwpLcW+Wljc=; b=Gm3VjKXxf/T2YGHZHBIsa6og20ovyKLsg9984uAc60BNdWCmvJDuTpSHRCmI1/ULqp J9sVsH+DsZCOYpXzpLdBTSWYXHN+A2kqu9NJ9oJxoK/FEYkgXg78cLM9c6WxiA/3LTLS dJBadhdyWnzUglkc6K3BkyBLC/1A78ZWlR0rCNqQV1zPzRDPVyME/wHSzg1SknkOwbXY 7V+QWMeLs/l+O29z5pCzSmhTT43fN4UyOFwCHw2yqUVhb/oXCw8erFVpXr4jamTG5SD1 t9rjAGFfx72qx55cJ7FHf8WUr27vM1+itb06GQePihjaXxx1zIkqBp0tb89sHFwwIYeu zmrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hf0glRMT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id b64-20020a0dc043000000b005a81a9a2628si1581895ywd.499.2023.10.27.01.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hf0glRMT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 0232E8084063; Fri, 27 Oct 2023 01:05:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235109AbjJ0IEn (ORCPT + 26 others); Fri, 27 Oct 2023 04:04:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235096AbjJ0IEf (ORCPT ); Fri, 27 Oct 2023 04:04:35 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B66AD62 for ; Fri, 27 Oct 2023 01:04:20 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4083f613275so13303485e9.2 for ; Fri, 27 Oct 2023 01:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698393858; x=1698998658; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/IF1VOPdi0K4kIRvpjz08HAORhp3LmbyMbIJ+gO1rNg=; b=Hf0glRMTjYhF+QmxPCc3BphrnRo7GwxHj5/6qmmHNeB2FzhBMbagqddrHWwL47y/4Q 5JQ6DvRhT2qjVBc+LPTUOWX5VUBdfkDoN5ownLCJ9GUlkSwQAjIax1aCoPiz0I7XVzLO ChXb+SM/gPhtsnZ7pwW3e8iZHCU6gEvKNTy8+Ydv+XLaMy6/rgn4wCXZ4nE5KusDnYGK estgYZ/3sgrbWCKCMqHOf5vC0jh6UexRDv2BVmpaeisfvfq4TAgvg5lRYDG3ddA3UoCI DFVF+mO0PSxPz0/QLE6U3Oacj30dVe1A7fZW4XXZPWCkZxVO3gFRGGgrv1g/q/gDEYNX XO5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698393858; x=1698998658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/IF1VOPdi0K4kIRvpjz08HAORhp3LmbyMbIJ+gO1rNg=; b=uIxMgqIyjCE2sJzIAOCESlQ96TJ9nDbjCAs9G52/GeS0bV/bMd93yAu4Wc5onlXuQB 4jbnQeDEgyKYfAvY5jj6UAxcPIEistoJaNFnk/Jvd41dgDVjWsPk92B4ycEfmC8mSgHu WWWYlbc2iSBi+TFcjYdZ18hEqduRuJCzaZmJezgsjFMFaYtiPv6xsI4rwytTLgGUfIKq uRUxj3a+nY0RgiWRcjVdYBrRSdoQc7SR7Cp2QMVqT9TBlLeLLJf3nWrMxBOp6B/dsywX t6FX+pBC8CgPSkkxKzKueiaoasY8JDPBS+Bwn2WipBSa0Q1iqnaypnFEx5v4LXf90wEI +OXQ== X-Gm-Message-State: AOJu0Yz1PW6YXLEvGJ8b3oYwEsOk39K6cAhIRv6IerBpua9CM/y/qphX 4nN6Gn3ePJbGenxVhgzkQEC1VA== X-Received: by 2002:a05:600c:4ed2:b0:408:2f50:f228 with SMTP id g18-20020a05600c4ed200b004082f50f228mr1650096wmq.41.1698393858093; Fri, 27 Oct 2023 01:04:18 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:c5e:e24e:ad0b:58c6]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c025100b004083729fc14sm4397488wmj.20.2023.10.27.01.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:04:17 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, sudeep.holla@arm.com, gregkh@linuxfoundation.org, rafael@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, viresh.kumar@linaro.org, lenb@kernel.org, robert.moore@intel.com, lukasz.luba@arm.com, ionela.voinescu@arm.com, pierre.gondois@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH v4 7/7] arm64/amu: use capacity_ref_freq to set AMU ratio Date: Fri, 27 Oct 2023 10:04:00 +0200 Message-Id: <20231027080400.56703-8-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027080400.56703-1-vincent.guittot@linaro.org> References: <20231027080400.56703-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:05:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780895178120349787 X-GMAIL-MSGID: 1780895178120349787 Use the new capacity_ref_freq 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 --- arch/arm64/kernel/topology.c | 26 ++++++++++++++------------ drivers/base/arch_topology.c | 12 +++++++++++- include/linux/arch_topology.h | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 817d788cd866..626031076b75 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 assosciated 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,12 @@ 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; + WRITE_ONCE(per_cpu(arch_max_freq_scale, cpu), (unsigned long)ratio); - return 0; + return; } static void amu_scale_freq_tick(void) @@ -195,10 +200,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 d4bef370feb3..3cba7dc753b3 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_ref_freq, 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_ref_freq, cpu) = policy->cpuinfo.max_freq; + freq_inv_set_max_ratio(cpu, + per_cpu(capacity_ref_freq, 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 38ca6c76af56..ffdf0b7c55fa 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_ */