From: yeom Date: Wed, 17 Nov 2010 03:40:36 +0000 (+0000) Subject: assigns workerID to the workerTR X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=dfffe4be1b50521032648f7ec6e56c276a18ea24;p=IRC.git assigns workerID to the workerTR --- diff --git a/Robust/src/Runtime/oooJava/rcr_runtime.c b/Robust/src/Runtime/oooJava/rcr_runtime.c index 3887636e..e144844d 100644 --- a/Robust/src/Runtime/oooJava/rcr_runtime.c +++ b/Robust/src/Runtime/oooJava/rcr_runtime.c @@ -10,6 +10,7 @@ void * workerTR(void *x) { struct trQueue * queue=(struct trQueue *)x; allHashStructures=queue->allHashStructures; + myWorkerID=queue->id; CP_CREATE(); diff --git a/Robust/src/Runtime/oooJava/rcr_runtime.h b/Robust/src/Runtime/oooJava/rcr_runtime.h index e32e081b..50573c99 100644 --- a/Robust/src/Runtime/oooJava/rcr_runtime.h +++ b/Robust/src/Runtime/oooJava/rcr_runtime.h @@ -2,6 +2,7 @@ #define RCR_RUNTIME_H extern __thread struct trQueue * TRqueue; +extern __thread int myWorkerID; void * workerTR(void *); diff --git a/Robust/src/Runtime/oooJava/trqueue.c b/Robust/src/Runtime/oooJava/trqueue.c index 1b63685d..c3f1734a 100644 --- a/Robust/src/Runtime/oooJava/trqueue.c +++ b/Robust/src/Runtime/oooJava/trqueue.c @@ -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);} diff --git a/Robust/src/Runtime/oooJava/trqueue.h b/Robust/src/Runtime/oooJava/trqueue.h index 575ca8b5..aaa646dc 100644 --- a/Robust/src/Runtime/oooJava/trqueue.h +++ b/Robust/src/Runtime/oooJava/trqueue.h @@ -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); diff --git a/Robust/src/Runtime/squeue.h b/Robust/src/Runtime/squeue.h index b67f3b92..f15c1a13 100644 --- a/Robust/src/Runtime/squeue.h +++ b/Robust/src/Runtime/squeue.h @@ -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; } diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c index 00e9e12a..108a3917 100644 --- a/Robust/src/Runtime/workschedule.c +++ b/Robust/src/Runtime/workschedule.c @@ -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 ); }