[PATCH -rt] clean up pi_lock in rtmutex

From: Steven Rostedt
Date: Tue Aug 01 2006 - 09:54:50 EST


Ingo,

This is pretty much the same patch that I sent to mainline to clean up
the rtmutex code. I gave the reasons why in that patch, so I'm not
going to repeat them here. This is for 2.6.17-rt7

-- Steve

Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>

Index: linux-2.6.17-rt7/kernel/rtmutex.c
===================================================================
--- linux-2.6.17-rt7.orig/kernel/rtmutex.c 2006-08-01 09:40:36.000000000 -0400
+++ linux-2.6.17-rt7/kernel/rtmutex.c 2006-08-01 09:53:41.000000000 -0400
@@ -419,7 +419,7 @@ static int task_blocks_on_rt_mutex(struc
{
struct rt_mutex_waiter *top_waiter = waiter;
task_t *owner = rt_mutex_owner(lock);
- int boost = 0, res;
+ int chain_walk = 0, res;
unsigned long flags;

spin_lock_irqsave(&current->pi_lock, flags);
@@ -444,23 +444,24 @@ static int task_blocks_on_rt_mutex(struc
plist_add(&waiter->pi_list_entry, &owner->pi_waiters);

__rt_mutex_adjust_prio(owner);
- if (owner->pi_blocked_on) {
- boost = 1;
- get_task_struct(owner);
- }
- spin_unlock_irqrestore(&owner->pi_lock, flags);
- }
- else if (debug_rt_mutex_detect_deadlock(waiter, detect_deadlock)) {
- spin_lock_irqsave(&owner->pi_lock, flags);
- if (owner->pi_blocked_on) {
- boost = 1;
- get_task_struct(owner);
- }
+ if (owner->pi_blocked_on)
+ chain_walk = 1;
+
spin_unlock_irqrestore(&owner->pi_lock, flags);
}
- if (!boost)
+ else if (debug_rt_mutex_detect_deadlock(waiter, detect_deadlock))
+ chain_walk = 1;
+
+ if (!chain_walk)
return 0;

+ /*
+ * The owner can't disappear while holding a lock,
+ * so the owner struct is protected by wait_lock.
+ * Gets dropped in rt_mutex_adjust_prio_chain()!
+ */
+ get_task_struct(owner);
+
spin_unlock(&lock->wait_lock);

res = rt_mutex_adjust_prio_chain(owner, detect_deadlock, lock,
@@ -542,7 +543,7 @@ static void remove_waiter(struct rt_mute
struct rt_mutex_waiter *waiter __IP_DECL__)
{
int first = (waiter == rt_mutex_top_waiter(lock));
- int boost = 0;
+ int chain_walk = 0;
task_t *owner = rt_mutex_owner(lock);
unsigned long flags;

@@ -566,18 +567,20 @@ static void remove_waiter(struct rt_mute
}
__rt_mutex_adjust_prio(owner);

- if (owner->pi_blocked_on) {
- boost = 1;
- get_task_struct(owner);
- }
+ if (owner->pi_blocked_on)
+ chain_walk = 1;
+
spin_unlock_irqrestore(&owner->pi_lock, flags);
}

WARN_ON(!plist_node_empty(&waiter->pi_list_entry));

- if (!boost)
+ if (!chain_walk)
return;

+ /* gets dropped in rt_mutex_adjust_prio_chain()! */
+ get_task_struct(owner);
+
spin_unlock(&lock->wait_lock);

rt_mutex_adjust_prio_chain(owner, 0, lock, NULL __IP__);


-
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/