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: 13372589 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73FE7CA0FE9 for ; Fri, 1 Sep 2023 13:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=G9Co9lwHfyxMfYgR3PhK8zSVF2E2NohenELmYD2naIA=; b=xvAbM/GBbQNbaE SmhNA3E1IL9Yo2hOeTEGM742CMaLkP7qnQVoQIreKbKpzYMAOexJP67P84HRTIK8StOq4YVbQtfpE hrx7aQdDHh4ybX4BTmI3MbzLB3gHhH7rSQsM4SXGIozBnqGvwZecrsv4c7F7juQSTROhEIOaI3ONP NYtNGHJ2rMuFn3WxFH1lhYSkrZ691tGnXnqhS/Rb36RzdYSCXZ2kOjSR2tmvVeyZvZ3Diga3njBa0 56o7zPZV6u7MVtdjAQUvUWa5o9GjAG1TdPY6ROcpNlARYnFkncH9xIJPqpAHqq6Y/AkWs3IuScgdk OfPiSXkBHYvCnMaWs+8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qc3oC-00HXNV-1a; Fri, 01 Sep 2023 13:03:32 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qc3o7-00HXHz-0F for linux-arm-kernel@lists.infradead.org; Fri, 01 Sep 2023 13:03:28 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31de47996c8so1656853f8f.2 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=lists.infradead.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=Ch0A21/wQesZxla0Xmw1qB6nBqJ7daDxF7R02Ue9pbhOBLPcxevVG1AkM1sIWgqhY8 YbK2IEfPYtS4hncA2HKvaJ7ukWRsMT3WKlcQRNYA0k17ymE348kg/SXCEhMlmtp/6DZt n/r+UtOk6KE3OvAhc7xVQkd5NrkwD/tehBE7XvAzs3EuyrEAXs0I7TQjiUNeKHcCB8Ba cJ9rSnMJeIlhWzya5DqRWvS4ZTF/lUbK+sIIovMKrZbMdPXqQoNpW7ZYpktOjwDgUm3O 2YN5nwGO735PSpxsL0PK7flYeFqquyxlh5tMdjqq0JaahwcR+1jpQYx4uHKJYn1Aigw9 7vCw== 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=EzRVQmU3QCsgmqkr8n0Jsxe3n/vYs3ryIT2UIkudwyP1c3fhd/d9AqUqlIJusBz16Y Yf25UAGRMr6IBTWowaOOMN8w+KogkCy8SDo9uZl33dukT028yV5UgUmBBpNucbEk0rA4 UDL249BkOVmIGXCXRxayOtI6vwvRdzaTti1qENAuVEfPHfV9AkFm8fXy6/mdd0XMNae2 b/dYw1246F/oVquQObIK08jvikLaXV+BLOYChYJattEqoqJVU6/yByn+QtANky35zhwG PWdEZnYVkgY7CXpXt/xSXDz3ejODMb+MHOV7jQlFoQN7fXVr++oB1D/CA+lLRS/sfB3p IbUg== X-Gm-Message-State: AOJu0YzaAAjlunxmh9HjQO5sQMavBtNtHATClUAOx0hc+5FCNeAbruqV 6TgUdWTnZ3Xdxl7/uqetEWWqdA== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230901_060327_188557_38331B5E X-CRM114-Status: GOOD ( 14.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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