Skip to contentSkip to conversation

fix realtime atomic_add() inline asm

PATCH In review Cyril Hrubis 2 participants 3 messages Sep 2, 2010 – Sep 20, 2010 6 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix realtime atomic_add() inline asm

Hi!
The atomic_add() assembler for x86 is missing hint for gcc that value of v->counter is being modified by xaddl instruction and as this variable is changed only from this asm runtime, some combination of gcc optimalizations allows for this value to be placed in binary .rodata section resulting in realtime tests segfaulting when trying to do atomic_add(). It's reproducible on SLES11 (gcc 4.3.2) with -O2.

Patch attached.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/realtime/include/librttest.h +1 -1
index e526ab4..cddc399 100644
@@ -119,7 +119,7 @@ static inline int atomic_add(int i, atomic_t *v)
 	__i = i;
 	asm volatile(
 			"lock; xaddl %0, %1;"
-			:"=r"(i)
+			:"=r"(i), "+m" (v->counter)
 			:"m"(v->counter), "0"(i));
 	return i + __i;
 #elif defined(__powerpc__)

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 5 lines · Darren Hart

For what it's worth, I think the bug that Cyril found just further supports Gowri's patch to get rid of the asm altogether and go with the glibc built-ins. This keeps all these sorts of low-level details in one place and avoids duplication. My two cents.

Quoted 65 lines

--
Darren Hart

Quoted 60 lines · Subrata Modak
Quoted 2 lines · gowrishankar

Hi Cyril,
Do you wish to ack my patch ?

Cyril,

Waiting for your endorsement/rejection !!

Regards--
Subrata

Quoted 49 lines

Thanks,
Gowrishankar

Quoted 44 lines · Subrata Modak

Can both of you agree to send a single patch ?

Regards--
Subrata

Quoted 37 lines · gowrishankar
Quoted 6 lines · Subrata Modak

Darren/Gowri,

Are you aware of this patch ? Can you please provide your comments ?

Subrata/Cyril,
Apologies that I tagged this mail, but somehow forgot to reply immediately.

I had already prepared a patch (before Cyril shared his part) to make atomic_add much more maintenance free and sharing with you guys now. Please find it attached.

Thanks,
Gowrishankar

Quoted 17 lines

Regards--
Subrata

Quoted 11 lines · Cyril Hrubis

Hi!
The atomic_add() assembler for x86 is missing hint for gcc that value of v->counter is being modified by xaddl instruction and as this variable is changed only from this asm runtime, some combination of gcc optimalizations allows for this value to be placed in binary .rodata section resulting in realtime tests segfaulting when trying to do atomic_add(). It's reproducible on SLES11 (gcc 4.3.2) with -O2.

Patch attached.

Agreed. In this particular case (IMO) LTP doesn't need to reimplement the atomic functions, because it's probably less tested and more buggy than the glibc equivalents. I'm [almost] always in favor of removing unnecessary duplication. This is one of the cases that I fully support.
Thanks,
-Garrett

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#8 lore raw
In reply to a message not in the archive

Hi!

Quoted 6 lines
Quoted 2 lines

Hi Cyril,
Do you wish to ack my patch ?

Cyril,

Waiting for your endorsement/rejection !!

Sorry, I've been out of the office for some time.

Using __sync_add_and_fetch() is better solution as far as we use gcc (1), but we were using gcc extended assembler (2) before, so we should be safe here. You can add my ack to previous patch.

1) http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Atomic-Builtins.html

2) http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Extended-Asm.html#Extended-Asm

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list