Author: Remi Meier
Branch: contention-counter
Changeset: r651:ce3149d0935f
Date: 2014-01-10 13:20 +0100
http://bitbucket.org/pypy/stmgc/changeset/ce3149d0935f/

Log:    do penalty/contention based scheduling

diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -99,16 +99,16 @@
 /* CONTENTION COUNTER THINGS */
 #define RPY_STM_CONT_RMA_SAMPLES 64
 
+gcptr get_original_of(gcptr P)
+{
+  if (UNLIKELY(!(P->h_tid & GCFLAG_PREBUILT_ORIGINAL)) && P->h_original)
+    return (gcptr)P->h_original;
+  return P;
+}
+
 void abort_because_of(gcptr L) 
 {
-  gcptr obj = (gcptr)L->h_original;
-  if (!obj || (L->h_tid & GCFLAG_PREBUILT_ORIGINAL)) {
-    obj = L;
-
-    /* abort-object should never be a priv_from_prot
-       *without* an original */
-    assert(!(L->h_tid & GCFLAG_PRIVATE_FROM_PROTECTED));
-  }
+  gcptr obj = get_original_of(L);
 
   //g->h_contention += (g->h_contention + 1) << 2;
   revision_t old =  (RPY_STM_CONT_RMA_SAMPLES - 1) * obj->h_contention;
@@ -119,9 +119,7 @@
 
 void commit_object(gcptr L)
 {
-  gcptr obj = L;
-  if (!(L->h_tid & GCFLAG_PREBUILT_ORIGINAL) && L->h_original)
-    obj = (gcptr)L->h_original;
+  gcptr obj = get_original_of(L);
 
   revision_t old = obj->h_contention;
   revision_t old_rma = (RPY_STM_CONT_RMA_SAMPLES - 1) * old;
@@ -129,6 +127,8 @@
   obj->h_contention = old_rma / RPY_STM_CONT_RMA_SAMPLES;
 }
 
+
+
 /************************************************************/
 
 static void ValidateNow(struct tx_descriptor *);
@@ -306,6 +306,10 @@
      added just now by a parallel thread during stealing... */
   /*assert(!(P->h_tid & GCFLAG_MOVED));*/
   fxcache_add(&d->recent_reads_cache, P);
+
+  /* update penalty for reading */
+  gcptr o = get_original_of(P);
+  d->penalty += (o->h_contention >> 1) + 1;
   return P;
 
  follow_stub:;
@@ -1156,6 +1160,7 @@
   assert(!g2l_any_entry(&d->public_to_private));
   assert(d->old_thread_local_obj == NULL);
 
+  d->penalty = 0;
   d->count_reads = 1;
   fxcache_clear(&d->recent_reads_cache);
   gcptrlist_clear(&d->abortinfo);
diff --git a/c4/et.h b/c4/et.h
--- a/c4/et.h
+++ b/c4/et.h
@@ -173,6 +173,8 @@
   /* sync with pypy stmgc: */
   NURSERY_FIELDS_DECL
 
+  revision_t penalty;
+  
   long atomic;   /* 0 = not atomic, > 0 atomic */
   unsigned long count_reads;
   unsigned long reads_size_limit;        /* see should_break_tr. */
diff --git a/c4/stmsync.c b/c4/stmsync.c
--- a/c4/stmsync.c
+++ b/c4/stmsync.c
@@ -46,7 +46,8 @@
         assert(d->reads_size_limit_nonatomic == 0);
 #endif
 
-    return (sync_required | d->count_reads) >= d->reads_size_limit;
+    return (sync_required | d->penalty) >= d->reads_size_limit;
+    /* return (sync_required | d->count_reads) >= d->reads_size_limit; */
 }
 
 static void init_shadowstack(void)
@@ -179,12 +180,12 @@
            When such a shortened transaction succeeds, the next one will
            see its length limit doubled, up to the maximum. */
         if (counter == 0 && stm_active != 2) {
-            unsigned 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;
+            /* unsigned 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) {
             stm_begin_transaction(&_jmpbuf, NULL);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to