[Patch 4/5] sched: introduce a mutex and corresponding API to serialize access to doms_cur[] array

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Srivatsa Vaddagiri
Date: Monday, November 26, 2007 - 10:21 pm

doms_cur[] array represents various scheduling domains which are mutually
exclusive. Currently cpusets code can modify this array (by calling
partition_sched_domains()) as a result of user modifying sched_load_balance 
flag for various cpusets.

This patch introduces a mutex and corresponding API (only when
CONFIG_FAIR_GROUP_SCHED is defined) which allows a reader to safely read the
doms_cur[] array w/o worrying abt concurrent modifications to the array.

The fair group scheduler code (introduced in next patch of this series)
makes use of this mutex to walk thr' doms_cur[] array while rebalancing
shares of task groups across cpus.

Signed-off-by: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>

---
 kernel/sched.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+)

Index: current/kernel/sched.c
===================================================================
--- current.orig/kernel/sched.c
+++ current/kernel/sched.c
@@ -186,6 +186,9 @@ static struct cfs_rq *init_cfs_rq_p[NR_C
  */
 static DEFINE_MUTEX(task_group_mutex);
 
+/* doms_cur_mutex serializes access to doms_cur[] array */
+static DEFINE_MUTEX(doms_cur_mutex);
+
 /* Default task group.
  *	Every task in system belong to this group at bootup.
  */
@@ -236,11 +239,23 @@ static inline void unlock_task_group_lis
 	mutex_unlock(&task_group_mutex);
 }
 
+static inline void lock_doms_cur(void)
+{
+	mutex_lock(&doms_cur_mutex);
+}
+
+static inline void unlock_doms_cur(void)
+{
+	mutex_unlock(&doms_cur_mutex);
+}
+
 #else
 
 static inline void set_task_cfs_rq(struct task_struct *p, unsigned int cpu) { }
 static inline void lock_task_group_list(void) { }
 static inline void unlock_task_group_list(void) { }
+static inline void lock_doms_cur(void) { }
+static inline void unlock_doms_cur(void) { }
 
 #endif	/* CONFIG_FAIR_GROUP_SCHED */
 
@@ -6547,6 +6562,8 @@ void partition_sched_domains(int ndoms_n
 {
 	int i, j;
 
+	lock_doms_cur();
+
 	/* always unregister in case we don't destroy any domains */
 	unregister_sched_domain_sysctl();
 
@@ -6587,6 +6604,8 @@ match2:
 	ndoms_cur = ndoms_new;
 
 	register_sched_domain_sysctl();
+
+	unlock_doms_cur();
 }
 
 #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)


-- 
Regards,
vatsa
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/2] sched: Group scheduler related patches, Srivatsa Vaddagiri, (Mon Nov 19, 5:27 am)
[PATCH 1/2] sched: Minor cleanups, Srivatsa Vaddagiri, (Mon Nov 19, 5:28 am)
[PATCH 2/2] sched: Improve fairness of cpu allocation for ..., Srivatsa Vaddagiri, (Mon Nov 19, 5:30 am)
Re: [PATCH 1/2] sched: Minor cleanups, Ingo Molnar, (Mon Nov 19, 6:08 am)
Re: [PATCH 1/2] sched: Minor cleanups, Srivatsa Vaddagiri, (Mon Nov 19, 8:01 am)
Re: [PATCH 2/2] sched: Improve fairness of cpu allocation ..., Srivatsa Vaddagiri, (Mon Nov 19, 8:03 am)
Re: [PATCH 2/2] sched: Improve fairness of cpu allocation ..., Srivatsa Vaddagiri, (Mon Nov 19, 9:06 am)
[PATCH 0/4] sched: group scheduler related patches (V3), Srivatsa Vaddagiri, (Sun Nov 25, 10:00 pm)
[PATCH 1/4] sched: code cleanup, Srivatsa Vaddagiri, (Sun Nov 25, 10:02 pm)
[PATCH 2/4] sched: minor fixes for group scheduler, Srivatsa Vaddagiri, (Sun Nov 25, 10:03 pm)
[Patch 3/4 v1] sched: change how cpu load is calculated, Srivatsa Vaddagiri, (Sun Nov 25, 10:05 pm)
[Patch 3/4 v2] sched: change how cpu load is calculated, Srivatsa Vaddagiri, (Sun Nov 25, 10:06 pm)
[Patch 4/4] sched: Improve fairness of cpu bandwidth alloc ..., Srivatsa Vaddagiri, (Sun Nov 25, 10:09 pm)
[Patch 0/5] sched: group scheduler related patches (V4), Srivatsa Vaddagiri, (Mon Nov 26, 10:06 pm)
[Patch 1/5] sched: code cleanup, Srivatsa Vaddagiri, (Mon Nov 26, 10:08 pm)
[Patch 3/5 v1] sched: change how cpu load is calculated, Srivatsa Vaddagiri, (Mon Nov 26, 10:11 pm)
[Patch 3/5 v2] sched: change how cpu load is calculated, Srivatsa Vaddagiri, (Mon Nov 26, 10:12 pm)
[Patch 4/5] sched: introduce a mutex and corresponding API ..., Srivatsa Vaddagiri, (Mon Nov 26, 10:21 pm)
[Patch 5/5] sched: Improve fairness of cpu bandwidth alloc ..., Srivatsa Vaddagiri, (Mon Nov 26, 10:27 pm)
Re: [Patch 0/5] sched: group scheduler related patches (V4), Srivatsa Vaddagiri, (Tue Nov 27, 4:42 am)