From patchwork Thu Feb 8 11:55:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp109995dyd; Thu, 8 Feb 2024 03:57:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCURECgJIPzYmqThvQjGBiuHeItteIsk1g7b1VAk9+9OKkXzZg6SGCetZwl/4CognT/I9LepNXE0Xww7ZKrj8TR0HZwOjg== X-Google-Smtp-Source: AGHT+IEiSkeT1JIJbWA+SYn+62FMCTHrgFAe7D01NZX+djGcZYeoYbheSW27FLzvYcrNNM8qldP6 X-Received: by 2002:a05:6a00:27a1:b0:6e0:5cb7:168c with SMTP id bd33-20020a056a0027a100b006e05cb7168cmr4148136pfb.17.1707393451202; Thu, 08 Feb 2024 03:57:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393451; cv=pass; d=google.com; s=arc-20160816; b=j4/vDMJP3CNJ9FGcPPYQidhQAbTLqVb96tAddbXIEaS8Iwz9tE7vwCX2JkEJ9YkMwp Rp8X7J5oSBGvoUogjP0sLAx6+jwQid7F+hqNw4dwvO8+y27s1iH0G3tHG+ucKf6kmWGQ D3J+RKSda3bJ0DFYs0YSOCttEeXZEYl8NitqQPVfiyroQI7Y/ETXe0fhArQNlTy2wqiY 66Xt8cTn4NT5axgVQSW+VEvIVatddJKOA/hU9yPfjIvkMZEc/gqfWQS7uMGW/29swIbb 8hgv8b8VgotDliTlTfSCmu3eXghGC8TPTOdakgH309gJNJ+o14VXi9uzHKuPlaIsCOJS 2Yqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=/r4N6VsZ8/qe/wqCW0BqzD+PyOsJELYWwW7UyTyMS6I=; fh=+aD0/yY+QNUmHoBkna2rTxcoXXcGTQ4tyos9RQGbDqo=; b=zz2ALSiq1sOUKmc6vjgphTXUdP0MPJkee5ycqsh6DOzJbrmjp/gsmuC7NK9/UTxWSK RZGxUi6eyBg2VQGRAySmNzZCX+qk74cAiSbtnZvNfxabo5ZmM92q3yzIEWBzEkxGBqrO 7f0r//Qpo+vCq1e11JlFI8hXNZd2v8BoKybCcHsDogJie7FFP8/+XEbYpR3PtF0b9J5j DbS2dqbR230LYqALeiyE0wW7CxVFHmru/VpY60RNj/el+d/jmRwKWzLXNa0ngJ20kACW tUzssi76kIPjtogSmArIDuMT6LVvDGi6CuKTn3tKWXLuWvQgbfSlKE8zcsoh9/WAc5DC 8C+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWIg48czVsVisMAl4qEbAqfh2Lam1TO/11uoC4CLRh3OvL5c9kr6J/B0SBC1kysCsDmCv4Jz5sV834kL6qzwN2M48KJVw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jw16-20020a056a00929000b006e06f330bdasi2919828pfb.55.2024.02.08.03.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0167828C02C for ; Thu, 8 Feb 2024 11:57:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D463762F4; Thu, 8 Feb 2024 11:56:22 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C241762C5; Thu, 8 Feb 2024 11:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393380; cv=none; b=Snd0jMfugaC2abcw3tNSrXJ5UNHbbR0yo0MC0JlIrl5ZYcDGqw45OSHfT26o4LUU54R4Iln6lgPP+MeeumMM0oc7poa/o0+QSRcRNuyNJ4n9jMaXWnqd5nkK/mNCUVsbu1kIO7QfmMKBJOxGSlHwi/SFApWFf3uh6hSfY965QSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393380; c=relaxed/simple; bh=EgS98AzIrfTEkTeSSi8iSkdXy/W4/EMIsMiXga11j8A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UozrOH42QHl4DlAHS5VCh+1GmR6JU+QP6YU40jHjviRTbkxxgIZHT6ksRoIfuiXAYo/ZwYWeDgrYAhFNcttYhb54ZF/pAkwHlQy0s6cMyAyPWKMZilpkhB2pEzRyJuGHFd+sjPkSPf30KkNeBlDxNRgoeR55/CQdqLdlhtGRWIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F30501FB; Thu, 8 Feb 2024 03:56:59 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE4093F5A1; Thu, 8 Feb 2024 03:56:14 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com, Hongyan Xia Subject: [PATCH v8 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Thu, 8 Feb 2024 11:55:38 +0000 Message-Id: <20240208115557.1273962-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331795314127603 X-GMAIL-MSGID: 1790331795314127603 The Energy Model (EM) is going to support runtime modification. There are going to be 2 EM tables which store information. This patch aims to prepare the code to be generic and use one of the tables. The function will no longer get a pointer to 'struct em_perf_domain' (the EM) but instead a pointer to 'struct em_perf_state' (which is one of the EM's tables). Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to be re-used. Return an index for the best performance state for a given EM table. The function arguments that are introduced should allow to work on different performance state arrays. The caller of em_pd_get_efficient_state() should be able to use the index either on the default or the modifiable EM table. Reviewed-by: Daniel Lezcano Reviewed-by: Hongyan Xia Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 88d91e087471..1dcd1645dde7 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -175,33 +175,35 @@ void em_dev_unregister_perf_domain(struct device *dev); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM - * @pd : Performance domain for which we want an efficient frequency - * @freq : Frequency to map with the EM + * @table: List of performance states, in ascending order + * @nr_perf_states: Number of performance states + * @freq: Frequency to map with the EM + * @pd_flags: Performance Domain flags * * It is called from the scheduler code quite frequently and as a consequence * doesn't implement any check. * - * Return: An efficient performance state, high enough to meet @freq + * Return: An efficient performance state id, high enough to meet @freq * requirement. */ -static inline -struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, - unsigned long freq) +static inline int +em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, + unsigned long freq, unsigned long pd_flags) { struct em_perf_state *ps; int i; - for (i = 0; i < pd->nr_perf_states; i++) { - ps = &pd->table[i]; + for (i = 0; i < nr_perf_states; i++) { + ps = &table[i]; if (ps->frequency >= freq) { - if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; - break; + return i; } } - return ps; + return nr_perf_states - 1; } /** @@ -226,7 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { unsigned long freq, ref_freq, scale_cpu; struct em_perf_state *ps; - int cpu; + int cpu, i; if (!sum_util) return 0; @@ -250,7 +252,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - ps = em_pd_get_efficient_state(pd, freq); + i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, + pd->flags); + ps = &pd->table[i]; /* * The capacity of a CPU in the domain at the performance state (ps)