Keep a record of how many mutexes are held by any task. This allows cpu scheduler code to use this information in decision making for tasks that hold contended resources. Signed-off-by: Con Kolivas --- include/linux/init_task.h | 1 + include/linux/sched.h | 1 + kernel/fork.c | 1 + kernel/mutex.c | 25 +++++++++++++++++++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) Index: linux-2.6.20-ck1/include/linux/init_task.h =================================================================== --- linux-2.6.20-ck1.orig/include/linux/init_task.h 2007-02-05 22:52:04.000000000 +1100 +++ linux-2.6.20-ck1/include/linux/init_task.h 2007-02-16 19:01:31.000000000 +1100 @@ -135,6 +135,7 @@ extern struct group_info init_groups; .signal = {{0}}}, \ .blocked = {{0}}, \ .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \ + .mutexes_held = 0, \ .journal_info = NULL, \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl = ATOMIC_INIT(0), \ Index: linux-2.6.20-ck1/include/linux/sched.h =================================================================== --- linux-2.6.20-ck1.orig/include/linux/sched.h 2007-02-16 19:01:31.000000000 +1100 +++ linux-2.6.20-ck1/include/linux/sched.h 2007-02-16 19:01:31.000000000 +1100 @@ -992,6 +992,7 @@ struct task_struct { struct held_lock held_locks[MAX_LOCK_DEPTH]; unsigned int lockdep_recursion; #endif + unsigned long mutexes_held; /* journalling filesystem info */ void *journal_info; Index: linux-2.6.20-ck1/kernel/fork.c =================================================================== --- linux-2.6.20-ck1.orig/kernel/fork.c 2007-02-05 22:52:04.000000000 +1100 +++ linux-2.6.20-ck1/kernel/fork.c 2007-02-16 19:01:31.000000000 +1100 @@ -1058,6 +1058,7 @@ static struct task_struct *copy_process( p->io_context = NULL; p->io_wait = NULL; p->audit_context = NULL; + p->mutexes_held = 0; cpuset_fork(p); #ifdef CONFIG_NUMA p->mempolicy = mpol_copy(p->mempolicy); Index: linux-2.6.20-ck1/kernel/mutex.c =================================================================== --- linux-2.6.20-ck1.orig/kernel/mutex.c 2007-02-05 22:52:04.000000000 +1100 +++ linux-2.6.20-ck1/kernel/mutex.c 2007-02-16 19:01:31.000000000 +1100 @@ -60,6 +60,16 @@ EXPORT_SYMBOL(__mutex_init); static void fastcall noinline __sched __mutex_lock_slowpath(atomic_t *lock_count); +static inline void inc_mutex_count(void) +{ + current->mutexes_held++; +} + +static inline void dec_mutex_count(void) +{ + current->mutexes_held--; +} + /*** * mutex_lock - acquire the mutex * @lock: the mutex to be acquired @@ -89,6 +99,7 @@ void inline fastcall __sched mutex_lock( * 'unlocked' into 'locked' state. */ __mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath); + inc_mutex_count(); } EXPORT_SYMBOL(mutex_lock); @@ -114,6 +125,7 @@ void fastcall __sched mutex_unlock(struc * into 'unlocked' state: */ __mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath); + dec_mutex_count(); } EXPORT_SYMBOL(mutex_unlock); @@ -283,9 +295,14 @@ __mutex_lock_interruptible_slowpath(atom */ int fastcall __sched mutex_lock_interruptible(struct mutex *lock) { + int ret; + might_sleep(); - return __mutex_fastpath_lock_retval + ret = __mutex_fastpath_lock_retval (&lock->count, __mutex_lock_interruptible_slowpath); + if (likely(!ret)) + inc_mutex_count(); + return ret; } EXPORT_SYMBOL(mutex_lock_interruptible); @@ -340,8 +357,12 @@ static inline int __mutex_trylock_slowpa */ int fastcall __sched mutex_trylock(struct mutex *lock) { - return __mutex_fastpath_trylock(&lock->count, + int ret = __mutex_fastpath_trylock(&lock->count, __mutex_trylock_slowpath); + + if (likely(ret)) + inc_mutex_count(); + return ret; } EXPORT_SYMBOL(mutex_trylock);