Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4495694rdh; Wed, 29 Nov 2023 03:11:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcISXP5BF1UOVVwaM5uR0VaHpqIPvg3AZALw5VAl330nuCq2E8+JcQ7nH+qN7Zejgz7P28 X-Received: by 2002:a05:6a20:914e:b0:187:d44:59f1 with SMTP id x14-20020a056a20914e00b001870d4459f1mr17303654pzc.31.1701256311971; Wed, 29 Nov 2023 03:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701256311; cv=none; d=google.com; s=arc-20160816; b=k89b5ok4AVaucmEacEoc8mf1AQSjJMSs89kewBe9x61j4tv8T6pIvVFSciiRV34FhT gAGFYk6xkTj6xSOrYU1cvmQpK4GuFjVKGc0U0Ra9qrz6+rpi4c7nLa8KId03MHZ/mP+q Tf/mYz1hRUi4pq/86doVosPftffCm570RM+3ieBdOSovhmkxYEK9e3ngzuk7O4oDkrmj mt0xSMkjGcYhoNZALBIU+jYuxYRuZFpuMo9I89J26u21R4rD6kkN0kq7nVlJ/OYHrpAU iUPyVFvJrfxEDgFeseHhU60YEB9bxbXb9MSF8ZVIvdT8Q8Xq4TJ1qchxZWi+gdA9OOCz JAjA== 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=a8N2H8sZp51OSG1dnN2BOGTT4W5ePhs+P+IPm9RwFEg=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=OLSy8muqpVZJpY3lFpJqTpdzWQRLBUSxmyoKAKe3w618FJ6qcHuxeZXpf76bMWsm+V H4Wd2yyKZQ0+H2GYUhqw1OLrmzfPemGJ57Oxd42YyWCd5P6PAJFS9ulwCYZegJeDmmpo +0e/QvMn+ViMoeCIc7xa28F/lZprYN1b3pDyO8BvTGuYSy3tP1lNFUjL99fQmVGiGgsc uYbqbD6dgpICsLwtSFTBHRcRdSa7qHzCAcZxVF36vEVW1iisdJB42cog3yvOhTy/HYsy ZAypx0lhaSOB/A7Pn1IAgQAUiSTp4o69kwacO+ix7C24xU9hLY0SabHgeqW6DPhRxkrH cGhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c7-20020a63d147000000b005b9a467330esi1169648pgj.707.2023.11.29.03.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:11:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id C762780747A3; Wed, 29 Nov 2023 03:11:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbjK2LLB (ORCPT + 99 others); Wed, 29 Nov 2023 06:11:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232223AbjK2LKK (ORCPT ); Wed, 29 Nov 2023 06:10:10 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5031E1FE1; Wed, 29 Nov 2023 03:09:01 -0800 (PST) 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 35F6E2F4; Wed, 29 Nov 2023 03:09:48 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.4.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9E0913F5A1; Wed, 29 Nov 2023 03:08:58 -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 Subject: [PATCH v5 22/23] PM: EM: Add em_dev_compute_costs() as API for device drivers Date: Wed, 29 Nov 2023 11:08:52 +0000 Message-Id: <20231129110853.94344-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231129110853.94344-1-lukasz.luba@arm.com> References: <20231129110853.94344-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:11:15 -0800 (PST) The device drivers can modify EM at runtime by providing a new EM table. The EM is used by the EAS and the em_perf_state::cost stores pre-calculated value to avoid overhead. This patch provides the API for device drivers to calculate the cost values properly (and not duplicate the same code). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 ++++++++ kernel/power/energy_model.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 9c47388482a0..836622b1a0a1 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -170,6 +170,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, void em_dev_unregister_perf_domain(struct device *dev); struct em_perf_table __rcu *em_allocate_table(struct em_perf_domain *pd); void em_free_table(struct em_perf_table __rcu *table); +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -355,6 +357,12 @@ static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) return NULL; } static inline void em_put_table(void) {} +static inline +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 234823c0e59d..fadfdefbe5f0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -286,6 +286,24 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +/** + * em_dev_compute_costs() - Calculate cost values for new runtime EM table + * @dev : Device for which the EM table is to be updated + * @table : The new EM table that is going to get the costs calculated + * + * Calculate the em_perf_state::cost values for new runtime EM table. The + * values are used for EAS during task placement. It also calculates and sets + * the efficiency flag for each performance state. When the function finish + * successfully the EM table is ready to be updated and used by EAS. + * + * Return 0 on success or a proper error in case of failure. + */ +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return em_compute_costs(dev, table, NULL, nr_states, 0); +} + /** * em_dev_update_perf_domain() - Update runtime EM table for a device * @dev : Device for which the EM is to be updated -- 2.25.1