From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F5743FA5F9 for ; Thu, 26 Mar 2026 15:17:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774538262; cv=none; b=FZzcBVwqcT5ZHsuUmvCRyOHVRVYMt+Ubu3ymDk6ZOHIFdr0Fd0RJsqwe3AReVtOIXRs/GF6mD8qj0mMm/wvTKn8Mw/OOiKFQ5JDuDbODIQVYKyS62JyEtwl482QK2hhnrJBhmvEX3YOh37rlW5/XdScDIDVXDE9ShDWLx71HE0g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774538262; c=relaxed/simple; bh=Iyn9fq7Fg10vd4OfRf4E9TEBoU9ShDzaNgTf/vWWRSw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rc6pCILQ4lFH+CJtNRi3LPz/wPX3mYfdsaTsT6qWw2i4GRlDRC0RJey9tQ18YgEQozFRaRWJvYxdBdCxsM12YWJQav/Fy50naM0SmHcGNrRBWHsRzjrong6W3YP8NAgGpE/xkWz+dByWvzaC2ZlwJ7bJRL24QrdceCyJwebDZlo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=foxB+9tf; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="foxB+9tf" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 3CE29BDE0C; Thu, 26 Mar 2026 15:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1774537819; bh=M1+Dtm74mh1nMGihjL6ZTbw1kVNoWgQVSWL33VEGTMg=; h=From:To:Cc:Subject:Date; b=foxB+9tflNYRsMsAY4hojtZCw/YTQr+FELes3WoVGZTqYTw4RLvxG6kVkDfPhx1Es WfZSO0LF7OxaHQKKEsEqP2ELT19d7KZXMxVcw9n1dzDXFfT8Ja254y5nkHoj8mBT01 8W0qKSjrh3q1FwHjrVma7oHJAxOp21dXQUbuZX7U= From: Dmitry Ilvokhin To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Thomas Bogendoerfer , Juergen Gross , Ajay Kaher , Alexey Makhalov , Broadcom internal kernel review list , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann , Dennis Zhou , Tejun Heo , Christoph Lameter , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers Cc: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, virtualization@lists.linux.dev, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, kernel-team@meta.com, Dmitry Ilvokhin Subject: [PATCH v4 0/5] locking: contended_release tracepoint instrumentation Date: Thu, 26 Mar 2026 15:09:59 +0000 Message-ID: X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The existing contention_begin/contention_end tracepoints fire on the waiter side. The lock holder's identity and stack can be captured at contention_begin time (e.g. perf lock contention --lock-owner), but this reflects the holder's state when a waiter arrives, not when the lock is actually released. This series adds a contended_release tracepoint that fires on the holder side when a lock with waiters is released. This provides: - Hold time estimation: when the holder's own acquisition was contended, its contention_end (acquisition) and contended_release can be correlated to measure how long the lock was held under contention. - The holder's stack at release time, which may differ from what perf lock contention --lock-owner captures if the holder does significant work between the waiter's arrival and the unlock. Note: for reader/writer locks, the tracepoint fires for every reader releasing while a writer is waiting, not only for the last reader. v3 -> v4: - Fix spurious events in __percpu_up_read(): guard with rcuwait_active(&sem->writer) to avoid tracing during the RCU grace period after a writer releases (Sashiko). - Fix possible use-after-free in semaphore up(): move trace_contended_release() inside the sem->lock critical section (Sashiko). - Fix build failure with CONFIG_PARAVIRT_SPINLOCKS=y: introduce queued_spin_release() as the arch-overridable unlock primitive, so queued_spin_unlock() can be a generic tracing wrapper. Convert x86 (paravirt) and MIPS overrides (Sashiko). - Add EXPORT_TRACEPOINT_SYMBOL_GPL(contended_release) for module support (Sashiko). - Split spinning locks patch: factor out queued_spin_release() as a separate preparatory commit (Sashiko). - Make read unlock tracepoint behavior consistent across all reader/writer lock types: fire for every reader releasing while a writer is waiting (rwsem, rwbase_rt were previously last-reader only). v2 -> v3: - Added new patch: extend contended_release tracepoint to queued spinlocks and queued rwlocks (marked as RFC, requesting feedback). This is prompted by Matthew Wilcox's suggestion to try to come up with generic instrumentation, instead of instrumenting each "special" lock manually. See [1] for the discussion. - Reworked tracepoint placement to fire before the lock is released and before the waiter is woken where possible, for consistency with spinning locks where there is no explicit wake (inspired by Usama Arif's suggestion). - Remove unnecessary linux/sched.h include from trace/events/lock.h. RFC -> v2: - Add trace_contended_release_enabled() guard before waiter checks that exist only for the tracepoint (Steven Rostedt). - Rename __percpu_up_read_slowpath() to __percpu_up_read() (Peter Zijlstra). - Add extern for __percpu_up_read() (Peter Zijlstra). - Squashed tracepoint introduction and usage commits (Masami Hiramatsu). v3: https://lore.kernel.org/all/cover.1773858853.git.d@ilvokhin.com/ v2: https://lore.kernel.org/all/cover.1773164180.git.d@ilvokhin.com/ RFC: https://lore.kernel.org/all/cover.1772642407.git.d@ilvokhin.com/ [1]: https://lore.kernel.org/all/aa7G1nD7Rd9F4eBH@casper.infradead.org/ Dmitry Ilvokhin (5): tracing/lock: Remove unnecessary linux/sched.h include locking/percpu-rwsem: Extract __percpu_up_read() locking: Add contended_release tracepoint to sleepable locks locking: Factor out queued_spin_release() locking: Add contended_release tracepoint to spinning locks arch/mips/include/asm/spinlock.h | 6 +-- arch/x86/include/asm/paravirt-spinlock.h | 6 +-- include/asm-generic/qrwlock.h | 48 ++++++++++++++++++++---- include/asm-generic/qspinlock.h | 33 ++++++++++++++-- include/linux/percpu-rwsem.h | 15 ++------ include/trace/events/lock.h | 18 ++++++++- kernel/locking/mutex.c | 4 ++ kernel/locking/percpu-rwsem.c | 29 ++++++++++++++ kernel/locking/qrwlock.c | 16 ++++++++ kernel/locking/qspinlock.c | 8 ++++ kernel/locking/rtmutex.c | 1 + kernel/locking/rwbase_rt.c | 6 +++ kernel/locking/rwsem.c | 10 ++++- kernel/locking/semaphore.c | 4 ++ 14 files changed, 172 insertions(+), 32 deletions(-) -- 2.52.0