From patchwork Thu Feb 8 11:55:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp113891dyd; Thu, 8 Feb 2024 04:03:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV1L8yYeM9DtLnS5YMLfjD7pMMdED7wOi/5rLx//OWnUIiOTdsLA2EQPv2Gff0rGmrlWCBOrvi7/LZ2hQd0R+S18BSqCQ== X-Google-Smtp-Source: AGHT+IGhEkFSi+y9nwLpZj/e9F3fu0I68WoWELvGOfMdq88PE8qplkCEJFT4hjQejTcYoDuvuxBU X-Received: by 2002:a05:6214:1c0e:b0:686:8ffe:1278 with SMTP id u14-20020a0562141c0e00b006868ffe1278mr9489609qvc.4.1707393815943; Thu, 08 Feb 2024 04:03:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393815; cv=pass; d=google.com; s=arc-20160816; b=c42hPUi9IFuqG0pAt5QLEB5nHxiqlwmQ5eNd5RS0WstZoS4FEEDvaIqB5SEqwCWADg AhMUSqxHXMdUICJIivZecvNAoIvvdYHWXP9T7qH4qXnE4xQqEjymbXicYD7AwOLnypW3 A95xiSZrwVwMTd9sOKRIQoA/T9Tm4NLNagf1ZxFUAMR/XHxTBCy80cLEIPInL/uL3PAo KVIjO7AiHJntZogjyI6Tyisot4EPavk6DMJKf0SPSbti4sveq618OZ0PaJLdAS6LUO/p BZ7WxFvSE9VRsYkR3LG7tRM1RfbseJ/fgDHq4iO6YpbibruaO7Epym5lhjz8e6FmS2Nq adwQ== 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=MfKVP4hOIZVwFQsZHHBqK1R4iwjUJsWN9z0HxpPHRiM=; fh=nggrAJYqx7Z/Vnlf2hI3iPBYdgyZolz2td3nnMQYo60=; b=pRPqv0IkHAfHFQLkAnrSu4EEHqY+vV4q+2bFBqLaYbz/+Z39+DVL7RJuyHbQeCgKyU FZ2tgXmgfF45GsTp7EnDq5ShDHs4Xx6mDByVS/jwjf8efkU1XTXJGeL2Mpft3y6F9Vcd JUXmdqvZCYJHzhpXyiCEyyLcuhN1hnQRs/aI1vjOnZwrDwgmwzEozCXlOI3rtotC4AbO 8yOjHmLZDvum0Ks0MXfb4z3a6u755UsX0qdlNLWlzTrvyjOInnSgpZmYNpBvowKihvvR 6oly6e91UWYcp6YX7lpLyCLg214aJ3g8w9Vc8BrSOFz9yhKy7SlH27mClhCflOl2ggIT 4OMA==; dara=google.com 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-58016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58016-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCV6TFYulq2oXkXa3KwadSHz+HaXnyqbqu3chqWW+8NU0ppUTBFQq8TZrnVA46UgaCC6H45ZCGJ64uD7WLECHNyp8ey4mA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gw12-20020a0562140f0c00b0068ccc9a0ef4si289605qvb.494.2024.02.08.04.03.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:03:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-58016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58016-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 721F61C28267 for ; Thu, 8 Feb 2024 12:03:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A5ED81AAA; Thu, 8 Feb 2024 11:57:16 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A84C8002E; Thu, 8 Feb 2024 11:57:11 +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=1707393434; cv=none; b=ntycIZgKHXyjixu4juEyF3osKVcJUdHohKrjwiguNCYxZNs/JmvrI6PCElVmMpYtd/WbPunfsIX8p3T0YiR2RrK9kAq80vPqojo4QeQRV6EPXIcqUMt0FqIMV+oP35ApNANKECrDTqT+7k4P1Qq03U8pE72rj+qJKHDcF8DBUOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393434; c=relaxed/simple; bh=ObVLAB8KuRCDvRT3WPT0Lj1kkK4Fwrkdi2IV35YawEs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oSdpLl+KRREvPSYZALkQZf8odmTOIghtZrEKSsmUkwL1lPKTcmcoD9LHcG5SsGy/atAuR33888qanNOnQW8bBrVLltnMW/Oo/O0Oa4Zob6X32Rt1b/XT3rFoS6RjIBG+oFEYHU9gjF99gLkRy6oG1x2I4VEyxKYeQXqjPlBpts0= 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 98F801FB; Thu, 8 Feb 2024 03:57:53 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B03DD3F5A1; Thu, 8 Feb 2024 03:57:08 -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 v8 22/23] PM: EM: Add em_dev_compute_costs() Date: Thu, 8 Feb 2024 11:55:56 +0000 Message-Id: <20240208115557.1273962-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332177638859432 X-GMAIL-MSGID: 1790332177638859432 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). Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann 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 92866a81abe4..770755df852f 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_table_alloc(struct em_perf_domain *pd); void em_table_free(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 @@ -379,6 +381,12 @@ struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) { return NULL; } +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 57838d28af85..7101fa3fa0c0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -276,6 +276,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