All of lore.kernel.org
 help / color / mirror / Atom feed
From: mathieu.desnoyers@polymtl.ca (Mathieu Desnoyers)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/1] [RFC] arm: add half-word __xchg
Date: Thu, 18 Mar 2010 09:50:08 -0400	[thread overview]
Message-ID: <20100318135008.GA11800@Krystal> (raw)
In-Reply-To: <1268919221-2748-1-git-send-email-virtuoso@slind.org>

* 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@slind.org>
> CC: linux-arm-kernel-bounces at lists.infradead.org
> CC: Imre Deak <imre.deak@nokia.com>
> CC: Mathieu Desnoyers <mathieu.desnoyers@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;

You don't need to put this one explicitly. See the default case of the
switch.

But.. thinking about it. It's bad to have a 2-byte xchg primitive that
only works on UP and breaks the build on SMP. We should instead
implement a workaround based on __cmpxchg4 to perform the 2-byte xchg().

Thanks,

Mathieu

> +#else
> +		ret = __xchg_local_generic(x, ptr, 2);
> +#endif
> +		break;
> +#endif
>  	case 4:
>  		asm volatile("@	__xchg4\n"
>  		"1:	ldrex	%0, [%3]\n"
> @@ -277,17 +330,9 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
>  #error SMP is not supported on this platform
>  #endif
>  	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:
>  	case 4:
> -		raw_local_irq_save(flags);
> -		ret = *(volatile unsigned long *)ptr;
> -		*(volatile unsigned long *)ptr = x;
> -		raw_local_irq_restore(flags);
> +		ret = __xchg_local_generic(x, ptr, size);
>  		break;
>  #else
>  	case 1:
> -- 
> 1.6.3.3
> 

-- 
Mathieu Desnoyers
Operating System Efficiency Consultant
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2010-03-18 13:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-10 16:22 __xchg for sizes other than 32bit Imre Deak
2010-03-10 17:35 ` Russell King - ARM Linux
2010-03-10 20:02   ` [PATCH] ARM support single byte cmpxchg and cmpxchg_local on ARMv6 Mathieu Desnoyers
2010-03-10 20:30     ` Russell King - ARM Linux
2010-03-10 21:15       ` Mathieu Desnoyers
2010-03-10 23:16   ` __xchg for sizes other than 32bit Jamie Lokier
2010-03-18  9:29   ` [PATCH 1/1] [RFC] arm: add half-word __xchg Alexander Shishkin
2010-03-18 12:32     ` Mathieu Desnoyers
2010-03-18 12:37       ` Alexander Shishkin
2010-03-18 13:33       ` Alexander Shishkin
2010-03-18 13:50         ` Mathieu Desnoyers [this message]
2010-03-18 16:33           ` Imre Deak
2010-03-18 17:21             ` Mathieu Desnoyers
2010-03-18 19:00               ` Imre Deak
2010-03-18 19:30                 ` Mathieu Desnoyers
2010-03-19  1:49           ` Jamie Lokier
2010-03-19  2:12             ` Mathieu Desnoyers
2010-03-19  3:36               ` Jamie Lokier
2010-03-25 15:52           ` [PATCH 1/1] [RFCv2] " Alexander Shishkin
2010-03-25 16:42           ` Alexander Shishkin
2010-03-27 22:52             ` Russell King - ARM Linux
2010-03-28  0:14               ` Jamie Lokier
2010-03-28  0:18                 ` Russell King - ARM Linux
2010-03-28  1:00                 ` Mathieu Desnoyers
2010-03-28 14:39                   ` Jamie Lokier

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=20100318135008.GA11800@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.