From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] ARM: spinlock: use ticket algorithm for ARMv6+ locking implementation
Date: Mon, 25 Jun 2012 10:36:48 +0100 [thread overview]
Message-ID: <20120625093648.GC22128@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1206221443100.10229@xanadu.home>
Hi Nicolas,
Thanks for looking at this.
On Fri, Jun 22, 2012 at 09:08:47PM +0100, Nicolas Pitre wrote:
> On Fri, 22 Jun 2012, Will Deacon wrote:
>
> > Ticket spinlocks ensure locking fairness by reducing the thundering herd
> > effect when acquiring a lock.
>
> The conventional thundering herd effect is still there as all waiting
> CPUs are still woken up from WFE upon a spin_unlock with a SEV. Maybe
> the fact that the actual spinning is no longer banging on the exclusion
> monitor does count as reduction of the thundering herd effect at that
> level though, and if that is what you meant then this could be precised
> here.
Sure, I can clarify that. The thundering herd effect is reduced because (a)
the cacheline can remain shared and (b) the memory access time doesn't
determine the winner.
> > This is especially important on systems
> > where memory-access times are not necessarily uniform when accessing
> > the lock structure (for example, on a multi-cluster platform where the
> > lock is allocated into L1 when a CPU releases it).
>
> In which case it is more about fairness. This algorithm brings fairness
> due to its FIFO nature, despite possible memory access speed
> differences. And that is even more important than the thundering herd
> effect. Solving both at once is of course all good.
Precisely.
> > This patch implements the ticket spinlock algorithm for ARM, replacing
> > the simpler implementation for ARMv6+ processors.
> >
> > Cc: Nicolas Pitre <nico@fluxnic.net>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
>
> A minor remarks below. Otherwise...
>
> Reviewed-by: Nicolas Pitre <nico@linaro.org>
Thanks Nicolas.
> > static inline int arch_spin_trylock(arch_spinlock_t *lock)
> > {
> > unsigned long tmp;
> > + u32 slock;
> >
> > __asm__ __volatile__(
> > -" ldrex %0, [%1]\n"
> > -" teq %0, #0\n"
> > -" strexeq %0, %2, [%1]"
> > - : "=&r" (tmp)
> > - : "r" (&lock->lock), "r" (1)
> > +" ldrex %0, [%2]\n"
> > +" cmp %0, %0, ror #16\n"
> > +" movne %1, #1\n"
>
> You could replace the above 2 insns with:
>
> subs %1, %0, %0, ror #16
Wahey, that is extremely concise!
Cheers,
Will
next prev parent reply other threads:[~2012-06-25 9:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 15:15 [PATCH 0/2] Implement ticket spinlocks for ARM Will Deacon
2012-06-22 15:15 ` [PATCH 1/2] ARM: spinlock: use ticket algorithm for ARMv6+ locking implementation Will Deacon
2012-06-22 20:08 ` Nicolas Pitre
2012-06-25 9:36 ` Will Deacon [this message]
2012-06-22 15:15 ` [PATCH 2/2] ARM: rwlocks: remove unused branch labels from trylock routines Will Deacon
2012-06-22 20:22 ` Nicolas Pitre
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=20120625093648.GC22128@mudshark.cambridge.arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.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;
as well as URLs for NNTP newsgroup(s).