Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH] s390/rwlock: Add contention tracepoints to rwlock slowpath
@ 2026-09-08 11:26 Jan Polensky
  2026-09-08 11:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Polensky @ 2026-09-08 11:26 UTC (permalink / raw)
  To: hca, gor, agordeev; +Cc: borntraeger, svens, ciunas, linux-s390, linux-kernel

Instrument arch_read_lock_wait() and arch_write_lock_wait() with
trace_contention_begin() and trace_contention_end().

These tracepoints are used by lock contention analysis tools such as
perf lock contention to identify contended rwlocks and measure wait
times. The generic implementation in kernel/locking/qrwlock.c already
emits the same events from its read and write slowpaths.

For arch_read_lock_wait(), the in_interrupt() fast-path is intentionally
left outside the tracepoint scope. That path spins without entering the
wait queue, so it does not represent queue-based contention and its
duration is not comparable to the normal slowpath. This matches the
behaviour of queued_read_lock_slowpath() in qrwlock.c.

The include for <trace/events/lock.h> is already present from
commit ffa796cc1f45 ("s390/spinlock: Add contention tracepoints to
lock slowpath").

Signed-off-by: Jan Polensky <japo@linux.ibm.com>
---
 arch/s390/lib/spinlock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c
index dbabca35c008..9094617a5e00 100644
--- a/arch/s390/lib/spinlock.c
+++ b/arch/s390/lib/spinlock.c
@@ -316,6 +316,7 @@ void arch_read_lock_wait(arch_rwlock_t *rw)
 		return;
 	}
 
+	trace_contention_begin(rw, LCB_F_SPIN | LCB_F_READ);
 	/* Remove this reader again to allow recursive read locking */
 	__atomic_add_const(-1, &rw->cnts);
 	/* Put the reader into the wait queue */
@@ -326,6 +327,7 @@ void arch_read_lock_wait(arch_rwlock_t *rw)
 	while (READ_ONCE(rw->cnts) & 0x10000)
 		barrier();
 	arch_spin_unlock(&rw->wait);
+	trace_contention_end(rw, 0);
 }
 EXPORT_SYMBOL(arch_read_lock_wait);
 
@@ -333,6 +335,7 @@ void arch_write_lock_wait(arch_rwlock_t *rw)
 {
 	int old;
 
+	trace_contention_begin(rw, LCB_F_SPIN | LCB_F_WRITE);
 	/* Add this CPU to the write waiters */
 	__atomic_add(0x20000, &rw->cnts);
 
@@ -349,6 +352,7 @@ void arch_write_lock_wait(arch_rwlock_t *rw)
 	}
 
 	arch_spin_unlock(&rw->wait);
+	trace_contention_end(rw, 0);
 }
 EXPORT_SYMBOL(arch_write_lock_wait);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] s390/rwlock: Add contention tracepoints to rwlock slowpath
  2026-09-08 11:26 [PATCH] s390/rwlock: Add contention tracepoints to rwlock slowpath Jan Polensky
@ 2026-09-08 11:36 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-08 11:36 UTC (permalink / raw)
  To: Jan Polensky
  Cc: Christian Borntraeger, Heiko Carstens, linux-s390, Vasily Gorbik,
	Alexander Gordeev

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Calling trace_contention_begin() before decrementing the tentative reader count exacerbates lock contention by blocking writers and risks deadlocks on recursive tracing.
--

commit 9f56bec8e5a4a2cdb518e49ae0095e4ddfeee5e0
Author: Jan Polensky <japo@linux.ibm.com>

s390/rwlock: Add contention tracepoints to rwlock slowpath

This commit instruments arch_read_lock_wait() and arch_write_lock_wait()
with lock contention tracepoints on s390. This aims to support lock
contention analysis tools like perf by identifying contended rwlocks and
measuring wait times.

> diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c
> index dbabca35c008c..9094617a5e00b 100644
> --- a/arch/s390/lib/spinlock.c
> +++ b/arch/s390/lib/spinlock.c
> @@ -316,6 +316,7 @@ void arch_read_lock_wait(arch_rwlock_t *rw)
>  		return;
>  	}
>  
> +	trace_contention_begin(rw, LCB_F_SPIN | LCB_F_READ);
>  	/* Remove this reader again to allow recursive read locking */
>  	__atomic_add_const(-1, &rw->cnts);

[Severity: High]
Does placing trace_contention_begin() before decrementing the tentative
reader count risk a deadlock?

If a reader enters arch_read_lock_wait() while a writer is waiting, the
reader has already incremented the lock's read count. If a trace probe
attached to trace_contention_begin() recursively acquires the same read
lock, it will enter arch_read_lock_wait(), decrement its own count, and
block on arch_spin_lock(&rw->wait).

Simultaneously, the waiting writer holds the rw->wait spinlock and spins
forever waiting for the outer reader's count to drop to zero. The inner
reader spins forever waiting for the writer to release rw->wait, forming
an ABBA deadlock.

Even without recursive tracing, does holding the elevated reader count
during the tracepoint unnecessarily delay waiting writers? The generic
queued_read_lock_slowpath() appears to decrement the count before
executing the tracepoint to avoid this issue.

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908112607.828469-1-japo@linux.ibm.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-08 11:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08 11:26 [PATCH] s390/rwlock: Add contention tracepoints to rwlock slowpath Jan Polensky
2026-09-08 11:36 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox