bug fixes in gCollect.c and gCollect.h
authoradash <adash>
Tue, 29 Jul 2008 01:49:11 +0000 (01:49 +0000)
committeradash <adash>
Tue, 29 Jul 2008 01:49:11 +0000 (01:49 +0000)
changes to trans.c that aids in prefetch cache allocation

Robust/src/Runtime/DSTM/interface/addUdpEnhance.h
Robust/src/Runtime/DSTM/interface/dstm.h
Robust/src/Runtime/DSTM/interface/gCollect.c
Robust/src/Runtime/DSTM/interface/gCollect.h
Robust/src/Runtime/DSTM/interface/ip.c
Robust/src/Runtime/DSTM/interface/objstr.c
Robust/src/Runtime/DSTM/interface/trans.c

index 3a0f9174c69590e8ee0838ebbe15fb12546237de..f68e5ca08ba1768238a5662ef84eb1c05c8cbba0 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _UDP_H
-#define _UDP_H
+#ifndef _ADDUDPENHANCE_H
+#define _ADDUDPENHANCE_H
 
 #include "dstm.h"
 
index c97787c34535981f0279f50d368aaef0fb586231..1f32fad641eaa97cc8e2953c73812c8719607446 100644 (file)
@@ -142,7 +142,6 @@ typedef struct objheader {
 #define GETSIZE(size, x) size=classsize[TYPE(x)]
 #endif
 
-
 typedef struct objstr {
        unsigned int size; //this many bytes are allocated after this header
        void *top;
index 0c0ad9f7528b40aea1bfc3957d81ec7cbb4e9c56..3d1371b3afcbf917043269ee7e9b2f3d70f8ab19 100644 (file)
@@ -14,46 +14,39 @@ void initializePCache() {
 }
 
 void *prefetchobjstrAlloc(unsigned int size) {
-  void * ptr;
+  void * ptr = NULL;
   if(pNodeInfo->num_old_objstr <= PREFETCH_FLUSH_COUNT_THRESHOLD) {
     //regular allocation 
-    pthread_mutex_lock(&prefetchcache_mutex);
     if((ptr = normalPrefetchAlloc(prefetchcache, size)) == NULL) {
       printf("Error: %s() prefetch cache alloc error %s, %d\n", __func__, __FILE__, __LINE__);
-      pthread_mutex_unlock(&prefetchcache_mutex);
       return NULL;
     }
-    pthread_mutex_unlock(&prefetchcache_mutex);
     return ptr;
   } else {
     // Iterate through available blocks to see if size can be allocated
-    if((ptr = lookUpFreeSpace(size)) != NULL) {
+    if((ptr = lookUpFreeSpace(pNodeInfo->newptr, pNodeInfo->oldptr, size)) != NULL) {
       return ptr;
     } else { //allocate new block if size not available
       if(size >= pNodeInfo->maxsize) {
-        objstr_t *tmp;
-        if((tmp = (objstr_t *) calloc(1, (sizeof(objstr_t) +size))) == NULL) {
+        if((ptr = allocateNew(size)) == NULL) {
           printf("Error: %s() Calloc error %s %d\n", __func__, __FILE__, __LINE__);
           return NULL;
         }
-        tmp->size = size;
-        tmp->top = (void *)(((unsigned int)tmp) + sizeof(objstr_t) + size);
-        //Insert newly allocated block into linked list of prefetch cache
-        tmp->next = ((objstr_t *)(pNodeInfo->newptr))->next;
-        ((objstr_t *)(pNodeInfo->newptr))->next = tmp;
-        pNodeInfo->num_old_objstr++;
-        // Update maxsize of prefetch objstr blocks 
-        if(pNodeInfo->maxsize < tmp->size)
-          pNodeInfo->maxsize = tmp->size;
-        return (void *)(((unsigned int)tmp) + sizeof(objstr_t));
+        return ptr;
       } else { //If size less then reclaim old blocks
-        if((ptr = clearNBlocks(pNodeInfo->oldptr, pNodeInfo->newptr, size)) == NULL) {
-          printf("%s(): Error in flushing from cache blocks %s, %d\n", __func__, __FILE__, __LINE__);
-          return NULL;
-        }
+        clearNBlocks(pNodeInfo->oldptr, pNodeInfo->newptr);
         //update oldptr and newptr
         updatePtrs();
-        return ptr;
+        //look for free space if available in the free blocks
+        if((ptr = lookUpFreeSpace(pNodeInfo->newptr, pNodeInfo->oldptr, size)) != NULL) {
+          return ptr;
+        } else {
+          if((ptr = allocateNew(size)) == NULL) {
+            printf("Error: %s() Calloc error %s %d\n", __func__, __FILE__, __LINE__);
+            return NULL;
+          }
+          return ptr;
+        }
       }
     }
   }
@@ -88,7 +81,7 @@ void *normalPrefetchAlloc(objstr_t *store, unsigned int size) {
       }
       //Update maxsize of objstr blocks, num of blocks and newptr 
       pNodeInfo->num_old_objstr++;
-      if(pNodeInfo->num_old_objstr == PREFETCH_FLUSH_COUNT_THRESHOLD/2)
+      if(pNodeInfo->num_old_objstr <= PREFETCH_FLUSH_COUNT_THRESHOLD/2)
         pNodeInfo->newptr = store;
       if(pNodeInfo->maxsize < size)
         pNodeInfo->maxsize = size;
@@ -100,22 +93,22 @@ void *normalPrefetchAlloc(objstr_t *store, unsigned int size) {
   }
 }
 
-void *lookUpFreeSpace(int size) {
+void *lookUpFreeSpace(void *startAddr, void *endAddr, int size) {
   objstr_t *ptr;
   void *tmp;
-  ptr = (objstr_t *) (pNodeInfo->newptr);
-  while(ptr != NULL && ((unsigned long int)ptr!= (unsigned long int)pNodeInfo->oldptr)) { //always insert in the new region
+  ptr = (objstr_t *) (startAddr);
+  while(ptr != NULL && ((unsigned long int)ptr!= (unsigned long int)endAddr)) { 
     if(((unsigned int)ptr->top - (((unsigned int)ptr) + sizeof(objstr_t)) + size) <= ptr->size) { //store not full
       tmp = ptr->top;
       ptr->top += size;
       return tmp;
-    } 
+    }
     ptr = ptr->next;
   }
   return NULL;
 }
 
-void *clearNBlocks(void *oldaddr, void * newaddr, unsigned int size){
+void clearNBlocks(void *oldaddr, void * newaddr) {
   int count = 0;
   objstr_t *tmp = (objstr_t *) oldaddr;
   pthread_mutex_lock(&pflookup.lock);
@@ -123,15 +116,12 @@ void *clearNBlocks(void *oldaddr, void * newaddr, unsigned int size){
     void * begin = (void *)tmp+sizeof(objstr_t);
     void * end = (void *)tmp+sizeof(objstr_t)+tmp->size;
     tmp->top = (void *)tmp+sizeof(objstr_t);
-    //TODO only for testing purpose, remove later
     clearPLookUpTable(begin, end);
+    //TODO only for testing purpose, remove later
     memset(tmp->top, 0, tmp->size);
     tmp = tmp->next;
   }
   pthread_mutex_unlock(&pflookup.lock);
-  void *ptr = ((objstr_t *)oldaddr)->top;
-  ((objstr_t *)oldaddr)->top += size;
-  return ptr;
 }
 
 void clearPLookUpTable(void *begin, void *end) {
@@ -158,3 +148,21 @@ void updatePtrs() {
   pNodeInfo->oldptr = pNodeInfo->newptr;
   pNodeInfo->newptr = ptr;
 }
+
+void *allocateNew(unsigned int size) {
+  objstr_t *tmp;
+  if((tmp = (objstr_t *) calloc(1, (sizeof(objstr_t) +size))) == NULL) {
+    printf("Error: %s() Calloc error %s %d\n", __func__, __FILE__, __LINE__);
+    return NULL;
+  }
+  tmp->size = size;
+  tmp->top = (void *)(((unsigned int)tmp) + sizeof(objstr_t) + size);
+  //Insert newly allocated block into linked list of prefetch cache
+  tmp->next = ((objstr_t *)(pNodeInfo->newptr))->next;
+  ((objstr_t *)(pNodeInfo->newptr))->next = tmp;
+  pNodeInfo->num_old_objstr++;
+  // Update maxsize of prefetch objstr blocks 
+  if(pNodeInfo->maxsize < tmp->size)
+    pNodeInfo->maxsize = tmp->size;
+  return (void *)(((unsigned int)tmp) + sizeof(objstr_t));
+}
index 4ffc9a294c7326e4fa8828f9ff3b80da794f8595..f45075a12dca5154e4afb1a689d381f120ebb0e2 100644 (file)
@@ -2,7 +2,6 @@
 #define _GCOLLECT_H
 
 #include "dstm.h"
-//#include "prelookup.h"
 
 /***********************************
  ****** Global constants **********
@@ -25,8 +24,9 @@ typedef struct prefetchNodeInfo {
 void *prefetchobjstrAlloc(unsigned int size);
 void *normalPrefetchAlloc(objstr_t *, unsigned int);
 void initializePCache();
-void *lookUpFreeSpace(int);
-void *clearNBlocks(void *, void *, unsigned int);
+void *lookUpFreeSpace(void *, void *, int);
+void clearNBlocks(void *, void *);
 void clearPLookUpTable(void *, void *);
 void updatePtrs();
+void *allocateNew(unsigned int size);
 #endif
index bbd8e2f67329f7f9cad69e8df19a56712a6128dd..9c97347e5b8422e8ecdb198df0bbe7e1aab2d0af 100644 (file)
@@ -29,6 +29,9 @@ void midtoIP(unsigned int mid, char *ptr) {
        i.c = (mid & 0x0000ff00) >> 8;
        i.d = mid & 0x000000ff;
        sprintf(ptr, "%d.%d.%d.%d", i.a, i.b, i.c, i.d);
+#ifdef DEBUG
+       printf("DEBUG-> midtoIP() mid = %d.%d.%d.%d\n", i.a, i.b, i.c, i.d);
+#endif
        return;
 }
 
index e7caec5661c13b29ab477c4298d4f732bfa3281a..32bf38de875de47051e699e6a5c87bb34ce1c4c9 100644 (file)
@@ -1,5 +1,4 @@
 #include "dstm.h"
-extern objstr_t *prefetchcache;
 
 objstr_t *objstrCreate(unsigned int size) {
   objstr_t *tmp;
@@ -36,20 +35,20 @@ void *objstrAlloc(objstr_t *store, unsigned int size) {
     if (store->next == NULL) {
       //end of list, all full
       if (size > DEFAULT_OBJ_STORE_SIZE) {
-       //in case of large objects
-       if((store->next = (objstr_t *)calloc(1,(sizeof(objstr_t) + size))) == NULL) {
-         printf("%s() Calloc error at line %d, %s\n", __func__, __LINE__, __FILE__);
-         return NULL;
-       }
-       store = store->next;
-       store->size = size;
+        //in case of large objects
+        if((store->next = (objstr_t *)calloc(1,(sizeof(objstr_t) + size))) == NULL) {
+          printf("%s() Calloc error at line %d, %s\n", __func__, __LINE__, __FILE__);
+          return NULL;
+        }
+        store = store->next;
+        store->size = size;
       } else {
-       if((store->next = calloc(1,(sizeof(objstr_t) + DEFAULT_OBJ_STORE_SIZE))) == NULL) {
-         printf("%s() Calloc error at line %d, %s\n", __func__, __LINE__, __FILE__);
-         return NULL;
-       }
-       store = store->next;
-       store->size = DEFAULT_OBJ_STORE_SIZE;
+        if((store->next = calloc(1,(sizeof(objstr_t) + DEFAULT_OBJ_STORE_SIZE))) == NULL) {
+          printf("%s() Calloc error at line %d, %s\n", __func__, __LINE__, __FILE__);
+          return NULL;
+        }
+        store = store->next;
+        store->size = DEFAULT_OBJ_STORE_SIZE;
       }
       store->top = (void *)(((unsigned int)store) + sizeof(objstr_t) + size);
       return (void *)(((unsigned int)store) + sizeof(objstr_t));
index c4139fc0ee4718c391f8302c293d52ebe593b66c..943ea720ece390c530e5e85017c07c0857f3c66a 100644 (file)
@@ -9,6 +9,7 @@
 #include "threadnotify.h"
 #include "queue.h"
 #include "addUdpEnhance.h"
+#include "gCollect.h"
 #ifdef COMPILER
 #include "thread.h"
 #endif
@@ -19,6 +20,7 @@
 
 /* Global Variables */
 extern int classsize[];
+
 objstr_t *prefetchcache; //Global Prefetch cache
 pthread_mutex_t prefetchcache_mutex;// Mutex to lock Prefetch Cache
 pthread_mutexattr_t prefetchcache_mutex_attr; /* Attribute for lock to make it a recursive lock */
@@ -44,8 +46,8 @@ pthread_mutex_t atomicObjLock;
 /***********************************
  * Global Variables for statistics
  **********************************/
-extern int numTransCommit;
-extern int numTransAbort;
+int numTransCommit = 0;
+int numTransAbort = 0;
 
 void printhex(unsigned char *, int);
 plistnode_t *createPiles(transrecord_t *);
@@ -92,6 +94,7 @@ int recv_data_errorcode(int fd , void *buf, int buflen) {
     if (numbytes==0)
       return 0;
     if (numbytes == -1) {
+      perror("recv");
       return -1;
     }
     buffer += numbytes;
@@ -226,6 +229,7 @@ void transInit() {
   int retval;
   //Create and initialize prefetch cache structure
   prefetchcache = objstrCreate(PREFETCH_CACHE_SIZE);
+  initializePCache();
   
   /* Initialize attributes for mutex */
   pthread_mutexattr_init(&prefetchcache_mutex_attr);
@@ -588,7 +592,7 @@ int transCommit(transrecord_t *record) {
   
   if(treplyctrl == TRANS_ABORT) {
 #ifdef TRANSSTATS
-    ++numTransAbort;
+    numTransAbort++;
 #endif
     /* Free Resources */
     objstrDelete(record->cache);
@@ -599,7 +603,7 @@ int transCommit(transrecord_t *record) {
     return TRANS_ABORT;
   } else if(treplyctrl == TRANS_COMMIT) {
 #ifdef TRANSSTATS
-    ++numTransCommit;
+    numTransCommit++;
 #endif
     /* Free Resources */
     objstrDelete(record->cache);
@@ -642,7 +646,7 @@ void *transRequest(void *threadarg) {
 
   /* Open Connection */
   if (connect(sd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
-    perror("Error in connect for TRANS_REQUEST\n");
+    perror("transRequest() connect");
     close(sd);
     pthread_exit(NULL);
   }
@@ -679,7 +683,7 @@ void *transRequest(void *threadarg) {
     recv_data(sd, &length, sizeof(int));
     void *newAddr;
     pthread_mutex_lock(&prefetchcache_mutex);
-    if ((newAddr = objstrAlloc(prefetchcache, length)) == NULL) {
+    if ((newAddr = prefetchobjstrAlloc((unsigned int)length)) == NULL) {
       printf("Error: %s() objstrAlloc error for copying into prefetch cache %s, %d\n", __func__, __FILE__, __LINE__);
       close(sd);
       pthread_exit(NULL);
@@ -841,8 +845,9 @@ int updatePrefetchCache(thread_data_array_t* tdata, int numoid, char oidType) {
     header = (objheader_t *) chashSearch(tdata->rec->lookupTable, oid);
     //copy object into prefetch cache
     GETSIZE(size, header);
-    if ((newAddr = objstrAlloc(prefetchcache, (size + sizeof(objheader_t)))) == NULL) {
+    if ((newAddr = prefetchobjstrAlloc(size + sizeof(objheader_t))) == NULL) {
       printf("Error: %s() objstrAlloc error for copying into prefetch cache %s, %d\n", __func__, __FILE__, __LINE__);
+      pthread_mutex_unlock(&prefetchcache_mutex);
       return -1;
     }
     pthread_mutex_unlock(&prefetchcache_mutex);
@@ -1320,10 +1325,9 @@ int getPrefetchResponse(int sd) {
   control = *((char *) recvbuffer);
   if(control == OBJECT_FOUND) {
     oid = *((unsigned int *)(recvbuffer + sizeof(char)));
-    //printf("oid %d found\n",oid);
     size = size - (sizeof(char) + sizeof(unsigned int));
     pthread_mutex_lock(&prefetchcache_mutex);
-    if ((modptr = objstrAlloc(prefetchcache, size)) == NULL) {
+    if ((modptr = prefetchobjstrAlloc(size)) == NULL) {
       printf("Error: objstrAlloc error for copying into prefetch cache %s, %d\n", __FILE__, __LINE__);
       pthread_mutex_unlock(&prefetchcache_mutex);
       return -1;