Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp293658rdb; Wed, 17 Jan 2024 02:03:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqxJBOMmfMR6onk02vrtoFZo6kIKC2BCFOM4TmgjQETDf7XpKoJQW19HRurfkQ4ryi0NaQ X-Received: by 2002:a17:902:680f:b0:1d6:f1c2:9dae with SMTP id h15-20020a170902680f00b001d6f1c29daemr755502plk.10.1705485787405; Wed, 17 Jan 2024 02:03:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485787; cv=pass; d=google.com; s=arc-20160816; b=ayLPgyrCYWYBySP6yo5SEGGyJtvo5HAhGZwopcGBjGGZbgjKI2/Fv6Ch9QL+9GbbpV NeGFPiOnjRPBK9HcBYFFXrviBubcmjR7fsrb2m8b6Pe2SG9DzwtLiT2RvRujKAaRxReB uSeDdqHxflHiMYPazCehMe5iTyJSFdIK4H8Zw9jJVffjEVBmc4UHM92qYdbq0e0zENcl fx6Dz+0c4EW2iviU9BssHni7JPx+MElUchYN8TNnhn4wBXDQUUWWlEbtfAFCmn/6O0Pg Rcm+f4Ol0BxvENRxvi7vPFIf3+8Zvq+jBs/RYBmma5+iGP3NkDkE2qDz5L7jYA5Ob6vp p80w== 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=vJMdtZdOtrb9QcW4CMQsyoF/cY5IZdrvK7Nb1VQTSGk=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=R+WGE327z5zm25rW+6EVkloRPWolx0xrNjdT0yeqd3AzIyRIptR5hHAwXa7ob20tk0 J1Uk4/Z7gTuyrQUr1B8ZpeWZl5B7wtlwnzb/3V3sIo9PU7XMLNWIGQ+8AKisOBkJUIw2 bVydT1sMiAA8MXQAwsSe4FME87yJooVbZSH+vKIq2/UvrOxfu4utTchfKxB82T4l+5QI FYte/RnDoTzGJ9HQj6ZvG6NNTZvks5/28ValzY3Pd444GsZFi/f59Oau/SH1lRzcv4B3 oKN5cztae5GAA+Zy2v/OQgUIBdHNSS34dkyDiQcMOCIqthfzBXHQWkJKIBcRYSzsswFN 8Usg== 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-28793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j8-20020a170902da8800b001d4e1edaf59si445994plx.61.2024.01.17.02.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-28793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28793-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EF8B9B2116A for ; Wed, 17 Jan 2024 10:02:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 404B7219F5; Wed, 17 Jan 2024 09:57:07 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A8B021376; Wed, 17 Jan 2024 09:57:05 +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=1705485426; cv=none; b=VuZqFmUEN/k2aqF6CuHSy+Lnyys126Hxc/h/Q+X61OaRH8oqnVUgUvCyVvo2veXVu4v2JHYMwpo5qU2kv8IbJpwaAaKsvd32ygjaGSq3OKmwaN7tbESw7Vgg5CPQI18DuiPvMuvTJzkJix8J59AVr7UnQQTo2bPgVyKzQ9gifpg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485426; c=relaxed/simple; bh=A2pgHBmRnmRSJFL5C5XWdn1pDAImwUbEwNRZLTh2wQw=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=Wg34bI7b7rJ1ttMiuxqiMm4DGvces214OczX/jR5ZgQ31dKFSzRe7JyR+ycyNb0stcfz8MrFrAbWRBp5VP/8ijt9Vtaht3ZYECBsp0SJ6tztpQbPy9fyoTBF/mNJ/S3aDMM26RIynNnhtAMNb8AhZrEVGB2j04PLZfIrmei8Jmc= 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 EF09711FB; Wed, 17 Jan 2024 01:57:50 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2609B3F5A1; Wed, 17 Jan 2024 01:57:02 -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 v7 22/23] PM: EM: Add em_dev_compute_costs() Date: Wed, 17 Jan 2024 09:57:13 +0000 Message-Id: <20240117095714.1524808-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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 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 e91c8efb5361..104cc2e2aa84 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 -- 2.25.1