Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp411532lqc; Fri, 8 Mar 2024 00:46:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXeSDnvgQ9E0vw90XCCcBLe4eI/AG6bJ6LyDb4q1ODRRMYVrMSwdMJgEutKQogenIxXZT11ehCpkJH3r8bOE7AzfsdB5gigLglL3A9hzg== X-Google-Smtp-Source: AGHT+IEtHKxzu8fWND8IhzwmqSUwPbbdFMsG4k1Dqu8zclq5bX6ogmYf8OZB0Xn1pS0seAKUdUCu X-Received: by 2002:a17:907:d501:b0:a45:f262:bc2f with SMTP id wb1-20020a170907d50100b00a45f262bc2fmr584521ejc.5.1709887578300; Fri, 08 Mar 2024 00:46:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709887578; cv=pass; d=google.com; s=arc-20160816; b=v+EZzPNVjeGz1CdcqlXMcNuAC45UT59C9tT07oVll1j2i40E2dfhil/wRrl1G35PdG ooOVd8djCI/mEEKwVvxF/whIl4dHvWhRbxwrWOZeZQ52QEcLZB6TMaiJeYuuJZoQLWRy KtlsNlA2oJtJwVbM1euIiK/VhsgEs6jrQQ+1Wec02Lr0H1S8hc9Bo8+NN5XTRA+A62UD sCYrOeQghMIxw0wAYibseyWzY6rnPWnaDaWjDu08GmcGkQk9LODxeEFFA8AelcjycLkq rS+Ryv2bC/klT47IqqlQ2Lv/HqZsFkHLtuErA5rxr8maUA4E601RMEQdtNc9DoF4s05K 5jHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=xCzQX5Cknr92J8pIhij9J7BHQrCZg1jHxaGNczjXrnQ=; fh=MftTBfO83rhq0lcVwCD4e9ZVjdKiNen4ApW/4YFq9zo=; b=0+2PdGO10Ncv38V6s657ffb5QyXyFBK9koSeSKDw+iSUhaNPIzOgQshVAXLT5gnxNg z8absIkKmzLUxOJLXp+jbYXdHLM7kjhCMzZ8guctMjD0CRtD2/U8ULsCkacI0xq+yjny FVW336i2eRhPpWWLVYFReFm0O8ZZ58fPvNXrrotxtn7kgE/wpKsABejyggDFQuiOZHkP oQM/ZX2sQeQAgOeZxMZY82+bIA68TCGynhxxsAmIgmptSAJgluHTp8+FEc7y9dPQNGFW rhc5f7QpvnIqEPiMpEU4Ny0GZhDuUB0QTzJ5X5xspVDCY/QnBm02zhOAZY6IXAbJcUv6 yh7w==; 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-96687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96687-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lt26-20020a170906fa9a00b00a456286be4dsi4081382ejb.127.2024.03.08.00.46.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 00:46:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-96687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96687-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0FDC81F2419B for ; Fri, 8 Mar 2024 08:46:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AA4852F96; Fri, 8 Mar 2024 08:44:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B39452F6B; Fri, 8 Mar 2024 08:44:39 +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=1709887481; cv=none; b=ltgqxfdBVxHy5xkPk3a5kJRp7BHMh5erof3NxpIptz5FAfkghb1uTGRZY5aeAqM9dQRm2JTFUBNiR6r00IlYucUfXGs3sCLAI6kIpU3p0un8IScFNg52Ps7dYAecIMgqlf8+d6u5nucmhnpTnXoR1DwkQl+YWnfoWKecFv9HN7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709887481; c=relaxed/simple; bh=14VPe0pUD24RgR8UUeJpMDtadw2Rx3IIZ/obF0bI/aU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ejnkSnFfjBc13XHcdJAm/tOjRRmoR0ydlxCJjBXD/khwFAe/KiJ/I3lMjTgxxJmuBjm7er8M7MBiPHDhUPs7gaJ99AqUm0fOXOdfTlA6QxcBlw6bZmmBAr1CAInFR9cOWx0EyDaZVeIZRFn677LNuD8fXqDIY7a6JnF7niuVd+8= 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 5D274C15; Fri, 8 Mar 2024 00:45:10 -0800 (PST) Received: from [10.57.10.181] (unknown [10.57.10.181]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 79A893F762; Fri, 8 Mar 2024 00:44:30 -0800 (PST) Message-ID: <3a11f361-4bb5-4a17-b07d-aac549264cc8@arm.com> Date: Fri, 8 Mar 2024 08:44:49 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] thermal: cooling: Fix unneeded conversions in cpufreq_cooling and devfreq_cooling Content-Language: en-US To: PoShao Chen Cc: dietmar.eggemann@arm.com, rafael@kernel.org, mingo@kernel.org, rafael.j.wysocki@intel.com, rui.zhang@intel.com, vincent.guittot@linaro.org, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, amit.kachhap@gmail.com, clive.lin@mediatek.com, ccj.yeh@mediatek.com, ching-hao.hsu@mediatek.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org References: <20240308065922.10329-1-poshao.chen@mediatek.com> <20240308065922.10329-2-poshao.chen@mediatek.com> From: Lukasz Luba In-Reply-To: <20240308065922.10329-2-poshao.chen@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi PoShao, On 3/8/24 06:59, PoShao Chen wrote: > Fix the incorrect division of power values by MICROWATT_PER_MILLIWATT for > non-microwatt units in the Energy Model (EM) by adding an > em_is_microwatts() check. This ensures that power values are only converted > when the EM specifies microwatts, allowing for accurate interpretation of > power according to the unit defined by the EM. > > Signed-off-by: PoShao Chen > --- > drivers/thermal/cpufreq_cooling.c | 6 ++++-- > drivers/thermal/devfreq_cooling.c | 12 ++++++++---- > 2 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c > index 9d1b1459700d..5324b9766843 100644 > --- a/drivers/thermal/cpufreq_cooling.c > +++ b/drivers/thermal/cpufreq_cooling.c > @@ -120,7 +120,8 @@ static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_cdev, > } > > power_mw = table[i + 1].power; > - power_mw /= MICROWATT_PER_MILLIWATT; > + if (em_is_microwatts(cpufreq_cdev->em)) > + power_mw /= MICROWATT_PER_MILLIWATT; > rcu_read_unlock(); > > return power_mw; > @@ -139,7 +140,8 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, > for (i = cpufreq_cdev->max_level; i > 0; i--) { > /* Convert EM power to milli-Watts to make safe comparison */ > em_power_mw = table[i].power; > - em_power_mw /= MICROWATT_PER_MILLIWATT; > + if (em_is_microwatts(cpufreq_cdev->em)) > + em_power_mw /= MICROWATT_PER_MILLIWATT; > if (power >= em_power_mw) > break; > } > diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c > index 50dec24e967a..c28e0c4a63d6 100644 > --- a/drivers/thermal/devfreq_cooling.c > +++ b/drivers/thermal/devfreq_cooling.c > @@ -222,7 +222,8 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd > dfc->res_util = table[state].power; > rcu_read_unlock(); > > - dfc->res_util /= MICROWATT_PER_MILLIWATT; > + if (em_is_microwatts(dfc->em_pd)) > + dfc->res_util /= MICROWATT_PER_MILLIWATT; > > dfc->res_util *= SCALE_ERROR_MITIGATION; > > @@ -247,7 +248,8 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd > *power = table[perf_idx].power; > rcu_read_unlock(); > > - *power /= MICROWATT_PER_MILLIWATT; > + if (em_is_microwatts(dfc->em_pd)) > + *power /= MICROWATT_PER_MILLIWATT; > /* Scale power for utilization */ > *power *= status.busy_time; > *power >>= 10; > @@ -279,7 +281,8 @@ static int devfreq_cooling_state2power(struct thermal_cooling_device *cdev, > *power = table[perf_idx].power; > rcu_read_unlock(); > > - *power /= MICROWATT_PER_MILLIWATT; > + if (em_is_microwatts(dfc->em_pd)) > + *power /= MICROWATT_PER_MILLIWATT; > > return 0; > } > @@ -321,7 +324,8 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, > for (i = dfc->max_state; i > 0; i--) { > /* Convert EM power to milli-Watts to make safe comparison */ > em_power_mw = table[i].power; > - em_power_mw /= MICROWATT_PER_MILLIWATT; > + if (em_is_microwatts(dfc->em_pd)) > + em_power_mw /= MICROWATT_PER_MILLIWATT; > if (est_power >= em_power_mw) > break; > } Thanks for the patches and reporting this! I have checked the commit which introduced the micro-Watts. All the drivers where aligned to register the new uW values, also your mediatek-cpufreq-hw.c ae6ccaa650380d243 I have also check current upstream and all drivers there provide the uW to the em_dev_register_perf_domain(). Is it some out-of-tree kernel driver, which shows this issue? I would need to check all places and force actually to provide the uW to the EM registration function. It's pointless to try to support mW just because the flag in the registration wasn't set by some downstream driver. Let me re-write that bit in the EM... Regards, Lukasz