From 4de7c3ba83a0ea55dffa98f03bd85fb446aa3cce Mon Sep 17 00:00:00 2001 From: adash Date: Thu, 3 Dec 2009 17:37:40 +0000 Subject: [PATCH] change prefetch lookup table's insert method to avoid duplicate entries in the 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 | 8 +-- Robust/src/Runtime/DSTM/interface/prelookup.c | 52 +++++++++++++++++-- Robust/src/Runtime/DSTM/interface/prelookup.h | 4 +- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Robust/src/Runtime/DSTM/interface/prefetch.c b/Robust/src/Runtime/DSTM/interface/prefetch.c index 2a083aaf..23454d5a 100644 --- a/Robust/src/Runtime/DSTM/interface/prefetch.c +++ b/Robust/src/Runtime/DSTM/interface/prefetch.c @@ -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); } diff --git a/Robust/src/Runtime/DSTM/interface/prelookup.c b/Robust/src/Runtime/DSTM/interface/prelookup.c index 8c09c101..9a3d5361 100644 --- a/Robust/src/Runtime/DSTM/interface/prelookup.c +++ b/Robust/src/Runtime/DSTM/interface/prelookup.c @@ -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) { diff --git a/Robust/src/Runtime/DSTM/interface/prelookup.h b/Robust/src/Runtime/DSTM/interface/prelookup.h index c4950584..58b75f42 100644 --- a/Robust/src/Runtime/DSTM/interface/prelookup.h +++ b/Robust/src/Runtime/DSTM/interface/prelookup.h @@ -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*/ -- 2.34.1