[pypy-commit] pypy stm: Progress.

arigo noreply at buildbot.pypy.org
Sun Oct 30 17:05:41 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48609:e6522686416a
Date: 2011-10-30 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/e6522686416a/

Log:	Progress.

diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -134,7 +134,7 @@
         if self.config.translation.stm:
             from pypy.translator.stm import transform
             transformer = transform.STMTransformer(self.translator)
-            transformer.transform()
+            transformer.transform(self.getentrypointptr())
             log.info("Software Transactional Memory transformation applied")
 
         gcpolicyclass = self.get_gcpolicyclass()
@@ -472,7 +472,9 @@
         s_result = annmodel.SomeInteger()
         graph = mix.getgraph(entrypoint_wrapper, args_s, s_result)
         mix.finish()
-        return getfunctionptr(graph)
+        res = getfunctionptr(graph)
+        self._entrypoint_wrapper = res
+        return res
 
     def cmdexec(self, args='', env=None, err=False, expect_crash=False):
         assert self._compiled
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,6 @@
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.objspace.flow.model import Constant
-from pypy.translator.c.support import cdecl
+from pypy.translator.c.support import cdecl, c_string_constant
 from pypy.translator.stm.rstm import size_of_voidp
 
 
@@ -105,7 +105,9 @@
     return 'STM_TRANSACTION_BOUNDARY();'
 
 def stm_try_inevitable(funcgen, op):
-    return 'stm_try_inevitable();'
+    info = op.args[0].value
+    string_literal = c_string_constant(info)
+    return 'stm_try_inevitable(STM_EXPLAIN1(%s));' % (string_literal,)
 
 
 def op_stm(funcgen, op):
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
@@ -21,6 +21,7 @@
 
 #include "src_stm/et.h"
 #include "src_stm/atomic_ops.h"
+#include "src/debug_print.h"
 
 /************************************************************/
 
@@ -537,6 +538,7 @@
 
 void stm_descriptor_init(void)
 {
+  PYPY_DEBUG_START("stm-init");
   if (thread_descriptor != NULL)
     thread_descriptor->init_counter++;
   else
@@ -554,6 +556,7 @@
 
       thread_descriptor = d;
     }
+  PYPY_DEBUG_STOP("stm-init");
 }
 
 void stm_descriptor_done(void)
@@ -563,36 +566,40 @@
   if (d->init_counter > 0)
     return;
 
+  PYPY_DEBUG_START("stm-done");
   thread_descriptor = NULL;
 
-  int num_aborts = 0, num_spinloops = 0;
-  int i, prevchar;
-  for (i=0; i<ABORT_REASONS; i++)
-    num_aborts += d->num_aborts[i];
-  for (i=0; i<SPINLOOP_REASONS; i++)
-    num_spinloops += d->num_spinloops[i];
+  if (PYPY_HAVE_DEBUG_PRINTS) {
+    int num_aborts = 0, num_spinloops = 0;
+    int i, prevchar;
+    for (i=0; i<ABORT_REASONS; i++)
+      num_aborts += d->num_aborts[i];
+    for (i=0; i<SPINLOOP_REASONS; i++)
+      num_spinloops += d->num_spinloops[i];
 
-  fprintf(stderr, "thread %lx: %d commits, %d aborts ",
-          d->my_lock_word,
-          d->num_commits,
-          num_aborts);
+    fprintf(PYPY_DEBUG_FILE, "thread %lx: %d commits, %d aborts ",
+            d->my_lock_word,
+            d->num_commits,
+            num_aborts);
 
-  for (i=0; i<ABORT_REASONS; i++)
-    fprintf(stderr, "%c%d", i == 0 ? '[' : ',',
-            d->num_aborts[i]);
+    for (i=0; i<ABORT_REASONS; i++)
+      fprintf(PYPY_DEBUG_FILE, "%c%d", i == 0 ? '[' : ',',
+              d->num_aborts[i]);
 
-  for (i=1; i<SPINLOOP_REASONS; i++)  /* num_spinloops[0] == num_aborts */
-    fprintf(stderr, "%c%d", i == 1 ? '|' : ',',
-            d->num_spinloops[i]);
+    for (i=1; i<SPINLOOP_REASONS; i++)  /* num_spinloops[0] == num_aborts */
+      fprintf(PYPY_DEBUG_FILE, "%c%d", i == 1 ? '|' : ',',
+              d->num_spinloops[i]);
 
 #ifdef COMMIT_OTHER_INEV
-  for (i=0; i<OTHERINEV_REASONS; i++)
-    fprintf(stderr, "%c%d", i == 0 ? '|' : ',',
-            d->num_otherinev[i]);
+    for (i=0; i<OTHERINEV_REASONS; i++)
+      fprintf(PYPY_DEBUG_FILE, "%c%d", i == 0 ? '|' : ',',
+              d->num_otherinev[i]);
 #endif
 
-  fprintf(stderr, "]\n");
+    fprintf(PYPY_DEBUG_FILE, "]\n");
+  }
   free(d);
+  PYPY_DEBUG_STOP("stm-done");
 }
 
 void* stm_perform_transaction(void*(*callback)(void*), void *arg)
@@ -690,7 +697,7 @@
   return d->end_time;
 }
 
-void stm_try_inevitable(void)
+void stm_try_inevitable(STM_CCHARP1(why))
 {
   /* when a transaction is inevitable, its start_time is equal to
      global_timestamp and global_timestamp cannot be incremented
@@ -699,11 +706,22 @@
   struct tx_descriptor *d = thread_descriptor;
 
 #ifdef RPY_ASSERT
+  PYPY_DEBUG_START("stm-inevitable");
+  if (PYPY_HAVE_DEBUG_PRINTS)
+    {
+      fprintf(PYPY_DEBUG_FILE, "%s%s\n", why,
+              is_inevitable(d) ? " (already inevitable)" : "");
+    }
   assert(d->transaction_active);
 #endif
 
   if (is_inevitable(d))
-    return;  /* I am already inevitable */
+    {
+#ifdef RPY_ASSERT
+      PYPY_DEBUG_STOP("stm-inevitable");
+#endif
+      return;  /* I am already inevitable */
+    }
 
   while (1)
     {
@@ -740,13 +758,16 @@
   CFENCE;
   d_inev_checking = 1;
 #endif
+#ifdef RPY_ASSERT
+  PYPY_DEBUG_STOP("stm-inevitable");
+#endif
 }
 
-void stm_try_inevitable_if(jmp_buf *buf)
+void stm_try_inevitable_if(jmp_buf *buf  STM_CCHARP(why))
 {
   struct tx_descriptor *d = thread_descriptor;
-  if (d && d->setjmp_buf == buf)    /* XXX remove the test for 'd != NULL' */
-    stm_try_inevitable();
+  if (d->setjmp_buf == buf)
+    stm_try_inevitable(STM_EXPLAIN1(why));
 }
 
 void stm_begin_inevitable_transaction(void)
@@ -793,9 +814,15 @@
 
 void stm_transaction_boundary(jmp_buf* buf)
 {
+#ifdef RPY_ASSERT
+  PYPY_DEBUG_START("stm-boundary");
+#endif
   stm_commit_transaction();
   setjmp(*buf);
   stm_begin_transaction(buf);
+#ifdef RPY_ASSERT
+  PYPY_DEBUG_STOP("stm-boundary");
+#endif
 }
 
 // XXX little-endian only!
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
@@ -11,6 +11,18 @@
 #include <setjmp.h>
 #include "src/commondefs.h"
 
+#ifdef RPY_ASSERT
+#  define STM_CCHARP(arg)     , char* arg
+#  define STM_CCHARP1(arg)    char* arg
+#  define STM_EXPLAIN(info)   , info
+#  define STM_EXPLAIN1(info)  info
+#else
+#  define STM_CCHARP(arg)     /* nothing */
+#  define STM_CCHARP1(arg)    void
+#  define STM_EXPLAIN(info)   /* nothing */
+#  define STM_EXPLAIN1(info)  /* nothing */
+#endif
+
 
 void stm_descriptor_init(void);
 void stm_descriptor_done(void);
@@ -19,8 +31,8 @@
 long stm_commit_transaction(void);
 long stm_read_word(long* addr);
 void stm_write_word(long* addr, long val);
-void stm_try_inevitable(void);
-void stm_try_inevitable_if(jmp_buf* buf);
+void stm_try_inevitable(STM_CCHARP1(why));
+void stm_try_inevitable_if(jmp_buf* buf  STM_CCHARP(why));
 void stm_begin_inevitable_transaction(void);
 void stm_abort_and_retry(void);
 void stm_transaction_boundary(jmp_buf* buf);
@@ -31,8 +43,9 @@
        setjmp(_jmpbuf);                   \
        stm_begin_transaction(&_jmpbuf)
 
-#define STM_DECLARE_VARIABLE()          jmp_buf jmpbuf
-#define STM_MAKE_INEVITABLE()           stm_try_inevitable_if(&jmpbuf)
+#define STM_DECLARE_VARIABLE()          ; jmp_buf jmpbuf
+#define STM_MAKE_INEVITABLE()           stm_try_inevitable_if(&jmpbuf  \
+                                                        STM_EXPLAIN("return"))
 #define STM_TRANSACTION_BOUNDARY()      stm_transaction_boundary(&jmpbuf)
 
 // XXX little-endian only!
diff --git a/pypy/translator/stm/test/targetdemo.py b/pypy/translator/stm/test/targetdemo.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/stm/test/targetdemo.py
@@ -0,0 +1,22 @@
+#from pypy.module.thread import ll_thread
+from pypy.translator.stm import rstm
+
+
+
+
+
+# __________  Entry point  __________
+
+def entry_point(argv):
+    print "hello world"
+    rstm.transaction_boundary()
+    i = 100
+    while i > 1:
+        i *= 0.821
+    rstm.transaction_boundary()
+    return 0
+
+# _____ Define and setup target ___
+
+def target(*args):
+    return entry_point, None
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -1,11 +1,13 @@
-from pypy.objspace.flow.model import SpaceOperation
+from pypy.objspace.flow.model import SpaceOperation, Constant
+from pypy.annotation import model as annmodel
+from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
 from pypy.translator.stm import _rffi_stm
 from pypy.translator.unsimplify import varoftype
 from pypy.rpython.lltypesystem import lltype
 
 
 ALWAYS_ALLOW_OPERATIONS = set([
-    'int_*', 'uint_*', 'llong_*', 'ullong_*',
+    'int_*', 'uint_*', 'llong_*', 'ullong_*', 'float_*',
     'same_as', 'cast_*',
     'direct_call',
     'debug_print', 'debug_assert',
@@ -27,13 +29,17 @@
     def __init__(self, translator=None):
         self.translator = translator
 
-    def transform(self):
+    def transform(self, entrypointptr):
+        assert not hasattr(self.translator, 'stm_transformation_applied')
+        entrypointgraph = entrypointptr._obj.graph
         for graph in self.translator.graphs:
+            if graph is entrypointgraph:
+                continue
             self.seen_transaction_boundary = False
             self.transform_graph(graph)
             if self.seen_transaction_boundary:
                 self.add_stm_declare_variable(graph)
-        self.add_descriptor_init_stuff()
+        self.add_descriptor_init_stuff(entrypointgraph)
         self.translator.stm_transformation_applied = True
 
     def transform_block(self, block):
@@ -64,17 +70,24 @@
         for block in graph.iterblocks():
             self.transform_block(block)
 
-    def add_descriptor_init_stuff(self):
-        from pypy.translator.unsimplify import call_initial_function
-        from pypy.translator.unsimplify import call_final_function
+    def add_descriptor_init_stuff(self, entrypointgraph):
+        #
         def descriptor_init():
             _rffi_stm.descriptor_init()
             _rffi_stm.begin_inevitable_transaction()
-        def descriptor_done():
-            _rffi_stm.commit_transaction()
-            _rffi_stm.descriptor_done()
-        call_initial_function(self.translator, descriptor_init)
-        call_final_function(self.translator, descriptor_done)
+        #def descriptor_done():
+        #    _rffi_stm.commit_transaction()
+        #    _rffi_stm.descriptor_done()
+        #
+        annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
+        c_init = annhelper.constfunc(descriptor_init, [], annmodel.s_None)
+        #c_done = annhelper.constfunc(descriptor_done, [], annmodel.s_None)
+        annhelper.finish()
+        block = entrypointgraph.startblock
+        v = varoftype(lltype.Void)
+        op = SpaceOperation('direct_call', [c_init], v)
+        block.operations.insert(0, op)
+        #...add c_done...
 
     def add_stm_declare_variable(self, graph):
         block = graph.startblock
@@ -111,6 +124,8 @@
 
 
 def turn_inevitable_and_proceed(newoperations, op):
-    op1 = SpaceOperation('stm_try_inevitable', [], varoftype(lltype.Void))
+    c_info = Constant(op.opname, lltype.Void)
+    op1 = SpaceOperation('stm_try_inevitable', [c_info],
+                         varoftype(lltype.Void))
     newoperations.append(op1)
     newoperations.append(op)


More information about the pypy-commit mailing list