From: adash Date: Wed, 3 Feb 2010 02:50:59 +0000 (+0000) Subject: implementing sandbox X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fed8fac8c10740a5336921755a150216ca028b87;p=IRC.git implementing sandbox check-in all the manual prefetch changes --- diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index df4a20ca..5220a82d 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -279,6 +279,7 @@ cnodetmp=cnodetmp->next;\ __attribute__((pure)) objheader_t *transRead(unsigned int); __attribute__((pure)) objheader_t *transRead2(unsigned int); +//__attribute__((pure)) objheader_t *transRead2(unsigned int, char ptr[]); objheader_t *transCreateObj(unsigned int); //returns oid header int transCommit(); //return 0 if successful void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins diff --git a/Robust/src/Runtime/DSTM/interface/prefetch.c b/Robust/src/Runtime/DSTM/interface/prefetch.c index 63df5e5b..aaaf1c03 100644 --- a/Robust/src/Runtime/DSTM/interface/prefetch.c +++ b/Robust/src/Runtime/DSTM/interface/prefetch.c @@ -9,6 +9,28 @@ extern sockPoolHashTable_t *transPResponseSocketPool; extern pthread_mutex_t prefetchcache_mutex; extern prehashtable_t pflookup; +//#define LOGTIMES +#ifdef LOGTIMES +extern char bigarray1[6*1024*1024]; +extern unsigned int bigarray2[6*1024*1024]; +extern unsigned int bigarray3[6*1024*1024]; +extern long long bigarray4[6*1024*1024]; +extern int bigarray5[6*1024*1024]; +extern int bigindex1; +#define LOGTIME(x,y,z,a,b) {\ + int tmp=bigindex1; \ + bigarray1[tmp]=x; \ + bigarray2[tmp]=y; \ + bigarray3[tmp]=z; \ + bigarray4[tmp]=a; \ + bigarray5[tmp]=b; \ + bigindex1++; \ +} +#else +#define LOGTIME(x,y,z,a,b) +//log(eventname, oid, type, time, unqiue id) +#endif + // Function for new prefetch call void rangePrefetch(unsigned int oid, short numoffset, short *offsets) { /* Allocate memory in prefetch queue and push the block there */ @@ -20,6 +42,7 @@ void rangePrefetch(unsigned int oid, short numoffset, short *offsets) { ((unsigned int *)node)[0] = oid; index = index + (sizeof(unsigned int)); *((short *)(node+index)) = numoffset; + LOGTIME('R',oid,numoffset,0,0); index = index + (sizeof(short)); memcpy(node+index, offsets, numoffset * sizeof(short)); movehead(qnodesize); @@ -68,13 +91,20 @@ perMcPrefetchList_t *processLocal(char *ptr, int numprefetches) { int offstop=numoffset-2; int countInvalidObj=-1; + int isLastOffset=0; + if(offstop==0) { //if no offsets + isLastOffset=1; + } - objheader_t * header = searchObjInv(oid, top, &countInvalidObj); + objheader_t * header = searchObjInv(oid, top, &countInvalidObj, &isLastOffset); if (header==NULL) { + LOGTIME('b',oid,0,0,countInvalidObj); //forward prefetch if(oid!=0) { int machinenum = lhashSearch(oid); - insertPrefetch(machinenum, oid, numoffset, offsetarray, &head); + if(machinenum != myIpAddr) { + insertPrefetch(machinenum, oid, numoffset, offsetarray, &head); + } } //update ptr ptr=((char *)&offsetarray[numoffset])+sizeof(int); @@ -83,34 +113,45 @@ perMcPrefetchList_t *processLocal(char *ptr, int numprefetches) { dfsList[0]=oid; dfsList[1]=0; + LOGTIME('B',oid,TYPE(header),0,countInvalidObj); //Start searching the dfsList for(top=0; top>=0;) { - oid=getNextOid(header, offsetarray, dfsList, top, &countInvalidObj); + if(top == offstop) { + isLastOffset=1; + } + oid=getNextOid(header, offsetarray, dfsList, top, &countInvalidObj, &isLastOffset); + LOGTIME('O',oid,0,0,countInvalidObj); if (oid&1) { int oldisField=TYPE(header) < NUMCLASSES; top+=2; dfsList[top]=oid; dfsList[top+1]=0; - header=searchObjInv(oid, top, &countInvalidObj); + header=searchObjInv(oid, top, &countInvalidObj, &isLastOffset); if (header==NULL) { + LOGTIME('c',oid,top,0,countInvalidObj); //forward prefetch int machinenum = lhashSearch(oid); - - if (oldisField&&(dfsList[top-1]!=GET_RANGE(offsetarray[top+1]))) { - insertPrefetch(machinenum, oid, 2+numoffset-top, &offsetarray[top-2], &head); - } else { - insertPrefetch(machinenum, oid, numoffset-top, &offsetarray[top], &head); + if(machinenum != myIpAddr) { + if (oldisField&&(dfsList[top-1]!=GET_RANGE(offsetarray[top+1]))) { + insertPrefetch(machinenum, oid, 2+numoffset-top, &offsetarray[top-2], &head); + } else { + insertPrefetch(machinenum, oid, numoffset-top, &offsetarray[top], &head); + } } } else if (top=0;) { - oid=getNextOid(header, offsetarray, dfsList, top, NULL); + oid=getNextOid(header, offsetarray, dfsList, top, NULL, NULL); if (oid&1) { int oldisField=TYPE(header) < NUMCLASSES; top+=2; @@ -180,24 +223,32 @@ perMcPrefetchList_t *processRemote(unsigned int oid, short * offsetarray, int s dfsList[top+1]=0; header=searchObj(oid); if (header==NULL) { - //forward prefetch - //int machinenum = lhashSearch(oid); - if (oldisField&&(dfsList[top-1]!=GET_RANGE(offsetarray[top+1]))) { - // insertPrefetch(machinenum, oid, 2+numoffset-top, &offsetarray[top-2], &head); - } else { - // insertPrefetch(machinenum, oid, numoffset-top, &offsetarray[top], &head); - } + LOGTIME('h',oid,top,0,0); + //forward prefetch + /* + int machinenum = lhashSearch(oid); + if (oldisField&&(dfsList[top-1]!=GET_RANGE(offsetarray[top+1]))) { + insertPrefetch(machinenum, oid, 2+numoffset-top, &offsetarray[top-2], &head); + } else { + insertPrefetch(machinenum, oid, numoffset-top, &offsetarray[top], &head); + } + */ } else { - sendOidFound(header, oid, sd, buffer, &bufoffset); + sendOidFound(header, oid, sd,writebuffer); + LOGTIME('H',oid,TYPE(header),0,top); if (topnext; } @@ -484,7 +538,7 @@ int rangePrefetchReq(int acceptfd, struct readstruct * readbuffer) { short offsetsarry[numoffset]; recv_data_buf(acceptfd, readbuffer, offsetsarry, numoffset*sizeof(short)); - perMcPrefetchList_t * pilehead=processRemote(baseoid, offsetsarry, sd, numoffset, mid); + perMcPrefetchList_t * pilehead=processRemote(baseoid, offsetsarry, sd, numoffset, mid, &writebuffer); if (pilehead!= NULL) { perMcPrefetchList_t *ptr = pilehead; @@ -507,7 +561,7 @@ int rangePrefetchReq(int acceptfd, struct readstruct * readbuffer) { } -unsigned int getNextOid(objheader_t * header, short * offsetarray, unsigned int *dfsList, int top, int *countInvalidObj) +unsigned int getNextOid(objheader_t * header, short * offsetarray, unsigned int *dfsList, int top, int *countInvalidObj, int *isLastOffset) { int startindex= offsetarray[top+2]; int currcount = dfsList[top+1]; @@ -548,7 +602,7 @@ unsigned int getNextOid(objheader_t * header, short * offsetarray, unsigned int if(currcount!=0 & range != 0) { //go to the next offset - header=searchObjInv(dfsList[top+2], top, countInvalidObj); + header=searchObjInv(dfsList[top+2], top, countInvalidObj, isLastOffset); if (header==NULL) return 2; } @@ -557,20 +611,32 @@ unsigned int getNextOid(objheader_t * header, short * offsetarray, unsigned int } } -void flushResponses(int sd, char * buffer, int * bufoffset) { - if ((*bufoffset)!=0) { - send_data(sd, buffer, *bufoffset); - *bufoffset=0; +void flushResponses(int sd, struct writestruct *writebuffer) { + if ((writebuffer->offset)>WTOP) { + send_data(sd, writebuffer->buf, writebuffer->offset); + writebuffer->offset=0; } } -int sendOidFound(objheader_t * header, unsigned int oid, int sd, char *buffer, int *bufoffset) { - int incr; +int sendOidFound(objheader_t * header, unsigned int oid, int sd, struct writestruct *writebuffer) { + //char *sendbuffer; int objsize; GETSIZE(objsize, header); - int size = sizeof(objheader_t) + objsize; - char *sendbuffer; - + int size = sizeof(int) + sizeof(char) + sizeof(unsigned int) +sizeof(objheader_t) + objsize; + char sendbuffer[size+1]; + sendbuffer[0]=TRANS_PREFETCH_RESPONSE; + int incr = 1; + *((int *)(sendbuffer + incr)) = size; + incr += sizeof(int); + *((char *)(sendbuffer + incr)) = OBJECT_FOUND; + incr += sizeof(char); + *((unsigned int *)(sendbuffer+incr)) = oid; + incr += sizeof(unsigned int); + memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t)); + send_buf(sd, writebuffer, sendbuffer, size+1); + + /* + //TODO: dead code --- stick it around for sometime if ((incr=(*bufoffset))==0) { buffer[incr] = TRANS_PREFETCH_RESPONSE; incr+=sizeof(char); @@ -597,6 +663,7 @@ int sendOidFound(objheader_t * header, unsigned int oid, int sd, char *buffer, i if ((*bufoffset)==0) { send_data(sd, sendbuffer, size+incr); } + */ return 0; } diff --git a/Robust/src/Runtime/DSTM/interface/prefetch.h b/Robust/src/Runtime/DSTM/interface/prefetch.h index 46c6b75d..0fe19ae2 100644 --- a/Robust/src/Runtime/DSTM/interface/prefetch.h +++ b/Robust/src/Runtime/DSTM/interface/prefetch.h @@ -54,8 +54,7 @@ void proPrefetchQDealloc(perMcPrefetchList_t *); void rangePrefetch(unsigned int, short, short *); void *transPrefetchNew(); perMcPrefetchList_t* processLocal(char *ptr, int); -//perMcPrefetchList_t *processRemote(unsigned int oid, short * offsetarray, int sd, short numoffset); -perMcPrefetchList_t *processRemote(unsigned int oid, short * offsetarray, int sd, short numoffset, unsigned int mid); +perMcPrefetchList_t *processRemote(unsigned int oid, short * offsetarray, int sd, short numoffset, unsigned int mid, struct writestruct *writebuffer); void insertPrefetch(int, unsigned int, short, short*, perMcPrefetchList_t **); /******** Sending and Receiving Prefetches *******/ @@ -64,13 +63,13 @@ int rangePrefetchReq(int acceptfd, struct readstruct * readbuffer); int processOidFound(objheader_t *, short *, int, int, int); int getRangePrefetchResponse(int sd, struct readstruct *); INLINE objheader_t *searchObj(unsigned int); -INLINE objheader_t *searchObjInv(unsigned int, int, int*); +INLINE objheader_t *searchObjInv(unsigned int, int, int*, int*); /*********** Functions for computation at the participant end **********/ -unsigned int getNextOid(objheader_t * header, short * offsetarray, unsigned int *dfsList, int top, int *); -int sendOidFound(objheader_t *, unsigned int, int, char *buffer, int *bufoffset); +unsigned int getNextOid(objheader_t * header, short * offsetarray, unsigned int *dfsList, int top, int *, int*); +int sendOidFound(objheader_t *, unsigned int, int, struct writestruct *writebuffer); int sendOidNotFound(unsigned int oid, int sd); -void flushResponses(int sd, char * buffer, int * bufoffset); +void flushResponses(int sd, struct writestruct *writebuffer); #endif diff --git a/Robust/src/Runtime/DSTM/interface/sandbox.c b/Robust/src/Runtime/DSTM/interface/sandbox.c new file mode 100644 index 00000000..e4eea7a1 --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/sandbox.c @@ -0,0 +1,134 @@ +#include "sanbox.h" +#include "dstm.h" +#include "runtime.h" + +/* Do sandboxing */ +void errorhandler(int sig, struct sigcontext ctx) { + //TODO modify this + if (sig == SIGSEGV) //Invalid memory segment access + printf("Got signal %d, faulty address is %p, " + "from %p\n", sig, ctx.cr2, ctx.eip); + else + printf("Got signal %d\n", sig); + + threadhandler(sig, ctx); +} + +int checktrans() { + /* Create info to keep track of numelements */ + unsigned int size = c_size; + chashlistnode_t *curr = c_table; + int i; + nodeElem_t *head=NULL; + + for(i = 0; i< size; i++) { + chashlistnode_t *curr = &ptr[i]; + /* Inner loop to traverse the linked list of the cache lookupTable */ + while(curr != NULL) { + if (curr->key == 0) + break; + objheader_t *headeraddr=(objheader_t*) curr->val; + unsigned int machinenum; + if (STATUS(headeraddr) & NEW || (mhashSearch(curr->key) != NULL)) { + machinenum = myIpAddr; + } else if ((machinenum = lhashSearch(curr->key)) == 0) { + printf("Error: No such machine %s, %d\n", __FILE__, __LINE__); + return 0; + } + head = createList(head, headeraddr, machinenum, c_numelements); + curr = curr->next; + } + } + /* Send oid and versions for checking */ + verify(); + + //free head + deletehead(head); + return 0; +} + +nodeElem_t * createList(nodeElem_t *head, objheader_t *headeraddr, unsigned int mid, + unsigned int c_numelements) { + + nodeElem_t *ptr, *tmp; + int found = 0, offset = 0; + tmp = head; + + while(tmp != NULL) { + if(tmp->mid == mid) { + if (STATUS(headeraddr) & DIRTY) { + tmp->oidmod[tmp->nummod]->oid = OID(headeraddr); + tmp->oidmod[tmp->nummod]->version = headeraddr->version; + tmp->nummod++; + } else { + tmp->oidread[tmp->numread]->oid = OID(headeraddr); + tmp->oidread[tmp->numread]->version = headeraddr->version; + tmp->numread++; + } + found = 1; + break; + } + tmp = tmp->next; + } + //Add oid for any new machine + if (!found) { + ptr = makehead(c_numelements); + if((ptr = makehead(c_numelements)) == NULL) { + return NULL; + } + ptr->mid = mid; + if (STATUS(headeraddr) & DIRTY) { + ptr->oidmod[tmp->nummod]->oid = OID(headeraddr); + ptr->oidmod[tmp->nummod]->version = headeraddr->version; + ptr->nummod++; + } else { + ptr->oidread[tmp->numread]->oid = OID(headeraddr); + ptr->oidread[tmp->numread]->version = headeraddr->version; + ptr->numread++; + } + ptr->next = head; + head = ptr; + } + return head; +} + +nodeElem_t * makehead(unsigned int numelements) { + nodeElem_t *head; + //Create the first element + if((head = calloc(1, sizeof(nodeElem_t))) == NULL) { + printf("Calloc error %s %d\n", __FILE__, __LINE__); + return NULL; + } + if ((head->oidmod = calloc(numelements, sizeof(elem_t))) == NULL) { + printf("Calloc error %s %d\n", __FILE__, __LINE__); + free(head); + return NULL; + } + if ((head->oidread = calloc(numelements, sizeof(elem_t))) == NULL) { + printf("Calloc error %s %d\n", __FILE__, __LINE__); + free(head); + free(head->oidmod); + return NULL; + } + head->mid = 0; + head->nummod = head->numread = 0; + head->next = NULL; + return head; +} + +//Delete the entire list +void pDelete(nodeElem_t *head) { + nodeElem_t *next, *tmp; + tmp = head; + while(tmp != NULL) { + next = tmp->next; + free(tmp->oidmod); + free(tmp->oidread); + free(tmp); + tmp = next; + } + return; +} + +void verify() { +} diff --git a/Robust/src/Runtime/DSTM/interface/sandbox.h b/Robust/src/Runtime/DSTM/interface/sandbox.h new file mode 100644 index 00000000..b9844dff --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/sandbox.h @@ -0,0 +1,30 @@ +#ifndef SANDBOX_H +#define SANDBOX_H + +#include +extern __thread chashlistnode_t *c_table; +extern __thread unsigned int c_size; +extern __thread unsigned int c_numelements; + +typedef struct elem { + unsigned int oid; + unsigned short version; +} elem_t; + +typedef struct nodeElem { + unsigned int mid; + unsigned int numread; + unsigned int nummod; + elem_t *oidread; + elem_t *oidmod; + struct nodeElem *next; +} nodeElem_t; + + +int checktrans(); +void errorhandler(int sig, struct sigcontext ctx); +nodeElem_t * makehead(unsigned int numelements); +void deletehead(nodeElem_t *head); +nodeElem_t * createList(nodeElem_t *, objheader_t *, unsigned int, unsigned int); + +#endif diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c index 11e27984..564100b7 100644 --- a/Robust/src/Runtime/DSTM/interface/trans.c +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -789,6 +789,7 @@ remoteread: #ifdef COMPILER #ifdef CACHE LOGOIDTYPE("RR",oid, TYPE(objcopy),myrdtsc()); + LOGTIME('r', oid, TYPE(objcopy),myrdtsc(),0); //Copy object to prefetch cache pthread_mutex_lock(&prefetchcache_mutex); objheader_t *headerObj; @@ -1628,6 +1629,7 @@ int checkoid(unsigned int oid, int isLastOffset) { //Found on machine return 1; } else if ((header=prehashSearch(oid))!=NULL) { + //if the last offset then prefetch object if((STATUS(header) & DIRTY) && isLastOffset) { return 0; } @@ -1829,7 +1831,7 @@ int getPrefetchResponse(int sd, struct readstruct *readbuffer) { /* Do a version comparison if the oid exists */ if((oldptr = prehashSearch(oid)) != NULL) { /* If older version then update with new object ptr */ - if(((objheader_t *)oldptr)->version <= ((objheader_t *)modptr)->version) { + if(((objheader_t *)oldptr)->version < ((objheader_t *)modptr)->version) { prehashInsert(oid, modptr); } } else { /* Else add the object ptr to hash table*/