Commits

Armin Rigo  committed 65eb6e4

Tweaks.

  • Participants
  • Parent commits 755507f
  • Branches stm

Comments (0)

Files changed (4)

File pypy/translator/stm/funcgen.py

 
 
 def op_stm(funcgen, op):
-    assert funcgen.db.translator.stm_transformation_applied
+    if not getattr(funcgen.db.translator, 'stm_transformation_applied', None):
+        raise AssertionError("STM transformation not applied.  You need '--stm'")
     func = globals()[op.opname]
     return func(funcgen, op)

File pypy/translator/stm/src_stm/et.c

 #include "src_stm/et.h"
 #include "src_stm/atomic_ops.h"
 
-#ifdef RPY_STM_ASSERT
+#ifdef PYPY_STANDALONE         /* obscure: cannot include debug_print.h if compiled */
+# define RPY_STM_DEBUG_PRINT   /* via ll2ctypes; only include it in normal builds */
 # include "src/debug_print.h"
 #endif
 
 /* mutex: only to avoid busy-looping too much in tx_spinloop() below */
 static pthread_mutex_t mutex_inevitable = PTHREAD_MUTEX_INITIALIZER;
 # ifdef RPY_STM_ASSERT
+unsigned long locked_by = 0;
 void mutex_lock(void)
 {
   unsigned long pself = (unsigned long)pthread_self();
   if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE,
                                       "%lx: mutex inev locking...\n", pself);
+  assert(locked_by != pself);
   pthread_mutex_lock(&mutex_inevitable);
+  locked_by = pself;
   if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE,
                                       "%lx: mutex inev locked\n", pself);
 }
 void mutex_unlock(void)
 {
   unsigned long pself = (unsigned long)pthread_self();
+  locked_by = 0;
   pthread_mutex_unlock(&mutex_inevitable);
   if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE,
                                       "%lx: mutex inev unlocked\n", pself);
 
 void stm_descriptor_init(void)
 {
-#ifdef RPY_STM_ASSERT
-  PYPY_DEBUG_START("stm-init");
-#endif
   if (thread_descriptor != NULL)
     thread_descriptor->init_counter++;
   else
       struct tx_descriptor *d = malloc(sizeof(struct tx_descriptor));
       memset(d, 0, sizeof(struct tx_descriptor));
 
+#ifdef RPY_STM_DEBUG_PRINT
+      PYPY_DEBUG_START("stm-init");
+#endif
+
       /* initialize 'my_lock_word' to be a unique negative number */
       d->my_lock_word = (owner_version_t)d;
       if (!IS_LOCKED(d->my_lock_word))
       d->init_counter = 1;
 
       thread_descriptor = d;
+
+#ifdef RPY_STM_DEBUG_PRINT
+      if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE, "thread %lx starting\n",
+                                          d->my_lock_word);
+      PYPY_DEBUG_STOP("stm-init");
+#endif
     }
-#ifdef RPY_STM_ASSERT
-  PYPY_DEBUG_STOP("stm-init");
-#endif
 }
 
 void stm_descriptor_done(void)
 
   thread_descriptor = NULL;
 
-#ifdef RPY_STM_ASSERT
+#ifdef RPY_STM_DEBUG_PRINT
   PYPY_DEBUG_START("stm-done");
   if (PYPY_HAVE_DEBUG_PRINTS) {
     int num_aborts = 0, num_spinloops = 0;
   struct tx_descriptor *d = thread_descriptor;
   unsigned long curtime;
 
+#ifdef RPY_STM_ASSERT
+  assert(!d->transaction_active);
+#endif
+
  retry:
   mutex_lock();   /* possibly waiting here */
 

File pypy/translator/stm/test/targetdemo.py

 
 
 NUM_THREADS = 4
-LENGTH      = 1000
+LENGTH      = 10000
 
 
 class Node:

File pypy/translator/stm/transform.py

                 self.add_stm_declare_variable(graph)
             if self.seen_gc_stack_bottom:
                 self.add_descriptor_init_stuff(graph)
-        self.add_descriptor_init_stuff(entrypointgraph)
+        self.add_descriptor_init_stuff(entrypointgraph, main=True)
         self.translator.stm_transformation_applied = True
 
     def transform_block(self, block):
         for block in graph.iterblocks():
             self.transform_block(block)
 
-    def add_descriptor_init_stuff(self, graph):
-        f_init = _rffi_stm.descriptor_init_and_being_inevitable_transaction
-        f_done = _rffi_stm.commit_transaction_and_descriptor_done
+    def add_descriptor_init_stuff(self, graph, main=False):
+        if main:
+            f_init = _rffi_stm.descriptor_init_and_being_inevitable_transaction
+            f_done = _rffi_stm.commit_transaction_and_descriptor_done
+        else:
+            f_init = _rffi_stm.descriptor_init
+            f_done = _rffi_stm.descriptor_done
         c_init = Constant(f_init, lltype.typeOf(f_init))
         c_done = Constant(f_done, lltype.typeOf(f_done))
         #
         if STRUCT._immutable_field(op.args[1].value):
             op1 = op
         elif STRUCT._gckind == 'raw':
-            turn_inevitable(newoperations, "getfield_raw")
+            turn_inevitable(newoperations, "getfield-raw")
             op1 = op
         else:
             op1 = SpaceOperation('stm_getfield', op.args, op.result)
         if STRUCT._immutable_field(op.args[1].value):
             op1 = op
         elif STRUCT._gckind == 'raw':
-            turn_inevitable(newoperations, "setfield_raw")
+            turn_inevitable(newoperations, "setfield-raw")
             op1 = op
         else:
             op1 = SpaceOperation('stm_setfield', op.args, op.result)