Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1059853rdh; Mon, 25 Sep 2023 01:48:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeEvVYT3I6cCEDuHmePtTQy+IAw4zuMrRqtuiuk7basJKfT6o68Hf3cCnVV6yS8dj3j/1v X-Received: by 2002:a05:6a20:9704:b0:153:a160:89dc with SMTP id hr4-20020a056a20970400b00153a16089dcmr6031006pzc.58.1695631731525; Mon, 25 Sep 2023 01:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695631731; cv=none; d=google.com; s=arc-20160816; b=s44kvQSDdOA4vRgI+Z++UxJx21pAeIlTHWDJPud329I/Vc3DNGKMU5/DtWKZsS/jFy NakceMxTfd08eA7ybuMX/0Gc6uH/SuqypkJ+CqliJbKmL1vhjzImJjltF4yGpzE+r1op IRb+Mcxb0x6AWJ9hzQLIpZRZ96WferJs7d98CXKJjg2vQ6KIIAkYsxZBTPSyJ2T895pM hNOSAJefExgAlVs0WDetIt8msH8nmbTzmsZnqlszZH+aKfwUarXYTLB9FsPWhR66KGfN FVLP0TA993FES3SBYDAotuc5emp1VzeVtHuqanXP3NAm9riqjBtWL4k2H1zHmz4A7LQq uHQQ== 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=HfkuYA/xL5oppUy+KAWLxXiDZxtbOLAxnDNn6vWCmiY=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=XhXbGDA/7ByRZwOBgy4X1Pw+Gbn2vq6EibKb031oBXW27Uih6jop8TPcbo5K3eWLfX TvvquNTuVM3R5KxnqSDvlpfPieHPICwMp0C17kiFBaaGQ1kS4N71JgKIB3G6yKZS4anh jh2Rw8gjrUo2J5qe67dqWPKhybec6gd4Upv+NMdyauVjonGeivNaABvd/btZUuZ+htCj VXTxBEvzuYQS27ZhvrgP0gXPN2ifgO3Z3nEDB4vZW2UT8f2xZD7HkhPiciymciGid8Ft bgoG+tRvg5FEdWP7iEc14VhoKTUfJmWEspA0bNRtQ0cPwm3R+1UgqXs8pteh4LXI4WRZ Sh2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id mi18-20020a17090b4b5200b00274c70feb29si5150428pjb.162.2023.09.25.01.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:48:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 425D68020912; Mon, 25 Sep 2023 01:11:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232707AbjIYILh (ORCPT + 99 others); Mon, 25 Sep 2023 04:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232720AbjIYILc (ORCPT ); Mon, 25 Sep 2023 04:11:32 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46EEB19A; Mon, 25 Sep 2023 01:11:23 -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 2E8CEDA7; Mon, 25 Sep 2023 01:12:01 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.93.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 861193F5A1; Mon, 25 Sep 2023 01:11:20 -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, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com Subject: [PATCH v4 04/18] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Mon, 25 Sep 2023 09:11:25 +0100 Message-Id: <20230925081139.1305766-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230925081139.1305766-1-lukasz.luba@arm.com> References: <20230925081139.1305766-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 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 01:11:49 -0700 (PDT) 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