Skip to content

Commit

Permalink
sched: Convert pi_lock to raw_spinlock
Browse files Browse the repository at this point in the history
Convert locks which cannot be sleeping locks in preempt-rt to
raw_spinlocks.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Thomas Gleixner committed Dec 14, 2009
1 parent fe84122 commit 1d61548
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion include/linux/init_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extern struct cred init_cred;
.journal_info = NULL, \
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
.fs_excl = ATOMIC_INIT(0), \
.pi_lock = __SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
.pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
.timer_slack_ns = 50000, /* 50 usec default slack */ \
.pids = { \
[PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
Expand Down
2 changes: 1 addition & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ struct task_struct {
#endif

/* Protection of the PI data structures: */
spinlock_t pi_lock;
raw_spinlock_t pi_lock;

#ifdef CONFIG_RT_MUTEXES
/* PI waiters blocked on a rt_mutex held by this task */
Expand Down
2 changes: 1 addition & 1 deletion kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ NORET_TYPE void do_exit(long code)
* an exiting task cleaning up the robust pi futexes.
*/
smp_mb();
spin_unlock_wait(&tsk->pi_lock);
raw_spin_unlock_wait(&tsk->pi_lock);

if (unlikely(in_atomic()))
printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n",
Expand Down
4 changes: 2 additions & 2 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,9 @@ SYSCALL_DEFINE1(set_tid_address, int __user *, tidptr)

static void rt_mutex_init_task(struct task_struct *p)
{
spin_lock_init(&p->pi_lock);
raw_spin_lock_init(&p->pi_lock);
#ifdef CONFIG_RT_MUTEXES
plist_head_init(&p->pi_waiters, &p->pi_lock);
plist_head_init_raw(&p->pi_waiters, &p->pi_lock);
p->pi_blocked_on = NULL;
#endif
}
Expand Down
38 changes: 19 additions & 19 deletions kernel/futex.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ static void free_pi_state(struct futex_pi_state *pi_state)
* and has cleaned up the pi_state already
*/
if (pi_state->owner) {
spin_lock_irq(&pi_state->owner->pi_lock);
raw_spin_lock_irq(&pi_state->owner->pi_lock);
list_del_init(&pi_state->list);
spin_unlock_irq(&pi_state->owner->pi_lock);
raw_spin_unlock_irq(&pi_state->owner->pi_lock);

rt_mutex_proxy_unlock(&pi_state->pi_mutex, pi_state->owner);
}
Expand Down Expand Up @@ -470,18 +470,18 @@ void exit_pi_state_list(struct task_struct *curr)
* pi_state_list anymore, but we have to be careful
* versus waiters unqueueing themselves:
*/
spin_lock_irq(&curr->pi_lock);
raw_spin_lock_irq(&curr->pi_lock);
while (!list_empty(head)) {

next = head->next;
pi_state = list_entry(next, struct futex_pi_state, list);
key = pi_state->key;
hb = hash_futex(&key);
spin_unlock_irq(&curr->pi_lock);
raw_spin_unlock_irq(&curr->pi_lock);

spin_lock(&hb->lock);

spin_lock_irq(&curr->pi_lock);
raw_spin_lock_irq(&curr->pi_lock);
/*
* We dropped the pi-lock, so re-check whether this
* task still owns the PI-state:
Expand All @@ -495,15 +495,15 @@ void exit_pi_state_list(struct task_struct *curr)
WARN_ON(list_empty(&pi_state->list));
list_del_init(&pi_state->list);
pi_state->owner = NULL;
spin_unlock_irq(&curr->pi_lock);
raw_spin_unlock_irq(&curr->pi_lock);

rt_mutex_unlock(&pi_state->pi_mutex);

spin_unlock(&hb->lock);

spin_lock_irq(&curr->pi_lock);
raw_spin_lock_irq(&curr->pi_lock);
}
spin_unlock_irq(&curr->pi_lock);
raw_spin_unlock_irq(&curr->pi_lock);
}

static int
Expand Down Expand Up @@ -558,7 +558,7 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
* change of the task flags, we do this protected by
* p->pi_lock:
*/
spin_lock_irq(&p->pi_lock);
raw_spin_lock_irq(&p->pi_lock);
if (unlikely(p->flags & PF_EXITING)) {
/*
* The task is on the way out. When PF_EXITPIDONE is
Expand All @@ -567,7 +567,7 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
*/
int ret = (p->flags & PF_EXITPIDONE) ? -ESRCH : -EAGAIN;

spin_unlock_irq(&p->pi_lock);
raw_spin_unlock_irq(&p->pi_lock);
put_task_struct(p);
return ret;
}
Expand All @@ -586,7 +586,7 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
WARN_ON(!list_empty(&pi_state->list));
list_add(&pi_state->list, &p->pi_state_list);
pi_state->owner = p;
spin_unlock_irq(&p->pi_lock);
raw_spin_unlock_irq(&p->pi_lock);

put_task_struct(p);

Expand Down Expand Up @@ -794,16 +794,16 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this)
}
}

spin_lock_irq(&pi_state->owner->pi_lock);
raw_spin_lock_irq(&pi_state->owner->pi_lock);
WARN_ON(list_empty(&pi_state->list));
list_del_init(&pi_state->list);
spin_unlock_irq(&pi_state->owner->pi_lock);
raw_spin_unlock_irq(&pi_state->owner->pi_lock);

spin_lock_irq(&new_owner->pi_lock);
raw_spin_lock_irq(&new_owner->pi_lock);
WARN_ON(!list_empty(&pi_state->list));
list_add(&pi_state->list, &new_owner->pi_state_list);
pi_state->owner = new_owner;
spin_unlock_irq(&new_owner->pi_lock);
raw_spin_unlock_irq(&new_owner->pi_lock);

spin_unlock(&pi_state->pi_mutex.wait_lock);
rt_mutex_unlock(&pi_state->pi_mutex);
Expand Down Expand Up @@ -1529,18 +1529,18 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
* itself.
*/
if (pi_state->owner != NULL) {
spin_lock_irq(&pi_state->owner->pi_lock);
raw_spin_lock_irq(&pi_state->owner->pi_lock);
WARN_ON(list_empty(&pi_state->list));
list_del_init(&pi_state->list);
spin_unlock_irq(&pi_state->owner->pi_lock);
raw_spin_unlock_irq(&pi_state->owner->pi_lock);
}

pi_state->owner = newowner;

spin_lock_irq(&newowner->pi_lock);
raw_spin_lock_irq(&newowner->pi_lock);
WARN_ON(!list_empty(&pi_state->list));
list_add(&pi_state->list, &newowner->pi_state_list);
spin_unlock_irq(&newowner->pi_lock);
raw_spin_unlock_irq(&newowner->pi_lock);
return 0;

/*
Expand Down
4 changes: 2 additions & 2 deletions kernel/rtmutex-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ do { \
if (rt_trace_on) { \
rt_trace_on = 0; \
console_verbose(); \
if (spin_is_locked(&current->pi_lock)) \
spin_unlock(&current->pi_lock); \
if (raw_spin_is_locked(&current->pi_lock)) \
raw_spin_unlock(&current->pi_lock); \
} \
} while (0)

Expand Down
58 changes: 29 additions & 29 deletions kernel/rtmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ static void rt_mutex_adjust_prio(struct task_struct *task)
{
unsigned long flags;

spin_lock_irqsave(&task->pi_lock, flags);
raw_spin_lock_irqsave(&task->pi_lock, flags);
__rt_mutex_adjust_prio(task);
spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
}

/*
Expand Down Expand Up @@ -195,7 +195,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
/*
* Task can not go away as we did a get_task() before !
*/
spin_lock_irqsave(&task->pi_lock, flags);
raw_spin_lock_irqsave(&task->pi_lock, flags);

waiter = task->pi_blocked_on;
/*
Expand Down Expand Up @@ -232,7 +232,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,

lock = waiter->lock;
if (!spin_trylock(&lock->wait_lock)) {
spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
cpu_relax();
goto retry;
}
Expand All @@ -253,13 +253,13 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
plist_add(&waiter->list_entry, &lock->wait_list);

/* Release the task */
spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
put_task_struct(task);

/* Grab the next task */
task = rt_mutex_owner(lock);
get_task_struct(task);
spin_lock_irqsave(&task->pi_lock, flags);
raw_spin_lock_irqsave(&task->pi_lock, flags);

if (waiter == rt_mutex_top_waiter(lock)) {
/* Boost the owner */
Expand All @@ -277,7 +277,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
__rt_mutex_adjust_prio(task);
}

spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);

top_waiter = rt_mutex_top_waiter(lock);
spin_unlock(&lock->wait_lock);
Expand All @@ -288,7 +288,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
goto again;

out_unlock_pi:
spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
out_put_task:
put_task_struct(task);

Expand All @@ -313,9 +313,9 @@ static inline int try_to_steal_lock(struct rt_mutex *lock,
if (pendowner == task)
return 1;

spin_lock_irqsave(&pendowner->pi_lock, flags);
raw_spin_lock_irqsave(&pendowner->pi_lock, flags);
if (task->prio >= pendowner->prio) {
spin_unlock_irqrestore(&pendowner->pi_lock, flags);
raw_spin_unlock_irqrestore(&pendowner->pi_lock, flags);
return 0;
}

Expand All @@ -325,15 +325,15 @@ static inline int try_to_steal_lock(struct rt_mutex *lock,
* priority.
*/
if (likely(!rt_mutex_has_waiters(lock))) {
spin_unlock_irqrestore(&pendowner->pi_lock, flags);
raw_spin_unlock_irqrestore(&pendowner->pi_lock, flags);
return 1;
}

/* No chain handling, pending owner is not blocked on anything: */
next = rt_mutex_top_waiter(lock);
plist_del(&next->pi_list_entry, &pendowner->pi_waiters);
__rt_mutex_adjust_prio(pendowner);
spin_unlock_irqrestore(&pendowner->pi_lock, flags);
raw_spin_unlock_irqrestore(&pendowner->pi_lock, flags);

/*
* We are going to steal the lock and a waiter was
Expand All @@ -350,10 +350,10 @@ static inline int try_to_steal_lock(struct rt_mutex *lock,
* might be task:
*/
if (likely(next->task != task)) {
spin_lock_irqsave(&task->pi_lock, flags);
raw_spin_lock_irqsave(&task->pi_lock, flags);
plist_add(&next->pi_list_entry, &task->pi_waiters);
__rt_mutex_adjust_prio(task);
spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
}
return 1;
}
Expand Down Expand Up @@ -420,7 +420,7 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
unsigned long flags;
int chain_walk = 0, res;

spin_lock_irqsave(&task->pi_lock, flags);
raw_spin_lock_irqsave(&task->pi_lock, flags);
__rt_mutex_adjust_prio(task);
waiter->task = task;
waiter->lock = lock;
Expand All @@ -434,17 +434,17 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,

task->pi_blocked_on = waiter;

spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);

if (waiter == rt_mutex_top_waiter(lock)) {
spin_lock_irqsave(&owner->pi_lock, flags);
raw_spin_lock_irqsave(&owner->pi_lock, flags);
plist_del(&top_waiter->pi_list_entry, &owner->pi_waiters);
plist_add(&waiter->pi_list_entry, &owner->pi_waiters);

__rt_mutex_adjust_prio(owner);
if (owner->pi_blocked_on)
chain_walk = 1;
spin_unlock_irqrestore(&owner->pi_lock, flags);
raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
}
else if (debug_rt_mutex_detect_deadlock(waiter, detect_deadlock))
chain_walk = 1;
Expand Down Expand Up @@ -483,7 +483,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
struct task_struct *pendowner;
unsigned long flags;

spin_lock_irqsave(&current->pi_lock, flags);
raw_spin_lock_irqsave(&current->pi_lock, flags);

waiter = rt_mutex_top_waiter(lock);
plist_del(&waiter->list_entry, &lock->wait_list);
Expand All @@ -500,7 +500,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)

rt_mutex_set_owner(lock, pendowner, RT_MUTEX_OWNER_PENDING);

spin_unlock_irqrestore(&current->pi_lock, flags);
raw_spin_unlock_irqrestore(&current->pi_lock, flags);

/*
* Clear the pi_blocked_on variable and enqueue a possible
Expand All @@ -509,7 +509,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
* waiter with higher priority than pending-owner->normal_prio
* is blocked on the unboosted (pending) owner.
*/
spin_lock_irqsave(&pendowner->pi_lock, flags);
raw_spin_lock_irqsave(&pendowner->pi_lock, flags);

WARN_ON(!pendowner->pi_blocked_on);
WARN_ON(pendowner->pi_blocked_on != waiter);
Expand All @@ -523,7 +523,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
next = rt_mutex_top_waiter(lock);
plist_add(&next->pi_list_entry, &pendowner->pi_waiters);
}
spin_unlock_irqrestore(&pendowner->pi_lock, flags);
raw_spin_unlock_irqrestore(&pendowner->pi_lock, flags);

wake_up_process(pendowner);
}
Expand All @@ -541,15 +541,15 @@ static void remove_waiter(struct rt_mutex *lock,
unsigned long flags;
int chain_walk = 0;

spin_lock_irqsave(&current->pi_lock, flags);
raw_spin_lock_irqsave(&current->pi_lock, flags);
plist_del(&waiter->list_entry, &lock->wait_list);
waiter->task = NULL;
current->pi_blocked_on = NULL;
spin_unlock_irqrestore(&current->pi_lock, flags);
raw_spin_unlock_irqrestore(&current->pi_lock, flags);

if (first && owner != current) {

spin_lock_irqsave(&owner->pi_lock, flags);
raw_spin_lock_irqsave(&owner->pi_lock, flags);

plist_del(&waiter->pi_list_entry, &owner->pi_waiters);

Expand All @@ -564,7 +564,7 @@ static void remove_waiter(struct rt_mutex *lock,
if (owner->pi_blocked_on)
chain_walk = 1;

spin_unlock_irqrestore(&owner->pi_lock, flags);
raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
}

WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
Expand Down Expand Up @@ -592,15 +592,15 @@ void rt_mutex_adjust_pi(struct task_struct *task)
struct rt_mutex_waiter *waiter;
unsigned long flags;

spin_lock_irqsave(&task->pi_lock, flags);
raw_spin_lock_irqsave(&task->pi_lock, flags);

waiter = task->pi_blocked_on;
if (!waiter || waiter->list_entry.prio == task->prio) {
spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
return;
}

spin_unlock_irqrestore(&task->pi_lock, flags);
raw_spin_unlock_irqrestore(&task->pi_lock, flags);

/* gets dropped in rt_mutex_adjust_prio_chain()! */
get_task_struct(task);
Expand Down
Loading

0 comments on commit 1d61548

Please sign in to comment.