On Monday 06 September 2010 09:46 PM, Subrata Modak wrote:
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
Regards--
Subrata
On Thu, 2010-09-02 at 16:47 +0200, Cyril Hrubis wrote:
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.
Signed-off-by: Cyril Hrubis [email protected]
------------------------------------------------------------------------------
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
>From ce9fe6dd1bfcdeb04f920f36bfce2ab72bab8aa6 Mon Sep 17 00:00:00 2001
From: gowrishankar <[email protected]>
Date: Wed, 7 Jul 2010 16:53:57 +0530
Subject: [PATCH] ltp/realtime: update atomic_add to use glibc builtin
In recent gcc (v4.3.4 atleast) O2 optimization makes the current atomic_add
function malfunctioning for some reason (need to refer glibc changes for more
details!). To avoid these sort of problems in future, it is good to make use
of glibc builtin.
Signed-off-by: Gowrishankar <[email protected]>
Signed-off-by: Darren Hart <[email protected]>
Tested-by: Gowrishankar <[email protected]>
---
testcases/realtime/include/librttest.h | 43 +-------------------------------
1 files changed, 1 insertions(+), 42 deletions(-)
diff --git a/testcases/realtime/include/librttest.h b/testcases/realtime/include/librttest.h
index e526ab4..b20615a 100644
--- a/testcases/realtime/include/librttest.h
+++ b/testcases/realtime/include/librttest.h
@@ -114,48 +114,7 @@ extern double pass_criteria;
*/
static inline int atomic_add(int i, atomic_t *v)
{
-#if defined(__x86_64__) || defined(__i386__)
- int __i;
- __i = i;
- asm volatile(
- "lock; xaddl %0, %1;"
- :"=r"(i)
- :"m"(v->counter), "0"(i));
- return i + __i;
-#elif defined(__powerpc__)
-#define ISYNC_ON_SMP "\n\tisync\n"
-#define LWSYNC_ON_SMP __stringify(LWSYNC) "\n"
- int t;
- asm volatile(
-" lwsync \n\
-1: lwarx %0,0,%2 # atomic_add_return \n\
- add %0,%1,%0\n\
- stwcx. %0,0,%2 \n\
- bne- 1b"
- ISYNC_ON_SMP
- : "=&r" (t)
- : "r" (i), "r" (&v->counter)
- : "cc", "memory");
-
- return t;
-#elif defined(__sh__)
- unsigned long t;
-
- __asm__ __volatile__ (
-"1: movli.l @%2, %0 \n"
-" add %1, %0 \n"
-" movco.l %0, @%2 \n"
-" bf 1b \n"
-" synco \n"
- : "=&z" (t)
- : "r" (i), "r" (&v->counter)
- : "t");
-
- return t;
-#else
-#error
-#endif
-
+ return __sync_add_and_fetch(&v->counter, i);
}
/* atomic_inc: atomically increment the integer passed by reference
*/
--
1.7.0.4
------------------------------------------------------------------------------
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