Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2580241rdg; Mon, 16 Oct 2023 08:32:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8aXPAqsyFlHwNYREGivGNczJlgNIyR7z5Yb/iGz2lsSfGuIxs04IAkcLFAAyLusYrBUrq X-Received: by 2002:a05:6871:441a:b0:1e9:9867:247 with SMTP id nd26-20020a056871441a00b001e998670247mr17584854oab.47.1697470350483; Mon, 16 Oct 2023 08:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697470350; cv=none; d=google.com; s=arc-20160816; b=Bq6NF/+060CwxwuiSpdIYn70zjNqFnHIDpbvd443TpP5mEBhYUHRXnYfvYFhZNBanf QuJiR9bJIVYYyfFPHN8LMW+d7RqLcqS4GwE0Vw+oLD0vt72YzA27uOMbMCKBElEVByBr BtSCmGHg7T+faxVAKk88HnSJei2S1xB+7I6jRZTi0kuq+RI18eCWn2BO1ayV1b8oWsa8 4AZW1WzJR3Ar5I8jUTNJhnt7+EQ/9/E6/JVzawWOIcsiqRG9P+t0bKds2GeIEA8QFIvq 5H1InW33AA/qK68AvzTNv9ZOq3PlsEXp/XVhm9d9ssR2YWqSiVm9m2F1bNcBKE5FThr8 ITdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5pngVXoLiR/0bx1FlI0DnQePf5uJ9GAS4LvTh4IY1Rk=; fh=T1LC5uX+U75isHlyb7jE9iioqwZXwn1MyMR9nT7Dm/4=; b=wc3+qpyY5/KMv7CWDFHdV/pS+r+wBb6JBeKjJ3oUuCLV+D7qrVd/zljcQBVSOOcasO LVYFscxyP5zbdM+mGhWzijElbyf3U6EStHp2KhI8uYwUlD3mfgH9tl02UgF1UR+CbUGK h3LeWiqiTLH7L1zRlS1JoLjtA5LygkZuCRsGXHADoGNl9YxDdNPo1WaiXXozCrKXR3MI 30n4DQCLazMC/z5rG3xwFApklpBX4iunKK2fNd/EMglRDNiJj+nrligU+4sM4kcVYqte GrKpjZn39wp5UukhClTsLnYqZ4m0LOrAK8N3WnSky70TQoH4BwmbjQI6C3yw3LyK+6CD fA3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EVo3XDaP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y193-20020a638aca000000b005653e3f6d58si6228691pgd.748.2023.10.16.08.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 08:32:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EVo3XDaP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id A4791803EB85; Mon, 16 Oct 2023 08:32:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232582AbjJPPcS (ORCPT + 99 others); Mon, 16 Oct 2023 11:32:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231896AbjJPPcR (ORCPT ); Mon, 16 Oct 2023 11:32:17 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12B883 for ; Mon, 16 Oct 2023 08:32:15 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5a1d89ff4b9so2517597a12.0 for ; Mon, 16 Oct 2023 08:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697470335; x=1698075135; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5pngVXoLiR/0bx1FlI0DnQePf5uJ9GAS4LvTh4IY1Rk=; b=EVo3XDaPZO5aibDThpCEPFkwbQTLzeHQHmthGXdeMJPVShOEL4XIl8n9JlC/0uku5J Jc6INq5JtfbQj7TDjrlky3Ge7W2r1+FZ6YpKJDX+UuU3f8eB2T67DVmlCuLBS/SgkaFb N7O4EWeLZsVXuGK/x0QX/DQNfAJGfxjJQ4hZHThsWfN9B1+H+xLbzWxKNiIYLuvwhBny izvXN3GwIQmwxmKr+/Dtzw1884gOkfoTsNeQSqh890umRujMrPVDCr3hhKbsMGd8iRWh mnvtwCJnaJ01O/dae/YV59VBA5Jhtl9HbAxCYH5/eyitk+MxoVknSHWVmDnYr802BCxs R2Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697470335; x=1698075135; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5pngVXoLiR/0bx1FlI0DnQePf5uJ9GAS4LvTh4IY1Rk=; b=JM3oDofZJWHIpfBmsOD10sLa/zorY0MabGhaMacopj14cZODQddFkTuqRk49Pq9Owm WSUjWdyTEOHq5rjP5DvePQEmMgARqICiDMnJi5PIfffaW4Fvix4skv/+oNQMljsT+eoz 9Y9bveU8f5Xh0A7KSGkNLYwM8COJw7Ey/h14Vl2aixem5Oe0xMtsmq916uz9WRzMma15 KPYYm6EnfIIzPH0vVqCOitHPAJT7BpJZGNrLsBL5iuCKmzt+bop5pb9qGcIgIj1qm8f3 hZGwwf5FAkw5ovREPlC73iUUiZwIoyY2nq/aZx2Rk9AckSEQ7LoLYGpuujj9suncHCTV 0cbw== X-Gm-Message-State: AOJu0YwVcR/47suRczLSzDjVX7KUBrFI25Pj/4D/ooHZjX4LoQkfR1Ek xVnj9IigxEbIjeUtVFxh7DZ/kEAlJcEX9g0AMSdGIA== X-Received: by 2002:a05:6a20:9793:b0:174:af85:954b with SMTP id hx19-20020a056a20979300b00174af85954bmr8954867pzc.22.1697470335048; Mon, 16 Oct 2023 08:32:15 -0700 (PDT) MIME-Version: 1.0 References: <20231009103621.374412-7-vincent.guittot@linaro.org> In-Reply-To: From: Vincent Guittot Date: Mon, 16 Oct 2023 17:32:03 +0200 Message-ID: Subject: Re: [PATCH v2 6/6] cpufreq/cppc: set the frequency used for capacity computation To: Ionela Voinescu Cc: Pierre Gondois , 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, lukasz.luba@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org, conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org Content-Type: text/plain; charset="UTF-8" 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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 08:32:27 -0700 (PDT) Hi Ionela, On Mon, 16 Oct 2023 at 14:13, Ionela Voinescu wrote: > > Hi both, > > On Wednesday 11 Oct 2023 at 16:25:46 (+0200), Vincent Guittot wrote: > > On Wed, 11 Oct 2023 at 12:27, Pierre Gondois wrote: > > > > > > Hello Vincent, > > > > > > On 10/9/23 12:36, Vincent Guittot wrote: > > > > cppc cpufreq driver can register an artificial energy model. In such case, > > > > it also have to register the frequency that is used to define the CPU > > > > capacity > > > > > > > > Signed-off-by: Vincent Guittot > > > > --- > > > > drivers/cpufreq/cppc_cpufreq.c | 18 ++++++++++++++++++ > > > > 1 file changed, 18 insertions(+) > > > > > > > > diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c > > > > index fe08ca419b3d..24c6ba349f01 100644 > > > > --- a/drivers/cpufreq/cppc_cpufreq.c > > > > +++ b/drivers/cpufreq/cppc_cpufreq.c > > > > @@ -636,6 +636,21 @@ static int populate_efficiency_class(void) > > > > return 0; > > > > } > > > > > > > > + > > > > +static void cppc_cpufreq_set_capacity_ref_freq(struct cpufreq_policy *policy) > > > > +{ > > > > + struct cppc_perf_caps *perf_caps; > > > > + struct cppc_cpudata *cpu_data; > > > > + unsigned int ref_freq; > > > > + > > > > + cpu_data = policy->driver_data; > > > > + perf_caps = &cpu_data->perf_caps; > > > > + > > > > + ref_freq = cppc_cpufreq_perf_to_khz(cpu_data, perf_caps->highest_perf); > > > > + > > > > + per_cpu(capacity_ref_freq, policy->cpu) = ref_freq; > > > > > > 'capacity_ref_freq' seems to be updated only if CONFIG_ENERGY_MODEL is set. However in > > > [1], get_capacity_ref_freq() relies on 'capacity_ref_freq'. The cpufreq_schedutil governor > > > should have a valid 'capacity_ref_freq' value set if the CPPC cpufreq driver is used > > > without energy model I believe. > > > > we can disable it by setting capacity_ref_freq to 0 so it will > > fallback on cpuinfo like intel and amd which uses default > > SCHED_CAPACITY_SCALE capacity > > > > Could you provide me with more details about your platform ? I still > > try to understand how the cpu compute capacity is set up on your > > system. How do you set per_cpu cpu_scale variable ? we should set the > > ref freq at the same time > > > > Yes, the best place to set it would be in: > drivers/base/arch_topology.c: topology_init_cpu_capacity_cppc() Thanks. I didn't notice it > > But: > - That function reuses topology_normalize_cpu_scale() and when called > it needs to have capacity_ref_freq = 1. So either capacity_ref_freq > needs to be set for each CPU after topology_normalize_cpu_scale() is > called or we should not call topology_normalize_cpu_scale() here and > just unpack a CPPC specific version of it in > topology_init_cpu_capacity_cppc(). The latter is probably better as > we avoid iterating through all CPUs a couple of times. > > - When set, capacity_ref_freq needs to be a "frequency" (at least > in reference to the reference frequencies provided by CPPC). So > cppc_cpufreq_khz_to_perf() and cppc_cpufreq_perf_to_khz() would need > to move to drivers/acpi/cppc_acpi.c. They don't have any dependency > on cpufreq (policies) so that should be alright. > > topology_init_cpu_capacity_cppc() is a better place to set > capacity_ref_freq because one can do it for each CPU, and it not only I agree, topology_init_cpu_capacity_cppc() is the best place to set capacity_ref_freq() > caters for the EAS case but also for frequency invariance, when > arch_set_freq_scale() is called, if no counters are supported. > > When counters are supported, there are still two loose threads: > - amu_fie_setup(): Vincent, would you mind completely removing > cpufreq_get_hw_max_freq() and reusing arch_scale_freq_ref() here? I wonder if we can have a ordering dependency problem as both init_cpu_capacity_notifier() and init_amu_fie_notifier() are registered for the same CPUFREQ_POLICY_NOTIFIER event and I'm not sure it will happen in the right ordering > > - It would be nice if cppc_scale_freq_workfn() would use > arch_scale_freq_ref() as well, for consistency. But it would need > to be converted back to performance before use, so that would mean > extra work on the tick, which is not ideal. This once seems more complex as it implies other arch that are not using arch_topology.c and would need more rework so I would prefer to make it a separate patchset Thanks Vincent > > Basically it would be good if what gets used for capacity > (arch_scale_freq_ref()) gets used for frequency invariance as well, > in all locations. > > Thanks, > Ionela. > > > > > > > Also 'capacity_ref_freq' seems to be set only for 'policy->cpu'. I believe it should > > > be set for the whole perf domain in case this 'policy->cpu' goes offline. > > > > > > Another thing, related my comment to [1] and to [2], for CPPC the max capacity matches > > > the boosting frequency. We have: > > > 'non-boosted max capacity' < 'boosted max capacity'. > > > - > > > If boosting is not enabled, the CPU utilization can still go above the 'non-boosted max > > > capacity'. The overutilization of the system seems to be triggered by comparing the CPU > > > util to the 'boosted max capacity'. So systems might not be detected as overutilized. > > > > As Peter mentioned, we have to decide what is the original compute > > capacity of your CPUs which is usually the sustainable max compute > > capacity, especially when using EAS and EM > > > > > > > > For the EAS energy computation, em_cpu_energy() tries to predict the frequency that will > > > be used. It is currently unknown to the function that the frequency request will be > > > clamped by __resolve_freq(): > > > get_next_freq() > > > \-cpufreq_driver_resolve_freq() > > > \-__resolve_freq() > > > This means that the energy computation might use boosting frequencies, which are not > > > available. > > > > > > Regards, > > > Pierre > > > > > > [1]: [PATCH v2 4/6] cpufreq/schedutil: use a fixed reference frequency > > > [2]: https://lore.kernel.org/lkml/20230905113308.GF28319@noisy.programming.kicks-ass.net/ > > > > > > > +} > > > > + > > > > static void cppc_cpufreq_register_em(struct cpufreq_policy *policy) > > > > { > > > > struct cppc_cpudata *cpu_data; > > > > @@ -643,6 +658,9 @@ static void cppc_cpufreq_register_em(struct cpufreq_policy *policy) > > > > EM_ADV_DATA_CB(cppc_get_cpu_power, cppc_get_cpu_cost); > > > > > > > > cpu_data = policy->driver_data; > > > > + > > > > + cppc_cpufreq_set_capacity_ref_freq(policy); > > > > + > > > > em_dev_register_perf_domain(get_cpu_device(policy->cpu), > > > > get_perf_level_count(policy), &em_cb, > > > > cpu_data->shared_cpu_map, 0);