change prefetch lookup table's insert method to avoid duplicate entries in the
authoradash <adash>
Thu, 3 Dec 2009 17:37:40 +0000 (17:37 +0000)
committeradash <adash>
Thu, 3 Dec 2009 17:37:40 +0000 (17:37 +0000)
prefetch lookup table
No need to call remove method before insert method in the prefetch cache lookup table

Robust/src/Runtime/DSTM/interface/prefetch.c
Robust/src/Runtime/DSTM/interface/prelookup.c
Robust/src/Runtime/DSTM/interface/prelookup.h

index 2a083aaff1c3fb9f98fcd678e32d744aa4e0b63a..23454d5a2a9c3759149c2ca4e13bc766c9635170 100644 (file)
@@ -399,10 +399,10 @@ int getRangePrefetchResponse(int sd, struct readstruct * readbuffer) {
       /* Insert into prefetch hash lookup table */
       void * oldptr;
       if((oldptr = prehashSearch(oid)) != NULL) {
-       if(((objheader_t *)oldptr)->version <= ((objheader_t *)ptr)->version) {
-         prehashRemove(oid);
-         prehashInsert(oid, ptr);
-       }
+        if(((objheader_t *)oldptr)->version < ((objheader_t *)ptr)->version) {
+          //prehashRemove(oid);
+          prehashInsert(oid, ptr);
+        }
       } else {
        prehashInsert(oid, ptr);
       }
index 8c09c1010f559913e24902f6940c4db322433d1f..9a3d5361d95f1dc73052b14ed8d944728e2150c2 100644 (file)
@@ -9,7 +9,6 @@ prehashtable_t pflookup; //Global prefetch cache table
 
 unsigned int prehashCreate(unsigned int size, float loadfactor) {
   prehashlistnode_t *nodes;
-  int i;
 
   // Allocate space for the hash table
   if((nodes = calloc(size, sizeof(prehashlistnode_t))) == NULL) {
@@ -43,7 +42,53 @@ unsigned int prehashFunction(unsigned int key) {
 
 //Store oids and their pointers into hash
 void prehashInsert(unsigned int key, void *val) {
-  prehashlistnode_t *ptr;
+  prehashlistnode_t *ptr,*node,*tmp;
+  int index, isFound=0;
+  if(key==0) {
+    printf("Error: Trying to insert invalid key and value\n");
+    return;
+  }
+  if(pflookup.numelements > (pflookup.threshold)) {
+    //Resize
+    unsigned int newsize = pflookup.size << 1;
+    pthread_mutex_lock(&pflookup.lock);
+    prehashResize(newsize);
+    pthread_mutex_unlock(&pflookup.lock);
+  }
+
+  ptr = &pflookup.table[(key & pflookup.mask)>>1];
+  pthread_mutex_lock(&pflookup.lock);
+  if((ptr->key==0) && (ptr->next== NULL)) { //Insert at the first bin of the table
+    ptr->key = key;
+    ptr->val = val;
+    pflookup.numelements++;
+  } else {
+    tmp = ptr;
+    while(tmp != NULL) { 
+      if(tmp->key == key) {
+        isFound=1;
+        tmp->val = val;//Replace value for an exsisting key
+        pthread_mutex_unlock(&pflookup.lock);
+        return;
+      }
+      tmp=tmp->next;
+    }
+    if(!isFound) { //Insert new key and value into the chain of linked list for the given bin
+      node = calloc(1, sizeof(prehashlistnode_t));
+      node->key = key;
+      node->val = val ;
+      node->next = ptr->next;
+      ptr->next=node;
+      pflookup.numelements++;
+    }
+  }
+  pthread_mutex_unlock(&pflookup.lock);
+  return;
+}
+
+/*
+void prehashInsert(unsigned int key, void *val) {
+  prehashlistnode_t *ptr,*node;
   pthread_mutex_lock(&pflookup.lock);
 
   if(pflookup.numelements > (pflookup.threshold)) {
@@ -60,7 +105,7 @@ void prehashInsert(unsigned int key, void *val) {
     ptr->key = key;
     ptr->val = val;
   } else {                      // Insert in the beginning of linked list
-    prehashlistnode_t * node = calloc(1, sizeof(prehashlistnode_t));
+    node = calloc(1, sizeof(prehashlistnode_t));
     node->key = key;
     node->val = val ;
     node->next = ptr->next;
@@ -68,6 +113,7 @@ void prehashInsert(unsigned int key, void *val) {
   }
   pthread_mutex_unlock(&pflookup.lock);
 }
+*/
 
 // Search for an address for a given oid
 INLINE void *prehashSearch(unsigned int key) {
index c49505844eaa6e21ee05e0de68719ca22c12134c..58b75f421944ae9a7b1b766c72dd3e035d1cede4 100644 (file)
@@ -27,8 +27,8 @@ typedef struct prehashtable {
   pthread_mutex_t lock;
   pthread_mutexattr_t prefetchmutexattr;
   pthread_cond_t cond;
-  struct objstr *hack2;
-  struct objstr *hack;
+  //struct objstr *hack2;
+  //struct objstr *hack;
 } prehashtable_t;
 
 /* Prototypes for hash*/