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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
Subject: rt/rwlock: Remove recursive support
From: Thomas Gleixner <tglx@linutronix.de>
Date: Fri, 28 Jul 2017 12:35:23 +0200
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
include/linux/rwlock_types_rt.h | 1
kernel/locking/rt.c | 56 ++++++++--------------------------------
2 files changed, 12 insertions(+), 45 deletions(-)
--- a/include/linux/rwlock_types_rt.h
+++ b/include/linux/rwlock_types_rt.h
@@ -10,7 +10,6 @@
*/
typedef struct {
struct rt_mutex lock;
- int read_depth;
unsigned int break_lock;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
--- a/kernel/locking/rt.c
+++ b/kernel/locking/rt.c
@@ -211,46 +211,28 @@ int __lockfunc rt_write_trylock(rwlock_t
rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
else
migrate_enable();
-
return ret;
}
EXPORT_SYMBOL(rt_write_trylock);
int __lockfunc rt_write_trylock_irqsave(rwlock_t *rwlock, unsigned long *flags)
{
- int ret;
-
*flags = 0;
- ret = rt_write_trylock(rwlock);
- return ret;
+ return rt_write_trylock(rwlock);
}
EXPORT_SYMBOL(rt_write_trylock_irqsave);
int __lockfunc rt_read_trylock(rwlock_t *rwlock)
{
struct rt_mutex *lock = &rwlock->lock;
- int ret = 1;
-
- /*
- * recursive read locks succeed when current owns the lock,
- * but not when read_depth == 0 which means that the lock is
- * write locked.
- */
- if (rt_mutex_owner(lock) != current) {
- migrate_disable();
- ret = rt_mutex_trylock(lock);
- if (ret)
- rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
- else
- migrate_enable();
-
- } else if (!rwlock->read_depth) {
- ret = 0;
- }
+ int ret;
+ migrate_disable();
+ ret = rt_mutex_trylock(lock);
if (ret)
- rwlock->read_depth++;
-
+ rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
+ else
+ migrate_enable();
return ret;
}
EXPORT_SYMBOL(rt_read_trylock);
@@ -266,17 +248,9 @@ void __lockfunc rt_read_lock(rwlock_t *r
{
struct rt_mutex *lock = &rwlock->lock;
-
- /*
- * recursive read locks succeed when current owns the lock
- */
- if (rt_mutex_owner(lock) != current) {
- rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
- __rt_spin_lock(lock);
- }
- rwlock->read_depth++;
+ rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
+ __rt_spin_lock(lock);
}
-
EXPORT_SYMBOL(rt_read_lock);
void __lockfunc rt_write_unlock(rwlock_t *rwlock)
@@ -290,19 +264,15 @@ EXPORT_SYMBOL(rt_write_unlock);
void __lockfunc rt_read_unlock(rwlock_t *rwlock)
{
- /* Release the lock only when read_depth is down to 0 */
- if (--rwlock->read_depth == 0) {
- rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
- __rt_spin_unlock(&rwlock->lock);
- migrate_enable();
- }
+ rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
+ __rt_spin_unlock(&rwlock->lock);
+ migrate_enable();
}
EXPORT_SYMBOL(rt_read_unlock);
unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock)
{
rt_write_lock(rwlock);
-
return 0;
}
EXPORT_SYMBOL(rt_write_lock_irqsave);
@@ -310,7 +280,6 @@ EXPORT_SYMBOL(rt_write_lock_irqsave);
unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock)
{
rt_read_lock(rwlock);
-
return 0;
}
EXPORT_SYMBOL(rt_read_lock_irqsave);
@@ -325,7 +294,6 @@ void __rt_rwlock_init(rwlock_t *rwlock,
lockdep_init_map(&rwlock->dep_map, name, key, 0);
#endif
rwlock->lock.save_state = 1;
- rwlock->read_depth = 0;
}
EXPORT_SYMBOL(__rt_rwlock_init);
|