This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3.3/3.4]: Fix two locking issues on PA

This patch fixes two locking issues that I found in testing this weekend.

On a hppa1.1 machine, the locking code would sometimes go into an infinite
loop.  This was caused by the lock being misaligned.  The lock must be
16-byte aligned on PA 1.x machines.  The former placement of the alignment
attribute didn't give the expected alignment.

I didn't detect this in previous testing and many subsequent builds
which were all done on PA 2.0 machines.  Contrary to the architecture book,
the ldcw instruction only requires 4-byte alignment on a coherent PA 2
machine.  Just found this out last week.  This was added to the PA
errata this year.  Guess it shows that I should test on an old machine
from time to time.

The second change was to use a volatile asm to reset the lock to prevent
gcc from moving code into or out of the locked range.  A special instruction
to provide ordered operation on PA 2.0 was used.  PA 2.0 processors
have a large reorder buffer, so the processor could move code into or out
of the locked range.  This insn't a problem on PA 1.x as all loads and stores
are strongly ordered.

Tested on hppa64-hp-hpux11.X 3.3 and 3.4, hppa1.1-hp-hpux10.20 3.4,
and hppa-unknown-linux-gnu 3.3 and 3.4.

Installed to 3.3 and trunk.

J. David Anglin                        
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

2003-02-08  John David Anglin  <>

	* hppa/atomicity.h (__Atomicity_lock<__inst>::_S_atomicity_lock):
	Correct alignment.
	(__exchange_and_add, __atomic_add): Use PA 2.0 ordered store to reset

Index: config/cpu/hppa/atomicity.h
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/config/cpu/hppa/atomicity.h,v
retrieving revision 1.1
diff -u -3 -p -r1.1 atomicity.h
--- config/cpu/hppa/atomicity.h	5 Nov 2002 19:17:37 -0000	1.1
+++ config/cpu/hppa/atomicity.h	9 Feb 2003 03:08:41 -0000
@@ -25,11 +25,12 @@ typedef int _Atomic_word;
 template <int __inst>
 struct __Atomicity_lock
-  static volatile int __attribute__ ((aligned (16))) _S_atomicity_lock;
+  static volatile int _S_atomicity_lock;
 template <int __inst>
-volatile int __Atomicity_lock<__inst>::_S_atomicity_lock = 1;
+volatile int
+__Atomicity_lock<__inst>::_S_atomicity_lock __attribute__ ((aligned (16))) = 1;
 /* Because of the lack of weak support when using the hpux
    som linker, we explicitly instantiate the atomicity lock
@@ -58,8 +59,9 @@ __exchange_and_add (volatile _Atomic_wor
   result = *__mem;
   *__mem = result + __val;
-  __asm__ __volatile__("");
-  lock = tmp;
+  /* Reset lock with PA 2.0 "ordered" store.  */
+  __asm__ __volatile__ ("stw,ma %1,0(%0)"
+			: : "r" (&lock), "r" (tmp) : "memory");
   return result;
@@ -80,8 +82,9 @@ __atomic_add (_Atomic_word* __mem, int _
 			: "r" (&lock));
   *__mem += __val;
-  __asm__ __volatile__("");
-  lock = tmp;
+  /* Reset lock with PA 2.0 "ordered" store.  */
+  __asm__ __volatile__ ("stw,ma %1,0(%0)"
+			: : "r" (&lock), "r" (tmp) : "memory");

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]