mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Turquette <mturquette@linaro.org>
To: peterz@infradead.org, mingo@kernel.org
Cc: linux-kernel@vger.kernel.org, preeti@linux.vnet.ibm.com,
	Morten.Rasmussen@arm.com, riel@redhat.com, efault@gmx.de,
	nicolas.pitre@linaro.org, inaro-kernel@lists.linaro.org,
	daniel.lezcano@linaro.org, patches@linaro.org,
	eas-dev@lists.linaro.org, dietmar.eggemann@arm.com,
	vincent.guittot@linaro.org, amit.kucheria@linaro.org,
	juri.lelli@arm.com, rjw@rjwysocki.net, viresh.kumar@linaro.org,
	ashwin.chaugule@linaro.org, alex.shi@linaro.org,
	Michael Turquette <mturquette@linaro.org>
Subject: [PATCH 3/4] sched: export get_cpu_usage & capacity_orig_of
Date: Mon,  4 May 2015 15:10:40 -0700	[thread overview]
Message-ID: <1430777441-15087-4-git-send-email-mturquette@linaro.org> (raw)
In-Reply-To: <1430777441-15087-1-git-send-email-mturquette@linaro.org>

get_cpu_usage and capacity_orig_of are useful for a cpu frequency
scaling policy which is based on cfs load tracking and cpu capacity
metrics. Expose these calls in sched.h so that they can be used in such
a policy.

Signed-off-by: Michael Turquette <mturquette@linaro.org>
---
 kernel/sched/fair.c  | 32 --------------------------------
 kernel/sched/sched.h | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 75aec8d..9e37d49 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4366,11 +4366,6 @@ static unsigned long capacity_of(int cpu)
 	return cpu_rq(cpu)->cpu_capacity;
 }
 
-static unsigned long capacity_orig_of(int cpu)
-{
-	return cpu_rq(cpu)->cpu_capacity_orig;
-}
-
 static unsigned long cpu_avg_load_per_task(int cpu)
 {
 	struct rq *rq = cpu_rq(cpu);
@@ -4784,33 +4779,6 @@ next:
 done:
 	return target;
 }
-/*
- * get_cpu_usage returns the amount of capacity of a CPU that is used by CFS
- * tasks. The unit of the return value must be the one of capacity so we can
- * compare the usage with the capacity of the CPU that is available for CFS
- * task (ie cpu_capacity).
- * cfs.utilization_load_avg is the sum of running time of runnable tasks on a
- * CPU. It represents the amount of utilization of a CPU in the range
- * [0..SCHED_LOAD_SCALE].  The usage of a CPU can't be higher than the full
- * capacity of the CPU because it's about the running time on this CPU.
- * Nevertheless, cfs.utilization_load_avg can be higher than SCHED_LOAD_SCALE
- * because of unfortunate rounding in avg_period and running_load_avg or just
- * after migrating tasks until the average stabilizes with the new running
- * time. So we need to check that the usage stays into the range
- * [0..cpu_capacity_orig] and cap if necessary.
- * Without capping the usage, a group could be seen as overloaded (CPU0 usage
- * at 121% + CPU1 usage at 80%) whereas CPU1 has 20% of available capacity
- */
-static int get_cpu_usage(int cpu)
-{
-	unsigned long usage = cpu_rq(cpu)->cfs.utilization_load_avg;
-	unsigned long capacity = capacity_orig_of(cpu);
-
-	if (usage >= SCHED_LOAD_SCALE)
-		return capacity;
-
-	return (usage * capacity) >> SCHED_LOAD_SHIFT;
-}
 
 /*
  * select_task_rq_fair: Select target runqueue for the waking task in domains
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index e0e1299..8bf35d3 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1396,6 +1396,39 @@ unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu)
 }
 #endif
 
+static inline unsigned long capacity_orig_of(int cpu)
+{
+	return cpu_rq(cpu)->cpu_capacity_orig;
+}
+
+/*
+ * get_cpu_usage returns the amount of capacity of a CPU that is used by CFS
+ * tasks. The unit of the return value must be the one of capacity so we can
+ * compare the usage with the capacity of the CPU that is available for CFS
+ * task (ie cpu_capacity).
+ * cfs.utilization_load_avg is the sum of running time of runnable tasks on a
+ * CPU. It represents the amount of utilization of a CPU in the range
+ * [0..SCHED_LOAD_SCALE].  The usage of a CPU can't be higher than the full
+ * capacity of the CPU because it's about the running time on this CPU.
+ * Nevertheless, cfs.utilization_load_avg can be higher than SCHED_LOAD_SCALE
+ * because of unfortunate rounding in avg_period and running_load_avg or just
+ * after migrating tasks until the average stabilizes with the new running
+ * time. So we need to check that the usage stays into the range
+ * [0..cpu_capacity_orig] and cap if necessary.
+ * Without capping the usage, a group could be seen as overloaded (CPU0 usage
+ * at 121% + CPU1 usage at 80%) whereas CPU1 has 20% of available capacity
+ */
+static inline int get_cpu_usage(int cpu)
+{
+	unsigned long usage = cpu_rq(cpu)->cfs.utilization_load_avg;
+	unsigned long capacity = capacity_orig_of(cpu);
+
+	if (usage >= SCHED_LOAD_SCALE)
+		return capacity;
+
+	return (usage * capacity) >> SCHED_LOAD_SHIFT;
+}
+
 static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta)
 {
 	rq->rt_avg += rt_delta * arch_scale_freq_capacity(NULL, cpu_of(rq));
-- 
1.9.1


  parent reply	other threads:[~2015-05-04 22:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04 22:10 [PATCH 0/4] scheduler-based cpu frequency scaling Michael Turquette
2015-05-04 22:10 ` [PATCH 1/4] arm: Frequency invariant scheduler load-tracking support Michael Turquette
2015-05-04 22:10 ` [PATCH 2/4] sched: sched feature for cpu frequency selection Michael Turquette
2015-05-04 22:10 ` Michael Turquette [this message]
2015-05-04 22:10 ` [PATCH 4/4] sched: cpufreq_cfs: pelt-based cpu frequency scaling Michael Turquette
2015-05-05  9:00   ` Peter Zijlstra
2015-05-05 12:16     ` Juri Lelli
     [not found]     ` <20150505182347.16410.16338@quantum>
2015-05-06 12:22       ` Peter Zijlstra
     [not found]         ` <20150507041725.16410.58417@quantum>
2015-05-07  6:23           ` Peter Zijlstra
2015-05-07 10:49           ` Juri Lelli
2015-05-07 14:25             ` Michael Turquette
2015-05-05  9:01   ` Peter Zijlstra
2015-05-05  9:04   ` Peter Zijlstra
2015-05-04 23:27 ` [PATCH 0/4] scheduler-based " Rafael J. Wysocki
2015-05-05 18:28   ` Mike Turquette
2015-05-06 16:50 ` [PATCH] sched/core: Add empty 'gov_cfs_update_cpu' function definition for NON-SMP systems Abel Vesa
2015-05-07  4:18   ` Michael Turquette

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=1430777441-15087-4-git-send-email-mturquette@linaro.org \
    --to=mturquette@linaro.org \
    --cc=Morten.Rasmussen@arm.com \
    --cc=alex.shi@linaro.org \
    --cc=amit.kucheria@linaro.org \
    --cc=ashwin.chaugule@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=eas-dev@lists.linaro.org \
    --cc=efault@gmx.de \
    --cc=inaro-kernel@lists.linaro.org \
    --cc=juri.lelli@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=patches@linaro.org \
    --cc=peterz@infradead.org \
    --cc=preeti@linux.vnet.ibm.com \
    --cc=riel@redhat.com \
    --cc=rjw@rjwysocki.net \
    --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

all inboxes | Powered by JetHome®