History

futex: Rework futex_lock_pi() to use rt_mutex_*_proxy_lock()

By changing futex_lock_pi() to use rt_mutex_*_proxy_lock() all wait_list modifications are done under both hb->lock and wait_lock. This closes the obvious interleave pattern between futex_lock_pi() and futex_unlock_pi(), but not entirely so. See below: Before: futex_lock_pi() futex_unlock_pi() unlock hb->lock lock hb->lock unlock hb->lock lock rt_mutex->wait_lock unlock rt_mutex_wait_lock -EAGAIN lock rt_mutex->wait_lock list_add unlock rt_mutex->wait_lock schedule() lock rt_mutex->wait_lock list_del unlock rt_mutex->wait_lock <idem> -EAGAIN lock hb->lock After: futex_lock_pi() futex_unlock_pi() lock hb->lock lock rt_mutex->wait_lock list_add unlock rt_mutex->wait_lock unlock hb->lock schedule() lock hb->lock unlock hb->lock lock hb->lock lock rt_mutex->wait_lock list_del unlock rt_mutex->wait_lock lock rt_mutex->wait_lock unlock rt_mutex_wait_lock -EAGAIN unlock hb->lock It does however solve the earlier starvation/live-lock scenario which got introduced with the -EAGAIN since unlike the before scenario; where the -EAGAIN happens while futex_unlock_pi() doesn't hold any locks; in the after scenario it happens while futex_unlock_pi() actually holds a lock, and then it is serialized on that lock.

Peter Zijlstra committed 9 years ago

Commit cfafcd11 parent 38d589f3 files · +62 −42Browse files

Showing the changes to kernel/locking (2 of 3 files). Show all

Unified · Split

2 files
  1. kernel/locking/rtmutex.c +7 −19
  2. kernel/locking/rtmutex_common.h +0 −1
kernel/locking/rtmutex.c+7−19
@@ -1492,19 +1492,6 @@ int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock) · 1491 unmodified lines
1492}1492}
1493EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);1493EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
1494 1494
1495/*
1496 * Futex variant with full deadlock detection.
1497 * Futex variants must not use the fast-path, see __rt_mutex_futex_unlock().
1498 */
1499int __sched rt_mutex_timed_futex_lock(struct rt_mutex *lock,
1500 struct hrtimer_sleeper *timeout)
1501{
1502 might_sleep();
1503
1504 return rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE,
1505 timeout, RT_MUTEX_FULL_CHAINWALK);
1506}
1507
1508/*1495/*
1509 * Futex variant, must not use fastpath.1496 * Futex variant, must not use fastpath.
1510 */1497 */
@@ -1782,12 +1769,6 @@ int rt_mutex_wait_proxy_lock(struct rt_mutex *lock, · 271 unmodified lines
1782 /* sleep on the mutex */1769 /* sleep on the mutex */
1783 ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);1770 ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
1784 1771
1785 /*
1786 * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
1787 * have to fix that up.
1788 */
1789 fixup_rt_mutex_waiters(lock);
1790
1791 raw_spin_unlock_irq(&lock->wait_lock);1772 raw_spin_unlock_irq(&lock->wait_lock);
1792 1773
1793 return ret;1774 return ret;
@@ -1827,6 +1808,13 @@ bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock, · 33 unmodified lines
1827 fixup_rt_mutex_waiters(lock);1808 fixup_rt_mutex_waiters(lock);
1828 cleanup = true;1809 cleanup = true;
1829 }1810 }
1811
1812 /*
1813 * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
1814 * have to fix that up.
1815 */
1816 fixup_rt_mutex_waiters(lock);
1817
1830 raw_spin_unlock_irq(&lock->wait_lock);1818 raw_spin_unlock_irq(&lock->wait_lock);
1831 1819
1832 return cleanup;1820 return cleanup;
kernel/locking/rtmutex_common.h+0−1
@@ -113,7 +113,6 @@ extern int rt_mutex_wait_proxy_lock(struct rt_mutex *lock, · 112 unmodified lines
113extern bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,113extern bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
114 struct rt_mutex_waiter *waiter);114 struct rt_mutex_waiter *waiter);
115 115
116extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
117extern int rt_mutex_futex_trylock(struct rt_mutex *l);116extern int rt_mutex_futex_trylock(struct rt_mutex *l);
118 117
119extern void rt_mutex_futex_unlock(struct rt_mutex *lock);118extern void rt_mutex_futex_unlock(struct rt_mutex *lock);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t