arm: Adding support for atomic half word exchange
My apologies, the e-mail editor was not configured properly. CC'ed to relevant maintainers and reposting once again with proper formatting.
Since 16 bit half word exchange was not there and MCS based qspinlock by Waiman's xchg_tail() requires an atomic exchange on a half word, here is a small modification to __xchg() code to support the exchange. ARMv6 and lower does not have support for LDREXH, so we need to make sure things do not break when we're compiling on ARMv6.
--- arch/arm/include/asm/cmpxchg.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/arm/include/asm/cmpxchg.h +18 -0
@@ -50,6 +50,24 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size : "r" (x), "r" (ptr) : "memory", "cc");break ; +#if !defined (CONFIG_CPU_V6 ) +/* +* Halfword exclusive exchange +* This is new implementation as qspinlock +* wants 16 bit atomic CAS. +* This is not supported on ARMv6. +*/ +case 2 : + asmvolatile ("@ __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 ; +#endif case 4 : asmvolatile ("@ __xchg4\n" "1: ldrex %0, [%3]\n"
Regards,
Sarbojit
------- Original Message -------
Sender : Catalin Marinas<[email protected]>
Date : Aug 19, 2015 21:43 (GMT+05:30)
Title : Re: [PATCH] arm: Adding support for atomic half word exchange
Quoted 4 lines · Sarbojit Ganguly
Since 16 bit half word exchange was not there and MCS based qspinlock by Waiman's
xchg_tail()requires an atomic exchange on a half word, here is a small modification to__xchg()code to support the exchange. ARMv6 and lower does not have support for LDREXH, so we need to make sure things do not break when we're compiling on ARMv6.
First of all, please wrap the text appropriately.
Secondly, you need to cc the relevant maintainer and mailing list (try running ./scripts/get_maintainer.pl on this patch to get some hints).
Signature · 1 line
Catalinÿôèº{.nÇ+‰·Ÿ®‰†+%ŠËÿ±éݶ¥Šwÿº{.nÇ+‰·¥Š{±þG«�éÿŠ{ayºÊ‡Ú™ë,j¢f£¢·hš�ï�êÿ‘êçz_è®(階ŠÝ¢j"�ú¶m§ÿÿ¾«þG«�éÿ¢¸?™¨èÚ&£ø§~�á¶iO•æ¬z·švØ^¶m§ÿÿÃÿ¶ìÿ¢¸?–I¥Quoted 19 lines · Sarbojit Ganguly
My apologies, the e-mail editor was not configured properly. CC'ed to relevant maintainers and reposting once again with proper formatting.
Since 16 bit half word exchange was not there and MCS based qspinlock by Waiman's
xchg_tail()requires an atomic exchange on a half word, here is a small modification to__xchg()code to support the exchange. ARMv6 and lower does not have support for LDREXH, so we need to make sure things do not break when we're compiling on ARMv6.Signed-off-by Sarbojit Ganguly <[email protected]>--- arch/arm/include/asm/cmpxchg.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)arch/arm/include/asm/cmpxchg.h +0
-0
arch/arm/include/asm/cmpxchg.h static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size · line 59
Quoted 10 lines
arch/arm/include/asm/cmpxchg.h +7
-0@@ -50,6 +50,24 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size : "r" (x), "r" (ptr) : "memory", "cc");break ; +#if !defined (CONFIG_CPU_V6 ) +/* +* Halfword exclusive exchange +* This is new implementation as qspinlock +* wants 16 bit atomic CAS. +* This is not supported on ARMv6. +*/
I don't think you need this comment. We don't use qspinlock on arch/arm/.
Quoted 4 lines
arch/arm/include/asm/cmpxchg.h +4
-0+case 2 : + asmvolatile ("@ __xchg2\n" +"1: ldrexh %0, [%3]\n" + " strexh %1, %2, [%3]\n"
arch/arm/include/asm/cmpxchg.h static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size · line 73
Quoted 10 lines
arch/arm/include/asm/cmpxchg.h +7
-0+ " teq %1, #0\n" + " bne 1b" + : "=&r" (ret), "=&r" (tmp) + : "r" (x), "r" (ptr) + : "memory", "cc"); +break ; +#endif case 4 : asmvolatile ("@ __xchg4\n" "1: ldrex %0, [%3]\n"
We have the same issue with the byte exclusives, so I think you need to extend the guard you're adding to cover that case too (which is a bug in current mainline).
Will