From patchwork Fri Sep 1 13:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 719841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D502CA0FE8 for ; Fri, 1 Sep 2023 13:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349667AbjIANDc (ORCPT ); Fri, 1 Sep 2023 09:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349642AbjIAND1 (ORCPT ); Fri, 1 Sep 2023 09:03:27 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9875E7E for ; Fri, 1 Sep 2023 06:03:24 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31c4d5bd69cso1659761f8f.3 for ; Fri, 01 Sep 2023 06:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693573403; x=1694178203; 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=V5aYZdSdgznaVi+JliScjcxNZSCQD8Th20BQ7P8lBSs=; b=hO6xfBmPKBgbuknFzUx9djhsOZtlMuq9HbhytH/CkX7n1a7K7Ppwgg3wSN8ElMwOn2 /FbUOQZdqcKdECl5sdrAJI50ai9l6fgV6X9+FiZXQyJ9rsO9k6M/q12SFwK/pS8XIg/I GY84P/+ugAHDXz5ZaSIiIpSCw0QOVMAm53MtNAfq+M4RvOHwwBOmhHB7L/21qrLWvheL ZqyCNDs+JcbhHxBeihuDCzU80XVQd74n5BJ1oblot4ZlKMW78OjjrsvGHwGMhixwGV5t VaPNz6qJyPgUbWrPKTDhNdOt1QsHiTXPMVxU9Ks/PqAYsLhu/NHB4i9cpjEjULOMufsa j2Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693573403; x=1694178203; 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=V5aYZdSdgznaVi+JliScjcxNZSCQD8Th20BQ7P8lBSs=; b=J3fb2vHJkntPtnVOLrmBIg15NISVinYW1zMpEhIfUkuypBqmsFLrzD8Uzu/frpAJtC 1aE+XZCnlkss7wz4UcomucEQleCUDgjsRuhTNwOcDPjr1FFLsalwyIh2eQRm1CBKaC6m 9cbFv8OzJ86CvOlNaVnLFJbAoh0MdekTXl7dHW8VjQ/bFEtlfXV0TqOZkislM+K3s93P Q3hNHug17CZ/Oawg9KK0TaxpNe7+I2d1bHg54d4bs14n0dhjbUdDOKxCbVatN6kQszwn T4YHvQLdQOKQQVfdYvSMDsWtD/vEDF4BPlVfFBbDbqsw4rxxMayqOTbkp/lWWqEPP7vZ xIMA== X-Gm-Message-State: AOJu0YzHotlET+fy+bjVP+2X9khtsZZOixJjos17IsCYCXjExiBDVzSQ CrDwm4HIuZEd5UtYOjP7ZuTT8w== X-Google-Smtp-Source: AGHT+IHWuDsPZBVeKEf+XTy2vPIdFmCGwE/gsGA3pylPfmUXuPXSa8EeuGjxUHsZSClfbNuuKWlS8Q== X-Received: by 2002:adf:e544:0:b0:31d:db92:31ae with SMTP id z4-20020adfe544000000b0031ddb9231aemr1715345wrm.44.1693573403268; Fri, 01 Sep 2023 06:03:23 -0700 (PDT) Received: from vingu-book.. ([2a01:e0a:f:6020:e9bd:add1:d9ac:7b3e]) by smtp.gmail.com with ESMTPSA id i14-20020adfdece000000b003142e438e8csm5167452wrn.26.2023.09.01.06.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 06:03:22 -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, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pm@vger.kernel.org Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, Vincent Guittot Subject: [PATCH 4/4] energy_model: use a fixed reference frequency Date: Fri, 1 Sep 2023 15:03:12 +0200 Message-Id: <20230901130312.247719-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230901130312.247719-1-vincent.guittot@linaro.org> References: <20230901130312.247719-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 when available or fallback to the last performance domain item otherwise. Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba --- include/linux/energy_model.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index b9caa01dfac4..7ee07be6928e 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -204,6 +204,20 @@ struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, return ps; } +#ifdef arch_scale_freq_ref +static __always_inline +unsigned long arch_scale_freq_ref_em(int cpu, struct em_perf_domain *pd) +{ + return arch_scale_freq_ref(cpu); +} +#else +static __always_inline +unsigned long arch_scale_freq_ref_em(int cpu, struct em_perf_domain *pd) +{ + return pd->table[pd->nr_perf_states - 1].frequency; +} +#endif + /** * em_cpu_energy() - Estimates the energy consumed by the CPUs of a * performance domain @@ -224,7 +238,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 +255,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_em(cpu, pd); 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