[pypy-commit] pypy stm-thread-2: Keep the abort info corresponding to the longest aborted transaction,

arigo noreply at buildbot.pypy.org
Fri Feb 22 17:49:01 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread-2
Changeset: r61619:181f9b1e8484
Date: 2013-02-22 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/181f9b1e8484/

Log:	Keep the abort info corresponding to the longest aborted
	transaction, in case there are several aborts before
	charp_inspect_abort_info() is called.

diff --git a/rpython/translator/stm/src_stm/et.c b/rpython/translator/stm/src_stm/et.c
--- a/rpython/translator/stm/src_stm/et.c
+++ b/rpython/translator/stm/src_stm/et.c
@@ -58,7 +58,8 @@
   struct G2L global_to_local;
   struct GcPtrList undolog;
   struct GcPtrList abortinfo;
-  char *lastabortinfo;
+  char *longest_abort_info;
+  long long longest_abort_info_time;
   struct FXCache recent_reads_cache;
 };
 
@@ -395,22 +396,34 @@
     elapsed_time = now.tv_sec - d->start_real_time.tv_sec;
     elapsed_time *= 1000000000;
     elapsed_time += now.tv_nsec - d->start_real_time.tv_nsec;
+    if (elapsed_time < 1)
+      elapsed_time = 1;
   }
   else {
-    elapsed_time = -1;
+    elapsed_time = 1;
   }
 
-  /* decode the 'abortinfo' and produce a human-readable summary in
-     the string 'lastabortinfo' */
-  size = _stm_decode_abort_info(d, elapsed_time, num, NULL);
-  free(d->lastabortinfo);
-  d->lastabortinfo = malloc(size);
-  if (d->lastabortinfo != NULL)
-    if (_stm_decode_abort_info(d, elapsed_time, num, d->lastabortinfo) != size)
-      {
-        fprintf(stderr, "during stm abort: object mutated unexpectedly\n");
-        abort();
-      }
+  if (elapsed_time >= d->longest_abort_info_time)
+    {
+      /* decode the 'abortinfo' and produce a human-readable summary in
+         the string 'longest_abort_info' */
+      size = _stm_decode_abort_info(d, elapsed_time, num, NULL);
+      free(d->longest_abort_info);
+      d->longest_abort_info = malloc(size);
+      if (d->longest_abort_info == NULL)
+        d->longest_abort_info_time = 0;   /* out of memory! */
+      else
+        {
+          if (_stm_decode_abort_info(d, elapsed_time,
+                                     num, d->longest_abort_info) != size)
+            {
+              fprintf(stderr,
+                      "during stm abort: object mutated unexpectedly\n");
+              abort();
+            }
+          d->longest_abort_info_time = elapsed_time;
+        }
+    }
 
   /* run the undo log in reverse order, cancelling the values set by
      stm_ThreadLocalRef_LLSet(). */
diff --git a/rpython/translator/stm/src_stm/rpyintf.c b/rpython/translator/stm/src_stm/rpyintf.c
--- a/rpython/translator/stm/src_stm/rpyintf.c
+++ b/rpython/translator/stm/src_stm/rpyintf.c
@@ -307,7 +307,10 @@
 char *stm_inspect_abort_info(void)
 {
     struct tx_descriptor *d = thread_descriptor;
-    return d->lastabortinfo;
+    if (d->longest_abort_info_time <= 0)
+        return NULL;
+    d->longest_abort_info_time = 0;
+    return d->longest_abort_info;
 }
 
 long stm_extraref_llcount(void)
diff --git a/rpython/translator/stm/test/test_ztranslated.py b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -143,12 +143,14 @@
                 globf.xy = 100 + retry_counter
 
         def check(_, retry_counter):
+            last = rstm.charp_inspect_abort_info()
             rstm.abort_info_push(globf, ('[', 'xy', ']', 'yx'))
             setxy(globf, retry_counter)
             if retry_counter < 3:
                 rstm.abort_and_retry()
             #
-            print rffi.charp2str(rstm.charp_inspect_abort_info())
+            print rffi.charp2str(last)
+            print int(bool(rstm.charp_inspect_abort_info()))
             #
             rstm.abort_info_pop(2)
             return 0
@@ -158,9 +160,10 @@
 
         def main(argv):
             Parent().xy = 0
+            globf.xy = -2
             globf.yx = 'hi there %d' % len(argv)
             perform_transaction(lltype.nullptr(PS.TO))
             return 0
         t, cbuilder = self.compile(main)
         data = cbuilder.cmdexec('a b')
-        assert 'li102ee10:hi there 3e\n' in data
+        assert 'li102ee10:hi there 3e\n0\n' in data


More information about the pypy-commit mailing list