public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: PoShao Chen <poshao.chen@mediatek.com>
To: <linux-kernel@vger.kernel.org>, <linux-pm@vger.kernel.org>
Cc: <lukasz.luba@arm.com>, <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>, <poshao.chen@mediatek.com>
Subject: [PATCH 2/2] thermal: cooling: Fix unneeded conversions in cpufreq_cooling and devfreq_cooling
Date: Fri, 8 Mar 2024 14:59:22 +0800	[thread overview]
Message-ID: <20240308065922.10329-2-poshao.chen@mediatek.com> (raw)
In-Reply-To: <20240308065922.10329-1-poshao.chen@mediatek.com>

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 <poshao.chen@mediatek.com>
---
 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;
 	}
-- 
2.18.0


  reply	other threads:[~2024-03-08  7:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  6:59 [PATCH 1/2] PM: EM: Add macro em_is_microwatts() PoShao Chen
2024-03-08  6:59 ` PoShao Chen [this message]
2024-03-08  8:44   ` [PATCH 2/2] thermal: cooling: Fix unneeded conversions in cpufreq_cooling and devfreq_cooling Lukasz Luba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240308065922.10329-2-poshao.chen@mediatek.com \
    --to=poshao.chen@mediatek.com \
    --cc=amit.kachhap@gmail.com \
    --cc=ccj.yeh@mediatek.com \
    --cc=ching-hao.hsu@mediatek.com \
    --cc=clive.lin@mediatek.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=mingo@kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox