IMPORT: lorw: support inlining the wait call

Now when PLOCK_LORW_INLINE_WAIT is defined, the pl_wait_unlock_long()
calls in pl_lorw_rdlock() and pl_lorw_wrlock() will be inlined so that
all the CPU time is accounted for in the calling function.

This is plock upstream commit c993f81d581732a6eb8fe3033f21970420d21e5e.
This commit is contained in:
Willy Tarreau 2023-08-16 22:40:05 +02:00
parent 66dcc0550e
commit e56275378f
1 changed files with 20 additions and 0 deletions

View File

@ -1318,14 +1318,22 @@ static inline void pl_lorw_rdlock(unsigned long *lock)
* lock to be empty of visitors.
*/
if (lk & PLOCK_LORW_WRQ_MASK)
#if defined(PLOCK_LORW_INLINE_WAIT)
lk = __pl_wait_unlock_long(lock, PLOCK_LORW_WRQ_MASK);
#else
lk = pl_wait_unlock_long(lock, PLOCK_LORW_WRQ_MASK);
#endif
/* count us as visitor among others */
lk = pl_ldadd_acq(lock, PLOCK_LORW_SHR_BASE);
/* wait for end of exclusive access if any */
if (lk & PLOCK_LORW_EXC_MASK)
#if defined(PLOCK_LORW_INLINE_WAIT)
lk = __pl_wait_unlock_long(lock, PLOCK_LORW_EXC_MASK);
#else
lk = pl_wait_unlock_long(lock, PLOCK_LORW_EXC_MASK);
#endif
}
@ -1341,7 +1349,11 @@ static inline void pl_lorw_wrlock(unsigned long *lock)
*/
lk = pl_deref_long(lock);
if (__builtin_expect(lk & PLOCK_LORW_WRQ_MASK, 1))
#if defined(PLOCK_LORW_INLINE_WAIT)
lk = __pl_wait_unlock_long(lock, PLOCK_LORW_WRQ_MASK);
#else
lk = pl_wait_unlock_long(lock, PLOCK_LORW_WRQ_MASK);
#endif
do {
/* let's check for the two sources of contention at once */
@ -1354,12 +1366,20 @@ static inline void pl_lorw_wrlock(unsigned long *lock)
/* note below, an OR is significantly cheaper than BTS or XADD */
if (!(lk & PLOCK_LORW_WRQ_MASK))
pl_or_noret(lock, PLOCK_LORW_WRQ_BASE);
#if defined(PLOCK_LORW_INLINE_WAIT)
lk = __pl_wait_unlock_long(lock, PLOCK_LORW_SHR_MASK);
#else
lk = pl_wait_unlock_long(lock, PLOCK_LORW_SHR_MASK);
#endif
}
/* And also wait for a previous writer to finish. */
if (lk & PLOCK_LORW_EXC_MASK)
#if defined(PLOCK_LORW_INLINE_WAIT)
lk = __pl_wait_unlock_long(lock, PLOCK_LORW_EXC_MASK);
#else
lk = pl_wait_unlock_long(lock, PLOCK_LORW_EXC_MASK);
#endif
}
/* A fresh new reader may appear right now if there were none