Author: Armin Rigo <[email protected]>
Branch: stm-thread-2
Changeset: r60046:b0df504dfd7b
Date: 2013-01-14 09:48 +0100
http://bitbucket.org/pypy/pypy/changeset/b0df504dfd7b/

Log:    Trying to implement the idea of decreasing the limit more subtly:
        set it to 94% of the read size at the point the abort occurred.
        (This is what I meant, and not f3d388a6c22d from stm-logging.)
        Measures needed.

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
@@ -367,6 +367,7 @@
 static void AbortTransaction(int num)
 {
   struct tx_descriptor *d = thread_descriptor;
+  long limit;
   assert(d->active);
   assert(!is_inevitable(d));
   assert(num < ABORT_REASONS);
@@ -374,6 +375,15 @@
 
   CancelLocks(d);
 
+  /* upon abort, set the reads size limit to 94% of how much was read
+     so far.  This should ensure that, assuming the retry does the same
+     thing, it will commit just before it reaches the conflicting point. */
+  limit = d->list_of_read_objects.size;
+  if (limit > 0) {
+      limit -= (limit >> 4);
+      d->reads_size_limit_nonatomic = limit;
+  }
+
   gcptrlist_clear(&d->list_of_read_objects);
   gcptrlist_clear(&d->gcroots);
   g2l_clear(&d->global_to_local);
diff --git a/pypy/translator/stm/src_stm/rpyintf.c 
b/pypy/translator/stm/src_stm/rpyintf.c
--- a/pypy/translator/stm/src_stm/rpyintf.c
+++ b/pypy/translator/stm/src_stm/rpyintf.c
@@ -154,12 +154,19 @@
   do
     {
       v_counter = counter + 1;
-      /* initialize 'reads_size_limit_nonatomic' from the configured
-         length limit, scaled down by a factor of 2 for each time we
-         retry an aborted transaction.  Note that as soon as such a
-         shortened transaction succeeds, the next one will again have
-         full length, for now. */
-      d->reads_size_limit_nonatomic = stm_regular_length_limit >> counter;
+      /* If counter==0, initialize 'reads_size_limit_nonatomic' from the
+         configured length limit.  If counter>0, we did an abort, which
+         has configured 'reads_size_limit_nonatomic' to a smaller value.
+         When such a shortened transaction succeeds, the next one will
+         see its length limit doubled, up to the maximum. */
+      if (counter == 0) {
+          long limit = d->reads_size_limit_nonatomic;
+          if (limit != 0 && limit < (stm_regular_length_limit >> 1))
+              limit = (limit << 1) | 1;
+          else
+              limit = stm_regular_length_limit;
+          d->reads_size_limit_nonatomic = limit;
+      }
       if (!d->atomic)
         BeginTransaction(&_jmpbuf);
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to