Re: [PATCH v3 10/25] openrisc: add spinlock implementation

From: Peter Zijlstra
Date: Wed Feb 22 2017 - 07:02:32 EST


On Wed, Feb 22, 2017 at 12:37:09PM +0100, Peter Zijlstra wrote:
> On Wed, Feb 22, 2017 at 04:11:39AM +0900, Stafford Horne wrote:
>
>
> > +static inline int arch_spin_trylock(arch_spinlock_t *lock)
> > +{
> > + unsigned long contended, tmp;
> > + u32 slock;
> > +
> > + /* contended = (lock->tickets.owner != lock->tickets.next) */
> > + __asm__ __volatile__(
> > + "1: l.lwa %0, 0(%3) \n"
> > + " l.srli %1, %0, 16 \n"
> > + " l.andi %2, %0, 0xffff \n"
> > + " l.sfeq %1, %2 \n"
> > + " l.bnf 1f \n"
> > + " l.ori %1, r0, 1 \n"
> > + " l.add %0, %0, %4 \n"
> > + " l.swa 0(%3), %0 \n"
> > + " l.bnf 1b \n"
> > + " l.ori %1, r0, 0 \n"
>
> #ifdef CONFIG_SMP
> " l.sync \n"
> #endif

Never mind, this part is silly, your l.swa already implies an l.sync. So
you can completely remove the smp_mb() here.