This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: libstdc++ atomicity.h and ppc405 problem (was: RE: Regressiontes t for thread safety?)
- From: Dan Kegel <dkegel at ixiacom dot com>
- To: Dan Kegel <dkegel at ixiacom dot com>
- Cc: 'Loren James Rittle ' <rittle at latour dot rsch dot comm dot mot dot com>, Dan Kegel --foward<dank at kegel dot com>, "'libstdc++ at gcc dot gnu dot org '" <libstdc++ at gcc dot gnu dot org>, JanOlderdissen <jolderdissen at ixiacom dot com>, Bryan Rittmeyer<brittmeyer at ixiacom dot com>, Doug Schafer <doug at ixiacom dot com>
- Date: Thu, 18 Jul 2002 16:10:17 -0700
- Subject: Re: libstdc++ atomicity.h and ppc405 problem (was: RE: Regressiontes t for thread safety?)
- References: <9A9C83C019F35D47A570460E87D5D8AB02759342@racerx.ixiacom.com>
Dan Kegel wrote:
> ... according to ppc405 erratum #77 in
http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/89DED00DEBFF54BF
87256A8000491BA2/$file/405CR_C_errata_1_2.pdf
the STWCX instruction is buggy in the ppc405; since it is used by
libstdc++-v3/config/cpu/powerpc/bits/atomicity.h,
and that file hasn't changed in two years, the bug is
probably still there.
A bit more detail: in the ppc405 linux kernel port, the changeset
that introduced the workaround is:
ChangeSet@1.489 2001-09-21 03:00:38-04:00 dan@netx4.com
Update from David Gibson to properly implement the IBM4xx Errata #77
solution. This places certain pipeline operations prior to the
executing of a stwcx. instruction.
See e.g.
http://ppc.bkbits.net:8080/linuxppc_2_4_devel/cset@1.489?nav=index.html|src/|src/include|src/include/asm-ppc|related/include/asm-ppc/atomic.h
OK, that fixes the kernel. We already had that. What we need on
top of that is a fix for gcc's stdlibc++. Here's what I'm trying:
First, in gcc/config/rs6000/rs6000.h, define __PPC405__ when compiling for ppc405.
Second, insert the 'sync' instruction into atomicity.h like so:
--- gcc-3.0.2/libstdc++-v3/config/cpu/powerpc/bits/atomicity.h.orig Tue Feb 27 16:04:08 2001
+++ gcc-3.0.2/libstdc++-v3/config/cpu/powerpc/bits/atomicity.h Thu Jul 18 13:36:39 2002
@@ -32,6 +32,18 @@
typedef int _Atomic_word;
+#ifdef __PPC405__
+/* fix PPC405 specific bug: errata #77 - JRO 07/18/02 & dank
+ See erratum 77 in
+ http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/89DED00DEBFF54BF87256A8000491BA2/$file/405CR_C_errata_1_2.pdf
+ See also version 1.21 of arch/ppc/kernel/ppc_asm.h, Fri Sep 21 00:00:34 2001
+ in ChangeSet 1.489 at http://ppc.bkbits.net:8080/linuxppc_2_4_devel
+*/
+#define __LIBSTDCPP_PPC405_ERR77_SYNC "sync \n\t"
+#else
+#define __LIBSTDCPP_PPC405_ERR77_SYNC
+#endif
+
static inline _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add (volatile _Atomic_word* __mem, int __val)
@@ -42,6 +54,7 @@
"0:\t"
"lwarx %0,0,%2 \n\t"
"add%I3 %1,%0,%3 \n\t"
+ __LIBSTDCPP_PPC405_ERR77_SYNC
"stwcx. %1,0,%2 \n\t"
"bne- 0b \n\t"
"/* End exchange & add */"
etc.
I'm building now; wish me luck :-)
- Dan