[PATCH 1/1] [RFC] arm: add half-word __xchg
Mathieu Desnoyers
mathieu.desnoyers at polymtl.ca
Thu Mar 18 13:21:41 EDT 2010
* Imre Deak (imre.deak at nokia.com) wrote:
> On Thu, Mar 18, 2010 at 02:50:08PM +0100, ext Mathieu Desnoyers wrote:
> > * Alexander Shishkin (virtuoso at slind.org) wrote:
> > > On systems where ldrexh/strexh are not available, use a generic local
> > > version or __bad_xchg() on SMP.
> > >
> > > Signed-off-by: Alexander Shishkin <virtuoso at slind.org>
> > > CC: linux-arm-kernel-bounces at lists.infradead.org
> > > CC: Imre Deak <imre.deak at nokia.com>
> > > CC: Mathieu Desnoyers <mathieu.desnoyers at polymtl.ca>
> > > ---
> > > arch/arm/include/asm/system.h | 65 ++++++++++++++++++++++++++++++++++------
> > > 1 files changed, 55 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
> > > index d65b2f5..82248ae 100644
> > > --- a/arch/arm/include/asm/system.h
> > > +++ b/arch/arm/include/asm/system.h
> > > @@ -218,6 +218,39 @@ do { \
> > > last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
> > > } while (0)
> > >
> > > +static inline unsigned long __xchg_local_generic(unsigned long x,
> > > + volatile void *ptr, int size)
> > > +{
> > > + extern void __bad_xchg(volatile void *, int);
> > > + unsigned long ret;
> > > + unsigned long flags;
> > > +
> > > + switch (size) {
> > > + case 1:
> > > + raw_local_irq_save(flags);
> > > + ret = *(volatile unsigned char *)ptr;
> > > + *(volatile unsigned char *)ptr = x;
> > > + raw_local_irq_restore(flags);
> > > + break;
> > > +
> > > + case 2:
> > > + raw_local_irq_save(flags);
> > > + ret = *(volatile unsigned short *)ptr;
> > > + *(volatile unsigned short *)ptr = x;
> > > + raw_local_irq_restore(flags);
> > > + break;
> > > +
> > > + case 4:
> > > + raw_local_irq_save(flags);
> > > + ret = *(volatile unsigned long *)ptr;
> > > + *(volatile unsigned long *)ptr = x;
> > > + raw_local_irq_restore(flags);
> > > + break;
> > > + }
> > > +
> > > + return ret;
> > > +}
> > > +
> > > #if defined(CONFIG_CPU_SA1100) || defined(CONFIG_CPU_SA110)
> > > /*
> > > * On the StrongARM, "swp" is terminally broken since it bypasses the
> > > @@ -262,6 +295,26 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
> > > : "r" (x), "r" (ptr)
> > > : "memory", "cc");
> > > break;
> > > +#ifdef CONFIG_CPU_32v6K
> > > + case 2:
> > > + asm volatile("@ __xchg2\n"
> > > + "1: ldrexh %0, [%3]\n"
> > > + " strexh %1, %2, [%3]\n"
> > > + " teq %1, #0\n"
> > > + " bne 1b"
> > > + : "=&r" (ret), "=&r" (tmp)
> > > + : "r" (x), "r" (ptr)
> > > + : "memory", "cc");
> > > + break;
> > > +#else
> > > + case 2:
> > > +#ifdef CONFIG_SMP
> > > + __bad_xchg(ptr, size), ret = 0;
> >
>
> On a related note, why can't we have __bad_xchg as an undefined function
> for detecting the error already in build time? That seems to be the
> approach in similar places.
And, unless I am missing your point entirely, this is exactly what is
done here.
Thanks,
Mathieu
>
> --Imre
>
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
More information about the linux-arm-kernel
mailing list