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 */
((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);
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);
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<offstop) {
+ LOGTIME('C',oid,TYPE(header),0,top);
//okay to continue going down
continue;
}
} else if (oid==2) {
+ LOGTIME('D',oid,0,0,top);
//send prefetch first
int objindex=top+2;
int machinenum = lhashSearch(dfsList[objindex]);
- insertPrefetch(machinenum, dfsList[objindex], numoffset-top, &offsetarray[top], &head);
+ if(machinenum != myIpAddr) {
+ insertPrefetch(machinenum, dfsList[objindex], numoffset-top, &offsetarray[top], &head);
+ }
}
//oid is 0
//go backwards until we can increment
if (top<countInvalidObj)
countInvalidObj=-1;
- header=searchObjInv(dfsList[top], top, &countInvalidObj);
+ header=searchObjInv(dfsList[top], top, &countInvalidObj, NULL);
//header shouldn't be null unless the object moves away, but allow
//ourselves the option to just continue on if we lose the object
} while(header==NULL);
+ LOGTIME('F',OID(header),TYPE(header),0,top);
//increment
dfsList[top+1]++;
}
return head;
}
-//#define PBUFFERSIZE 16384
-#define PBUFFERSIZE 2048
+#define PBUFFERSIZE 16384
//#define PBUFFERSIZE 8192 //Used only for Moldyn benchmark
-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) {
int top;
unsigned int dfsList[numoffset];
- char buffer[PBUFFERSIZE];
- int bufoffset=0;
+ //char buffer[PBUFFERSIZE];
+ //int bufoffset=0;
/* Initialize */
perMcPrefetchList_t *head = NULL;
int offstop=numoffset-2;
if (header==NULL) {
+ LOGTIME('g',oid,0,0,0);
//forward prefetch
//int machinenum = lhashSearch(oid);
//insertPrefetch(machinenum, oid, numoffset, offsetarray, &head);
return head;
} else {
- sendOidFound(header, oid, sd, buffer, &bufoffset);
+ sendOidFound(header, oid, sd, writebuffer);
}
dfsList[0]=oid;
dfsList[1]=0;
+ LOGTIME('G',OID(header),TYPE(header),0, 0);
//Start searching the dfsList
for(top=0; 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;
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 (top<offstop)
//okay to continue going down
continue;
}
} else if (oid==2) {
+ LOGTIME('I',oid,top,0,0);
//send prefetch first
int objindex=top+2;
- //int machinenum = lhashSearch(dfsList[objindex]);
- //insertPrefetch(machinenum, dfsList[objindex], numoffset-top, &offsetarray[top], &head);
+ //forward prefetch
+ /*
+ int machinenum = lhashSearch(dfsList[objindex]);
+ insertPrefetch(machinenum, dfsList[objindex], numoffset-top, &offsetarray[top], &head);
+ */
}
//oid is 0
//go backwards until we can increment
do {
top-=2;
if (top<0) {
- flushResponses(sd, buffer, &bufoffset);
+ flushResponses(sd, writebuffer);
return head;
}
} while(dfsList[top+1] == GET_RANGE(offsetarray[top + 3]));
//header shouldn't be null unless the object moves away, but allow
//ourselves the option to just continue on if we lose the object
} while(header==NULL);
+ LOGTIME('K',OID(header),TYPE(header),0,top);
//increment
dfsList[top+1]++;
}
- flushResponses(sd, buffer, &bufoffset);
+ flushResponses(sd, writebuffer);
return head;
}
}
-INLINE objheader_t *searchObjInv(unsigned int oid, int top, int *countInvalidObj) {
+INLINE objheader_t *searchObjInv(unsigned int oid, int top, int *countInvalidObj, int *isLastOffset) {
objheader_t *header;
if ((header = (objheader_t *)mhashSearch(oid)) != NULL) {
return header;
header = prehashSearch(oid);
if(header != NULL) {
if((STATUS(header) & DIRTY) && (countInvalidObj!= NULL)) {
- if ((*countInvalidObj)==-1) {
- *countInvalidObj=top;
- } else {
- return NULL;
- }
+ if ((*countInvalidObj)==-1) {
+ *countInvalidObj=top;
+ } else {
+ return NULL;
+ }
}
+ if((STATUS(header) & DIRTY) && isLastOffset)
+ return NULL;
}
return header;
}
len+=sizeof(int);
}
if(tmp!=NULL)
- send_buf(sd, & writebuffer, oidnoffset, len);
+ send_buf(sd, &writebuffer, oidnoffset, len);
else
- forcesend_buf(sd, & writebuffer, oidnoffset, len);
+ forcesend_buf(sd, &writebuffer, oidnoffset, len);
//send_data(sd, oidnoffset, len);
//tmp = tmp->next;
}
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;
}
-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];
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;
}
}
}
-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);
if ((*bufoffset)==0) {
send_data(sd, sendbuffer, size+incr);
}
+ */
return 0;
}
--- /dev/null
+#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() {
+}