1. Pypy
  2. Untitled project
  3. stmgc

Commits

Remi Meier  committed ce3149d

do penalty/contention based scheduling

  • Participants
  • Parent commits 83115a1
  • Branches contention-counter

Comments (0)

Files changed (3)

File c4/et.c

View file
 /* 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;
 
 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;
   obj->h_contention = old_rma / RPY_STM_CONT_RMA_SAMPLES;
 }
 
+
+
 /************************************************************/
 
 static void ValidateNow(struct tx_descriptor *);
      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:;
   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);

File c4/et.h

View file
   /* 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. */

File c4/stmsync.c

View file
         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)
            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);