rqspinlock: Perform AA checks immediately

Currently, while we enter the check_timeout call immediately due to the
way the ts.spin is initialized, we still invoke the AA and ABBA checks
in the second invocation, and only initialize the timestamp in the first
one. Since each iteration is at least done with a 1ms delay, this can
add delays in detection of AA deadlocks, up to a ms.

Rework check_timeout() to avoid this. First, call check_deadlock_AA()
while initializing the timestamps for the wait period. This also means
that we only do it once per waiting period, instead of every invocation.
Finally, drop check_deadlock() and call check_deadlock_ABBA() directly.

To save on unnecessary ktime_get_mono_fast_ns() in case of AA deadlock,
sample the time only if it returns 0.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20251128232802.1031906-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Kumar Kartikeya Dwivedi 2025-11-28 23:27:58 +00:00 committed by Alexei Starovoitov
parent beb7021a60
commit 5860f5ce47
1 changed files with 7 additions and 18 deletions

View File

@ -196,32 +196,21 @@ static noinline int check_deadlock_ABBA(rqspinlock_t *lock, u32 mask)
return 0; return 0;
} }
static noinline int check_deadlock(rqspinlock_t *lock, u32 mask)
{
int ret;
ret = check_deadlock_AA(lock);
if (ret)
return ret;
ret = check_deadlock_ABBA(lock, mask);
if (ret)
return ret;
return 0;
}
static noinline int check_timeout(rqspinlock_t *lock, u32 mask, static noinline int check_timeout(rqspinlock_t *lock, u32 mask,
struct rqspinlock_timeout *ts) struct rqspinlock_timeout *ts)
{ {
u64 time = ktime_get_mono_fast_ns();
u64 prev = ts->cur; u64 prev = ts->cur;
u64 time;
if (!ts->timeout_end) { if (!ts->timeout_end) {
ts->cur = time; if (check_deadlock_AA(lock))
ts->timeout_end = time + ts->duration; return -EDEADLK;
ts->cur = ktime_get_mono_fast_ns();
ts->timeout_end = ts->cur + ts->duration;
return 0; return 0;
} }
time = ktime_get_mono_fast_ns();
if (time > ts->timeout_end) if (time > ts->timeout_end)
return -ETIMEDOUT; return -ETIMEDOUT;
@ -231,7 +220,7 @@ static noinline int check_timeout(rqspinlock_t *lock, u32 mask,
*/ */
if (prev + NSEC_PER_MSEC < time) { if (prev + NSEC_PER_MSEC < time) {
ts->cur = time; ts->cur = time;
return check_deadlock(lock, mask); return check_deadlock_ABBA(lock, mask);
} }
return 0; return 0;