From: yeom Date: Mon, 5 Apr 2010 18:08:46 +0000 (+0000) Subject: bring last changes for proper handling 64bit before more changes are made. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=df8f8d67a8e2f41296ce6b96946679177c687ec5;p=IRC.git bring last changes for proper handling 64bit before more changes are made. --- diff --git a/Robust/src/Runtime/mlp_lock.h b/Robust/src/Runtime/mlp_lock.h index 9ce327c4..b1bea4ba 100644 --- a/Robust/src/Runtime/mlp_lock.h +++ b/Robust/src/Runtime/mlp_lock.h @@ -4,7 +4,7 @@ #include #include -#define __xg(x) ((volatile long *)(x)) +#define __xg(x) ((volatile INTPTR *)(x)) #define CFENCE asm volatile("":::"memory"); @@ -35,8 +35,19 @@ static inline int atomic_sub_and_test(int i, volatile int *v) { return c; } +#ifdef BIT64 +static inline INTPTR LOCKXCHG(volatile INTPTR * ptr, INTPTR val){ + INTPTR retval; + //note: xchgl always implies lock + __asm__ __volatile__("xchgq %0,%1" + : "=r"(retval) + : "m"(*ptr), "0"(val) + : "memory"); + return retval; + +} +#else static inline int LOCKXCHG(volatile int* ptr, int val){ - int retval; //note: xchgl always implies lock __asm__ __volatile__("xchgl %0,%1" @@ -46,6 +57,7 @@ static inline int LOCKXCHG(volatile int* ptr, int val){ return retval; } +#endif /* static inline int write_trylock(volatile int *lock) { @@ -58,32 +70,25 @@ static inline int write_trylock(volatile int *lock) { } */ -static inline int CAS(volatile int* mem, int cmp, int val){ - int prev; - asm volatile ("lock; cmpxchgl %1, %2" - : "=a" (prev) - : "r" (val), "m" (*(mem)), "0"(cmp) - : "memory", "cc"); - return prev; -} - -static inline long CAS32(volatile void *ptr, unsigned long old, unsigned long new){ - unsigned long prev; - __asm__ __volatile__("lock; cmpxchgl %k1,%2" +#ifdef BIT64 +static inline INTPTR CAS(volatile void *ptr, unsigned INTPTR old, unsigned INTPTR new){ + unsigned INTPTR prev; + __asm__ __volatile__("lock; cmpxchgq %1,%2" : "=a"(prev) : "r"(new), "m"(*__xg(ptr)), "0"(old) : "memory"); return prev; } - -static inline long long CAS64(volatile void *ptr, unsigned long long old, unsigned long long new){ - unsigned long long prev; - __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2" +#else +static inline long CAS(volatile void *ptr, unsigned long old, unsigned long new){ + unsigned long prev; + __asm__ __volatile__("lock; cmpxchgl %k1,%2" : "=a"(prev) : "r"(new), "m"(*__xg(ptr)), "0"(old) : "memory"); return prev; } +#endif static inline int BARRIER(){ CFENCE; diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index e0ab2b50..a63241cc 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -239,11 +239,11 @@ int ADDTABLE(MemoryQueue *q, REntry *r) { //at this point, have table Hashtable* table=(Hashtable*)q->tail; BinItem * val; - int key=generateKey((unsigned int)r->dynID); + int key=generateKey((unsigned int)(unsigned INTPTR)r->dynID); do { val=(BinItem*)0x1; BinElement* bin=table->array[key]; - val=(BinItem*)LOCKXCHG((unsigned int*)&(bin->head), (unsigned int)val);//note...talk to me about optimizations here. + val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(bin->head), (unsigned INTPTR)val);//note...talk to me about optimizations here. } while(val==(BinItem*)0x1); //at this point have locked bin if (val==NULL) { @@ -433,7 +433,7 @@ ADDVECTOR(MemoryQueue *Q, REntry *r) { r->vector=V; if (BARRIER() && V->item.status==READY) { void* flag=NULL; - flag=(void*)LOCKXCHG((unsigned int*)&(V->array[index]), (unsigned int)flag); + flag=(void*)LOCKXCHG((unsigned INTPTR*)&(V->array[index]), (unsigned INTPTR)flag); if (flag!=NULL) { if (isParent(r)) { //parent's retire immediately atomic_dec(&V->item.total); @@ -466,7 +466,7 @@ ADDSCC(MemoryQueue *Q, REntry *r) { Q->head=(MemoryQueueItem*)S; } void* flag=NULL; - flag=(void*)LOCKXCHG((unsigned int*)&(S->val), (unsigned int)flag); + flag=(void*)LOCKXCHG((unsigned INTPTR*)&(S->val), (unsigned INTPTR)flag); if (flag!=NULL) { return READY; } else { @@ -507,7 +507,7 @@ RETIREHASHTABLE(MemoryQueue *q, REntry *r) { } RETIREBIN(Hashtable *T, REntry *r, BinItem *b) { - int key=generateKey((unsigned int)r->dynID); + int key=generateKey((unsigned int)(unsigned INTPTR)r->dynID); if(isFineRead(r)) { atomic_dec(&b->total); } @@ -515,16 +515,15 @@ RETIREBIN(Hashtable *T, REntry *r, BinItem *b) { // CHECK FIRST IF next is nonnull to guarantee that b.total cannot change BinItem * val; do { - val=(BinItem*)1; - val=(BinItem*)LOCKXCHG((unsigned int*)&(T->array[key]->head), (unsigned int)val); - } while(val==(BinItem*)1); + val=(BinItem*)0x1; + val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(T->array[key]->head), (unsigned INTPTR)val); + } while(val==(BinItem*)0x1); // at this point have locked bin BinItem *ptr=val; int haveread=FALSE; - - int i; + int i; while (ptr!=NULL) { - if (isReadBinItem(ptr)) { + if (isReadBinItem(ptr)) { ReadBinItem* rptr=(ReadBinItem*)ptr; if (rptr->item.status==NOTREADY) { for (i=0;iindex;i++) { @@ -611,7 +610,7 @@ RESOLVECHAIN(MemoryQueue *Q) { break; } MemoryQueueItem* nextitem=head->next; - CAS32((unsigned int*)&(Q->head), (unsigned int)head, (unsigned int)nextitem); + CAS((unsigned INTPTR*)&(Q->head), (unsigned INTPTR)head, (unsigned INTPTR)nextitem); //oldvalue not needed... if we fail we just repeat } } @@ -624,7 +623,7 @@ RESOLVEHASHTABLE(MemoryQueue *Q, Hashtable *T) { BinItem* val; do { val=(BinItem*)1; - val=(BinItem*)LOCKXCHG((unsigned int*)&(bin->head), (unsigned int)val); + val=(BinItem*)LOCKXCHG((unsigned INTPTR*)&(bin->head), (unsigned INTPTR)val); } while (val==(BinItem*)1); //at this point have locked bin int haveread=FALSE; @@ -674,7 +673,7 @@ RESOLVEVECTOR(MemoryQueue *q, Vector *V) { //enqueue everything for (i=0;iarray[i]), (unsigned int)val); + val=(REntry*)LOCKXCHG((unsigned INTPTR*)&(tmp->array[i]), (unsigned INTPTR)val); if (val!=NULL) { resolveDependencies(val); if (isParent(val)) { @@ -693,7 +692,7 @@ RESOLVEVECTOR(MemoryQueue *q, Vector *V) { RESOLVESCC(SCC *S) { //precondition: SCC's state is READY void* flag=NULL; - flag=(void*)LOCKXCHG((unsigned int*)&(S->val), (unsigned int)flag); + flag=(void*)LOCKXCHG((unsigned INTPTR*)&(S->val), (unsigned INTPTR)flag); if (flag!=NULL) { resolveDependencies(flag); } @@ -710,3 +709,4 @@ resolveDependencies(REntry* rentry){ psem_give(&(rentry->parentStallSem)); } } +