get some more improvements...now at 12x speedup for remote array accesses
authorbdemsky <bdemsky>
Wed, 23 Sep 2009 09:36:19 +0000 (09:36 +0000)
committerbdemsky <bdemsky>
Wed, 23 Sep 2009 09:36:19 +0000 (09:36 +0000)
Robust/src/Runtime/DSTM/interface/clookup.c
Robust/src/Runtime/DSTM/interface/dstmserver.c
Robust/src/Runtime/DSTM/interface/trans.c

index d2ec50a9dd5c4efc807cc33cc1afc54a1e67b87e..5ce813e1202c0e9748a08dda419dd3b766f08167 100644 (file)
@@ -1,11 +1,19 @@
 #include "clookup.h"
 
+#define NUMCLIST 250
+typedef struct clist {
+  struct chashlistnode array[NUMCLIST];
+  int num;
+  struct clist *next;
+} cliststruct_t;
+
 __thread chashlistnode_t *c_table;
 __thread unsigned int c_size;
 __thread unsigned int c_mask;
 __thread unsigned int c_numelements;
 __thread unsigned int c_threshold;
 __thread double c_loadfactor;
+__thread cliststruct_t *c_structs;
 
 void t_chashCreate(unsigned int size, double loadfactor) {
   chashtable_t *ctable;
@@ -20,6 +28,7 @@ void t_chashCreate(unsigned int size, double loadfactor) {
   c_size = size;
   c_threshold=size*loadfactor;
   c_mask = (size << 1)-1;
+  c_structs=calloc(1,sizeof(cliststruct_t));
   c_numelements = 0; // Initial number of elements in the hash
 }
 
@@ -101,7 +110,6 @@ INLINE void * chashSearch(chashtable_t *table, unsigned int key) {
 void t_chashInsert(unsigned int key, void *val) {
   chashlistnode_t *ptr;
 
-
   if(c_numelements > (c_threshold)) {
     //Resize
     unsigned int newsize = c_size << 1;
@@ -115,7 +123,18 @@ void t_chashInsert(unsigned int key, void *val) {
     ptr->key=key;
     ptr->val=val;
   } else { // Insert in the beginning of linked list
-    chashlistnode_t * node = calloc(1, sizeof(chashlistnode_t));
+    chashlistnode_t * node;
+    if (c_structs->num<NUMCLIST) {
+      node=&c_structs->array[c_structs->num];
+      c_structs->num++;
+    } else {
+      //get new list                                                                
+      cliststruct_t *tcl=calloc(1,sizeof(cliststruct_t));
+      tcl->next=c_structs;
+      c_structs=tcl;
+      node=&tcl->array[0];
+      tcl->num=1;
+    }
     node->key = key;
     node->val = val;
     node->next = ptr->next;
@@ -273,16 +292,13 @@ unsigned int t_chashResize(unsigned int newsize) {
       if ((key=curr->key) == 0) {             //Exit inner loop if there the first element is 0
        break;                  //key = val =0 for element if not present within the hash table
       }
-      next = curr->next;
       index = (key & mask) >>1;
       tmp=&node[index];
+      next = curr->next;
       // Insert into the new table
       if(tmp->key == 0) {
-       tmp->key = curr->key;
+       tmp->key = key;
        tmp->val = curr->val;
-       if (!isfirst) {
-         free(curr);
-       }
       }/*
         NOTE:  Add this case if you change this...
         This case currently never happens because of the way things rehash....
@@ -326,17 +342,13 @@ void chashDelete(chashtable_t *ctable) {
 
 //Delete the entire hash table
 void t_chashDelete() {
-  int i;
-  chashlistnode_t *ptr = c_table;
-
-  for(i=0 ; i<c_size ; i++) {
-    chashlistnode_t * curr = ptr[i].next;
-    while(curr!=NULL) {
-      chashlistnode_t * next = curr->next;
-      free(curr);
-      curr=next;
-    }
+  cliststruct_t *ptr=c_structs;
+  while(ptr!=NULL) {
+    cliststruct_t *next=ptr->next;
+    free(ptr);
+    ptr=next;
   }
-  free(ptr);
+  free(c_table);
   c_table=NULL;
+  c_structs=NULL;
 }
index 0cb3490d2e74c5342e3252120fa73a8ca11fda52..fc95dbc38e02436bc90ba278fe7cb220315bf30d 100644 (file)
@@ -746,6 +746,7 @@ int prefetchReq(int acceptfd, struct readstruct * readbuffer) {
   unsigned int oid, mid=-1;
   objheader_t *header;
   oidmidpair_t oidmid;
+  struct writestruct writebuffer;
   int sd = -1;
   while(1) {
     recv_data_buf((int)acceptfd, readbuffer, &numoffset, sizeof(int));
@@ -755,10 +756,12 @@ int prefetchReq(int acceptfd, struct readstruct * readbuffer) {
     oid = oidmid.oid;
     if (mid != oidmid.mid) {
       if (mid!=-1) {
+       forcesend_buf(sd, &writebuffer, NULL, 0);
        freeSockWithLock(transPResponseSocketPool, mid, sd);
       }
       mid=oidmid.mid;
       sd = getSockWithLock(transPResponseSocketPool, mid);
+      writebuffer.offset=0;
     }
     short offsetarry[numoffset];
     recv_data_buf((int) acceptfd, readbuffer, offsetarry, numoffset*sizeof(short));
@@ -772,7 +775,7 @@ int prefetchReq(int acceptfd, struct readstruct * readbuffer) {
       *((int *) (sendbuffer+sizeof(char))) = size;
       *((char *)(sendbuffer + sizeof(char)+sizeof(int))) = OBJECT_NOT_FOUND;
       *((unsigned int *)(sendbuffer + sizeof(int) + sizeof(char)+sizeof(char))) = oid;
-      send_data(sd, sendbuffer, size+1);
+      send_buf(sd, &writebuffer, sendbuffer, size+1);
     } else { /* Object Found */
       int incr = 1;
       GETSIZE(objsize, header);
@@ -786,7 +789,7 @@ int prefetchReq(int acceptfd, struct readstruct * readbuffer) {
       *((unsigned int *)(sendbuffer+incr)) = oid;
       incr += sizeof(unsigned int);
       memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
-      send_data(sd, sendbuffer, size+1);
+      send_buf(sd, &writebuffer, sendbuffer, size+1);
 
       /* Calculate the oid corresponding to the offset value */
       for(i = 0 ; i< numoffset ; i++) {
@@ -816,7 +819,7 @@ int prefetchReq(int acceptfd, struct readstruct * readbuffer) {
          *((char *)(sendbuffer + sizeof(char)+sizeof(int))) = OBJECT_NOT_FOUND;
          *((unsigned int *)(sendbuffer + sizeof(char)+sizeof(int) + sizeof(char))) = oid;
 
-         send_data(sd, sendbuffer, size+1);
+         send_buf(sd, &writebuffer, sendbuffer, size+1);
          break;
        } else { /* Obj Found */
          int incr = 1;
@@ -831,14 +834,16 @@ int prefetchReq(int acceptfd, struct readstruct * readbuffer) {
          *((unsigned int *)(sendbuffer+incr)) = oid;
          incr += sizeof(unsigned int);
          memcpy(sendbuffer + incr, header, objsize + sizeof(objheader_t));
-         send_data(sd, sendbuffer, size+1);
+         send_buf(sd, &writebuffer, sendbuffer, size+1);
        }
       } //end of for
     }
   } //end of while
     //Release socket
-  if (mid!=-1)
+  if (mid!=-1) {
+    forcesend_buf(sd, &writebuffer, NULL, 0);
     freeSockWithLock(transPResponseSocketPool, mid, sd);
+  }
   return 0;
 }
 
index d9c35860f2806c35360f72dbe320297f25559814..97acba76ffb392d6c8ce18315ef215e2ed09b974 100644 (file)
@@ -284,7 +284,7 @@ inline int findmax(int *array, int arraylength) {
   return max;
 }
 
-#define INLINEPREFETCH 0
+//#define INLINEPREFETCH
 #define PREFTHRESHOLD 4
 
 /* This function is a prefetch call generated by the compiler that
@@ -1604,7 +1604,7 @@ void *transPrefetch(void *t) {
       mcdealloc(pilehead);
     }
     // Deallocate the prefetch queue pile node
-    inctail(numavailable);
+    incmulttail(count);
   }
 }