From patchwork Fri May 12 09:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 93086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4981923vqo; Fri, 12 May 2023 03:08:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4dtMCzNN3yafo+UEa4v0aDdwPGUfBN6Bgf++geIkx9j4ZE5Ri+39pFrLTcJv3W++bSkU0T X-Received: by 2002:a05:6a20:160a:b0:103:7b79:1506 with SMTP id l10-20020a056a20160a00b001037b791506mr10408428pzj.24.1683886113525; Fri, 12 May 2023 03:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683886113; cv=none; d=google.com; s=arc-20160816; b=YGvr3fUlTSXoWgudCSJ9MWuDZC17Hxg5r4jr6rSZ18Gxy2yce+YKFsVrGyU+QrFgOK A5nhmx5m79sAJPKPrRfZVkX7fF+6ca4HpdVWLpkyiDrvIgkxTl9/nbQyRn+y/FVXnoTC SFdexQv0m52LPWo8jVYaZcgaxmhiSVkrkGWTtF2vwW5RyfdcHn9P+dn/nr+9GcJHpSpM ogiRT+qpu5zki7OC/NyQY/HdyPEsL2oCytzb4/Aq4AtHuYwdrKbzliT4DsdzvTsieLvK LQQL3rRXPXcwdVQH/ssrEtse5WrzgHtANqaKCyYPtAE56zR/t/RJT6OCjlWDt8whd9T5 8z+Q== 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; bh=gu9yvEAWYXJF0qW9SJFTVh5HhfGeAgRh+7RvF/01tVg=; b=wA28ypcFmmLsaMCjezuUdoC/X7UF906lQ0K8C+Y8tmja6zBSGtITBTXFd1kxVd2jdx vWcbRKIEm0bOjqBJLhWcHYAKV4jUuYhfWtl1EDv+/r4KLGAlZxPGt4WXZhcxTE7X6bht fTVhhzFkwe4mG5LFUHdUzgWA2zp9ZIz7qZf6SmT0hbP0SV7tZTNzddBNOc+Vfctvb868 IN1rpQ7fBWa2g30OIVnfbbk5RrNZxTeUjWqwaCBO9HPX42qulrAn8qh3PjYGIAXNYBED 5SHgL4u4VE6cyGaPMVvhrgDQGN16mVnNvkYu8grF4YaYyToMoa/xtW5ASISuXCd/AtPJ d+LQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a63cf0d000000b005139e5df68asi8803524pgg.433.2023.05.12.03.08.18; Fri, 12 May 2023 03:08:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240670AbjELJ6l (ORCPT + 99 others); Fri, 12 May 2023 05:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240657AbjELJ6U (ORCPT ); Fri, 12 May 2023 05:58:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E323D120A8; Fri, 12 May 2023 02:58:06 -0700 (PDT) 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 2B22B165C; Fri, 12 May 2023 02:58:51 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.22.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DFC8F3F5A1; Fri, 12 May 2023 02:58:03 -0700 (PDT) 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, Pierre.Gondois@arm.com, ionela.voinescu@arm.com, rostedt@goodmis.org, mhiramat@kernel.org Subject: [PATCH v2 03/17] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Fri, 12 May 2023 10:57:29 +0100 Message-Id: <20230512095743.3393563-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512095743.3393563-1-lukasz.luba@arm.com> References: <20230512095743.3393563-1-lukasz.luba@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765682565233815626?= X-GMAIL-MSGID: =?utf-8?q?1765682565233815626?= Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to re-use. Return an index for the best performance state. 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. 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 b9caa01dfac4..8069f526c9d8 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 + * @state: 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, 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)