From 7154523cc091a3524ed71bf0ec6b996fc5074625 Mon Sep 17 00:00:00 2001 From: adash Date: Tue, 13 Apr 2010 01:26:19 +0000 Subject: [PATCH] annoying bug fixed; works well with current recovery system --- .../src/Runtime/DSTM/interface/altmlookup.h | 4 +- Robust/src/Runtime/DSTM/interface/dsmlock.c | 2 +- Robust/src/Runtime/DSTM/interface/dstm.h | 3 +- .../src/Runtime/DSTM/interface/dstmserver.c | 11 +++- Robust/src/Runtime/DSTM/interface/ip.c | 11 ++++ Robust/src/Runtime/DSTM/interface/ip.h | 1 + Robust/src/Runtime/DSTM/interface/sandbox.c | 2 + Robust/src/Runtime/DSTM/interface/signal.c | 5 +- Robust/src/Runtime/DSTM/interface/trans.c | 58 +++++++++---------- 9 files changed, 60 insertions(+), 37 deletions(-) diff --git a/Robust/src/Runtime/DSTM/interface/altmlookup.h b/Robust/src/Runtime/DSTM/interface/altmlookup.h index ca5ff1ec..a08adff8 100644 --- a/Robust/src/Runtime/DSTM/interface/altmlookup.h +++ b/Robust/src/Runtime/DSTM/interface/altmlookup.h @@ -1,5 +1,5 @@ -#ifndef _MLOOKUP_H_ -#define _MLOOKUP_H_ +#ifndef _ALTMLOOKUP_H_ +#define _ALTMLOOKUP_H_ #include #include diff --git a/Robust/src/Runtime/DSTM/interface/dsmlock.c b/Robust/src/Runtime/DSTM/interface/dsmlock.c index 69cb4d67..768ebab0 100644 --- a/Robust/src/Runtime/DSTM/interface/dsmlock.c +++ b/Robust/src/Runtime/DSTM/interface/dsmlock.c @@ -63,7 +63,7 @@ inline void write_unlock(volatile int *rw) { } inline int is_write_locked(volatile int *lock) { - return lock < 0; + return lock <= 0; } inline int is_read_locked(volatile int *lock) { diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index ed76898e..880d2b9b 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -5,6 +5,7 @@ #define MSG_NOSIGNAL 0 #endif +#define CFENCE asm volatile("":::"memory"); /*********************************************************** * Macros **********************************************************/ @@ -267,7 +268,7 @@ void mapObjMethod(unsigned short); void randomdelay(); void transStart(); -//#define TRANSREAD(x,y,z(tobe passed as a parameter to transRead2)) { +//#define TRANSREAD(x,y,z) /* Use "z" which is program point at which TRANSREAD is generated, use this as transRead2(inputvalue,z) */ #define TRANSREAD(x,y) { \ unsigned int inputvalue;\ if ((inputvalue=(unsigned int)y)==0) x=NULL;\ diff --git a/Robust/src/Runtime/DSTM/interface/dstmserver.c b/Robust/src/Runtime/DSTM/interface/dstmserver.c index 6a08dc32..eedd06b8 100644 --- a/Robust/src/Runtime/DSTM/interface/dstmserver.c +++ b/Robust/src/Runtime/DSTM/interface/dstmserver.c @@ -194,6 +194,10 @@ void *dstmAccept(void *acceptfd) { } } h = (objheader_t *) srcObj; + /* If object is write locked, just wait */ + /* May want to remove at some point */ + while((*(volatile int *)STATUSPTR(h))<=0) + sched_yield(); GETSIZE(size, h); size += sizeof(objheader_t); sockid = (int) acceptfd; @@ -385,10 +389,10 @@ int readClientReq(trans_commit_data_t *transinfo, int acceptfd, struct readstruc } ptr = (char *) modptr; for(i = 0 ; i < fixed.nummod; i++) { - int tmpsize; headaddr = (objheader_t *) ptr; oid = OID(headaddr); oidmod[i] = oid; + int tmpsize=0; GETSIZE(tmpsize, headaddr); ptr += sizeof(objheader_t) + tmpsize; } @@ -518,6 +522,7 @@ char handleTransReq(fixed_data_t *fixed, trans_commit_data_t *transinfo, unsigne int incr = sizeof(unsigned int) + sizeof(unsigned short); // Offset that points to next position in the objread array incr *= i; oid = *((unsigned int *)(objread + incr)); + incr += sizeof(unsigned int); version = *((unsigned short *)(objread + incr)); retval=getCommitCountForObjRead(oidnotfound, oidlocked, oidvernotmatch, &objnotfound, &objlocked, &objvernotmatch, @@ -865,6 +870,10 @@ void processVerNoMatch(unsigned int *oidnotfound, dst->___cachedHash___=src->___cachedHash___; memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___)); } + + //memory barrier + CFENCE; + header->version += 1; /* If threads are waiting on this object to be updated, notify them */ if(header->notifylist != NULL) { diff --git a/Robust/src/Runtime/DSTM/interface/ip.c b/Robust/src/Runtime/DSTM/interface/ip.c index d5c6b45a..e2823c54 100644 --- a/Robust/src/Runtime/DSTM/interface/ip.c +++ b/Robust/src/Runtime/DSTM/interface/ip.c @@ -35,6 +35,17 @@ void midtoIP(unsigned int mid, char *ptr) { return; } +/********** for DEBUGGING **************/ +char ip[16]; // for debugging purpose +char* midtoIPString(unsigned int mid){ + midtoIP(mid, ip); + return ip; +} + +/******************************/ + + + int checkServer(int mid, char *machineip) { int tmpsd; struct sockaddr_in serv_addr; diff --git a/Robust/src/Runtime/DSTM/interface/ip.h b/Robust/src/Runtime/DSTM/interface/ip.h index cbac6e64..59052548 100644 --- a/Robust/src/Runtime/DSTM/interface/ip.h +++ b/Robust/src/Runtime/DSTM/interface/ip.h @@ -12,5 +12,6 @@ unsigned int iptoMid(char *); void midtoIP(unsigned int, char *); int checkServer(int, char *); unsigned int getMyIpAddr(const char *interfaceStr); +char* midtoIPString(unsigned int mid); #endif diff --git a/Robust/src/Runtime/DSTM/interface/sandbox.c b/Robust/src/Runtime/DSTM/interface/sandbox.c index 301910f7..0eb8746b 100644 --- a/Robust/src/Runtime/DSTM/interface/sandbox.c +++ b/Robust/src/Runtime/DSTM/interface/sandbox.c @@ -53,6 +53,8 @@ int checktrans() { if (STATUS(headeraddr) & NEW) { //new objects cannot be stale } else if ((tmp=mhashSearch(curr->key)) != NULL) { + //memory barrier + CFENCE; if (tmp->version!=headeraddr->version) { //version mismatch deletehead(head); diff --git a/Robust/src/Runtime/DSTM/interface/signal.c b/Robust/src/Runtime/DSTM/interface/signal.c index 7f7f143a..ee60d0f2 100644 --- a/Robust/src/Runtime/DSTM/interface/signal.c +++ b/Robust/src/Runtime/DSTM/interface/signal.c @@ -22,7 +22,6 @@ extern int sendRemoteReq; void handle(); extern pfcstats_t *evalPrefetch; -/* void transStatsHandler(int sig, siginfo_t* info, void *context) { #ifdef TRANSSTATS char filepath[200], exectime[10]; @@ -69,8 +68,9 @@ void transStatsHandler(int sig, siginfo_t* info, void *context) { exit(0); #endif } -*/ + +/* void transStatsHandler(int sig, siginfo_t* info, void *context) { #ifdef TRANSSTATS printf("****** Transaction Stats ******\n"); @@ -92,6 +92,7 @@ void transStatsHandler(int sig, siginfo_t* info, void *context) { exit(0); #endif } +*/ void handle() { #ifdef TRANSSTATS diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c index ec852ce3..81e82148 100644 --- a/Robust/src/Runtime/DSTM/interface/trans.c +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -876,7 +876,6 @@ plistnode_t *createPiles() { if(curr->key == 0) break; headeraddr=(objheader_t *) curr->val; - //Get machine location for object id (and whether local or not) if (STATUS(headeraddr) & NEW || (mhashSearch(curr->key) != NULL)) { machinenum = myIpAddr; @@ -1066,7 +1065,7 @@ int transCommit() { free(tosend); return 1; } - GETSIZE(size,headeraddr); + GETSIZE(size,headeraddr); size+=sizeof(objheader_t); memcpy(modptr+offset, headeraddr, size); offset+=size; @@ -1550,6 +1549,9 @@ int transComProcess(trans_req_data_t *tdata, trans_commit_data_t *transinfo) { memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___)); } + //memory barrier + CFENCE; + header->version += 1; if(header->notifylist != NULL) { notifyAll(&header->notifylist, OID(header), header->version); @@ -2272,6 +2274,7 @@ void transAbort() { t_chashDelete(); } + /* This function inserts necessary information into * a machine pile data structure */ plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mid, int num_objs) { @@ -2340,35 +2343,30 @@ plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mi return pile; } +// relocate the position of myIp pile to end of list plistnode_t *sortPiles(plistnode_t *pileptr) { - plistnode_t *head, *ptr, *tail; - head = pileptr; - ptr = pileptr; - /* Get tail pointer */ - while(ptr!= NULL) { - tail = ptr; - ptr = ptr->next; - } - ptr = pileptr; - plistnode_t *prev = pileptr; - /* Arrange local machine processing at the end of the pile list */ - while(ptr != NULL) { - if(ptr != tail) { - if(ptr->mid == myIpAddr && (prev != pileptr)) { - prev->next = ptr->next; - ptr->next = NULL; - tail->next = ptr; - return pileptr; - } - if((ptr->mid == myIpAddr) && (prev == pileptr)) { - prev = ptr->next; - ptr->next = NULL; - tail->next = ptr; - return prev; - } - prev = ptr; - } - ptr = ptr->next; + plistnode_t *ptr, *tail; + tail = pileptr; + ptr = NULL; + /* Get tail pointer and myIp pile ptr */ + if(pileptr == NULL) + return pileptr; + + while(tail->next != NULL) { + if(tail->mid == myIpAddr) + ptr = tail; + tail = tail->next; + } + + // if ptr is null, then myIp pile is already at tail + if(ptr != NULL) { + /* Arrange local machine processing at the end of the pile list */ + tail->next = pileptr; + pileptr = ptr->next; + ptr->next = NULL; + return pileptr; } + + /* get too this point iff myIpAddr pile is at tail */ return pileptr; } -- 2.34.1