diff options
author | Ben Gardon <[email protected]> | 2021-02-02 10:57:13 -0800 |
---|---|---|
committer | Paolo Bonzini <[email protected]> | 2021-02-04 05:27:43 -0500 |
commit | a09a689a534183c48f200bc2de1ae61ae9c462ad (patch) | |
tree | 6d22a4c3a93f604b29d200434191480124e166f8 | |
parent | 26128cb6c7e6731fe644c687af97733adfdb5ee9 (diff) |
sched: Add needbreak for rwlocks
Contention awareness while holding a spin lock is essential for reducing
latency when long running kernel operations can hold that lock. Add the
same contention detection interface for read/write spin locks.
CC: Ingo Molnar <[email protected]>
CC: Will Deacon <[email protected]>
Acked-by: Peter Zijlstra <[email protected]>
Acked-by: Davidlohr Bueso <[email protected]>
Acked-by: Waiman Long <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
Signed-off-by: Ben Gardon <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
-rw-r--r-- | include/linux/sched.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 6e3a5eeec509..5d1378e5a040 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1912,6 +1912,23 @@ static inline int spin_needbreak(spinlock_t *lock) #endif } +/* + * Check if a rwlock is contended. + * Returns non-zero if there is another task waiting on the rwlock. + * Returns zero if the lock is not contended or the system / underlying + * rwlock implementation does not support contention detection. + * Technically does not depend on CONFIG_PREEMPTION, but a general need + * for low latency. + */ +static inline int rwlock_needbreak(rwlock_t *lock) +{ +#ifdef CONFIG_PREEMPTION + return rwlock_is_contended(lock); +#else + return 0; +#endif +} + static __always_inline bool need_resched(void) { return unlikely(tif_need_resched()); |