[RFC PATCH-tip v4 04/10] locking/rwsem: Enable count-based spinning on reader

2016-08-18 Thread Waiman Long
When the rwsem is owned by reader, writers stop optimistic spinning simply because there is no easy way to figure out if all the readers are actively running or not. However, there are scenarios where the readers are unlikely to sleep and optimistic spinning can help performance. This patch

[RFC PATCH-tip v4 05/10] locking/rwsem: move down rwsem_down_read_failed function

2016-08-18 Thread Waiman Long
Move the rwsem_down_read_failed() function down to below the optimistic spinning section before enabling optimistic spinning for the readers. It is because the rwsem_down_read_failed() function will call rwsem_optimistic_spin() in later patch. There is no change in code. Signed-off-by: Waiman

[RFC PATCH-tip v4 03/10] locking/rwsem: Make rwsem_spin_on_owner() return a tri-state value

2016-08-18 Thread Waiman Long
This patch modifies rwsem_spin_on_owner() to return a tri-state value to better reflect the state of lock holder which enables us to make a better decision of what to do next. Signed-off-by: Waiman Long --- kernel/locking/rwsem-xadd.c | 14 +- 1 files changed,

Re: [RFC PATCH-tip v4 07/10] locking/rwsem: Change RWSEM_WAITING_BIAS for better disambiguation

2016-08-18 Thread Wanpeng Li
2016-08-19 5:11 GMT+08:00 Waiman Long : > When the count value is in between 0 and RWSEM_WAITING_BIAS, there > are 2 possibilities. > Either a writer is present and there is no waiter count = 0x0001 >or there are waiters and readers. There is no easy way to count =

[RFC PATCH-tip v4 01/10] locking/osq: Make lock/unlock proper acquire/release barrier

2016-08-18 Thread Waiman Long
The osq_lock() and osq_unlock() function may not provide the necessary acquire and release barrier in some cases. This patch makes sure that the proper barriers are provided when osq_lock() is successful or when osq_unlock() is called. Suggested-by: Peter Zijlstra (Intel)

[RFC PATCH-tip v4 02/10] locking/rwsem: Stop active read lock ASAP

2016-08-18 Thread Waiman Long
Currently, when down_read() fails, the active read locking isn't undone until the rwsem_down_read_failed() function grabs the wait_lock. If the wait_lock is contended, it may takes a while to get the lock. During that period, writer lock stealing will be disabled because of the active read lock.

[RFC PATCH-tip v4 00/10] locking/rwsem: Enable reader optimistic spinning

2016-08-18 Thread Waiman Long
v3->v4: - Rebased to the latest tip tree due to changes to rwsem-xadd.c. - Update the OSQ patch to fix race condition. v2->v3: - Used smp_acquire__after_ctrl_dep() to provide acquire barrier. - Added the following new patches: 1) make rwsem_spin_on_owner() return a tristate value. 2)

[RFC PATCH-tip v4 07/10] locking/rwsem: Change RWSEM_WAITING_BIAS for better disambiguation

2016-08-18 Thread Waiman Long
When the count value is in between 0 and RWSEM_WAITING_BIAS, there are 2 possibilities. Either a writer is present and there is no waiter or there are waiters and readers. There is no easy way to know which is true unless the wait_lock is taken. This patch changes the RWSEM_WAITING_BIAS from

[RFC PATCH-tip v4 09/10] locking/rwsem: Enable reactivation of reader spinning

2016-08-18 Thread Waiman Long
Reader optimistic spinning will be disabled once the rspin_enabled count reaches 0. After that, it cannot be re-enabled. This may cause an eligible rwsem locked out of reader spinning because of a series of unfortunate events. This patch looks at the regular writer-on-writer spinning history. If

[RFC PATCH-tip v4 06/10] locking/rwsem: Move common rwsem macros to asm-generic/rwsem_types.h

2016-08-18 Thread Waiman Long
Almost all the macro definitions in the various architecture specific rwsem.h header files are essentially the same. This patch moves all of them into a common header asm-generic/rwsem_types.h to eliminate the duplication. Suggested-by: Peter Zijlstra (Intel) Signed-off-by: