From: Peter Zijlstra <peterz@infradead.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Waiman Long <longman@redhat.com>, Arnd Bergmann <arnd@arndb.de>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
Ingo Molnar <mingo@kernel.org>, Will Deacon <will.deacon@arm.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] locking: Remove an insn from spin and write locks
Date: Mon, 20 Aug 2018 17:56:50 +0200 [thread overview]
Message-ID: <20180820155650.GG24082@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180820155002.GB25153@bombadil.infradead.org>
On Mon, Aug 20, 2018 at 08:50:02AM -0700, Matthew Wilcox wrote:
> On Mon, Aug 20, 2018 at 11:14:04AM -0400, Waiman Long wrote:
> > On 08/20/2018 11:06 AM, Matthew Wilcox wrote:
> > > Both spin locks and write locks currently do:
> > >
> > > f0 0f b1 17 lock cmpxchg %edx,(%rdi)
> > > 85 c0 test %eax,%eax
> > > 75 05 jne [slowpath]
> > >
> > > This 'test' insn is superfluous; the cmpxchg insn sets the Z flag
> > > appropriately. Peter pointed out that using atomic_try_cmpxchg()
> > > will let the compiler know this is true. Comparing before/after
> > > disassemblies show the only effect is to remove this insn.
> ...
> > > static __always_inline int queued_spin_trylock(struct qspinlock *lock)
> > > {
> > > + u32 val = 0;
> > > +
> > > if (!atomic_read(&lock->val) &&
> > > - (atomic_cmpxchg_acquire(&lock->val, 0, _Q_LOCKED_VAL) == 0))
> > > + (atomic_try_cmpxchg(&lock->val, &val, _Q_LOCKED_VAL)))
> >
> > Should you keep the _acquire suffix?
>
> I don't know ;-) Probably. Peter didn't include it as part of his
> suggested fix, but on reviewing the documentation, it seems likely that
> it should be retained. I put them back in and (as expected) it changes
> nothing on x86-64.
Yeah, _acquire should be retained; sorry about loosing that. I'm neck
deep into tlb invalidate stuff and wrote this without much thinking
involved.
next prev parent reply other threads:[~2018-08-20 15:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-20 15:06 Matthew Wilcox
2018-08-20 15:14 ` Waiman Long
2018-08-20 15:50 ` Matthew Wilcox
2018-08-20 15:55 ` Waiman Long
2018-08-20 15:56 ` Peter Zijlstra [this message]
2018-08-20 16:26 ` Matthew Wilcox
2018-08-21 1:54 ` Will Deacon
2018-10-02 10:07 ` [tip:locking/core] locking/spinlocks: Remove an instruction " tip-bot for Matthew Wilcox
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=20180820155650.GG24082@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
--cc=willy@infradead.org \
/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
Powered by JetHome