[pypy-commit] pypy stm: (antocuni, arigo)

arigo noreply at buildbot.pypy.org
Mon Jan 16 18:56:28 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51362:f565b7971e14
Date: 2012-01-16 18:55 +0100
http://bitbucket.org/pypy/pypy/changeset/f565b7971e14/

Log:	(antocuni, arigo)

	A way to get and test the current transaction mode, for debugging.

diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -36,3 +36,4 @@
 
 descriptor_init = _rffi_stm.stm_descriptor_init
 descriptor_done = _rffi_stm.stm_descriptor_done
+debug_get_state = _rffi_stm.stm_debug_get_state
diff --git a/pypy/rlib/test/test_rstm.py b/pypy/rlib/test/test_rstm.py
--- a/pypy/rlib/test/test_rstm.py
+++ b/pypy/rlib/test/test_rstm.py
@@ -9,18 +9,24 @@
 
 def setx(arg):
     debug_print(arg.x)
+    assert rstm.debug_get_state() == 1
     if arg.x == 303:
         # this will trigger stm_become_inevitable()
         os.write(1, "hello\n")
+        assert rstm.debug_get_state() == 2
     arg.x = 42
 
 
 def test_stm_perform_transaction(initial_x=202):
     arg = Arg()
     arg.x = initial_x
+    assert rstm.debug_get_state() == -1
     rstm.descriptor_init()
+    assert rstm.debug_get_state() == 0
     rstm.perform_transaction(setx, Arg, arg)
+    assert rstm.debug_get_state() == 0
     rstm.descriptor_done()
+    assert rstm.debug_get_state() == -1
     assert arg.x == 42
 
 
diff --git a/pypy/translator/stm/_rffi_stm.py b/pypy/translator/stm/_rffi_stm.py
--- a/pypy/translator/stm/_rffi_stm.py
+++ b/pypy/translator/stm/_rffi_stm.py
@@ -46,3 +46,4 @@
                                      [CALLBACK, rffi.VOIDP], rffi.VOIDP)
 
 stm_abort_and_retry = llexternal('stm_abort_and_retry', [], lltype.Void)
+stm_debug_get_state = llexternal('stm_debug_get_state', [], lltype.Signed)
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
@@ -82,9 +82,7 @@
   owner_version_t my_lock_word;
   unsigned init_counter;
   struct RedoLog redolog;   /* last item, because it's the biggest one */
-#ifdef RPY_STM_ASSERT
   int transaction_active;
-#endif
 };
 
 /* global_timestamp contains in its lowest bit a flag equal to 1
@@ -148,9 +146,7 @@
 
 static _Bool is_inevitable(struct tx_descriptor *d)
 {
-#ifdef RPY_STM_ASSERT
   assert(d->transaction_active);
-#endif
   return is_inevitable_or_inactive(d);
 }
 
@@ -254,10 +250,8 @@
 {
   d->reads.size = 0;
   redolog_clear(&d->redolog);
-#ifdef RPY_STM_ASSERT
   assert(d->transaction_active);
   d->transaction_active = 0;
-#endif
   d->setjmp_buf = NULL;
 }
 
@@ -687,10 +681,8 @@
 void stm_begin_transaction(jmp_buf* buf)
 {
   struct tx_descriptor *d = thread_descriptor;
-#ifdef RPY_STM_ASSERT
   assert(!d->transaction_active);
   d->transaction_active = 1;
-#endif
   d->setjmp_buf = buf;
   d->start_time = d->last_known_global_timestamp & ~1;
 }
@@ -842,9 +834,7 @@
   struct tx_descriptor *d = thread_descriptor;
   unsigned long curtime;
 
-#ifdef RPY_STM_ASSERT
   assert(!d->transaction_active);
-#endif
 
  retry:
   mutex_lock();   /* possibly waiting here */
@@ -861,10 +851,8 @@
       if (bool_cas(&global_timestamp, curtime, curtime + 1))
         break;
     }
-#ifdef RPY_STM_ASSERT
   assert(!d->transaction_active);
   d->transaction_active = 1;
-#endif
   d->setjmp_buf = NULL;
   d->start_time = curtime;
 #ifdef COMMIT_OTHER_INEV
@@ -974,4 +962,17 @@
 #endif
 }
 
+long stm_debug_get_state(void)
+{
+  struct tx_descriptor *d = thread_descriptor;
+  if (!d)
+    return -1;
+  if (!d->transaction_active)
+    return 0;
+  if (!is_inevitable(d))
+    return 1;
+  else
+    return 2;
+}
+
 #endif  /* PYPY_NOT_MAIN_FILE */
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
@@ -37,6 +37,10 @@
 void stm_abort_and_retry(void);
 void stm_descriptor_init_and_being_inevitable_transaction(void);
 void stm_commit_transaction_and_descriptor_done(void);
+long stm_debug_get_state(void);  /* -1: descriptor_init() was not called
+                                     0: not in a transaction
+                                     1: in a regular transaction
+                                     2: in an inevitable transaction */
 
 /* for testing only: */
 #define STM_begin_transaction()         ; \
diff --git a/pypy/translator/stm/test/test_rffi_stm.py b/pypy/translator/stm/test/test_rffi_stm.py
--- a/pypy/translator/stm/test/test_rffi_stm.py
+++ b/pypy/translator/stm/test/test_rffi_stm.py
@@ -50,6 +50,19 @@
             return lltype.nullptr(rffi.VOIDP.TO)
     stm_descriptor_init()
     stm_perform_transaction(llhelper(CALLBACK, callback1),
-                        lltype.nullptr(rffi.VOIDP.TO))
+                            lltype.nullptr(rffi.VOIDP.TO))
     stm_descriptor_done()
     assert a.x == 420
+
+def test_stm_debug_get_state():
+    def callback1(x):
+        assert stm_debug_get_state() == 1
+        stm_try_inevitable()
+        assert stm_debug_get_state() == 2
+        return lltype.nullptr(rffi.VOIDP.TO)
+    assert stm_debug_get_state() == -1
+    stm_descriptor_init()
+    assert stm_debug_get_state() == 0
+    stm_perform_transaction(llhelper(CALLBACK, callback1),
+                            lltype.nullptr(rffi.VOIDP.TO))
+    stm_descriptor_done()


More information about the pypy-commit mailing list