mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chunyan Zhang <chunyan.zhang@unisoc.com>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Vincent Wang <vincent.wang@unisoc.com>,
	Quentin Perret <quentin.perret@arm.com>,
	<linux-kernel@vger.kernel.org>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Chunyan Zhang <chunyan.zhang@unisoc.com>
Subject: [PATCH V4] sched/cpufreq: initialize iowait_boost_max and iowait_boost with cpu capacity
Date: Fri, 22 Feb 2019 18:37:46 +0800	[thread overview]
Message-ID: <1550831866-32749-1-git-send-email-chunyan.zhang@unisoc.com> (raw)

From: Vincent Wang <vincent.wang@unisoc.com>

When a task that is in_iowait state is enqueued, cpufreq_update_util()
will be invoked with SCHED_CPUFREQ_IOWAIT flag. In this case,the value
of util and cap, which are parameters used in map_util_freq(), may be
cpu frequency, instead of cpu util and capactiy.

For some 32bit architectures, the size of unsigned long is 32. When
calculating freq, there may be an overflow error in this expression:

freq = (freq + (freq >> 2)) * util / cap;

To fix the issus, a new member min is added into the struct sg_cpu to
store the capacity of policy's min frequency. iowait_boost and
iowait_boost_max will be initialized with capacity instead of frequency.

Signed-off-by: Vincent Wang <vincent.wang@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
Changes from V3 (https://lkml.org/lkml/2019/1/29/346):
* Switch to a new method that will not lead in more calculation.

Changes from v2 (https://lkml.org/lkml/2019/1/9/1227):
* Fix for 32bit architectures only.

Changes from V1 (https://lkml.org/lkml/2018/12/24/22):
* Rebased onto v5.0-rc1;
* Addressed comments from Quentin Perret.

---
 kernel/sched/cpufreq_schedutil.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 033ec7c45f13..04eb44a9b550 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -53,6 +53,7 @@ struct sugov_cpu {
 
 	unsigned long		bw_dl;
 	unsigned long		max;
+	unsigned long		min;
 
 	/* The field below is for single-CPU policies only: */
 #ifdef CONFIG_NO_HZ_COMMON
@@ -275,12 +276,11 @@ static unsigned long sugov_get_util(struct sugov_cpu *sg_cpu)
 {
 	struct rq *rq = cpu_rq(sg_cpu->cpu);
 	unsigned long util = cpu_util_cfs(rq);
-	unsigned long max = arch_scale_cpu_capacity(NULL, sg_cpu->cpu);
 
-	sg_cpu->max = max;
 	sg_cpu->bw_dl = cpu_bw_dl(rq);
 
-	return schedutil_freq_util(sg_cpu->cpu, util, max, FREQUENCY_UTIL);
+	return schedutil_freq_util(sg_cpu->cpu, util, sg_cpu->max,
+				   FREQUENCY_UTIL);
 }
 
 /**
@@ -304,7 +304,7 @@ static bool sugov_iowait_reset(struct sugov_cpu *sg_cpu, u64 time,
 		return false;
 
 	sg_cpu->iowait_boost = set_iowait_boost
-		? sg_cpu->sg_policy->policy->min : 0;
+		? sg_cpu->min : 0;
 	sg_cpu->iowait_boost_pending = set_iowait_boost;
 
 	return true;
@@ -351,7 +351,7 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
 	}
 
 	/* First wakeup after IO: start with minimum boost */
-	sg_cpu->iowait_boost = sg_cpu->sg_policy->policy->min;
+	sg_cpu->iowait_boost = sg_cpu->min;
 }
 
 /**
@@ -398,7 +398,7 @@ static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time,
 		 * reach the minimum.
 		 */
 		sg_cpu->iowait_boost >>= 1;
-		if (sg_cpu->iowait_boost < sg_cpu->sg_policy->policy->min) {
+		if (sg_cpu->iowait_boost < sg_cpu->min) {
 			sg_cpu->iowait_boost = 0;
 			return;
 		}
@@ -823,6 +823,8 @@ static int sugov_start(struct cpufreq_policy *policy)
 {
 	struct sugov_policy *sg_policy = policy->governor_data;
 	unsigned int cpu;
+	unsigned long max_cap = arch_scale_cpu_capacity(NULL, policy->cpu);
+	unsigned long min_cap = max_cap * policy->min / policy->cpuinfo.max_freq;
 
 	sg_policy->freq_update_delay_ns	= sg_policy->tunables->rate_limit_us * NSEC_PER_USEC;
 	sg_policy->last_freq_update_time	= 0;
@@ -837,7 +839,9 @@ static int sugov_start(struct cpufreq_policy *policy)
 		memset(sg_cpu, 0, sizeof(*sg_cpu));
 		sg_cpu->cpu			= cpu;
 		sg_cpu->sg_policy		= sg_policy;
-		sg_cpu->iowait_boost_max	= policy->cpuinfo.max_freq;
+		sg_cpu->max			= max_cap;
+		sg_cpu->min			= min_cap;
+		sg_cpu->iowait_boost_max	= max_cap;
 	}
 
 	for_each_cpu(cpu, policy->cpus) {
-- 
2.17.1


             reply	other threads:[~2019-02-22 10:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 10:37 Chunyan Zhang [this message]
2019-02-22 10:59 ` Quentin Perret
2019-03-04  7:35   ` 答复: " Wang, Vincent (王争)
2019-03-04 13:58     ` Quentin Perret
2019-03-04 15:26       ` Peter Zijlstra
2019-03-04 16:48         ` Quentin Perret
2019-03-04 17:40           ` Peter Zijlstra
2019-03-04 17:44             ` Peter Zijlstra
2019-03-04 17:50             ` Quentin Perret
2019-03-04 18:47               ` Peter Zijlstra
2019-03-04 19:11                 ` Quentin Perret
2019-03-05  8:32                   ` [PATCH] sched/cpufreq: Fix 32bit math overflow Peter Zijlstra
2019-03-05 10:55                     ` Rafael J. Wysocki
2019-03-06  2:01                     ` Chunyan Zhang
2019-03-06  7:50                     ` Chunyan Zhang
2019-03-09 14:35                     ` [tip:sched/urgent] sched/cpufreq: Fix 32-bit " tip-bot for Peter Zijlstra
2019-03-19 11:10                     ` tip-bot for Peter Zijlstra
2019-03-04 17:40           ` 答复: [PATCH V4] sched/cpufreq: initialize iowait_boost_max and iowait_boost with cpu capacity Vincent Guittot
2019-03-04 17:49           ` Peter Zijlstra

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=1550831866-32749-1-git-send-email-chunyan.zhang@unisoc.com \
    --to=chunyan.zhang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=quentin.perret@arm.com \
    --cc=vincent.wang@unisoc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®