summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-05-17 09:33:10 -0500
committerNicholas E. Bofferding <bofferdn@us.ibm.com>2011-05-17 16:29:14 -0500
commit523f96160485edfd91adf1f789f9200fc80ba6e1 (patch)
treeccf356d1d35e36edf48a65bb444a5d35c9ac9d68 /src
parent7313facde362f1c29a4d579a918d7429f4cf2a6d (diff)
downloadtalos-hostboot-523f96160485edfd91adf1f789f9200fc80ba6e1.tar.gz
talos-hostboot-523f96160485edfd91adf1f789f9200fc80ba6e1.zip
Fix weak consistency bug in guard-aquire/guard-release
Change-Id: Iac6ff2df14ce5c900a0d4af90f475100dc5ad75f Reviewed-on: http://gfwr801.rchland.ibm.com:8080/gerrit/78 Tested-by: Jenkins Server Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/libc++/builtins.C47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/libc++/builtins.C b/src/libc++/builtins.C
index a336c46c3..04ea744f9 100755
--- a/src/libc++/builtins.C
+++ b/src/libc++/builtins.C
@@ -1,6 +1,8 @@
#include <stdint.h>
#include <stdlib.h>
+#include <arch/ppc.H>
+
void* operator new(size_t s)
{
return malloc(s);
@@ -33,50 +35,33 @@ void operator delete[](void* p)
extern "C" int __cxa_guard_acquire(volatile uint64_t* gv)
{
- // 0 -> uninitialized
- // 1 -> locked
- // 2 -> unlocked and initialized
+ // States:
+ // 0 -> uninitialized
+ // 1 -> locked
+ // 2 -> unlocked and initialized
uint32_t v = __sync_val_compare_and_swap((volatile uint32_t*)gv, 0, 1);
if (v == 0)
return 1;
if (v == 2)
return 0;
+
+ // Wait for peer thread to perform initialization (state 2).
while(2 != *(volatile uint32_t*)gv);
+
+ // Instruction barrier to ensure value is set before later loads execute.
+ isync();
+
return 0;
-/*
- register volatile void* guard = gv;
- register uint32_t c = 0;
-
- asm volatile(
- "__cxa_guard_acquire_begin:"
- "lwarx %0,0,%1;" // Load guard with reserve
- "cmpi 0,%0,0;" // Compare with 0
- "bne+ __cxa_guard_acquire_finish;" // != 0, goto "finished"
- "li %0, 1;" // Set to 1.
- "stwcx. %0,0,%1;" // Store against reserve
- "bne- __cxa_guard_acquire_begin;" // goto begin if failed store.
- "li %0, 3;" // Set to 3 -> success in lock
- "__cxa_guard_acquire_finish:"
- : "+r" (c) : "r" (guard): "memory","cc"
- );
- while (2 > c)
- {
- asm volatile("lwz %0, 0(%1);" : "=r" (c) : "r" (guard));
- }
- return (3 == c ? 1 : 0); // 3 means success in lock, return 1 (obtained)
- // 2 means initialized, return 0
-*/
}
extern "C" void __cxa_guard_release(volatile uint64_t* gv)
{
+ // Memory barrier to ensure all preceeding writes have completed before
+ // releasing guard.
+ lwsync();
+
(*(volatile uint32_t*)gv) = 2;
- /*
- register volatile void* guard = gv;
- register uint32_t c = 2;
- asm volatile("stw %0, 0(%1)" :: "r"(c) , "r" (guard): "memory");
- */
return;
}
OpenPOWER on IntegriCloud