[pypy-commit] pypy stm-thread-2: in-progress

arigo noreply at buildbot.pypy.org
Thu Sep 6 12:43:53 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread-2
Changeset: r57170:19cc3d85b179
Date: 2012-09-06 12:17 +0200
http://bitbucket.org/pypy/pypy/changeset/19cc3d85b179/

Log:	in-progress

diff --git a/pypy/rpython/memory/gctransform/boehmstm.py b/pypy/rpython/memory/gctransform/boehmstm.py
new file mode 100644
--- /dev/null
+++ b/pypy/rpython/memory/gctransform/boehmstm.py
@@ -0,0 +1,8 @@
+from pypy.rpython.memory.gctransform.boehm import BoehmGCTransformer
+from pypy.rpython.lltypesystem import lltype
+
+
+class BoehmSTMGCTransformer(BoehmGCTransformer):
+    HDR = lltype.Struct("header", ("hash", lltype.Signed),
+                                  ("tid", lltype.Signed),    # for flags only
+                                  ("revision", lltype.Unsigned))
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -603,6 +603,8 @@
             from pypy.translator.stm.funcgen import op_stm
             self.__class__.op_stm = op_stm
         return self.op_stm(op)
+    OP_STM_START_TRANSACTION = _OP_STM
+    OP_STM_STOP_TRANSACTION = _OP_STM
     OP_STM_BECOME_INEVITABLE = _OP_STM
     OP_STM_BARRIER = _OP_STM
     OP_STM_PTR_EQ = _OP_STM
diff --git a/pypy/translator/c/gc.py b/pypy/translator/c/gc.py
--- a/pypy/translator/c/gc.py
+++ b/pypy/translator/c/gc.py
@@ -199,6 +199,9 @@
 class BoehmGcPolicy(BasicGcPolicy):
 
     def gettransformer(self):
+        if self.db.translator.config.translation.stm:
+            from pypy.rpython.memory.gctransform import boehmstm
+            return boehmstm.BoehmSTMGCTransformer(self.db.translator)
         from pypy.rpython.memory.gctransform import boehm
         return boehm.BoehmGCTransformer(self.db.translator)
 
@@ -227,7 +230,7 @@
         from pypy.rpython.tool.rffi_platform import configure_boehm
         eci = eci.merge(configure_boehm())
 
-        pre_include_bits = []
+        pre_include_bits = ['#define USING_BOEHM_GC']
         if sys.platform.startswith('linux'):
             pre_include_bits += ["#define _REENTRANT 1",
                                  "#define GC_LINUX_THREADS 1"]
@@ -237,7 +240,6 @@
 
         eci = eci.merge(ExternalCompilationInfo(
             pre_include_bits=pre_include_bits,
-            post_include_bits=['#define USING_BOEHM_GC'],
             ))
 
         return eci
diff --git a/pypy/translator/stm/funcgen.py b/pypy/translator/stm/funcgen.py
--- a/pypy/translator/stm/funcgen.py
+++ b/pypy/translator/stm/funcgen.py
@@ -1,6 +1,18 @@
 from pypy.translator.c.support import c_string_constant
 
 
+def stm_start_transaction(funcgen, op):
+    # only for Boehm.  With stmgc, this operation should have been handled
+    # already by gctransform.
+    assert funcgen.db.translator.config.translation.gc == 'boehm'
+    return '/* stm_boehm_start_transaction(); */'
+
+def stm_stop_transaction(funcgen, op):
+    # only for Boehm.  With stmgc, this operation should have been handled
+    # already by gctransform.
+    assert funcgen.db.translator.config.translation.gc == 'boehm'
+    return 'stm_boehm_stop_transaction();'
+
 def stm_barrier(funcgen, op):
     level = op.args[0].value
     assert type(level) is str
@@ -20,7 +32,7 @@
     except IndexError:
         info = "rstm.become_inevitable"    # cannot insert it in 'llop'
     string_literal = c_string_constant(info)
-    return 'stm_try_inevitable(%s);' % (string_literal,)
+    return 'BecomeInevitable(%s);' % (string_literal,)
 
 def stm_jit_invoke_code(funcgen, op):
     XXX
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -11,11 +11,14 @@
 #include <assert.h>
 #include <pthread.h>
 
+#ifndef RPY_STM
+/* for tests, a few custom defines */
 #define RPY_STM_DEBUG_PRINT     1
 #define PYPY_DEBUG_START(s)     fprintf(stderr, "start: %s\n", s)
 #define PYPY_DEBUG_STOP(s)      fprintf(stderr, " stop: %s\n", s)
 #define PYPY_HAVE_DEBUG_PRINTS  1
 #define PYPY_DEBUG_FILE         stderr
+#endif
 
 #include "et.h"
 
@@ -178,17 +181,17 @@
   return R;
 }
 
-gcptr _DirectReadBarrier(gcptr G)
+gcptr stm_DirectReadBarrier(gcptr G)
 {
   return _direct_read_barrier(G, NULL, 0);
 }
 
-gcptr _DirectReadBarrierFromR(gcptr G, gcptr R_Container, size_t offset)
+gcptr stm_DirectReadBarrierFromR(gcptr G, gcptr R_Container, size_t offset)
 {
   return _direct_read_barrier(G, R_Container, offset);
 }
 
-gcptr _RepeatReadBarrier(gcptr O)
+gcptr stm_RepeatReadBarrier(gcptr O)
 {
   // LatestGlobalRevision(O) would either return O or abort
   // the whole transaction, so omitting it is not wrong
@@ -198,6 +201,7 @@
   return entry->val;
 }
 
+#if 0
 gcptr _NonTransactionalReadBarrier(gcptr P)
 {
   /* testing only: use this outside transactions to check the state */
@@ -217,6 +221,7 @@
     fprintf(stderr, "[---%p possibly outdated---]\n", P);
   return P;
 }
+#endif
 
 static gcptr Localize(struct tx_descriptor *d, gcptr R)
 {
@@ -236,7 +241,7 @@
   return L;
 }
 
-gcptr _WriteBarrier(gcptr P)
+gcptr stm_WriteBarrier(gcptr P)
 {
   gcptr R, W;
   if (!(P->h_tid & GCFLAG_GLOBAL))
@@ -259,7 +264,7 @@
   return W;
 }
 
-gcptr _WriteBarrierFromReady(gcptr R)
+gcptr stm_WriteBarrierFromReady(gcptr R)
 {
   gcptr W;
   if (!(R->h_tid & GCFLAG_GLOBAL))
@@ -650,7 +655,7 @@
   return P;
 }
 
-_Bool PtrEq(gcptr P1, gcptr P2)
+_Bool stm_PtrEq(gcptr P1, gcptr P2)
 {
   struct tx_descriptor *d = thread_descriptor;
   return GlobalizeForComparison(d, P1) == GlobalizeForComparison(d, P2);
@@ -658,10 +663,9 @@
 
 /************************************************************/
 
-void DescriptorInit(void)
+int DescriptorInit(void)
 {
-  assert(thread_descriptor == NULL);
-  if (1)
+  if (thread_descriptor == NULL)
     {
       struct tx_descriptor *d = malloc(sizeof(struct tx_descriptor));
       memset(d, 0, sizeof(struct tx_descriptor));
@@ -693,7 +697,10 @@
                 (long)d->my_lock, (long)pthread_self());
       PYPY_DEBUG_STOP("stm-init");
 #endif
+      return 1;
     }
+  else
+    return 0;
 }
 
 void DescriptorDone(void)
diff --git a/pypy/translator/stm/src_stm/et.h b/pypy/translator/stm/src_stm/et.h
--- a/pypy/translator/stm/src_stm/et.h
+++ b/pypy/translator/stm/src_stm/et.h
@@ -58,6 +58,10 @@
     (__builtin_expect((((gcptr)(P))->h_tid & GCFLAG_NOT_WRITTEN) == 0, 1) ? \
      (P) : (typeof(P))stm_WriteBarrier((gcptr)(P)))
 
+#define STM_BARRIER_G2W(G)                              \
+    (assert(((gcptr)(G))->h_tid & GCFLAG_GLOBAL),       \
+     (typeof(G))stm_WriteBarrier((gcptr)(G)))
+
 #define STM_BARRIER_R2W(R)                                                  \
     (__builtin_expect((((gcptr)(R))->h_tid & GCFLAG_NOT_WRITTEN) == 0, 1) ? \
      (R) : (typeof(R))stm_WriteBarrierFromReady((gcptr)(R)))
@@ -72,7 +76,7 @@
 void CommitTransaction(void);
 void BecomeInevitable(const char *why);
 //void BeginInevitableTransaction(void);
-void DescriptorInit(void);
+int DescriptorInit(void);
 void DescriptorDone(void);
 int _FakeReach(gcptr P);
 
@@ -105,4 +109,9 @@
                              void *save_and_restore);
 void stm_abort_and_retry(void);
 
+#ifdef USING_BOEHM_GC
+# define OP_GC_ADR_OF_ROOT_STACK_TOP(r)   r = NULL
+void stm_boehm_stop_transaction(void);
+#endif
+
 #endif  /* _ET_H */


More information about the pypy-commit mailing list