From patchwork Mon Dec 11 10:48:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13487016 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 C392AC4167B for ; Mon, 11 Dec 2023 10:49:50 +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=qhuJD+wDsp49CMfYz3iMtqcmGnU1217W/YbXrt70lH8=; b=f4UsKxCydkuzzI nZg1qIqIBbeoPhIK+BWt5JKbSAAzDDJTzcn6MNYHxh7OnmbjTcsDIO7pIV43Kwl0XpJt5sdbvUpWF lY7wayIbwRcHXINQXZIKV0nI6jGd6QYtUJtp602R0NgQGLNkiSthVWQoLMrNub/VB1XHA6hRSiEeA n7PVrTQN9XsHkt03iYzd1a7SPwkmqhUl4K6/fDdY86PgZ9FQ1BxMm/8NOVNOwFHSsXTljO1fYedkh f/cl1Sv2Ggqhh6lpRbNZCu81N8J/x1RBJqpCEL8hEX/fqjJGBYwQkupsWLGiNBw9Phk6vCo+65JFt Wws+kX0CHFSdHZ0HUf+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCdqi-004e5K-2m; Mon, 11 Dec 2023 10:49:20 +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 1rCdqc-004dzR-1x for linux-arm-kernel@lists.infradead.org; Mon, 11 Dec 2023 10:49:16 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-336121f93e3so980264f8f.0 for ; Mon, 11 Dec 2023 02:49:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702291746; x=1702896546; 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=19YdKXep2h2XKs9tI+n1uE2b2ri9zL5T7djiTxR5FZs=; b=eR47ecjzFMgSvhxLbTqxil+SBlHjFKaUd5UJeRKjYCf8pgjZ7sFOm0HCmGsqsN9wkh UIQyNhNiyHsXLwPP41Uyzp3GjnIouv8BZtmBtLacLk3A0Pmy1kIKHzYqk4ytLJtTy/ds 0So/rJXz3Lz2P3dQm2u3YYMP9eEVhrbPuqMM2il3M0jT+34pk6wDcldk258SaSm9lhWQ gb5Oy2HUR0nZh68dIgLbTCSvMLosPTAwijFlidnvj3QFlk+urr1adkIOpUg1Rs2HSpz1 l2wb7nZjA6SVXsTyb9M1jq/t2EGt3o9dJ4UKcSQGqAVJyJorKDXC+vttiPQQQ0GdvOtt B4TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702291746; x=1702896546; 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=19YdKXep2h2XKs9tI+n1uE2b2ri9zL5T7djiTxR5FZs=; b=pkpzaxKyYVr4G2qhM0jcpdqZ3N8tz6KpUi+7agVZjWyLnTA4670TkHeO+nMTpzpgxp jwerVNBVc0l3S5QbPASMk/C76xRmum4tnaBkP3BCbeaJTjIqQjhTSfaN5rMiNmGZdHiF EIHexQDPfs9nLMh1hYrwpUWX97cpAwX71Z4T4OTs4yYHpaC5yagN6P9Q1lXqkHbPcibf skbDH+jtTEARf4c5UvOx8pJyYtG7rz+VHIStcAhp68yLmSbaQrVrUhEgUOQjMag2Yz2S f34RduknzpYzeGnOb8QRNPSUYMQBpr60LTfiYD6B2NgJUvV4hmKJy75tqSnfcg1TZ9JD Wd6g== X-Gm-Message-State: AOJu0Yz0hwpnhc+fpnigRrTJP/9G50Fjzk72WGxDRPwMhZ5XiAB7kEgy IoqrN89DMG/ctpoxwdEe9Aj0gQ== X-Google-Smtp-Source: AGHT+IE6XqYGAPzyGfJojSMGYv4TCKNLa8KTkknwn96//z5+sFb+KJ1vbQvECdNkL4zdYu7uN7TYyg== X-Received: by 2002:adf:f3cf:0:b0:333:3d26:7b01 with SMTP id g15-20020adff3cf000000b003333d267b01mr3106219wrp.13.1702291745981; Mon, 11 Dec 2023 02:49:05 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:a8d:abc:f0ae:3066]) by smtp.gmail.com with ESMTPSA id e16-20020adffd10000000b003346db01263sm8232579wrr.104.2023.12.11.02.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 02:49:05 -0800 (PST) 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 Cc: conor.dooley@microchip.com, suagrfillet@gmail.com, ajones@ventanamicro.com, lftan@kernel.org, beata.michalska@arm.com, Vincent Guittot Subject: [PATCH v7 4/7] energy_model: Use a fixed reference frequency Date: Mon, 11 Dec 2023 11:48:52 +0100 Message-Id: <20231211104855.558096-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231211104855.558096-1-vincent.guittot@linaro.org> References: <20231211104855.558096-1-vincent.guittot@linaro.org> MIME-Version: 1.0 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 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index adec808b371a..88d91e087471 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -224,7 +224,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,10 +241,10 @@ 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 = 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