From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 87AE537B002; Thu, 16 Apr 2026 23:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776383655; cv=none; b=uZh0LNey33Td9ehg5684IgvV8fjuZhUAJ94T9mp2yOyyPjYahiVWLYruT5JFHnRROn+r02AjByifs3xvWO9XXxOt5B/EdknI2HuIjTiZbq169/chyyYZ8GjtYwGCsODFm7avX60gGTipGVmetbxHJjq9NyBAqFLTP0uEb3jZLU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776383655; c=relaxed/simple; bh=TXSRIJ/h22avk7murAB6glIED87kidjbJTYSFQI5SwI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mjxTlIPgKkTVKEeK1dGDlN73FLEttO2reeJJ77zJNyqiXMjWbdIGcssaj+Gcwwk+RikjqOQ5hLpAST/QDDlF6MRWbUxcsFRoylK8MM6sMAX476QMXvv0q1SNgMZlXqEnzHfUvp39itIPj9xfDpGX5XAf2YuSRuRET9XxcX652Nc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u01eqPN6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u01eqPN6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CFD1C2BCAF; Thu, 16 Apr 2026 23:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776383655; bh=TXSRIJ/h22avk7murAB6glIED87kidjbJTYSFQI5SwI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=u01eqPN68WSsjD3cD/F6AL+NPCxKGMcCe+WzvehEPA6ul0uV7ztfDDsEJ+a5IcinX UPPadarOwbfuJr8QzuLi2mxLddeRIBJ3bcfV6pHDieviyeDAvnMoG55BhEYB0DhO8l 0g8J5C9jfCx+YxBkCqAiO7vYYclrHUVBmGFEzEWPLK8nkf3fgqb77lh+ZBvJ2s7yT5 CFIhEwQ5DPGyrxGDnFqdP3YeuOG0l7qRzCsZw+f983jkklXWRSJz9PDgeg+7eD+kfh bfUQIMRk2dAB2NCWcX9Dsbuc1zuPUW9vVsKYuqVLlyyvSsQocAH6Rd2FiPZaUJmybt YeG6PDph5XO0w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C2A87CE08B2; Thu, 16 Apr 2026 16:54:14 -0700 (PDT) Date: Thu, 16 Apr 2026 16:54:14 -0700 From: "Paul E. McKenney" To: Dmitry Ilvokhin Cc: 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 , 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 Subject: Re: [PATCH v5 5/7] locking: Add contended_release tracepoint to qspinlock Message-ID: <2bc24e26-7b01-4e43-8f96-35334237397b@paulmck-laptop> Reply-To: paulmck@kernel.org References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Apr 16, 2026 at 03:05:11PM +0000, Dmitry Ilvokhin wrote: > Use the arch-overridable queued_spin_release(), introduced in the > previous commit, to ensure the tracepoint works correctly across all > architectures, including those with custom unlock implementations (e.g. > x86 paravirt). > > When the tracepoint is disabled, the only addition to the hot path is a > single NOP instruction (the static branch). When enabled, the contention > check, trace call, and unlock are combined in an out-of-line function to > minimize hot path impact, avoiding the compiler needing to preserve the > lock pointer in a callee-saved register across the trace call. > > Binary size impact (x86_64, defconfig): > uninlined unlock (common case): +680 bytes (+0.00%) > inlined unlock (worst case): +83659 bytes (+0.21%) > > The inlined unlock case could not be achieved through Kconfig options on > x86_64 as PREEMPT_BUILD unconditionally selects UNINLINE_SPIN_UNLOCK on > x86_64. The UNINLINE_SPIN_UNLOCK guards were manually inverted to force > inline the unlock path and estimate the worst case binary size increase. > > In practice, configurations with UNINLINE_SPIN_UNLOCK=n have already > opted against binary size optimization, so the inlined worst case is > unlikely to be a concern. > > Architectures with fully custom qspinlock implementations (e.g. > PowerPC) are not covered by this change. > > Signed-off-by: Dmitry Ilvokhin Much nicer split out! Acked-by: Paul E. McKenney > --- > include/asm-generic/qspinlock.h | 18 ++++++++++++++++++ > kernel/locking/qspinlock.c | 8 ++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/include/asm-generic/qspinlock.h b/include/asm-generic/qspinlock.h > index df76f34645a0..915a4c2777f6 100644 > --- a/include/asm-generic/qspinlock.h > +++ b/include/asm-generic/qspinlock.h > @@ -41,6 +41,7 @@ > > #include > #include > +#include > > #ifndef queued_spin_is_locked > /** > @@ -129,12 +130,29 @@ static __always_inline void queued_spin_release(struct qspinlock *lock) > } > #endif > > +DECLARE_TRACEPOINT(contended_release); > + > +extern void queued_spin_release_traced(struct qspinlock *lock); > + > /** > * queued_spin_unlock - unlock a queued spinlock > * @lock : Pointer to queued spinlock structure > + * > + * Generic tracing wrapper around the arch-overridable > + * queued_spin_release(). > */ > static __always_inline void queued_spin_unlock(struct qspinlock *lock) > { > + /* > + * Trace and release are combined in queued_spin_release_traced() so > + * the compiler does not need to preserve the lock pointer across the > + * function call, avoiding callee-saved register save/restore on the > + * hot path. > + */ > + if (tracepoint_enabled(contended_release)) { > + queued_spin_release_traced(lock); > + return; > + } > queued_spin_release(lock); > } > > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index af8d122bb649..c72610980ec7 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -104,6 +104,14 @@ static __always_inline u32 __pv_wait_head_or_lock(struct qspinlock *lock, > #define queued_spin_lock_slowpath native_queued_spin_lock_slowpath > #endif > > +void __lockfunc queued_spin_release_traced(struct qspinlock *lock) > +{ > + if (queued_spin_is_contended(lock)) > + trace_contended_release(lock); > + queued_spin_release(lock); > +} > +EXPORT_SYMBOL(queued_spin_release_traced); > + > #endif /* _GEN_PV_LOCK_SLOWPATH */ > > /** > -- > 2.52.0 >