From: gao.yunxiao6@gmail.com
To: lukasz.luba@arm.com, rui.zhang@intel.com,
daniel.lezcano@linaro.org, amitk@kernel.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
orsonzhai@gmail.com, zhang.lyra@gmail.com,
"jeson.gao" <jeson.gao@unisoc.com>
Subject: [PATCH] thermal: power_allocator: using round the division when re-divvying up power
Date: Mon, 15 Mar 2021 16:25:37 +0800 [thread overview]
Message-ID: <1615796737-4688-1-git-send-email-gao.yunxiao6@gmail.com> (raw)
From: "jeson.gao" <jeson.gao@unisoc.com>
The division is used directly in re-divvying up power, the decimal part will
be discarded, devices will get less than the extra_actor_power - 1.
if using round the division to make the calculation more accurate.
For example:
actor0 received more than it's max_power, it has the extra_power 759
actor1 received less than it's max_power, it require extra_actor_power 395
actor2 received less than it's max_power, it require extra_actor_power 365
actor1 and actor2 require the total capped_extra_power 760
using division in re-divvying up power
actor1 would actually get the extra_actor_power 394
actor2 would actually get the extra_actor_power 364
if using round the division in re-divvying up power
actor1 would actually get the extra_actor_power 394
actor2 would actually get the extra_actor_power 365
Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
---
drivers/thermal/gov_power_allocator.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
index 92acae53df49..2802a0e13c88 100644
--- a/drivers/thermal/gov_power_allocator.c
+++ b/drivers/thermal/gov_power_allocator.c
@@ -374,9 +374,11 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
*/
extra_power = min(extra_power, capped_extra_power);
if (capped_extra_power > 0)
- for (i = 0; i < num_actors; i++)
- granted_power[i] += (extra_actor_power[i] *
- extra_power) / capped_extra_power;
+ for (i = 0; i < num_actors; i++) {
+ u64 extra_range = (u64)extra_actor_power[i] * extra_power;
+ granted_power[i] += DIV_ROUND_CLOSEST_ULL(extra_range,
+ capped_extra_power);
+ }
}
static int allocate_power(struct thermal_zone_device *tz,
--
2.28.0
next reply other threads:[~2021-03-15 8:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 8:25 gao.yunxiao6 [this message]
2021-03-15 9:51 ` [PATCH] thermal: power_allocator: using round the division when re-divvying up power Lukasz Luba
2021-03-16 13:15 ` Daniel Lezcano
2021-03-16 13:16 ` Lukasz Luba
2021-03-17 11:20 ` gao yunxiao
2021-03-17 12:39 ` [thermal: thermal/next] thermal/core/power_allocator: Using " thermal-bot for jeson.gao
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=1615796737-4688-1-git-send-email-gao.yunxiao6@gmail.com \
--to=gao.yunxiao6@gmail.com \
--cc=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=jeson.gao@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=orsonzhai@gmail.com \
--cc=rui.zhang@intel.com \
--cc=zhang.lyra@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.