From: Con Kolivas <kernel@kolivas.org>
To: linux list <linux-kernel@vger.kernel.org>
Cc: ck list <ck@vds.kolivas.org>
Subject: [ckpatch][8/29] track_mutexes-1.patch
Date: Sun, 18 Jun 2006 17:31:14 +1000 [thread overview]
Message-ID: <200606181731.14664.kernel@kolivas.org> (raw)
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 <kernel@kolivas.org>
---
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-ck-dev/include/linux/init_task.h
===================================================================
--- linux-ck-dev.orig/include/linux/init_task.h 2006-06-18 15:20:14.000000000 +1000
+++ linux-ck-dev/include/linux/init_task.h 2006-06-18 15:23:44.000000000 +1000
@@ -120,6 +120,7 @@ extern struct group_info init_groups;
.blocked = {{0}}, \
.alloc_lock = SPIN_LOCK_UNLOCKED, \
.proc_lock = SPIN_LOCK_UNLOCKED, \
+ .mutexes_held = 0, \
.journal_info = NULL, \
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
.fs_excl = ATOMIC_INIT(0), \
Index: linux-ck-dev/include/linux/sched.h
===================================================================
--- linux-ck-dev.orig/include/linux/sched.h 2006-06-18 15:23:38.000000000 +1000
+++ linux-ck-dev/include/linux/sched.h 2006-06-18 15:23:44.000000000 +1000
@@ -845,6 +845,7 @@ struct task_struct {
/* mutex deadlock detection */
struct mutex_waiter *blocked_on;
#endif
+ unsigned long mutexes_held;
/* journalling filesystem info */
void *journal_info;
Index: linux-ck-dev/kernel/fork.c
===================================================================
--- linux-ck-dev.orig/kernel/fork.c 2006-06-18 15:20:14.000000000 +1000
+++ linux-ck-dev/kernel/fork.c 2006-06-18 15:23:44.000000000 +1000
@@ -1022,6 +1022,7 @@ static task_t *copy_process(unsigned lon
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-ck-dev/kernel/mutex.c
===================================================================
--- linux-ck-dev.orig/kernel/mutex.c 2006-06-18 15:20:14.000000000 +1000
+++ linux-ck-dev/kernel/mutex.c 2006-06-18 15:23:44.000000000 +1000
@@ -58,6 +58,16 @@ EXPORT_SYMBOL(__mutex_init);
static void fastcall noinline __sched
__mutex_lock_slowpath(atomic_t *lock_count __IP_DECL__);
+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
@@ -87,6 +97,7 @@ void fastcall __sched mutex_lock(struct
* 'unlocked' into 'locked' state.
*/
__mutex_fastpath_lock(&lock->count, __mutex_lock_slowpath);
+ inc_mutex_count();
}
EXPORT_SYMBOL(mutex_lock);
@@ -112,6 +123,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);
@@ -254,9 +266,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);
@@ -308,8 +325,12 @@ static inline int __mutex_trylock_slowpa
*/
int fastcall 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);
--
-ck
next reply other threads:[~2006-06-18 7:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-18 7:31 Con Kolivas [this message]
2006-06-18 10:58 ` [ckpatch][8/29] track_mutexes-1.patch Nikita Danilov
2006-06-18 11:28 ` [ck] " Juho Saarikko
2006-06-18 11:34 ` Con Kolivas
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=200606181731.14664.kernel@kolivas.org \
--to=kernel@kolivas.org \
--cc=ck@vds.kolivas.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.