changes. get rid of unnecessary iteration over the queue.
authoryeom <yeom>
Thu, 28 Jan 2010 02:03:06 +0000 (02:03 +0000)
committeryeom <yeom>
Thu, 28 Jan 2010 02:03:06 +0000 (02:03 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h

index 2ff070616836e1bf65a85bee3e8b24b14e0d58e5..cdcfb03f79aee23e03e943cf47e24a81625401c5 100644 (file)
@@ -3418,9 +3418,6 @@ public class BuildCode {
                        
                        output.println();
                        output.println("     /*add waiting queue element*/");
-                       output.println("     pthread_mutex_lock( &(parentCommon->lock) );");
-                       output.println("     struct Queue*  newWaitingItemQueue=createQueue();");
-                       
                        Set<WaitingElement> waitingQueueSet=graph.getWaitingElementSetBySESEID(fsen
                                        .getIdentifier(),seseLockSet);
                        if (waitingQueueSet.size() > 0) {
@@ -3430,7 +3427,7 @@ public class BuildCode {
                                output.println("     WaitingElement* newElement=NULL;");
                                output.println("     struct Queue* list=NULL;");
                                output.println("     struct QueueItem* newQItem=NULL;");
-//                             output.println("     pthread_mutex_lock( &(parentCommon->lock) );");
+                               output.println("     pthread_mutex_lock( &(parentCommon->lock) );");
                                for (Iterator iterator = waitingQueueSet.iterator(); iterator
                                                .hasNext();) {
                                        WaitingElement waitingElement = (WaitingElement) iterator.next();
@@ -3446,44 +3443,19 @@ public class BuildCode {
                                        output.println("     newElement=mlpCreateWaitingElement( "+waitingElement.getStatus()+", seseToIssue, list, waitingQueueItemID );");
                                        
                                        output
-                                                       .println("     newQItem=addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedWaitingQueue,"
-                                                                       + waitingElement.getWaitingID() + ",newElement);");
-                                       output
-                                                       .println("     addNewItem(newWaitingItemQueue,newQItem);");
-//                                     output.println("     ++(seseToIssue->common.unresolvedDependencies);");
+                                                       .println("     if(addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedWaitingQueue,"
+                                                                       + waitingElement.getWaitingID() + ",newElement)){");
                                        output.println("     ++(localCount);");
+                                       output.println("     } ");
+
                                        output
                                        .println();
                                }
-//                             output.println("     pthread_mutex_unlock( &(parentCommon->lock) );");
+                               output.println("     pthread_mutex_unlock( &(parentCommon->lock) );");
                                output.println("     }");
                        }
                        
-                       output.println("     /*decide whether it is runnable or not in regarding to memory conflicts*/");
-                       output.println("     {");
-                       output.println("      if( !isEmpty(newWaitingItemQueue) ){");
-//                     output.println("         pthread_mutex_lock( &(parentCommon->lock)  );");
-                       output.println("         int idx;");
-                       output.println("         for(idx = 0 ; idx < numRelatedWaitingQueue ; idx++){");
-                       output.println("            struct Queue *allocQueue=parentCommon->allocSiteArray[idx].waitingQueue;");
-                       output.println("            if( !isEmpty(allocQueue) ){");
-                       output.println("               struct QueueItem* nextQItem=getHead(allocQueue);");
-                       output.println("               while( nextQItem != NULL ){");
-                       output.println("                  if(contains(newWaitingItemQueue,nextQItem) && isRunnable(allocQueue,nextQItem)){");
-//                     output.println("                     if(seseToIssue->common.unresolvedDependencies>0)");
-//                     output.println("                     --(seseToIssue->common.unresolvedDependencies);");
-                       output.println("                     --(localCount);");
-                       output.println("                  }");
-                       output.println("                     nextQItem=getNextQueueItem(nextQItem);");
-                       output.println("               }");
-                       output.println("          }");
-                       output.println("        }");
-               
-                       output.println("     }");
-                       output.println("     }");
-                       output.println("        pthread_mutex_unlock( &(parentCommon->lock)  );");
                        output.println();
-                       
                }
 
     // eom
@@ -3729,7 +3701,6 @@ public class BuildCode {
        output.println("           while(nextQItem!=NULL){");
        output.println("              WaitingElement* nextItem=nextQItem->objectptr;");
        output.println("              SESEcommon* seseNextItem=(SESEcommon*)nextItem->seseRec;");
-//     output.println("              int isResolved=resolveWaitingQueue(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextQItem);");
        output.println("              int isResolved=isRunnable(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextQItem);");
        output.println("              if(seseNextItem->classID==___params___->common.parent->classID){"); // stall site
        output.println("                 if(isResolved){");
@@ -3738,25 +3709,21 @@ public class BuildCode {
        output.println("                    giveCount++;");
        output.println("                 }");
        output.println("                 if(!isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue)){");
-//     output.println("                    nextQItem=getHead(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
        output.println("                    nextQItem=getNextQueueItem(nextQItem);");
        output.println("                 }else{");
        output.println("                    nextQItem=NULL;");
        output.println("                 }");
        output.println("              }else{");
        output.println("                 if(isResolved){");
-//     output.println("                    pthread_mutex_lock( &(seseNextItem->lock) );");
-//     output.println("                    if(seseNextItem->unresolvedDependencies > 0){");
-//     output.println("                       --(seseNextItem->unresolvedDependencies);");
-//     output.println("                       if( seseNextItem->unresolvedDependencies == 0){");
-       //output.println("                          workScheduleSubmit( (void*)nextItem);");
+       output.println("                    struct QueueItem* currentItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextItem);");
+       output.println("                    nextQItem=getNextQueueItem(currentItem);");
+       output.println("                    removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,currentItem);");
        output.println("                       if( atomic_sub_and_test(1, &(seseNextItem->unresolvedDependencies)) ){");
        output.println("                            addNewItem(launchQueue,(void*)seseNextItem);");
        output.println("                       }");
-//     output.println("                    }");
-//     output.println("                    pthread_mutex_unlock( &(seseNextItem->lock) );");
+       output.println("                 }else{");
+       output.println("                    nextQItem=getNextQueueItem(nextQItem);");
        output.println("                 }");
-       output.println("                 nextQItem=getNextQueueItem(nextQItem);");
        output.println("               }");
        output.println("           } "); // end of while(nextQItem!=NULL)
        output.println("        }");
@@ -3764,7 +3731,6 @@ public class BuildCode {
 //     output.println("  }");
        output.println("  }");
        output.println("  pthread_mutex_unlock( &(___params___->common.parent->lock)  );");
-//     output.println("  pthread_mutex_unlock( &(___params___->common.parent->waitingQueueLock)  );");
        output.println("  if(!isEmpty(launchQueue)){");
        output.println("     struct QueueItem* qItem=getHead(launchQueue);");
        output.println("     while(qItem!=NULL){");
index bc4e2bcd2255bc7aab05ea50366c3019d3e9bcd0..1fa12b1d72c8d6983ab20bf994db87891b0d0013 100644 (file)
@@ -73,7 +73,26 @@ struct QueueItem* addWaitingQueueElement2(AllocSite* waitingQueueArray, int numW
   
 }
 
-struct QueueItem* addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec){
+int addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, WaitingElement* wElement){
+
+  int i;
+  struct QueueItem* newItem=NULL;
+  for(i=0;i<numAllocSites;i++){
+    if(allocSiteArray[i].id==allocID){
+      
+      if(isRunnableNewElement(allocSiteArray[i].waitingQueue,wElement)){
+       return 0;
+      }else{
+       addNewItemBack(allocSiteArray[i].waitingQueue,wElement);
+       return 1;
+      }
+    
+    }
+  }
+  return 0;
+}
+
+struct QueueItem* addWaitingQueueElement_backup(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec){
 
   int i;
   struct QueueItem* newItem=NULL;
@@ -98,6 +117,21 @@ int getQueueIdx(AllocSite* allocSiteArray, int numAllocSites, long  allocID){
   return -1;
 }
 
+int isRunnableNewElement(struct Queue* waitingQueue, WaitingElement* wItem){
+
+  if(!isEmpty(waitingQueue)){
+
+    struct QueueItem* current=getHead(waitingQueue);
+    while(current!=NULL){
+        if(isConflicted(current,wItem)){
+          return 0;
+        }
+                current=getNextQueueItem(current);
+    }
+  }
+  return 1;
+}
+
 int isRunnable(struct Queue* waitingQueue, struct QueueItem* qItem){
 
   if(!isEmpty(waitingQueue)){
@@ -105,7 +139,7 @@ int isRunnable(struct Queue* waitingQueue, struct QueueItem* qItem){
     struct QueueItem* current=getHead(waitingQueue);
     while(current!=NULL){
          if(current!=qItem){
-          if(isConflicted(current,qItem)){
+          if(isConflicted(current,(WaitingElement*)qItem->objectptr)){
             return 0;
           }
         }else{
@@ -117,9 +151,8 @@ int isRunnable(struct Queue* waitingQueue, struct QueueItem* qItem){
   return 1;
 }
 
-int isConflicted(struct QueueItem* prevItem, struct QueueItem* item){
+int isConflicted(struct QueueItem* prevItem, WaitingElement* element){
 
-  WaitingElement* element=item->objectptr;
   WaitingElement* prevElement=prevItem->objectptr;
 
   if(prevElement->id!=element->id){
index 4ea520e37d7a7ce1697fc65960be3ce8c76b5f6d..6c91758ea518e629d64977f3868a3f4bbcd4fccd 100644 (file)
@@ -93,7 +93,7 @@ void  mlpDestroySESErecord( void* seseRecord );
 
 AllocSite* mlpCreateAllocSiteArray(int numAllocSites);
 ConflictNode* mlpCreateConflictNode(int id);
-struct QueueItem* addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, void *seseRec);
+int addWaitingQueueElement(AllocSite* allocSiteArray, int numAllocSites, long allocID, WaitingElement* wElement);
 WaitingElement* mlpCreateWaitingElement(int status, void* seseToIssue, struct Queue* queue, int id);