Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp989368rdh; Fri, 27 Oct 2023 01:07:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGg3Y8kwdAKvuCuEZ5mR3+MouB3IaIoUn1zhM+SATLnjaVXVPpoopj4bhZMTZ3m/j7ldcm8 X-Received: by 2002:a25:9cc8:0:b0:d9a:5859:bf14 with SMTP id z8-20020a259cc8000000b00d9a5859bf14mr1625694ybo.64.1698394077925; Fri, 27 Oct 2023 01:07:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698394077; cv=none; d=google.com; s=arc-20160816; b=CMBJhGbPqu9T7XAgXNNcNPUafLnAp0ZPAdpTc3MkQ0/hLqYqdfnjmCvSIGi0M9+jTm zuFUuaas9sf/5VXUBxXtj9c+AEFmcNAGipNEk9JXK+OBxunWMeN9nYkt6hBOvhbnbX+N MdpGgi2Y0OZKqCxVjbMPPQhLJwnqYz3CHWoZTZmUroke3Mug+z9YXokcel4K2ixaLn/H 1s0qpUHnW9J0FPP/upy8hKjNHlzM+hC9+7ZOgwj4ePuhaJbogapn6l2NRHfByZMI+56e X1d6AXu0ucFiysWf5X2SNgPCqDE1QY0wNnP3xosQZNy2Eygt8KMiyc/JSRdQnUgEiFP7 EwPA== 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:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id 123-20020a250c81000000b00da0833f124esi1860993ybm.104.2023.10.27.01.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:07:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; 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:6 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 4677083A0C16; Fri, 27 Oct 2023 01:05:00 -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 S235032AbjJ0IEf (ORCPT + 99 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 Content-Transfer-Encoding: 8bit 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:00 -0700 (PDT) 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 -- 2.34.1