[PATCH] cpuset semaphore depth check optimize
authorPaul Jackson <pj@sgi.com>
Mon, 12 Sep 2005 11:30:30 +0000 (04:30 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 12 Sep 2005 16:16:27 +0000 (09:16 -0700)
Optimize the deadlock avoidance check on the global cpuset
semaphore cpuset_sem.  Instead of adding a depth counter to the
task struct of each task, rather just two words are enough, one
to store the depth and the other the current cpuset_sem holder.

Thanks to Nikita Danilov for the idea.

Signed-off-by: Paul Jackson <pj@sgi.com>
[ We may want to change this further, but at least it's now
  a totally internal decision to the cpusets code ]

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/sched.h
kernel/cpuset.c

index ed3bb19..38c8654 100644 (file)
@@ -785,7 +785,6 @@ struct task_struct {
        short il_next;
 #endif
 #ifdef CONFIG_CPUSETS
        short il_next;
 #endif
 #ifdef CONFIG_CPUSETS
-       short cpuset_sem_nest_depth;
        struct cpuset *cpuset;
        nodemask_t mems_allowed;
        int cpuset_mems_generation;
        struct cpuset *cpuset;
        nodemask_t mems_allowed;
        int cpuset_mems_generation;
index 407b5f0..79866bc 100644 (file)
@@ -180,6 +180,8 @@ static struct super_block *cpuset_sb = NULL;
  */
 
 static DECLARE_MUTEX(cpuset_sem);
  */
 
 static DECLARE_MUTEX(cpuset_sem);
+static struct task_struct *cpuset_sem_owner;
+static int cpuset_sem_depth;
 
 /*
  * The global cpuset semaphore cpuset_sem can be needed by the
 
 /*
  * The global cpuset semaphore cpuset_sem can be needed by the
@@ -200,16 +202,19 @@ static DECLARE_MUTEX(cpuset_sem);
 
 static inline void cpuset_down(struct semaphore *psem)
 {
 
 static inline void cpuset_down(struct semaphore *psem)
 {
-       if (current->cpuset_sem_nest_depth == 0)
+       if (cpuset_sem_owner != current) {
                down(psem);
                down(psem);
-       current->cpuset_sem_nest_depth++;
+               cpuset_sem_owner = current;
+       }
+       cpuset_sem_depth++;
 }
 
 static inline void cpuset_up(struct semaphore *psem)
 {
 }
 
 static inline void cpuset_up(struct semaphore *psem)
 {
-       current->cpuset_sem_nest_depth--;
-       if (current->cpuset_sem_nest_depth == 0)
+       if (--cpuset_sem_depth == 0) {
+               cpuset_sem_owner = NULL;
                up(psem);
                up(psem);
+       }
 }
 
 /*
 }
 
 /*