changes:
authorbdemsky <bdemsky>
Mon, 8 Nov 2010 08:09:12 +0000 (08:09 +0000)
committerbdemsky <bdemsky>
Mon, 8 Nov 2010 08:09:12 +0000 (08:09 +0000)
(1) create traversers only for non leaf threads
(2) fixup stuff to have separate tables for separate weakly connected components
(3) fixup stallsite code

12 files changed:
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/RuntimeConflictResolver.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h
Robust/src/Runtime/oooJava/TODO
Robust/src/Runtime/oooJava/hashStructure.c
Robust/src/Runtime/oooJava/hashStructure.h
Robust/src/Runtime/oooJava/rcr_runtime.c
Robust/src/Runtime/oooJava/rcr_runtime.h
Robust/src/Runtime/oooJava/trqueue.c
Robust/src/Runtime/oooJava/trqueue.h
Robust/src/Runtime/workschedule.c

index 3cfd382773baa4fb60ef2c459b28842df0857dce..a6f4cea64658716ec5d996dc758f7b54c046ad0f 100644 (file)
@@ -379,7 +379,7 @@ public class BuildCode {
     if(rcr != null) {
       rcr.close();
       System.out.println("Runtime Conflict Resolver Done.");
-    }  
+    }
   }
   
   /* This method goes though the call graph and tag those methods that are 
@@ -2564,6 +2564,10 @@ public class BuildCode {
     if( !fsen.getIsLeafSESE() ) {
       output.println("   runningSESE->taskRecordMemPool = poolcreate( "+
                      maxTaskRecSizeStr+", freshTaskRecordInitializer );");
+      if (state.RCR) {
+       output.println("   createTR();");
+       output.println("   runningSESE->allHashStructures=TRqueue->allHashStructures;");
+      }
     } else {
       // make it clear we purposefully did not initialize this
       output.println("   runningSESE->taskRecordMemPool = (MemPool*)0x7;");
@@ -3102,6 +3106,87 @@ public class BuildCode {
     throw new Error();
   }
 
+
+  void stallMEMRCR(FlatMethod fm, FlatNode fn, Set<Analysis.OoOJava.WaitingElement> waitingElementSet, PrintWriter output) {
+    output.println("// stall on parent's stall sites ");
+    output.println("   {");
+    output.println("     REntry* rentry;");
+    output.println("     SESEstall * stallrecord=(SESEstall *) poolalloc(runningSESE->taskRecordMemPool);");
+    output.println("     stallrecord->common.unresolvedDependencies=10000;");
+    output.println("     stallrecord->common.rcrstatus=1;");
+    output.println("     stallrecord->common.offsetToParamRecords=(INTPTR) & (((SESEstall *)0)->rcrRecords);");
+    output.println("     stallrecord->common.refCount = 3;");
+    output.println("     stallrecord->tag=rentry->tag;");
+    output.println("     int localCount=10000;");
+    output.println("     stallrecord->rcrRecords[0].index=0;");
+    output.println("     stallrecord->rcrRecords[0].flag=0;");
+    output.println("     stallrecord->rcrRecords[0].next=NULL;");
+    output.println("     stallrecord->common.parentsStallSem=&runningSESEstallSem;");
+
+    TempDescriptor stalltd=null;
+    for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
+      Analysis.OoOJava.WaitingElement waitingElement =(Analysis.OoOJava.WaitingElement) iterator.next();
+      if (waitingElement.getStatus() >= ConflictNode.COARSE) {
+       output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["
+                      + waitingElement.getQueueID() + "]," + waitingElement.getStatus()
+                      + ", (SESEcommon *) stallrecord, 1LL);");
+      } else {
+       throw new Error("Fine-grained conflict: This should not happen in RCR");
+      }
+      output.println("     rentry->parentStallSem=&runningSESEstallSem;");
+      output.println("     psem_reset( &runningSESEstallSem);");
+      output.println("     rentry->tag=runningSESEstallSem.tag;");
+      output.println("     rentry->queue=runningSESE->memoryQueueArray["
+                    + waitingElement.getQueueID() + "];");
+      output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["
+                    + waitingElement.getQueueID() + "],rentry)==READY) ");
+      output.println("       localCount--;");
+      if (stalltd==null) {
+       stalltd=waitingElement.getTempDesc();
+      } else if (stalltd!=waitingElement.getTempDesc()) {
+       throw new Error("Multiple temp descriptors at stall site"+stalltd+"!="+waitingElement.getTempDesc());
+      }
+    }
+
+    //did all of the course grained stuff
+    output.println("     if(!atomic_sub_and_test(localCount, &(stallrecord->common.unresolvedDependencies))) {");
+    //have to do fine-grained work also
+    output.println("       stallrecord->___obj___=(struct ___Object___ *)"
+                  + generateTemp(fm, stalltd, null) + ";");
+    output.println("       stallrecord->common.classID=-"
+                  + rcr.getTraverserID(stalltd, fn) + ";");
+
+    output.println("       enqueueTR(TRqueue, (void *)stallrecord);");
+
+    if (state.COREPROF) {
+      output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+      output
+       .println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
+      output.println("#endif");
+    }    
+    
+    output.println("       psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
+    
+    if (state.COREPROF) {
+      output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+      output
+       .println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
+      output.println("#endif");
+    }
+
+    output.println("     } else {");//exit if condition
+    //release traversers reference if we didn't use traverser
+    output.println("#ifndef OOO_DISABLE_TASKMEMPOOL");
+    output.println("  RELEASE_REFERENCE_TO((SESEcommon *)stallrecord);");
+    output.println("#endif");
+    output.println("     }");
+    //release our reference to stall record
+    output.println("#ifndef OOO_DISABLE_TASKMEMPOOL");
+    output.println("  RELEASE_REFERENCE_TO((SESEcommon *)stallrecord);");
+    output.println("#endif");
+    output.println("   }");//exit block
+  }
+
   protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) {
 
     // insert pre-node actions from the code plan
@@ -3286,88 +3371,55 @@ public class BuildCode {
             Set<Analysis.OoOJava.WaitingElement> waitingElementSet = graph.getStallSiteWaitingElementSet(fn, seseLockSet);
             
             if (waitingElementSet.size() > 0) {
-              output.println("// stall on parent's stall sites ");
-              output.println("   {");
-              output.println("     REntry* rentry;");
-
-              for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
-                Analysis.OoOJava.WaitingElement waitingElement =
-                    (Analysis.OoOJava.WaitingElement) iterator.next();
-                if (waitingElement.getStatus() >= ConflictNode.COARSE) {
-                  if (state.RCR) {
-                    output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["
-                        + waitingElement.getQueueID() + "]," + waitingElement.getStatus()
-                        + ", runningSESE, 1LL);");
-                  } else {
-                    output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["
-                        + waitingElement.getQueueID() + "]," + waitingElement.getStatus()
-                        + ", runningSESE);");
-                  }
-                } else {
-                  output.println("     rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["
-                      + waitingElement.getQueueID() + "]," + waitingElement.getStatus()
-                      + ", runningSESE,  (void*)&"
-                      + generateTemp(fm, waitingElement.getTempDesc(), lb) + ");");
-                }
-                output.println("     rentry->parentStallSem=&runningSESEstallSem;");
-                output.println("     psem_reset( &runningSESEstallSem);");
-                output.println("     rentry->tag=runningSESEstallSem.tag;");
-                output.println("     rentry->queue=runningSESE->memoryQueueArray["
-                    + waitingElement.getQueueID() + "];");
-                output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["
-                    + waitingElement.getQueueID() + "],rentry)==NOTREADY){");
-                if (state.COREPROF) {
-                  output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
-                  output
+             if (state.RCR) {
+               stallMEMRCR(fm, fn, waitingElementSet, output);
+             } else {
+               output.println("// stall on parent's stall sites ");
+               output.println("   {");
+               output.println("     REntry* rentry;");
+               
+               for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
+                 Analysis.OoOJava.WaitingElement waitingElement =
+                   (Analysis.OoOJava.WaitingElement) iterator.next();
+                 if (waitingElement.getStatus() >= ConflictNode.COARSE) {
+                   output.println("     rentry=mlpCreateREntry(runningSESE->memoryQueueArray["
+                                  + waitingElement.getQueueID() + "]," + waitingElement.getStatus()
+                                  + ", runningSESE);");
+                 } else {
+                   output.println("     rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray["
+                                  + waitingElement.getQueueID() + "]," + waitingElement.getStatus()
+                                  + ", runningSESE,  (void*)&"
+                                  + generateTemp(fm, waitingElement.getTempDesc(), lb) + ");");
+                 }
+                 output.println("     rentry->parentStallSem=&runningSESEstallSem;");
+                 output.println("     psem_reset( &runningSESEstallSem);");
+                 output.println("     rentry->tag=runningSESEstallSem.tag;");
+                 output.println("     rentry->queue=runningSESE->memoryQueueArray["
+                                + waitingElement.getQueueID() + "];");
+                 output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["
+                                + waitingElement.getQueueID() + "],rentry)==NOTREADY){");
+                 if (state.COREPROF) {
+                   output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+                   output
                       .println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
-                  output.println("#endif");
-                }
-                if (state.RCR) {
-                  // no need to enqueue parent effect if coarse grained conflict
-                  // clears us
-
-                  output.println("       while(stallrecord.common.rcrstatus) BARRIER();");
-                  // was the code above actually meant to look like this?
-                  // output.println("       while(stallrecord.common.rcrstatus) {");
-                  // output.println("         BARRIER();");
-                  // output.println("         sched_yield();");
-                  // output.println("       }");
-
-                  output.println("       stallrecord.common.parentsStallSem=&runningSESEstallSem;");
-                  output.println("       stallrecord.tag=rentry->tag;");
-                  output.println("       stallrecord.___obj___=(struct ___Object___ *)"
-                      + generateTemp(fm, waitingElement.getTempDesc(), null) + ";");
-                  output.println("       stallrecord.common.classID=-"
-                      + rcr.getTraverserID(waitingElement.getTempDesc(), fn) + ";");
-                  // mark the record used..so we won't use it again until it is
-                  // free
-                  // clear rcrRecord
-                  output.println("       stallrecord.rcrRecords[0].index=0;");
-                  output.println("       stallrecord.rcrRecords[0].flag=0;");
-                  output.println("       stallrecord.rcrRecords[0].next=NULL;");
-                  output.println("       stallrecord.common.rcrstatus=1;");
-                  output.println("       enqueueTR(TRqueue, (void *)&stallrecord);");
-                }
-
-                output
-                    .println("       psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
-
-                if (state.RCR) {
-                  output.println("       stallrecord.common.rcrstatus=0;");
-                }
-
-                if (state.COREPROF) {
-                  output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
-                  output
+                   output.println("#endif");
+                 }
+                 
+                 output.println("       psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
+                 
+                 if (state.COREPROF) {
+                   output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+                   output
                       .println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
-                  output.println("#endif");
-                }
-                output.println("     }  ");
-              }
-              output.println("   }");
-            }
-          }
-        }else{
+                   output.println("#endif");
+                 }
+                 output.println("     }  ");
+               }
+               output.println("   }");
+             }
+           }
+         }
+        } else{
           ParentChildConflictsMap conflictsMap = mlpa.getConflictsResults().get(fn);
           if (conflictsMap != null) {
             Set<Long> allocSet = conflictsMap.getAllocationSiteIDSetofStallSite();
@@ -4205,8 +4257,6 @@ public class BuildCode {
         output.println("     }");
       }
 
-
-
       if( state.COREPROF ) {
         output.println("#ifdef CP_EVENTID_PREPAREMEMQ");
         output.println("     CP_LOGEVENT( CP_EVENTID_PREPAREMEMQ, CP_EVENTTYPE_BEGIN );");
@@ -4703,20 +4753,20 @@ public class BuildCode {
       output.println("   }");
       output.println("{");
       output.println("  int idx,idx2;");
-      if(inset.size()==1){
-        output.println("  idx=0; {");
-      } else {
-        output.println("  for(idx=0;idx<" + inset.size() + ";idx++){");
+
+      //NEED TO FIX THIS
+      //XXXXXXXXX
+      output.println("    struct rcrRecord *rec;");
+      output.println("    struct Hashtable_rcr ** hashstruct=runningSESE->parent->allHashStructures;");
+      for(int i=0;i<inset.size();i++) {
+       output.println("    rec=&" + paramsprefix + "->rcrRecords["+i+"];");
+       output.println("    while(rec!=NULL) {");
+       output.println("      for(idx2=0;idx2<rec->index;idx2++) {");
+       output.println("        rcr_RETIREHASHTABLE(hashstruct["+rcr.getWeakID(inset.get(i),fsen)+"],&(___params___->common), rec->array[idx2], (BinItem_rcr *) rec->ptrarray[idx2]);");
+       output.println("      }");// exit idx2 for loop
+       output.println("      rec=rec->next;");
+       output.println("    }");// exit rec while loop
       }
-      output.println("    struct rcrRecord *rec=&" + paramsprefix + "->rcrRecords[idx];");
-      output.println("    while(rec!=NULL) {");
-      output.println("      for(idx2=0;idx2<rec->index;idx2++) {");
-      output
-          .println("        rcr_RETIREHASHTABLE(allHashStructures[0],&(___params___->common),rec->array[idx2], (BinItem_rcr *) rec->ptrarray[idx2]);");
-      output.println("      }");// exit idx2 for loop
-      output.println("      rec=rec->next;");
-      output.println("    }");// exit rec while loop
-      output.println("  }");// exit idx for loop
       output.println("}");
     }
 
@@ -4744,6 +4794,9 @@ public class BuildCode {
     // destroy this task's mempool if it is not a leaf task
     if( !fsen.getIsLeafSESE() ) {
       output.println("     pooldestroy( runningSESE->taskRecordMemPool );");
+      if (state.RCR) {
+        output.println("     returnTR();");
+      }
     }
     output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
 
index a326d8649ec95fe18728997d66a9fc7a2045fb12..b68bf535a92ec3779709d78f7f1c98713856ee4a 100644 (file)
@@ -38,6 +38,7 @@ public class RuntimeConflictResolver {
   //The Integer keeps track of the weakly connected group it's in (used in enumerateHeapRoots)
   private Hashtable<Taint, Integer> doneTaints;
   private Hashtable<Tuple, Integer> idMap=new Hashtable<Tuple,Integer>();
+  private Hashtable<Tuple, Integer> weakMap=new Hashtable<Tuple,Integer>();
   private Hashtable<Taint, Set<Effect>> globalEffects;
   private Hashtable<Taint, Set<Effect>> globalConflicts;
   private ArrayList<TraversalInfo> toTraverse;
@@ -307,6 +308,10 @@ public class RuntimeConflictResolver {
     removeInvalidChars(flatname) + "___("+varString+");";
   }
 
+  public int getWeakID(TempDescriptor invar, FlatNode fn) {
+    return weakMap.get(new Tuple(invar, fn)).intValue();
+  }
+
   public int getTraverserID(TempDescriptor invar, FlatNode fn) {
     Tuple t=new Tuple(invar, fn);
     if (idMap.containsKey(t))
@@ -379,20 +384,27 @@ public class RuntimeConflictResolver {
 
   //TODO: This is only temporary, remove when thread local variables are functional. 
   private void createMasterHashTableArray() {
-    headerFile.println("void createAndFillMasterHashStructureArray();");
-    cFile.println("void createAndFillMasterHashStructureArray() {\n" +
-               "  rcr_createMasterHashTableArray("+weaklyConnectedHRCounter + ");");
+    headerFile.println("struct Hashtable_rcr ** createAndFillMasterHashStructureArray();");
+    cFile.println("struct Hashtable_rcr ** createAndFillMasterHashStructureArray() {");
+    cFile.println("  struct Hashtable_rcr **table=rcr_createMasterHashTableArray("+weaklyConnectedHRCounter + ");");
     
     for(int i = 0; i < weaklyConnectedHRCounter; i++) {
-      cFile.println("  allHashStructures["+i+"] = (HashStructure *) rcr_createHashtable("+num2WeaklyConnectedHRGroup.get(i).connectedHRs.size()+");");
+      cFile.println("  table["+i+"] = (struct Hashtable_rcr *) rcr_createHashtable("+num2WeaklyConnectedHRGroup.get(i).connectedHRs.size()+");");
     }
+    cFile.println("  return table;");
     cFile.println("}");
   }
 
   private void printMasterTraverserInvocation() {
     headerFile.println("\nint tasktraverse(SESEcommon * record);");
     cFile.println("\nint tasktraverse(SESEcommon * record) {");
-    cFile.println("  if(!CAS(&record->rcrstatus,1,2)) return;");
+    cFile.println("  if(!CAS(&record->rcrstatus,1,2)) {");
+    //release traverser reference...no traversal necessary
+    cFile.println("#ifndef OOO_DISABLE_TASKMEMPOOL");
+    cFile.println("    RELEASE_REFERENCE_TO(record);");
+    cFile.println("#endif");
+    cFile.println("    return;");
+    cFile.println("  }");
     cFile.println("  switch(record->classID) {");
     
     for(Iterator<FlatSESEEnterNode> seseit=oooa.getAllSESEs().iterator();seseit.hasNext();) {
@@ -422,6 +434,11 @@ public class RuntimeConflictResolver {
     cFile.println("    default:\n    printf(\"Invalid SESE ID was passed in: %d.\\n\",record->classID);\n    break;");
     
     cFile.println("  }");
+    //release traverser reference...traversal finished...
+    //executing thread will clean bins for us
+    cFile.println("#ifndef OOO_DISABLE_TASKMEMPOOL");
+    cFile.println("    RELEASE_REFERENCE_TO(record);");
+    cFile.println("#endif");
     cFile.println("}");
   }
 
@@ -656,14 +673,10 @@ public class RuntimeConflictResolver {
       cFile.println(" return;");
     } else {
       cFile.println("    int totalcount=RUNBIAS;");      
-      if (taint.isStallSiteTaint()) {
+      if (!taint.isStallSiteTaint()) {
         cFile.println("    record->rcrRecords[0].count=RUNBIAS;");
-        cFile.println("    record->rcrRecords[0].index=0;");
-        cFile.println("    record->rcrRecords[0].next=NULL;");
       } else {
         cFile.println("    record->rcrRecords["+index+"].count=RUNBIAS;");
-        cFile.println("    record->rcrRecords["+index+"].index=0;");
-        cFile.println("    record->rcrRecords["+index+"].next=NULL;");
       }
       
       //clears queue and hashtable that keeps track of where we've been. 
@@ -690,8 +703,8 @@ public class RuntimeConflictResolver {
         cFile.println("     if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords[0].count))) {");
         cFile.println("         psem_give_tag(record->common.parentsStallSem, record->tag);");
         cFile.println("         BARRIER();");
-        cFile.println("         record->common.rcrstatus=0;");
         cFile.println("}");
+        cFile.println("         record->common.rcrstatus=0;");
       } else {
         cFile.println("     if(atomic_sub_and_test(RUNBIAS-totalcount,&(record->rcrRecords["+index+"].count))) {");
         cFile.println("        int flag=LOCKXCHG32(&(record->rcrRecords["+index+"].flag),0);");
@@ -914,6 +927,14 @@ public class RuntimeConflictResolver {
         num2WeaklyConnectedHRGroup.add(weaklyConnectedHRCounter, hg);
         weaklyConnectedHRCounter++;
       }
+      if(t.isRBlockTaint()) {
+       int id=connectedHRHash.get(t).id;
+       Tuple tup=new Tuple(t.getVar(),t.getSESE());
+       if (weakMap.containsKey(tup)) {
+         if (weakMap.get(tup).intValue()!=id)
+           throw new Error("Var/SESE not unique for weak component.");
+       } else weakMap.put(tup, new Integer(id));
+      }
     }
   }
   
index ee4a593feaba8fda8b97049597cc8ee5ff45074b..b7b458c8f70cdfc0d2c5ebba19aa4c1aee2a847c 100644 (file)
@@ -828,7 +828,13 @@ void resolveDependencies(REntry* rentry){
       }
     }
   } else if (type==PARENTCOARSE) {
-    psem_give_tag(rentry->parentStallSem, rentry->tag);
+    if (atomic_sub_and_test(1, &(seseCommon->unresolvedDependencies))) {
+      psem_give_tag(rentry->parentStallSem, rentry->tag);
+      //release our reference to stallrecord
+#ifndef OOO_DISABLE_TASKMEMPOOL
+      RELEASE_REFERENCE_TO(seseCommon);
+#endif
+    }
   } else {
     printf("ERROR: REntry type %d should never be generated in RCR..\n", rentry->type);
   }
index 63365aa56dc673ffccfbd4ec2652f3b184049d97..b52bb5690c9305ae4b5c679223af12a10b0c8969 100644 (file)
@@ -120,6 +120,7 @@ typedef struct SESEcommon_t {
   struct REntry_t* unresolvedRentryArray[NUMRENTRY];
 
 #ifdef RCR
+  struct Hashtable_rcr ** allHashStructures;
   int offsetToParamRecords;
   volatile int rcrstatus;
   volatile int retired;
index 551a2d3265493fe113fe63a6bf66d8890460ea9e..b217103d19f53e1e01a9014a262101f32713a1da 100644 (file)
@@ -6,3 +6,4 @@ Big TODOS:
 5) Recycling [recycle entries to improve runtime]
 6) Parallelize traversal
 7) Fix race on enqueue into table vs dequeue at retire... - done
+8) Fix stall stie handling -- done
\ No newline at end of file
index 414c6ea5eef60adf80c7078e32ee19e2e79ef09f..b7152ed6da020cd5b00d7fd69ccbc87184850e16 100644 (file)
@@ -8,7 +8,7 @@
 
 //NOTE: this is only temporary (for testing) and will be removed in favor of thread local variables
 //It's basically an array of hashStructures so we can simulate what would happen in a many-threaded version
-HashStructure ** allHashStructures;
+__thread HashStructure ** allHashStructures;
 #define ISWRITEBIN(x) (x&BINMASK)
 #define ISREADBIN(x) (!(x&BINMASK))
 //#define POPCOUNT(x) __builtin_popcountll(x)
@@ -39,8 +39,8 @@ inline enqueuerecord(struct rcrRecord *rcrrec, int tmpkey, BinItem_rcr *item) {
 }
 
 //NOTE: only temporary
-void rcr_createMasterHashTableArray(int maxSize){
-  allHashStructures = (HashStructure **) malloc(sizeof(HashStructure *) * maxSize);
+HashStructure ** rcr_createMasterHashTableArray(int maxSize){
+  return (HashStructure **) malloc(sizeof(HashStructure *) * maxSize);
 }
 
 HashStructure* rcr_createHashtable(int sizeofWaitingQueue){
index eb47a0cfdc184ea4a23abeb0543f89e7a0375783..4e324c65ad9a9e2de8e1a406e3fe0b3937db39b8 100644 (file)
@@ -72,9 +72,9 @@ typedef struct ReadBinItem_rcr {
   int index;
 } ReadBinItem_rcr;
 
-extern HashStructure ** allHashStructures;
+extern __thread HashStructure ** allHashStructures;
 
-void rcr_createMasterHashTableArray(int maxSize); //temporary
+HashStructure ** rcr_createMasterHashTableArray(int maxSize); //temporary
 HashStructure* rcr_createHashtable(int sizeofWaitingQueue);
 WriteBinItem_rcr* rcr_createWriteBinItem();
 ReadBinItem_rcr* rcr_createReadBinItem();
index 52b42a5668b62ce2d1fe6ea69e129b894d5504e9..3112ef89940b97242c504bfda130f7644c591115 100644 (file)
@@ -1,11 +1,13 @@
 #include "trqueue.h"
 #include "mlp_runtime.h"
 #include "rcr_runtime.h"
+#include "hashStructure.h"
 #include "structdefs.h"
 #include "RuntimeConflictResolver.h"
 
 void * workerTR(void *x) {
   struct trQueue * queue=(struct trQueue *)x;
+  allHashStructures=queue->allHashStructures;
   while(1) {
     SESEcommon * tmp;
     do {
@@ -23,4 +25,3 @@ void * workerTR(void *x) {
   return NULL;
 }
 
-__thread SESEstall stallrecord;
index aa2ad3f3204d849955e4c5d4899f4ac5594a0f5d..e32e081b663c699b231e2d245c37ec95c9adfec9 100644 (file)
@@ -5,5 +5,4 @@ extern __thread struct trQueue * TRqueue;
 
 void * workerTR(void *);
 
-extern __thread SESEstall stallrecord;
 #endif
index 55d105a0ac613b257472bb835fe4d9fc14d6fc45..68ef603f07798c14134af2494336b9fd124b842a 100644 (file)
@@ -2,6 +2,12 @@
 #include "stdlib.h"
 #include "stdio.h"
 #include "mlp_lock.h"
+#include <pthread.h>
+#include "structdefs.h"
+#include "RuntimeConflictResolver.h"
+
+struct trQueue * queuelist=NULL;
+pthread_mutex_t queuelock;
 
 //0 would mean sucess
 //1 would mean fail
@@ -34,10 +40,35 @@ void * dequeueTR(struct trQueue *q) {
   return ptr;
 }
 
-struct trQueue * allocTR() {
-  struct trQueue *ptr=malloc(sizeof(struct trQueue));
-  ptr->head=0;
-  ptr->tail=0;
-  return ptr;
+void createTR() {
+  struct trQueue *ptr=NULL;
+  pthread_mutex_lock(&queuelock);
+  ptr=queuelist;
+  if (ptr!=NULL)
+    queuelist=ptr->next;
+  pthread_mutex_unlock(&queuelock);
+  if (ptr==NULL) {
+    pthread_t thread;
+    pthread_attr_t nattr;
+    pthread_attr_init(&nattr);
+    pthread_attr_setdetachstate( &nattr, PTHREAD_CREATE_DETACHED);
+    ptr=malloc(sizeof(struct trQueue));
+    ptr->head=0;
+    ptr->tail=0;
+    ptr->allHashStructures=createAndFillMasterHashStructureArray();
+    int status=pthread_create( &thread, NULL, workerTR, (void *) ptr);
+    if (status!=0) {printf("ERROR\n");exit(-1);}
+    pthread_attr_destroy(&nattr);
+  }
+  TRqueue=ptr;
 }
 
+void returnTR() {
+  //return worker thread to pool
+  pthread_mutex_lock(&queuelock);
+  TRqueue->next=queuelist;
+  queuelist=TRqueue;
+  pthread_mutex_unlock(&queuelock);
+  //release our worker thread
+  TRqueue=NULL;
+}
index 28f974996c57112ab9966b3954aa2ce52a4ee714..575ca8b584b1d5311032f8feb01fc837c07d0493 100644 (file)
@@ -10,9 +10,12 @@ struct trQueue {
   volatile unsigned int head;
   char buffer[60];//buffer us to the next cache line
   volatile unsigned int tail;
+  struct trQueue *next;
+  struct Hashtable_rcr ** allHashStructures;
 };
 
 void enqueueTR(struct trQueue *, void * ptr);
 void * dequeueTR(struct trQueue *);
-struct trQueue * allocTR();
+void createTR();
+void returnTR();
 #endif
index 07709e85278f1655a5369835b9c49cfa6743db23..333bfb0e4cde9afc02ab0118e4768a29e4920c85 100644 (file)
@@ -27,7 +27,9 @@ int threadcount;
 pthread_mutex_t gclock;
 pthread_mutex_t gclistlock;
 pthread_cond_t gccond;
-
+#ifdef RCR
+extern pthread_mutex_t queuelock;
+#endif
 // in garbage.h, listitem is a struct with a pointer
 // to a stack, objects, etc. such that the garbage
 // collector can find pointers for garbage collection
@@ -128,38 +130,6 @@ void* workerMain( void* arg ) {
   // pass to the collector if collection occurs
   struct garbagelist emptygarbagelist = { 0, NULL };
 
-#ifdef RCR
-  //allocate task record queue
-  pthread_t thread;
-  pthread_attr_t nattr;  
-  pthread_attr_init( &nattr );
-  pthread_attr_setdetachstate( &nattr, PTHREAD_CREATE_DETACHED );
-
-  //set up the stall site SESErecord
-  stallrecord.common.offsetToParamRecords=(INTPTR) &((SESEstall *)0)->rcrRecords;
-  stallrecord.common.classID=-1;
-  stallrecord.common.rcrstatus=0;
-
-  //initialize rcrRecord
-  stallrecord.rcrRecords[0].next=NULL;
-  stallrecord.rcrRecords[0].index=0;
-  stallrecord.rcrRecords[0].count=0;
-
-  if( TRqueue == NULL ) {
-    TRqueue = allocTR();
-  }
-
-  int status = pthread_create( &thread,
-                              NULL,
-                              workerTR,
-                              (void*) TRqueue );
-
-  pthread_attr_destroy( &nattr );
-
-  if( status != 0 ) { printf( "Error\n" ); exit( -1 ); }
-#endif
-
-
   // Add this worker to the gc list
   pthread_mutex_lock( &gclistlock );
   threadcount++;
@@ -295,6 +265,9 @@ void workScheduleInit( int numProcessors,
   myWorkerID = 0;
   oid = 1;
 
+#ifdef RCR
+  pthread_mutex_init( &queuelock,     NULL );
+#endif
   pthread_mutex_init( &gclock,     NULL );
   pthread_mutex_init( &gclistlock, NULL );
   pthread_cond_init ( &gccond,     NULL );
@@ -311,12 +284,6 @@ void workScheduleInit( int numProcessors,
     dqInit( &(deques[i]) );
   }
   
-#ifdef RCR
-  //make sure the queue is initialized
-  if (TRqueue==NULL)
-    TRqueue=allocTR();
-#endif
-
   pthread_attr_init( &attr );
   pthread_attr_setdetachstate( &attr, 
                                PTHREAD_CREATE_JOINABLE );