From: Shirley Ma <mashirle@us.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
vivek@us.ibm.com, sri@us.ibm.com
Subject: [RFC PATCH 1/1] sched: Add a new API to find the prefer idlest cpu
Date: Sun, 22 Jul 2012 23:59:43 -0700 [thread overview]
Message-ID: <1343026783.13461.17.camel@oc3660625478.ibm.com> (raw)
In-Reply-To: <1343026634.13461.15.camel@oc3660625478.ibm.com>
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 64d9df5..46cc4a7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2806,4 +2806,6 @@ static inline unsigned long rlimit_max(unsigned int limit)
#endif /* __KERNEL__ */
+extern int find_idlest_prefer_cpu(struct cpumask *prefer,
+ struct cpumask *allowed, int prev_cpu);
#endif
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c099cc6..7240868 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -26,6 +26,7 @@
#include <linux/slab.h>
#include <linux/profile.h>
#include <linux/interrupt.h>
+#include <linux/export.h>
#include <trace/events/sched.h>
@@ -2809,6 +2810,35 @@ unlock:
return new_cpu;
}
+
+/*
+ * This API is used to find the most idle cpu from both preferred and
+ * allowed cpuset (such as cgroup controls cpuset). It helps per-cpu thread
+ * model to pick up the allowed local cpu to be scheduled.
+ * If these two cpusets have intersects, the cpu is chose from the intersects,
+ * if there is no intersects, then the cpu is chose from the allowed cpuset.
+ * prev_cpu helps to better local cache when prev_cpu is not busy.
+ */
+int find_idlest_prefer_cpu(struct cpumask *prefer, struct cpumask *allowed,
+ int prev_cpu)
+{
+ unsigned long load, min_load = ULONG_MAX;
+ int check, i, idlest = -1;
+
+ check = cpumask_intersects(prefer, allowed);
+ /* Traverse only the allowed CPUs */
+ if (check == 0)
+ prefer = allowed;
+ for_each_cpu_and(i, prefer, allowed) {
+ load = weighted_cpuload(i);
+ if (load < min_load || (load == min_load && i == prev_cpu)) {
+ min_load = load;
+ idlest = i;
+ }
+ }
+ return idlest;
+}
+EXPORT_SYMBOL(find_idlest_prefer_cpu);
#endif /* CONFIG_SMP */
static unsigned long
Shirley
next prev parent reply other threads:[~2012-07-23 6:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-23 6:57 [RFC PATCH 0/1] sched: Add a new API to find the prefer idlest cpu Shirley Ma
2012-07-23 6:59 ` Shirley Ma [this message]
2012-08-17 15:39 ` Shirley Ma
2012-08-17 16:48 ` Peter Zijlstra
2012-08-17 16:58 ` Shirley Ma
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=1343026783.13461.17.camel@oc3660625478.ibm.com \
--to=mashirle@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sri@us.ibm.com \
--cc=vivek@us.ibm.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;
as well as URLs for NNTP newsgroup(s).