[PATCH v2 6/7] cpusets: Optimize the implementation ofguarantee_online_cpus()
From: Srivatsa S. Bhat
Date: Fri May 04 2012 - 15:21:04 EST
A cpuset's cpus_allowed mask is kept updated upon CPU hotplug
events in such a way that it always contains online cpus. Using
this observation, rework the body of guarantee_online_cpus().
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@xxxxxxxxxxxxxxxxxx>
---
kernel/cpuset.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index c501a90..6446095 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -301,20 +301,23 @@ static struct file_system_type cpuset_fs_type = {
* One way or another, we guarantee to return some non-empty subset
* of cpu_online_mask.
*
+ * Optimization: The cpus_allowed mask of a cpuset is maintained in such
+ * a way as to always have online cpus, by doing the cpuset hiearchy walk
+ * if/when necessary during CPU hotplug. And hence, it fits the above
+ * requirement perfectly. The only point to watch out is that cpus_allowed
+ * can be empty when the cpuset has no tasks and user_cpus_allowed is empty.
+ *
* Call with callback_mutex held.
*/
static void guarantee_online_cpus(const struct cpuset *cs,
struct cpumask *pmask)
{
- while (cs && !cpumask_intersects(cs->user_cpus_allowed,
- cpu_online_mask))
- cs = cs->parent;
-
- if (cs)
- cpumask_and(pmask, cs->user_cpus_allowed, cpu_online_mask);
+ if (cs && !cpumask_empty(cs->cpus_allowed))
+ cpumask_copy(pmask, cs->cpus_allowed);
else
cpumask_copy(pmask, cpu_online_mask);
+
BUG_ON(!cpumask_intersects(pmask, cpu_online_mask));
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/