summaryrefslogtreecommitdiffstats
path: root/timer-handle-idle-trylock-in-get-next-timer-irq.patch
blob: 9fcb4a2a88df6c7e2efbac4a668ac3de06e3f63e (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
Subject: timer-handle-idle-trylock-in-get-next-timer-irq.patch
From: Thomas Gleixner <tglx@linutronix.de>
Date: Sun, 17 Jul 2011 22:08:38 +0200

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/spinlock_rt.h |   12 +++++++++++-
 kernel/rtmutex.c            |    7 +------
 kernel/timer.c              |    7 ++++---
 3 files changed, 16 insertions(+), 10 deletions(-)

Index: linux-stable/include/linux/spinlock_rt.h
===================================================================
--- linux-stable.orig/include/linux/spinlock_rt.h
+++ linux-stable/include/linux/spinlock_rt.h
@@ -53,7 +53,17 @@ extern void __lockfunc __rt_spin_unlock(
 
 #define spin_lock_irq(lock)		spin_lock(lock)
 
-#define spin_trylock(lock)		__cond_lock(lock, rt_spin_trylock(lock))
+#define spin_do_trylock(lock)		__cond_lock(lock, rt_spin_trylock(lock))
+
+#define spin_trylock(lock)			\
+({						\
+	int __locked;				\
+	migrate_disable();			\
+	__locked = spin_do_trylock(lock);	\
+	if (!__locked)				\
+		migrate_enable();		\
+	__locked;				\
+})
 
 #ifdef CONFIG_LOCKDEP
 # define spin_lock_nested(lock, subclass)		\
Index: linux-stable/kernel/rtmutex.c
===================================================================
--- linux-stable.orig/kernel/rtmutex.c
+++ linux-stable/kernel/rtmutex.c
@@ -861,15 +861,10 @@ EXPORT_SYMBOL(rt_spin_unlock_wait);
 
 int __lockfunc rt_spin_trylock(spinlock_t *lock)
 {
-	int ret;
+	int ret = rt_mutex_trylock(&lock->lock);
 
-	migrate_disable();
-	ret = rt_mutex_trylock(&lock->lock);
 	if (ret)
 		spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
-	else
-		migrate_enable();
-
 	return ret;
 }
 EXPORT_SYMBOL(rt_spin_trylock);
Index: linux-stable/kernel/timer.c
===================================================================
--- linux-stable.orig/kernel/timer.c
+++ linux-stable/kernel/timer.c
@@ -1393,9 +1393,10 @@ unsigned long get_next_timer_interrupt(u
 	/*
 	 * On PREEMPT_RT we cannot sleep here. If the trylock does not
 	 * succeed then we return the worst-case 'expires in 1 tick'
-	 * value:
+	 * value.  We use the rt functions here directly to avoid a
+	 * migrate_disable() call.
 	 */
-	if (!spin_trylock(&base->lock))
+	if (!spin_do_trylock(&base->lock))
 		return  now + 1;
 #else
 	spin_lock(&base->lock);
@@ -1405,7 +1406,7 @@ unsigned long get_next_timer_interrupt(u
 			base->next_timer = __next_timer_interrupt(base);
 		expires = base->next_timer;
 	}
-	spin_unlock(&base->lock);
+	rt_spin_unlock(&base->lock);
 
 	if (time_before_eq(expires, now))
 		return now;