Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7846354rdb; Thu, 4 Jan 2024 09:22:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwIoOYMWO0W/F28rvb2i2CQhbSR0KWK2/MlqDcBdFof6LymEXdx4uQqIKJZFdrST2mGG0Q X-Received: by 2002:a05:620a:47c2:b0:781:dc1c:3f12 with SMTP id du2-20020a05620a47c200b00781dc1c3f12mr862117qkb.75.1704388956252; Thu, 04 Jan 2024 09:22:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388956; cv=none; d=google.com; s=arc-20160816; b=wO2d98tR2altMMeCUxQxoXYjpI82ok4nT90iCtaS2DgtUnquQZ21sQdGP3Gz9LZnOA AfOy+NwR4+ZqjoDi/J1+7/t2AIEHOkxqEe6Hj14mqOaArYvS3KKoQES/cQbX53Dxf49Z 0stcQshkeSUQL/7YqVdP8m9M0epHmIm4uNe17MuUAIoFf20sE5hkp1PQpG3gj8D/wjUR W6ZLrQChdVsLe2i43JfZR65LGhHMevjsdTNclY6bFvv+6exK77/XgKpvB0r9ZAMPSWhg UUiYUeR6e9DxBBfAqisMrUmqmmJ8Tbl3laB+mS4QKIffonsXv7Vr68rir5I9DBMujzFN Ua8w== ARC-Message-Signature: i=1; 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=3LcV1qOCqS+SSHawywK0UaPbeyJC+/Uu/xXMyt/SwEg=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=RbtqxMUu+goJP1xJPKvoF7WN2YFDJlU8QR3bQudZVvpnkg2WkavwIdmRafY5LmrT/3 NcGR8QnBoGFA+FO4KUAOvT7TmLkyql7Z1e1c4VVlkq0nSEy2jsEUJSXh0TKqDoL3Ki3E /I8hFRt6MZLkA04aQd+BAWPGg1R+U+JebzYSUQtr8lywQnKqcOGmYNuZOf90/bho/Ulh gLY5gLF3Rdi+0mLnkdUrjCilBE0VjYr39pwamHThvwZ57GKs74xYMZzrR+NtEmlE5JQV B5WiMDzyZ0ALhQbsHSTIpLBXau9B1KdQI7Z8kkFykSUHs0xRuxVS7nyZazKyeDToSjDs u/Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id br10-20020a05620a460a00b0077fa5437f7fsi33389666qkb.354.2024.01.04.09.22.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:22:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17026-linux.lists.archive=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; spf=pass (google.com: domain of linux-kernel+bounces-17026-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17026-linux.lists.archive=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 05C311C2406C for ; Thu, 4 Jan 2024 17:22:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E1A52D615; Thu, 4 Jan 2024 17:15:53 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85BE13588E; Thu, 4 Jan 2024 17:15:51 +0000 (UTC) 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 282A2153B; Thu, 4 Jan 2024 09:16:37 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B2E583F64C; Thu, 4 Jan 2024 09:15:48 -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 v6 22/23] PM: EM: Add em_dev_compute_costs() as API for device drivers Date: Thu, 4 Jan 2024 17:15:52 +0000 Message-Id: <20240104171553.2080674-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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 Content-Transfer-Encoding: 8bit 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 dd8a69bdf0d0..f50f3c6ab2e5 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 @@ -375,6 +377,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 79877d8975d5..7f9337f4ae30 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -285,6 +285,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