Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp94550rwo; Fri, 21 Jul 2023 09:01:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGFbJtvVWal8FReovjoQ4cvHXKyz8t9Aasuu4VLG0TY64mWk3uGsJp0qO62zCdFIdtv7Z24 X-Received: by 2002:a05:6a20:4310:b0:134:9f4e:63f7 with SMTP id h16-20020a056a20431000b001349f4e63f7mr2350767pzk.12.1689955286310; Fri, 21 Jul 2023 09:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689955286; cv=none; d=google.com; s=arc-20160816; b=RIq/RWYAhbQBwl9hGg4S8+JeeSvOd5xryBf4mw1GP/4qKhDwtUw1XgoBI0kb3y3tpA UilaCxkiL4ZxsaChA18m2P26OCzbUCS8uMcPAwKZx8gprDm6kCvRNZqW9MnwQH8HEQCM iIgcCVRZLhfHh36IbYdIanv6JgPs62XaPgDp2C3cEwHl/28Axan61J3Qh4cT0VrwOKMx G5h1TMe4N78nEZxwACIL0UvcEhj5qbi1nqVEiy5LfYFfO+d2v/tVWoSWvBgQaQfCvBUy R/8/fokRC3SOeFRcq0ya2nhAvV/CcaEL1K/yJROpXMZrNfLmso0XBTLe/ZH/DAjk5REY wocg== 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=h1dSrfCQU8Fz4xDjuCRSJpI2OYasgs4RoWyJ540tEzs=; fh=X59gKo2bTEq2VHcwIFizOsXoeGl1m0HuKLr4L9qvQjg=; b=e816QN7na6p5dSb7nm4uNOBCR4vOnVb4LOb/vi7d+zbmWRNPzCD2XR0lJkbnjxXfqZ PuBJ0mWB93Rxl1wRX28DwIT84JGplIQvaNR6E4uqZl5+p++96OsKoMaV7NhepDhSWTx8 45C/3GxP6QrvYEqFd7xzmrJFx3l3eTdRo/qxfvW1/nFdlD+9QJtF/tn/hIuLuzMkbh5R AwIRnZ2H8WV4TY9cKGdLdtZUyg9CAbBodthjeXLDN1YGKmnWzzWFrfDDjHza5u0GiKVX J1vmPXIZgw3AV2oOsBGHePWcQg4lWn7RoaO6FIP/HUXXc+a8JgwmrA1EzjxoLk4lh7Fk KerQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020a63d752000000b005348885119asi3096158pgi.523.2023.07.21.09.01.07; Fri, 21 Jul 2023 09:01:26 -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 S232287AbjGUPuT (ORCPT + 99 others); Fri, 21 Jul 2023 11:50:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232290AbjGUPuP (ORCPT ); Fri, 21 Jul 2023 11:50:15 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 910CD2D7E; Fri, 21 Jul 2023 08:50:09 -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 C48E12F4; Fri, 21 Jul 2023 08:50:52 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.0.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 994C83F738; Fri, 21 Jul 2023 08:50:06 -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, mhiramat@kernel.org Subject: [PATCH v3 03/12] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Fri, 21 Jul 2023 16:50:13 +0100 Message-Id: <20230721155022.2339982-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230721155022.2339982-1-lukasz.luba@arm.com> References: <20230721155022.2339982-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 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 re-use. 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. 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) -- 2.25.1