if(state.RCR) {
//no need to enqueue parent effect if coarse grained conflict clears us
-
- output.println(" while(stallrecord.common.rcrstatus) {;}");
- output.println(" BARRIER();");
+ 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(" REntry* rentry=NULL;");
output.println(" INTPTR* pointer=NULL;");
output.println(" seseToIssue->common.rentryIdx=0;");
- output.println(" int dispCount;");
Vector<TempDescriptor> invars=fsen.getInVarsForDynamicCoarseConflictResolution();
System.out.println(fm.getMethod()+"["+invars+"]");
+
+ Vector<Long> queuetovar=new Vector<Long>();
+
for(int i=0;i<invars.size();i++) {
TempDescriptor td=invars.get(i);
Set<Analysis.OoOJava.WaitingElement> weset=seseWaitingQueue.getWaitingElementSet(td);
- if (weset==null)
- System.out.println("ERROR:"+td+" "+fsen+" "+fm.getMethod());
int numqueues=weset.size();
output.println(" seseToIssue->rcrRecords["+i+"].flag="+numqueues+";");
+ output.println(" int dispCount"+i+"=0;");
- //output.println(" seseToIssue->rcrRecords["+i+"].count=0;");
- //output.println(" seseToIssue->rcrRecords["+i+"].index=0;");
- //output.println(" seseToIssue->rcrRecords["+i+"].next=NULL;");
+ for(Iterator<Analysis.OoOJava.WaitingElement> wtit=weset.iterator();wtit.hasNext();) {
+ Analysis.OoOJava.WaitingElement waitingElement=wtit.next();
+ int queueID=waitingElement.getQueueID();
+ if (queueID>queuetovar.size())
+ queuetovar.setSize(queueID);
+ Long l=queuetovar.get(queueID);
+ long val=(l!=null)?l.longValue():0;
+ val=val|(1<<queueID);
+ queuetovar.set(queueID, new Long(val));
+ }
+ }
- output.println(" dispCount=0;");
+ HashSet generatedqueueentry=new HashSet();
+ for(int i=0;i<invars.size();i++) {
+ TempDescriptor td=invars.get(i);
+ Set<Analysis.OoOJava.WaitingElement> weset=seseWaitingQueue.getWaitingElementSet(td);
+ int numqueues=weset.size();
for(Iterator<Analysis.OoOJava.WaitingElement> wtit=weset.iterator();wtit.hasNext();) {
Analysis.OoOJava.WaitingElement waitingElement=wtit.next();
int queueID=waitingElement.getQueueID();
+ if (generatedqueueentry.contains(queueID))
+ continue;
+ else
+ generatedqueueentry.add(queueID);
+
assert(waitingElement.getStatus()>=ConflictNode.COARSE);
- output.println(" rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "]," + waitingElement.getStatus() + ", &(seseToIssue->common));");
+ long mask=queuetovar.get(queueID);
+ output.println(" rentry=mlpCreateREntry(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "]," + waitingElement.getStatus() + ", &(seseToIssue->common)"+mask+"LL);");
output.println(" seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
output.println(" rentry->queue=runningSESE->memoryQueueArray[" + waitingElement.getQueueID()+"];");
+
output.println(" if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],rentry)==READY) {");
- output.println(" dispCount++;");
+ for(int j=0;mask!=0;j++) {
+ if ((mask&1)==1)
+ output.println(" dispCount"+j+"++;");
+ mask=mask>>1;
+ }
output.println(" }");
}
- output.println(" if(!dispCount || !atomic_sub_and_test(dispCount,&(seseToIssue->rcrRecords["+i+"].flag)))");
- output.println(" localCount++;");
+
if (fsen.getDynamicInVarSet().contains(td)) {
// dynamic in-var case
//output.println(" pointer=seseToIssue->" + waitingElement.getDynID()+ "_srcSESE+seseToIssue->"+ waitingElement.getDynID()+ "_srcOffset;");
//output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", &(seseToIssue->common), pointer );");
}
}
+ for(int i=0;i<invars.size();i++) {
+ output.println(" if(!dispCount"+i+" || !atomic_sub_and_test(dispCount"+i+",&(seseToIssue->rcrRecords["+i+"].flag)))");
+ output.println(" localCount++;");
+ }
output.println(" }");
}
}
return newREntry;
}
-REntry* mlpCreateREntry(MemoryQueue* q, int type, SESEcommon* seseToIssue){
+#ifdef RCR
+REntry* mlpCreateREntry(MemoryQueue* q, int type, SESEcommon* seseToIssue, INTPTR mask) {
+#else
+REntry* mlpCreateREntry(MemoryQueue* q, int type, SESEcommon* seseToIssue) {
+#endif
#ifdef OOO_DISABLE_TASKMEMPOOL
REntry* newREntry=(REntry*)RUNMALLOC(sizeof(REntry));
#else
#endif
newREntry->type=type;
newREntry->seseRec=seseToIssue;
+#ifdef RCR
+ newREntry->mask=mask;
+#endif
return newREntry;
}
//at this point, have table
Hashtable* table=(Hashtable*)q->tail;
- r->hashtable=table; // set rentry's hashtable
+ r->qitem=(MemoryQueueItem *) table; // set rentry's hashtable
if( *(r->pointer)==0 ||
( *(r->pointer)!=0 &&
BARRIER() &&
if(inc){
atomic_inc(&T->item.total);
}
- r->hashtable=T;
+ r->qitem=(MemoryQueueItem *)T;
r->binitem=b;
be->tail=b;
be->head=b;//released lock
atomic_inc(&T->item.total);
}
- r->hashtable=T;
+ r->qitem=(MemoryQueueItem *)T;
r->binitem=(BinItem*)b;
be->tail->next=(BinItem*)b;
return retval;
}
-READBINCASE(Hashtable *T, REntry *r, BinItem *val, int key, int inc) {
+void READBINCASE(Hashtable *T, REntry *r, BinItem *val, int key, int inc) {
BinItem * bintail=T->array[key]->tail;
if (isReadBinItem(bintail)) {
return TAILREADCASE(T, r, val, bintail, key, inc);
if(inc){
atomic_inc(&T->item.total);
}
- r->hashtable=T;
+ r->qitem=(MemoryQueueItem *)T;
T->array[key]->head=val;//released lock
return retval;
}
-TAILWRITECASE(Hashtable *T, REntry *r, BinItem *val, BinItem *bintail, int key, int inc) {
+void TAILWRITECASE(Hashtable *T, REntry *r, BinItem *val, BinItem *bintail, int key, int inc) {
// WriteBinItem* wb=createWriteBinItem();
//wb->val=r;
//wb->item.total=1;//safe because item could not have started
if(inc){
atomic_inc(&T->item.total);
}
- r->hashtable=T;
+ r->qitem=(MemoryQueueItem *)T;
r->binitem=(BinItem*)rb;
T->array[key]->tail->next=(BinItem*)rb;
T->array[key]->tail=(BinItem*)rb;
T->array[key]->head=val;//released lock
}
-ADDVECTOR(MemoryQueue *Q, REntry *r) {
+void ADDVECTOR(MemoryQueue *Q, REntry *r) {
if(!isVector(Q->tail)) {
//Fast Case
if (isParentCoarse(r) && Q->tail->total==0 && Q->tail==Q->head) {
BARRIER();
V->index++;
//*****NEED memory barrier here to ensure compiler does not cache V.status*********
- r->vector=V;
+ r->qitem=(MemoryQueueItem *)V;
if (BARRIER() && V->item.status==READY) {
void* flag=NULL;
flag=(void*)LOCKXCHG((unsigned INTPTR*)&(V->array[index]), (unsigned INTPTR)flag);
//SCC's don't come in parent variety
-ADDSCC(MemoryQueue *Q, REntry *r) {
+void ADDSCC(MemoryQueue *Q, REntry *r) {
//added SCC
SCC* S=createSCC();
S->item.total=1;
S->val=r;
- r->scc=S;
+ r->qitem=(MemoryQueueItem *)S;
Q->tail->next=(MemoryQueueItem*)S;
//*** NEED BARRIER HERE
if (BARRIER() && Q->tail->status==READY && Q->tail->total==0 && Q->tail==Q->head) {
#endif
}
-RETIRESCC(MemoryQueue *Q, REntry *r) {
- SCC* s=r->scc;
+void RETIRESCC(MemoryQueue *Q, REntry *r) {
+ SCC* s=(SCC *)r->qitem;
s->item.total=0;//don't need atomicdec
RESOLVECHAIN(Q);
}
-RETIREHASHTABLE(MemoryQueue *q, REntry *r) {
- Hashtable *T=r->hashtable;
+void RETIREHASHTABLE(MemoryQueue *q, REntry *r) {
+ Hashtable *T=(Hashtable *)r->qitem;
BinItem *b=r->binitem;
RETIREBIN(T,r,b);
atomic_dec(&T->item.total);
}
}
-RETIREBIN(Hashtable *T, REntry *r, BinItem *b) {
+void RETIREBIN(Hashtable *T, REntry *r, BinItem *b) {
int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) );
if(isFineRead(r)) {
atomic_dec(&b->total);
}
-RETIREVECTOR(MemoryQueue *Q, REntry *r) {
- Vector* V=r->vector;
+void RETIREVECTOR(MemoryQueue *Q, REntry *r) {
+ Vector* V=(Vector *)r->qitem;
atomic_dec(&V->item.total);
if (V->item.next!=NULL && V->item.total==0) { //NOTE: ORDERING CRUCIAL HERE
RESOLVECHAIN(Q);
}
}
-RESOLVECHAIN(MemoryQueue *Q) {
+void RESOLVECHAIN(MemoryQueue *Q) {
while(TRUE) {
MemoryQueueItem* head=Q->head;
if (head->next==NULL||head->total!=0) {
}
-RESOLVEHASHTABLE(MemoryQueue *Q, Hashtable *T) {
+void RESOLVEHASHTABLE(MemoryQueue *Q, Hashtable *T) {
int binidx;
for (binidx=0;binidx<NUMBINS;binidx++) {
BinElement* bin=T->array[binidx];
}
}
-RESOLVEVECTOR(MemoryQueue *q, Vector *V) {
+void RESOLVEVECTOR(MemoryQueue *q, Vector *V) {
int i;
Vector* tmp=V;
//handle ready cases
}
}
-RESOLVESCC(SCC *S) {
+void RESOLVESCC(SCC *S) {
//precondition: SCC's state is READY
void* flag=NULL;
flag=(void*)LOCKXCHG((unsigned INTPTR*)&(S->val), (unsigned INTPTR)flag);
}
-resolveDependencies(REntry* rentry){
+void resolveDependencies(REntry* rentry){
SESEcommon* seseCommon=(SESEcommon*)rentry->seseRec;
- if(rentry->type==READ || rentry->type==WRITE || rentry->type==COARSE || rentry->type==SCCITEM){
+ int type=rentry->type;
+#ifdef RCR
+ if (type==COARSE||type==SCCITEM) {
+ struct rcrRecord * array=(struct rcrRecord *)(((char *)seseCommon)+seseCommon->offsetToParamRecords);
+ INTPTR mask=rentry->mask;
+ int index=-1;
+ while(mask!=0) {
+ int shift=__builtin_ctzll(mask)+1;
+ index+=shift;
+ if(atomic_sub_and_test(1, &array[index].flag)) {
+ if(atomic_sub_and_test(1, &(seseCommon->unresolvedDependencies)))
+ workScheduleSubmit((void *)seseCommon);
+ }
+ }
+ } else if (type==PARENTCOARSE) {
+ psem_give_tag(rentry->parentStallSem, rentry->tag);
+ } else {
+ printf("ERROR...\n");
+ }
+#else
+ if(type==READ || type==WRITE || type==COARSE || type==SCCITEM){
if( atomic_sub_and_test(1, &(seseCommon->unresolvedDependencies)) ){
workScheduleSubmit(seseCommon);
}
- }else if(rentry->type==PARENTREAD || rentry->type==PARENTWRITE ||rentry->type==PARENTCOARSE){
+ }else if(type==PARENTREAD || type==PARENTWRITE || type==PARENTCOARSE){
psem_give_tag(rentry->parentStallSem, rentry->tag);
}
+#endif
}
void INITIALIZEBUF(MemoryQueue * q){
}
-resolvePointer(REntry* rentry){
-
- Hashtable* table=rentry->hashtable;
+void resolvePointer(REntry* rentry){
+ Hashtable* table=(Hashtable *)rentry->qitem;
MemoryQueue* queue;
if(table==NULL || table->unresolvedQueue==NULL){
//resolved already before related rentry is enqueued to the waiting queue
}
void rehashMemoryQueue(SESEcommon* seseParent){
-#if 0
- // update memory queue
- int i,binidx;
- for(i=0; i<seseParent->numMemoryQueue; i++){
- MemoryQueue *memoryQueue=seseParent->memoryQueueArray[i];
- MemoryQueueItem *memoryItem=memoryQueue->head;
- MemoryQueueItem *prevItem=NULL;
- while(memoryItem!=NULL){
- if(memoryItem->type==HASHTABLE){
- //do re-hash!
- Hashtable* ht=(Hashtable*)memoryItem;
- Hashtable* newht=createHashtable();
- int binidx;
- for(binidx=0; binidx<NUMBINS; binidx++){
- BinElement *bin=ht->array[binidx];
- BinItem *binItem=bin->head;
- //traverse over the list of each bin
- while(binItem!=NULL){
- if(binItem->type==READBIN){
- ReadBinItem* readBinItem=(ReadBinItem*)binItem;
- int ridx;
- for(ridx=0; ridx<readBinItem->index; ridx++){
- REntry *rentry=readBinItem->array[ridx];
- int newkey=generateKey((unsigned int)(unsigned INTPTR)*(rentry->pointer));
- int status=rentry->binitem->status;
- ADDTABLEITEM(newht,rentry,TRUE);
- rentry->binitem->status=status; // update bin status as before rehash
- }
- }else{//write bin
- REntry *rentry=((WriteBinItem*)binItem)->val;
- int newkey=generateKey((unsigned int)(unsigned INTPTR)*(rentry->pointer));
- int status=rentry->binitem->status;
- ADDTABLEITEM(newht,rentry,TRUE);
- int newstatus=rentry->binitem->status;
- //printf("[%d]old status=%d new status=%d\n",i,status,newstatus);
- rentry->binitem->status=status; // update bin status as before rehash
- }
- binItem=binItem->next;
- }
- }
- newht->item.status=ht->item.status; // update hashtable status
- if(prevItem!=NULL){
- prevItem->next=(MemoryQueueItem*)newht;
- }else{
- if(memoryQueue->head==memoryQueue->tail){
- memoryQueue->tail=(MemoryQueueItem*)newht;
- }
- memoryQueue->head=(MemoryQueueItem*)newht;
- }
- newht->item.next=ht->item.next;
- }
- prevItem=memoryItem;
- memoryItem=memoryItem->next;
- }
- }
-#endif
}