Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp290952rdb; Wed, 17 Jan 2024 01:57:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEafV1EZpmOBiiQU3LWvNFArUopEzLQMhd0dM11VjHeQ6gX0mVmlv2wGr8RktJgkWZKlXt2 X-Received: by 2002:a17:906:1646:b0:a27:59a2:93ff with SMTP id n6-20020a170906164600b00a2759a293ffmr1824065ejd.161.1705485430690; Wed, 17 Jan 2024 01:57:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485430; cv=pass; d=google.com; s=arc-20160816; b=yDhtxPJliyhwSkZ+RA8iy2MFYj8LPZO5Z9RUOECBTalSR/Z5EPsnRPf7cQWeT8XMEU ix8Qx8EPxfmCL8znUkx7TcRdOYeKYT5F1PE2CR83p4Cbp6vC6wH5GVjq6t71eHqPMjb5 bHhFa7MZlCq2NrTwt42kD87QRMQI51SGl8yKr9GNT0Rhf1/8MRgWRDfy98CY05Rp8VeC MimG8bGjsltbX4NZrv7/4RuPIKECECtmpRlSC2wGC3Y1z6pmj7hNiVr+9Zyh0HXrOnZs jT+EGIDOYh1k7w3zeXgAhCJg0QfldeFRqhHyAJdBNCqPVc/JtFARCQgRiChVYLvBIiFX AfIg== 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=nHRmPZ4slt2aAj2ACk8bQgLJkuWnV4IJks2w8PbyiOA=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=Ynn3gp7RSKLjmuAV3kL/+Uv6jgpRkW1vLUkb+buzniTfDZOcDUCDW3VAkABkvxVX0q R+oc0PDCmfKGSa7rsb5DzcL0fRVSaqE7o8LzjUfhqtChcCSZK7Idrxr8+gMCJGxC0a1c ufa87YIWhF11D71a1uo66hIitclJsrOHjmMjayEXOMvm0W6mtR8nwUFlNzCv8IwdHNjc 6jTlSSqzSTK4mrRu7so75wrMcCEh3H5CGfj4SPuw0v2xZK8YS0vNjZW4o+3M4d+lsC9k v9qbFNQFXfw1HG6qovDVB0aw/awCQ6+AKwJqzaEyPAiBCHDo/PtzoKSUlPaUBCnI9VBJ rQ+g== 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-28774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28774-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z17-20020a170906241100b00a2d1c3c7506si3966836eja.442.2024.01.17.01.57.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:57:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-28774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28774-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 70AD11F24C1F for ; Wed, 17 Jan 2024 09:57:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B6241DA29; Wed, 17 Jan 2024 09:56:12 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F12C41427F; Wed, 17 Jan 2024 09:56:09 +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=1705485371; cv=none; b=aSOzRt0k7N01Vl6HJNCeuUbpmUE8LKlNSJRIxjkdh07Mx5yxu/FRin3Cqogld2IMU2+LT+yjRbXbOIVL0PCGibK1IK2KcecUxFJWv6hqqYb3+UPnorTGX7JRW5aPJ2Z3ih1pvazEWQrsmeRpqzrmvP31Ddy5am+O4wYTHZ9HBZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485371; c=relaxed/simple; bh=0r+OlijjkdGwdnfDmv2yF2N7o0VHYD3IW62Yb0+hBuk=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=AcpjApNwUg9KjjwQBZBdHJ3xvS40eKLFH4NymwJ8U+9B5en0YPPI24ND68ifCcYk/IoD1tDBob3zDb/9ENuMq2/lkL2vuJOeL23NIai/T0FroDYy9vJ9jA33bG46+nHJu/OI7CeVAmNwiUk7rzbCIZbZTo8BobfY1oyTLemnsKc= 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 02FF111FB; Wed, 17 Jan 2024 01:56:55 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2E4EB3F5A1; Wed, 17 Jan 2024 01:56:06 -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 Subject: [PATCH v7 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Wed, 17 Jan 2024 09:56:55 +0000 Message-Id: <20240117095714.1524808-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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 Content-Transfer-Encoding: 8bit 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 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 c19e7effe764..b01277b17946 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; @@ -251,7 +253,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) -- 2.25.1