mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: linux-kernel@vger.kernel.org, Lai Jiangshan <jiangshanlai@gmail.com>
Subject: Re: [PATCH] workqueue: Use atomic_try_cmpxchg_relaxed() in tryinc_node_nr_active()
Date: Thu, 17 Jul 2025 08:15:12 -1000	[thread overview]
Message-ID: <aHk9sFNyvzHx6Qjs@slm.duckdns.org> (raw)
In-Reply-To: <20250709131923.93776-1-ubizjak@gmail.com>

On Wed, Jul 09, 2025 at 03:19:03PM +0200, Uros Bizjak wrote:
> Use try_cmpxchg() family of locking primitives instead of
> cmpxchg(*ptr, old, new) == old.
> 
> The x86 CMPXCHG instruction returns success in the ZF flag, so this
> change saves a compare after CMPXCHG (and related move instruction
> in front of CMPXCHG).
> 
> Also, try_cmpxchg() implicitly assigns old *ptr value to "old" when
> CMPXCHG fails. There is no need to re-read the value in the loop.
> 
> The generated assembly improves from:
> 
>      3f7:	44 8b 0a             	mov    (%rdx),%r9d
>      3fa:	eb 12                	jmp    40e <...>
>      3fc:	8d 79 01             	lea    0x1(%rcx),%edi
>      3ff:	89 c8                	mov    %ecx,%eax
>      401:	f0 0f b1 7a 04       	lock cmpxchg %edi,0x4(%rdx)
>      406:	39 c1                	cmp    %eax,%ecx
>      408:	0f 84 83 00 00 00    	je     491 <...>
>      40e:	8b 4a 04             	mov    0x4(%rdx),%ecx
>      411:	41 39 c9             	cmp    %ecx,%r9d
>      414:	7f e6                	jg     3fc <...>
> 
> to:
> 
>     256b:	45 8b 08             	mov    (%r8),%r9d
>     256e:	41 8b 40 04          	mov    0x4(%r8),%eax
>     2572:	41 39 c1             	cmp    %eax,%r9d
>     2575:	7e 10                	jle    2587 <...>
>     2577:	8d 78 01             	lea    0x1(%rax),%edi
>     257a:	f0 41 0f b1 78 04    	lock cmpxchg %edi,0x4(%r8)
>     2580:	75 f0                	jne    2572 <...>
> 
> No functional change intended.
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Lai Jiangshan <jiangshanlai@gmail.com>

Applied to wq/for-6.17.

Thanks.

-- 
tejun

      reply	other threads:[~2025-07-17 18:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 13:19 Uros Bizjak
2025-07-17 18:15 ` Tejun Heo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aHk9sFNyvzHx6Qjs@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®