提交 ddb6c9b5 编写于 作者: T Thomas Gleixner 提交者: Ingo Molnar

locking, rwsem: Annotate inner lock as raw

There is no reason to allow the lock protecting rwsems (the
ownerless variant) to be preemptible on -rt. Convert it to raw.

In mainline this change documents the low level nature of
the lock - otherwise there's no functional difference. Lockdep
and Sparse checking will work as usual.
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Signed-off-by: NIngo Molnar <mingo@elte.hu>
上级 8292c9e1
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
struct rw_semaphore { struct rw_semaphore {
__s32 activity; __s32 activity;
spinlock_t wait_lock; raw_spinlock_t wait_lock;
struct list_head wait_list; struct list_head wait_list;
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map; struct lockdep_map dep_map;
......
...@@ -25,7 +25,7 @@ struct rw_semaphore; ...@@ -25,7 +25,7 @@ struct rw_semaphore;
/* All arch specific implementations share the same struct */ /* All arch specific implementations share the same struct */
struct rw_semaphore { struct rw_semaphore {
long count; long count;
spinlock_t wait_lock; raw_spinlock_t wait_lock;
struct list_head wait_list; struct list_head wait_list;
#ifdef CONFIG_DEBUG_LOCK_ALLOC #ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map; struct lockdep_map dep_map;
...@@ -56,9 +56,11 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem) ...@@ -56,9 +56,11 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
# define __RWSEM_DEP_MAP_INIT(lockname) # define __RWSEM_DEP_MAP_INIT(lockname)
#endif #endif
#define __RWSEM_INITIALIZER(name) \ #define __RWSEM_INITIALIZER(name) \
{ RWSEM_UNLOCKED_VALUE, __SPIN_LOCK_UNLOCKED(name.wait_lock), \ { RWSEM_UNLOCKED_VALUE, \
LIST_HEAD_INIT((name).wait_list) __RWSEM_DEP_MAP_INIT(name) } __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
LIST_HEAD_INIT((name).wait_list) \
__RWSEM_DEP_MAP_INIT(name) }
#define DECLARE_RWSEM(name) \ #define DECLARE_RWSEM(name) \
struct rw_semaphore name = __RWSEM_INITIALIZER(name) struct rw_semaphore name = __RWSEM_INITIALIZER(name)
......
...@@ -22,9 +22,9 @@ int rwsem_is_locked(struct rw_semaphore *sem) ...@@ -22,9 +22,9 @@ int rwsem_is_locked(struct rw_semaphore *sem)
int ret = 1; int ret = 1;
unsigned long flags; unsigned long flags;
if (spin_trylock_irqsave(&sem->wait_lock, flags)) { if (raw_spin_trylock_irqsave(&sem->wait_lock, flags)) {
ret = (sem->activity != 0); ret = (sem->activity != 0);
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
} }
return ret; return ret;
} }
...@@ -44,7 +44,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, ...@@ -44,7 +44,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
lockdep_init_map(&sem->dep_map, name, key, 0); lockdep_init_map(&sem->dep_map, name, key, 0);
#endif #endif
sem->activity = 0; sem->activity = 0;
spin_lock_init(&sem->wait_lock); raw_spin_lock_init(&sem->wait_lock);
INIT_LIST_HEAD(&sem->wait_list); INIT_LIST_HEAD(&sem->wait_list);
} }
EXPORT_SYMBOL(__init_rwsem); EXPORT_SYMBOL(__init_rwsem);
...@@ -145,12 +145,12 @@ void __sched __down_read(struct rw_semaphore *sem) ...@@ -145,12 +145,12 @@ void __sched __down_read(struct rw_semaphore *sem)
struct task_struct *tsk; struct task_struct *tsk;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
if (sem->activity >= 0 && list_empty(&sem->wait_list)) { if (sem->activity >= 0 && list_empty(&sem->wait_list)) {
/* granted */ /* granted */
sem->activity++; sem->activity++;
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
goto out; goto out;
} }
...@@ -165,7 +165,7 @@ void __sched __down_read(struct rw_semaphore *sem) ...@@ -165,7 +165,7 @@ void __sched __down_read(struct rw_semaphore *sem)
list_add_tail(&waiter.list, &sem->wait_list); list_add_tail(&waiter.list, &sem->wait_list);
/* we don't need to touch the semaphore struct anymore */ /* we don't need to touch the semaphore struct anymore */
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
/* wait to be given the lock */ /* wait to be given the lock */
for (;;) { for (;;) {
...@@ -189,7 +189,7 @@ int __down_read_trylock(struct rw_semaphore *sem) ...@@ -189,7 +189,7 @@ int __down_read_trylock(struct rw_semaphore *sem)
int ret = 0; int ret = 0;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
if (sem->activity >= 0 && list_empty(&sem->wait_list)) { if (sem->activity >= 0 && list_empty(&sem->wait_list)) {
/* granted */ /* granted */
...@@ -197,7 +197,7 @@ int __down_read_trylock(struct rw_semaphore *sem) ...@@ -197,7 +197,7 @@ int __down_read_trylock(struct rw_semaphore *sem)
ret = 1; ret = 1;
} }
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
return ret; return ret;
} }
...@@ -212,12 +212,12 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass) ...@@ -212,12 +212,12 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
struct task_struct *tsk; struct task_struct *tsk;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
if (sem->activity == 0 && list_empty(&sem->wait_list)) { if (sem->activity == 0 && list_empty(&sem->wait_list)) {
/* granted */ /* granted */
sem->activity = -1; sem->activity = -1;
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
goto out; goto out;
} }
...@@ -232,7 +232,7 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass) ...@@ -232,7 +232,7 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
list_add_tail(&waiter.list, &sem->wait_list); list_add_tail(&waiter.list, &sem->wait_list);
/* we don't need to touch the semaphore struct anymore */ /* we don't need to touch the semaphore struct anymore */
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
/* wait to be given the lock */ /* wait to be given the lock */
for (;;) { for (;;) {
...@@ -260,7 +260,7 @@ int __down_write_trylock(struct rw_semaphore *sem) ...@@ -260,7 +260,7 @@ int __down_write_trylock(struct rw_semaphore *sem)
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
if (sem->activity == 0 && list_empty(&sem->wait_list)) { if (sem->activity == 0 && list_empty(&sem->wait_list)) {
/* granted */ /* granted */
...@@ -268,7 +268,7 @@ int __down_write_trylock(struct rw_semaphore *sem) ...@@ -268,7 +268,7 @@ int __down_write_trylock(struct rw_semaphore *sem)
ret = 1; ret = 1;
} }
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
return ret; return ret;
} }
...@@ -280,12 +280,12 @@ void __up_read(struct rw_semaphore *sem) ...@@ -280,12 +280,12 @@ void __up_read(struct rw_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
if (--sem->activity == 0 && !list_empty(&sem->wait_list)) if (--sem->activity == 0 && !list_empty(&sem->wait_list))
sem = __rwsem_wake_one_writer(sem); sem = __rwsem_wake_one_writer(sem);
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
} }
/* /*
...@@ -295,13 +295,13 @@ void __up_write(struct rw_semaphore *sem) ...@@ -295,13 +295,13 @@ void __up_write(struct rw_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
sem->activity = 0; sem->activity = 0;
if (!list_empty(&sem->wait_list)) if (!list_empty(&sem->wait_list))
sem = __rwsem_do_wake(sem, 1); sem = __rwsem_do_wake(sem, 1);
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
} }
/* /*
...@@ -312,12 +312,12 @@ void __downgrade_write(struct rw_semaphore *sem) ...@@ -312,12 +312,12 @@ void __downgrade_write(struct rw_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
sem->activity = 1; sem->activity = 1;
if (!list_empty(&sem->wait_list)) if (!list_empty(&sem->wait_list))
sem = __rwsem_do_wake(sem, 0); sem = __rwsem_do_wake(sem, 0);
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
} }
...@@ -22,7 +22,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, ...@@ -22,7 +22,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
lockdep_init_map(&sem->dep_map, name, key, 0); lockdep_init_map(&sem->dep_map, name, key, 0);
#endif #endif
sem->count = RWSEM_UNLOCKED_VALUE; sem->count = RWSEM_UNLOCKED_VALUE;
spin_lock_init(&sem->wait_lock); raw_spin_lock_init(&sem->wait_lock);
INIT_LIST_HEAD(&sem->wait_list); INIT_LIST_HEAD(&sem->wait_list);
} }
...@@ -180,7 +180,7 @@ rwsem_down_failed_common(struct rw_semaphore *sem, ...@@ -180,7 +180,7 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
set_task_state(tsk, TASK_UNINTERRUPTIBLE); set_task_state(tsk, TASK_UNINTERRUPTIBLE);
/* set up my own style of waitqueue */ /* set up my own style of waitqueue */
spin_lock_irq(&sem->wait_lock); raw_spin_lock_irq(&sem->wait_lock);
waiter.task = tsk; waiter.task = tsk;
waiter.flags = flags; waiter.flags = flags;
get_task_struct(tsk); get_task_struct(tsk);
...@@ -204,7 +204,7 @@ rwsem_down_failed_common(struct rw_semaphore *sem, ...@@ -204,7 +204,7 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
adjustment == -RWSEM_ACTIVE_WRITE_BIAS) adjustment == -RWSEM_ACTIVE_WRITE_BIAS)
sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED); sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED);
spin_unlock_irq(&sem->wait_lock); raw_spin_unlock_irq(&sem->wait_lock);
/* wait to be given the lock */ /* wait to be given the lock */
for (;;) { for (;;) {
...@@ -245,13 +245,13 @@ struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem) ...@@ -245,13 +245,13 @@ struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
/* do nothing if list empty */ /* do nothing if list empty */
if (!list_empty(&sem->wait_list)) if (!list_empty(&sem->wait_list))
sem = __rwsem_do_wake(sem, RWSEM_WAKE_ANY); sem = __rwsem_do_wake(sem, RWSEM_WAKE_ANY);
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
return sem; return sem;
} }
...@@ -265,13 +265,13 @@ struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) ...@@ -265,13 +265,13 @@ struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sem->wait_lock, flags); raw_spin_lock_irqsave(&sem->wait_lock, flags);
/* do nothing if list empty */ /* do nothing if list empty */
if (!list_empty(&sem->wait_list)) if (!list_empty(&sem->wait_list))
sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED); sem = __rwsem_do_wake(sem, RWSEM_WAKE_READ_OWNED);
spin_unlock_irqrestore(&sem->wait_lock, flags); raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
return sem; return sem;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册