Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp291901lqh; Thu, 28 Mar 2024 02:05:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUMmXC1PhAdJ+NWYqGq74rmfsvVaZhSTEXBdj8Nm2GC4kdEbDbeeyrhi39OrIzcTZfGz/BNLibYsFHtKbvzUG5SsGT0HGHFVbq35vXBA== X-Google-Smtp-Source: AGHT+IELtkERrepR2FwI1cqG/F9A2i+uaKnz+HeJi9TCUGLH2WxVtiloyauhFHPqPY+0AYpNJzXm X-Received: by 2002:a05:6a20:baa7:b0:1a3:c976:a36d with SMTP id fb39-20020a056a20baa700b001a3c976a36dmr2287237pzb.30.1711616701428; Thu, 28 Mar 2024 02:05:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711616701; cv=pass; d=google.com; s=arc-20160816; b=ssHjAsmL+PHrkXpsNAHii45kVg/8avQrTiGIEhYQluCO0YTnUnIxRCFB+c2qhBZKR+ YvwoGtMNbAQoSw9PtbD0wTkwYfBGYj0sjqISkR5SxpjP4W9fKU5xLT5Spm/HD2qac6Nn SSFwaXBXsAfFy7OozJkcJs20KxCGrQIzXS1R2agqjjb6zVx/LMziwhd+7b8minm5NY94 7QqHfqSt5QVn0k9Eyh8OpzxzhVCWRDpxlCkEwNco907vBHAWp/gTxyyNrhBEVYBb3god WXIfcfviiMaGPtGrzupJgmGXSkoMZTtjdG+6VcBqxk0jwASAeERIPfSHVoh69m38vDdv 4xwA== 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=VxuByqEW5LXganckia1KPho6Xq8X1uEuf0mdyueUjdA=; fh=FmC2hJpJhN2HT2Kov+KiTeKhNOezP0K1ntHb8ZYpOKY=; b=diTki2SRe7NqXqC/dDZPkqtMDJ2uVHnGH8rjM0NkBVW4dIsehh7GAZYlYZb2nSJOev zBrkwPsMZKladN0jGaaWYJK38KIL86JL/lLFLUsvcF+Jb2eGVZ1cwwIEMVz+Y9jYTtZc ga2TC9J3ACeG9ltIrmGTnd9zmU5+hLO/tz986zdgjOGjmZ1sejc0peQzVMAwAggl4uWT gH3k5Ig1/d+zQrQBqdW/l2eLD0cugXiK9GZYHQHHV8wKsTayO1dVLNWlOMC0dKT81EyS iTN/faIYOaMEEWymrXL1AnPRCP2i5iHSmtHF8/DxqK1GxDZ0cvYu6yWni2+//H57cYxW Me5w==; 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-122610-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122610-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 r9-20020a170902c60900b001e20587b559si960707plr.282.2024.03.28.02.05.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 02:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122610-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-122610-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122610-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 844B1B25ADB for ; Thu, 28 Mar 2024 08:52:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 366EA65BA0; Thu, 28 Mar 2024 08:51:31 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08FDA657C1; Thu, 28 Mar 2024 08:51:28 +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=1711615890; cv=none; b=BMb1Tg3zfneT1jCyI1uMWDrHJ+z1iVA51SFfifnsOTG37enGcrYXtJrWNshdgIU8PpI8GNBLsq4t0cHfMVCz+IX0s+gC2+366U1yP+o0l1Ap6GSlySMXRluF5sRD+z55JIvsAwAz2opk8KSdaz/ucweU2jQ+6qfN5TVf2qW/wUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711615890; c=relaxed/simple; bh=OuWtOqF6MFJtj0nBtipe/PrVCqgOimHCQvOOQpylHpA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=esMvNjm2uDGxRs1NUsjYfHVvOMyNLYp+KbP/IdHs+m9pz6UqayLXoqwaUcO3Wxhz421RNkCYYPRvRWmDD2sT1kvTSbbocWeyY0obNVJgpCcUXAkAy/MFwYBKNtu2bpnP8GnIs/PodIE9s6ONixgfoLdGhCA72CGJLs3OZKqRT8k= 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 2C5E72F4; Thu, 28 Mar 2024 01:52:02 -0700 (PDT) Received: from e129166.arm.com (unknown [10.57.73.83]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C1CB03F7BD; Thu, 28 Mar 2024 01:51:25 -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, linux-arm-kernel@lists.infradead.org, sboyd@kernel.org, nm@ti.com, linux-samsung-soc@vger.kernel.org, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, krzysztof.kozlowski@linaro.org, alim.akhtar@samsung.com, m.szyprowski@samsung.com, mhiramat@kernel.org Subject: [PATCH v3 3/4] PM: EM: Add em_dev_update_chip_binning() Date: Thu, 28 Mar 2024 08:51:11 +0000 Message-Id: <20240328085112.3873050-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240328085112.3873050-1-lukasz.luba@arm.com> References: <20240328085112.3873050-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 Add a function which allows to modify easily the EM after the new voltage information is available. The device drivers for the chip can adjust the voltage values after setup. The voltage for the same frequency in OPP can be different due to chip binning. The voltage impacts the power usage and the EM power values can be updated to reflect that. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 5 ++++ kernel/power/energy_model.c | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 770755df852f1..d30d67c2f07cf 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -172,6 +172,7 @@ 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); +int em_dev_update_chip_binning(struct device *dev); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -387,6 +388,10 @@ int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, { return -EINVAL; } +static inline int em_dev_update_chip_binning(struct device *dev) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 6960dd7393b2d..e284aa335b6d0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -808,3 +808,51 @@ static void em_update_workfn(struct work_struct *work) { em_check_capacity_update(); } + +/** + * em_dev_update_chip_binning() - Update Energy Model after the new voltage + information is present in the OPPs. + * @dev : Device for which the Energy Model has to be updated. + * + * This function allows to update easily the EM with new values available in + * the OPP framework and DT. It can be used after the chip has been properly + * verified by device drivers and the voltages adjusted for the 'chip binning'. + */ +int em_dev_update_chip_binning(struct device *dev) +{ + struct em_perf_table __rcu *em_table; + struct em_perf_domain *pd; + int i, ret; + + if (IS_ERR_OR_NULL(dev)) + return -EINVAL; + + pd = em_pd_get(dev); + if (!pd) { + dev_warn(dev, "Couldn't find Energy Model\n"); + return -EINVAL; + } + + em_table = em_table_dup(pd); + if (!em_table) { + dev_warn(dev, "EM: allocation failed\n"); + return -ENOMEM; + } + + /* Update power values which might change due to new voltage in OPPs */ + for (i = 0; i < pd->nr_perf_states; i++) { + unsigned long freq = em_table->state[i].frequency; + unsigned long power; + + ret = dev_pm_opp_calc_power(dev, &power, &freq); + if (ret) { + em_table_free(em_table); + return ret; + } + + em_table->state[i].power = power; + } + + return em_recalc_and_update(dev, pd, em_table); +} +EXPORT_SYMBOL_GPL(em_dev_update_chip_binning); -- 2.25.1