From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A642FCD4F25 for ; Thu, 14 May 2026 14:13:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17DD76B0092; Thu, 14 May 2026 10:13:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 155F36B00CE; Thu, 14 May 2026 10:13:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 093216B00CF; Thu, 14 May 2026 10:13:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EE51D6B0092 for ; Thu, 14 May 2026 10:13:40 -0400 (EDT) Received: from smtpin26.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B8E101C0FBB for ; Thu, 14 May 2026 14:13:40 +0000 (UTC) X-FDA: 84766218600.26.CDE5303 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) by imf20.hostedemail.com (Postfix) with ESMTP id A78341C0013 for ; Thu, 14 May 2026 14:13:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=ilvokhin.com header.s=mail header.b=2LqHdCq5; spf=pass (imf20.hostedemail.com: domain of d@ilvokhin.com designates 178.62.254.231 as permitted sender) smtp.mailfrom=d@ilvokhin.com; dmarc=pass (policy=reject) header.from=ilvokhin.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1778768019; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CEtEQitvr5ZkBK9ei+U84T7UAt16YdxOYlqifuRSuCs=; b=nAkq+XYlvzj/Fh6SGxr6V3qUQ5iH9Dclcj681ySZmWfuDjlLOrTGE3HTQ0NrztkRuNLVBA 4w0sAEZeVxrGo9mP29r4JIZH1o7hAVt80JCJ1BMVjfOPJW30yUw4Hog5cW8jraai2j1vxp 5gn0ODoDo3j1uPQ9aAwEQY8TgHzFRhY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=ilvokhin.com header.s=mail header.b=2LqHdCq5; spf=pass (imf20.hostedemail.com: domain of d@ilvokhin.com designates 178.62.254.231 as permitted sender) smtp.mailfrom=d@ilvokhin.com; dmarc=pass (policy=reject) header.from=ilvokhin.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1778768019; a=rsa-sha256; cv=none; b=CpfYfHKv98NQuvQzDgb1oD6H5xHdvs7HCFL3mi0fF9/zdIwUHmvCSjbBHhMs0TMxdQqbyc O3tiygRGMywATGon9YJqMIN+XGF7p77e3bBGkb6e0B2Hv/gqdyWAidGxbdfBZZYaQp+B3K gvTSJjGNAKx+4obS6DlMJRDKi+rGyaA= Received: from shell.ilvokhin.com (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 92774D0572; Thu, 14 May 2026 14:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1778768016; bh=CEtEQitvr5ZkBK9ei+U84T7UAt16YdxOYlqifuRSuCs=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=2LqHdCq5tSBQ3BZqU0GmdOcvGsRqUa4wcPdAHu8hjvMz6CYEy0/FcUOv3IiSY6ajb LJ3OiABsNiurRx+c2LFTGtfo/wrG5XGj49b8jVqXLWLHz8oq3JNDQsDBaYJg6nMv4k SnM09PPyXc4AO4h3CaPUrJA/LHwqYctv2hZXMW48= Date: Thu, 14 May 2026 14:13:35 +0000 From: Dmitry Ilvokhin To: Steven Rostedt 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 , 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, "Paul E. McKenney" Subject: Re: [PATCH v6 5/7] locking: Add contended_release tracepoint to qspinlock Message-ID: References: <5d7ea75ffe74a785e6b234ada9f23c6373d4b4c1.1777999826.git.d@ilvokhin.com> <20260513114102.50f4ca68@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260513114102.50f4ca68@gandalf.local.home> X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A78341C0013 X-Stat-Signature: k13xc6p3gy85om8firwkorwyod4frdpd X-HE-Tag: 1778768018-275781 X-HE-Meta: U2FsdGVkX1/pT2b5PrvQhD7r0hyZHe3/y8PAW8wJLmjYG/RtwZwVehVvHOFqmXjL2Z+MJPeoP12FOFe+dtDVMJ9vJiWrYfbA8csnxYzsASEcc5dX9wJsL5Ng1WL1SfcLIOfB2vcy01VKYJOkNjxd+Qb4/iywkOw3lub5jdo/eBMxyxCJsjsH3l9inVbHwdcvqR85CrFe03mU25U2nGeRlU5ZYJv6hPMdbVq3WOuf/eKW3Il2fZWHWor0sO7jZPY3z6yZG+PO0Z5iYKGADMQC0CDo/TMvWcIoEJErblSQONedlUK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gWbFPn9cSGA== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, May 13, 2026 at 11:41:02AM -0400, Steven Rostedt wrote: > On Tue, 5 May 2026 17:09:34 +0000 > Dmitry Ilvokhin wrote: > > > Use the arch-overridable queued_spin_release(), introduced in the > > previous commit, to ensure the tracepoint works correctly across all > > Remove the ", introduced in the previous commit," That's useless in git > change logs. Thanks for the suggestion, will do here and in other places. [...] > > /** > > * 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; > > Get rid of the "return;". What does it save you? It just makes it that you > need to duplicate the code. Even though it's a one liner, it can cause bugs > in the future if this changes. You could call the function: > > do_trace_queued_spin_release_traced(lock); > > > > + } > > queued_spin_release(lock); > > } > > > > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > > index af8d122bb649..649fdca69288 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_call__contended_release(lock); > > + queued_spin_release(lock); > > And then remove the duplicate call of "queued_spin_release()" here. This is the scenario the comment above the static branch describes. Here's what it looks like in practice on x86_64 (defconfig, compiled with GCC 11). Current design (trace + unlock combined, with return): endbr64 xchg %ax,%ax ; NOP (static branch) movb $0x0,(%rdi) ; unlock decl %gs:__preempt_count je preempt jmp __x86_return_thunk call queued_spin_release_traced ; cold jmp preempt_handling ; cold call __SCT__preempt_schedule jmp __x86_return_thunk With the trace-only function (no return, unlock after the call): endbr64 push %rbx ; saves callee-saved rbx (!) mov %rdi,%rbx ; preserve lock across call (!) xchg %ax,%ax ; NOP (static branch) movb $0x0,(%rbx) ; unlock decl %gs:__preempt_count je preempt pop %rbx ; callee-saved restore (!) jmp __x86_return_thunk call queued_spin_release_traced ; cold jmp unlock ; cold call __SCT__preempt_schedule pop %rbx jmp __x86_return_thunk Three extra instructions marked by "!" on the hot path (push, mov, pop), all wasted when the tracepoint is off. That's the main reason for combining trace and unlock in the same out-of-line function.