From: "Paul E. McKenney" <paulmck@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Joel Fernandes <joel@joelfernandes.org>,
Uros Bizjak <ubizjak@gmail.com>,
rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <quic_neeraju@quicinc.com>,
Josh Triplett <josh@joshtriplett.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>
Subject: Re: [PATCH] rcu: use try_cmpxchg in check_cpu_stall
Date: Tue, 28 Feb 2023 13:29:11 -0800 [thread overview]
Message-ID: <20230228212911.GX2948950@paulmck-ThinkPad-P17-Gen-1> (raw)
In-Reply-To: <20230228160324.2a7c1012@gandalf.local.home>
On Tue, Feb 28, 2023 at 04:03:24PM -0500, Steven Rostedt wrote:
> On Tue, 28 Feb 2023 20:39:30 +0000
> Joel Fernandes <joel@joelfernandes.org> wrote:
>
> > On Tue, Feb 28, 2023 at 04:51:21PM +0100, Uros Bizjak wrote:
> > > Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
> > > check_cpu_stall. x86 CMPXCHG instruction returns success in ZF flag, so
> > > this change saves a compare after cmpxchg (and related move instruction in
> > > front of cmpxchg).
> >
> > In my codegen, I am not seeing mov instruction before the cmp removed, how
> > can that be? The rax has to be populated with a mov before cmpxchg right?
> >
> > So try_cmpxchg gives: mov, cmpxchg, cmp, jne
> > Where as cmpxchg gives: mov, cmpxchg, mov, jne
> >
> > So yeah you got rid of compare, but I am not seeing reduction in moves.
> > Either way, I think it is an improvement due to dropping cmp so:
>
> Did you get the above backwards?
>
> Anyway, when looking at the conversion of cmpxchg() to try_cmpxchg() that
> Uros sent to me for the ring buffer, the code went from:
>
> 0000000000000070 <ring_buffer_record_off>:
> 70: 48 8d 4f 08 lea 0x8(%rdi),%rcx
> 74: 8b 57 08 mov 0x8(%rdi),%edx
> 77: 89 d6 mov %edx,%esi
> 79: 89 d0 mov %edx,%eax
> 7b: 81 ce 00 00 10 00 or $0x100000,%esi
> 81: f0 0f b1 31 lock cmpxchg %esi,(%rcx)
> 85: 39 d0 cmp %edx,%eax
> 87: 75 eb jne 74 <ring_buffer_record_off+0x4>
> 89: e9 00 00 00 00 jmp 8e <ring_buffer_record_off+0x1e>
> 8a: R_X86_64_PLT32 __x86_return_thunk-0x4
> 8e: 66 90 xchg %ax,%ax
>
>
> To
>
> 00000000000001a0 <ring_buffer_record_off>:
> 1a0: 8b 47 08 mov 0x8(%rdi),%eax
> 1a3: 48 8d 4f 08 lea 0x8(%rdi),%rcx
> 1a7: 89 c2 mov %eax,%edx
> 1a9: 81 ca 00 00 10 00 or $0x100000,%edx
> 1af: f0 0f b1 57 08 lock cmpxchg %edx,0x8(%rdi)
> 1b4: 75 05 jne 1bb <ring_buffer_record_off+0x1b>
> 1b6: e9 00 00 00 00 jmp 1bb <ring_buffer_record_off+0x1b>
> 1b7: R_X86_64_PLT32 __x86_return_thunk-0x4
> 1bb: 89 c2 mov %eax,%edx
> 1bd: 81 ca 00 00 10 00 or $0x100000,%edx
> 1c3: f0 0f b1 11 lock cmpxchg %edx,(%rcx)
> 1c7: 75 f2 jne 1bb <ring_buffer_record_off+0x1b>
> 1c9: e9 00 00 00 00 jmp 1ce <ring_buffer_record_off+0x2e>
> 1ca: R_X86_64_PLT32 __x86_return_thunk-0x4
> 1ce: 66 90 xchg %ax,%ax
>
>
> It does add a bit more code, but the fast path seems better (where the
> cmpxchg succeeds). That would be:
>
> 00000000000001a0 <ring_buffer_record_off>:
> 1a0: 8b 47 08 mov 0x8(%rdi),%eax
> 1a3: 48 8d 4f 08 lea 0x8(%rdi),%rcx
> 1a7: 89 c2 mov %eax,%edx
> 1a9: 81 ca 00 00 10 00 or $0x100000,%edx
> 1af: f0 0f b1 57 08 lock cmpxchg %edx,0x8(%rdi)
> 1b4: 75 05 jne 1bb <ring_buffer_record_off+0x1b>
> 1b6: e9 00 00 00 00 jmp 1bb <ring_buffer_record_off+0x1b>
> 1b7: R_X86_64_PLT32 __x86_return_thunk-0x4
>
>
> Where there's only two moves and no cmp, where the former has 3 moves and a
> cmp in the fast path.
All well and good, but the stall-warning code is nowhere near a fastpath.
Is try_cmpxchg() considered more readable in this context?
Thanx, Paul
next prev parent reply other threads:[~2023-02-28 21:29 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 15:51 Uros Bizjak
2023-02-28 20:39 ` Joel Fernandes
2023-02-28 20:56 ` Joel Fernandes
2023-02-28 21:03 ` Steven Rostedt
2023-02-28 21:29 ` Paul E. McKenney [this message]
2023-02-28 21:41 ` Steven Rostedt
2023-02-28 21:56 ` Paul E. McKenney
2023-02-28 23:30 ` Joel Fernandes
2023-03-01 0:08 ` Steven Rostedt
2023-03-01 0:45 ` Joel Fernandes
2023-03-01 10:28 ` Uros Bizjak
2023-03-01 16:38 ` Steven Rostedt
2023-03-01 18:43 ` Uros Bizjak
2023-03-01 18:52 ` Steven Rostedt
2023-03-01 19:18 ` Uros Bizjak
2023-03-01 19:43 ` Steven Rostedt
2023-03-01 19:46 ` Joel Fernandes
2023-03-01 19:45 ` Joel Fernandes
2023-03-01 20:08 ` Paul E. McKenney
2023-03-01 20:18 ` Joel Fernandes
2023-03-01 20:18 ` Steven Rostedt
2023-03-01 20:36 ` Paul E. McKenney
2023-03-01 20:46 ` Steven Rostedt
2023-03-01 21:29 ` Paul E. McKenney
2023-03-01 9:52 ` Uros Bizjak
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=20230228212911.GX2948950@paulmck-ThinkPad-P17-Gen-1 \
--to=paulmck@kernel.org \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.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®