summaryrefslogtreecommitdiffstats
path: root/rtmutex-cleanup-the-adaptive-spin-code.patch
blob: 816aa4076a6556298b9f9a97b9fd0a2b9a92d4af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
From fa50e2f68f3b3fa4d538caba0cce736140ebff9c Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <tglx@linutronix.de>
Date: Fri, 3 Jul 2009 08:44:23 -0500
Subject: [PATCH] rtmutex: cleanup the adaptive spin code

commit edeb8fe63dce75e827a27292a186b98fe3d26959 in tip.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 kernel/rtmutex.c |   34 +++++++++-------------------------
 1 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
index 4d53d03..b649eb0 100644
--- a/kernel/rtmutex.c
+++ b/kernel/rtmutex.c
@@ -708,41 +708,22 @@ update_current(unsigned long new_state, unsigned long *saved_state)
 static int adaptive_wait(struct rt_mutex_waiter *waiter,
 			 struct task_struct *orig_owner)
 {
-	int sleep = 0;
-
 	for (;;) {
 
 		/* we are the owner? */
 		if (!waiter->task)
-			break;
+			return 0;
 
-		/*
-		 * We need to read the owner of the lock and then check
-		 * its state. But we can't let the owner task be freed
-		 * while we read the state. We grab the rcu_lock and
-		 * this makes sure that the owner task wont disappear
-		 * between testing that it still has the lock, and checking
-		 * its state.
-		 */
-		rcu_read_lock();
 		/* Owner changed? Then lets update the original */
-		if (orig_owner != rt_mutex_owner(waiter->lock)) {
-			rcu_read_unlock();
-			break;
-		}
+		if (orig_owner != rt_mutex_owner(waiter->lock))
+			return 0;
 
 		/* Owner went to bed, so should we */
-		if (!task_is_current(orig_owner)) {
-			sleep = 1;
-			rcu_read_unlock();
-			break;
-		}
-		rcu_read_unlock();
+		if (!task_is_current(orig_owner))
+			return 1;
 
 		cpu_relax();
 	}
-
-	return sleep;
 }
 #else
 static int adaptive_wait(struct rt_mutex_waiter *waiter,
@@ -820,11 +801,13 @@ rt_spin_lock_slowlock(struct rt_mutex *lock)
 		 */
 		current->lock_depth = -1;
 		orig_owner = rt_mutex_owner(lock);
+		get_task_struct(orig_owner);
 		raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
 
 		debug_rt_mutex_print_deadlock(&waiter);
 
 		if (adaptive_wait(&waiter, orig_owner)) {
+			put_task_struct(orig_owner);
 			update_current(TASK_UNINTERRUPTIBLE, &saved_state);
 			/*
 			 * The xchg() in update_current() is an implicit
@@ -833,7 +816,8 @@ rt_spin_lock_slowlock(struct rt_mutex *lock)
 			 */
 			if (waiter.task)
 				schedule_rt_mutex(lock);
-		}
+		} else
+			put_task_struct(orig_owner);
 
 		raw_spin_lock_irqsave(&lock->wait_lock, flags);
 		current->lock_depth = saved_lock_depth;
-- 
1.7.0.4