assigns workerID to the workerTR
authoryeom <yeom>
Wed, 17 Nov 2010 03:40:36 +0000 (03:40 +0000)
committeryeom <yeom>
Wed, 17 Nov 2010 03:40:36 +0000 (03:40 +0000)
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/squeue.h
Robust/src/Runtime/workschedule.c

index 3887636e5b2a89291b93276bd406625e44c0d524..e144844dfb8289688218f705f2b5300511258c67 100644 (file)
@@ -10,6 +10,7 @@
 void * workerTR(void *x) {
   struct trQueue * queue=(struct trQueue *)x;
   allHashStructures=queue->allHashStructures;
+  myWorkerID=queue->id;
 
   CP_CREATE();
 
index e32e081b663c699b231e2d245c37ec95c9adfec9..50573c99064507bc8796e6a92a3b30e30889cb67 100644 (file)
@@ -2,6 +2,7 @@
 #define RCR_RUNTIME_H
 
 extern __thread struct trQueue * TRqueue;
+extern __thread int myWorkerID;
 
 void * workerTR(void *);
 
index 1b63685d434680bfe8952208f839ff56905467eb..c3f1734aeac7e79ded12f466cd2a18d0366b46fe 100644 (file)
@@ -6,6 +6,7 @@
 #include "structdefs.h"
 #include "RuntimeConflictResolver.h"
 
+extern volatile int numWorkSchedWorkers;
 
 struct trQueue * queuelist=NULL;
 pthread_mutex_t queuelock;
@@ -43,10 +44,15 @@ void * dequeueTR(struct trQueue *q) {
 
 void createTR() {
   struct trQueue *ptr=NULL;
+  int myid;
   pthread_mutex_lock(&queuelock);
   ptr=queuelist;
-  if (ptr!=NULL)
+  if (ptr!=NULL) {
     queuelist=ptr->next;
+  } else {
+    myid=numWorkSchedWorkers;
+    numWorkSchedWorkers++;
+  }  
   pthread_mutex_unlock(&queuelock);
   if (ptr==NULL) {
     pthread_t thread;
@@ -56,6 +62,7 @@ void createTR() {
     ptr=malloc(sizeof(struct trQueue));
     ptr->head=0;
     ptr->tail=0;
+    ptr->id=myid;
     ptr->allHashStructures=createAndFillMasterHashStructureArray();
     int status=pthread_create( &thread, NULL, workerTR, (void *) ptr);
     if (status!=0) {printf("ERROR\n");exit(-1);}
index 575ca8b584b1d5311032f8feb01fc837c07d0493..aaa646dcd45477ff1333e6c8dc27fd3f63a46019 100644 (file)
@@ -12,6 +12,7 @@ struct trQueue {
   volatile unsigned int tail;
   struct trQueue *next;
   struct Hashtable_rcr ** allHashStructures;
+  int id;
 };
 
 void enqueueTR(struct trQueue *, void * ptr);
index b67f3b9210a4c11449772d6508d533459ebf69fe..f15c1a13f82b9077ba1b54865a42c2a675ca673a 100644 (file)
@@ -128,6 +128,7 @@ static inline void dqPushBottom( deque* p, void* work ) {
   ptr=(dequeItem *) (((unsigned INTPTR)ptr)+INCREMENTTAG);
   realptr->work=work;
   BARRIER();
+  //thread unsafe enqueue...only works if one thread enqueue to a queue
   p->tail->next=ptr;
   p->tail=realptr;
 }
index 00e9e12a10245da20503bcab5b8e49c8343753b9..108a39173991ce75b9938ce54a6f3f85d06018ca 100644 (file)
@@ -61,15 +61,16 @@ typedef struct workerData_t {
 
 // a thread should know its worker id in any
 // functions below
-static __thread int myWorkerID;
+__thread int myWorkerID;
 
 // the original thread starts up the work scheduler
 // and sleeps while it is running, it has no worker
 // ID so use this to realize that
-static const int workerID_NOTAWORKER = 0xffffff0;
+const int workerID_NOTAWORKER = 0xffffff0;
 
 
-int numWorkSchedWorkers;
+volatile int numWorkSchedWorkers;
+int realnumWorkSchedWorkers;
 static WorkerData*  workerDataArray;
 static pthread_t*   workerArray;
 
@@ -166,7 +167,8 @@ void* workerMain( void* arg ) {
         // try to steal from another queue, starting
         // with the last successful victim, don't check
         // your own deque
-        for( i = 0; i < numWorkSchedWorkers - 1; ++i ) {
+       int mynumWorkSchedWorkers=numWorkSchedWorkers;
+        for( i = 0; i < mynumWorkSchedWorkers - 1; ++i ) {
 
           workUnit = dqPopTop( &(deques[lastVictim]) );
           
@@ -182,10 +184,10 @@ void* workerMain( void* arg ) {
           }
        
           // choose next victim
-          lastVictim++; if( lastVictim == numWorkSchedWorkers ) { lastVictim = 0; }
+          lastVictim++; if( lastVictim == mynumWorkSchedWorkers ) { lastVictim = 0; }
           
           if( lastVictim == myWorkerID ) {
-            lastVictim++; if( lastVictim == numWorkSchedWorkers ) { lastVictim = 0; }
+            lastVictim++; if( lastVictim == mynumWorkSchedWorkers ) { lastVictim = 0; }
           }
         }
         // end steal attempts
@@ -281,13 +283,22 @@ void workScheduleInit( int numProcessors,
 
 
   numWorkSchedWorkers = numProcessors;
+  realnumWorkSchedWorkers=numProcessors;
 
   workFunc = func;
 
+#ifdef RCR
+  deques          = RUNMALLOC( sizeof( deque      )*numWorkSchedWorkers*2);
+#else
   deques          = RUNMALLOC( sizeof( deque      )*numWorkSchedWorkers );
+#endif
   workerDataArray = RUNMALLOC( sizeof( WorkerData )*numWorkSchedWorkers );
 
+#ifdef RCR
+  for( i = 0; i < numWorkSchedWorkers*2; ++i ) {
+#else
   for( i = 0; i < numWorkSchedWorkers; ++i ) {
+#endif
     dqInit( &(deques[i]) );
   }
   
@@ -331,7 +342,7 @@ void workScheduleBegin() {
   workerMain( (void*) &(workerDataArray[0]) );
 
   // then wait for all other workers to exit gracefully
-  for( i = 1; i < numWorkSchedWorkers; ++i ) {
+  for( i = 1; i < realnumWorkSchedWorkers; ++i ) {
     pthread_join( workerDataArray[i].workerThread, NULL );
   }