pflookup.threshold=loadfactor*size;
//Initilize
- for(i=0;i<NUMLOCKS;i++){
+ for(i=0;i<PRENUMLOCKS;i++){
pflookup.larray[i].lock=RW_LOCK_BIAS;
}
+ /*
+ //Intiliaze and set prefetch table mutex attribute
+ pthread_mutexattr_init(&pflookup.prefetchmutexattr);
+ //NOTE:PTHREAD_MUTEX_RECURSIVE is currently inside a #if_def UNIX98 in the pthread.h file
+ //Therefore use PTHREAD_MUTEX_RECURSIVE_NP instead
+ pthread_mutexattr_settype(&pflookup.prefetchmutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
+
+ //Initialize mutex var
+ pthread_mutex_init(&pflookup.lock, &pflookup.prefetchmutexattr);
+ //pthread_mutex_init(&pflookup.lock, NULL);
+ pthread_cond_init(&pflookup.cond, NULL);
+ */
+
return 0;
}
}
unsigned int keyindex=key>>1;
- volatile unsigned int * lockptr=&pflookup.larray[keyindex&LOCKMASK].lock;
+ volatile unsigned int * lockptr=&pflookup.larray[keyindex&PRELOCKMASK].lock;
while(!write_trylock(lockptr)) {
sched_yield();
}
ptr = &pflookup.table[keyindex&pflookup.mask];
- if((ptr->key==0) && (ptr->next== NULL)) { //Insert at the first bin of the table
+ if(ptr->key==0) { //Insert at the first bin of the table
ptr->key = key;
ptr->val = val;
atomic_inc(&pflookup.numelements);
isFound=1;
tmp->val = val;//Replace value for an exsisting key
write_unlock(lockptr);
-
return;
}
tmp=tmp->next;
}
// Search for an address for a given oid
-INLINE void *prehashSearch(unsigned int key) {
+void *prehashSearch(unsigned int key) {
int index;
unsigned int keyindex=key>>1;
- volatile unsigned int * lockptr=&pflookup.larray[keyindex&LOCKMASK].lock;
+ volatile unsigned int * lockptr=&pflookup.larray[keyindex&PRELOCKMASK].lock;
while(!read_trylock(lockptr)) {
sched_yield();
}
prehashlistnode_t *prev;
prehashlistnode_t *ptr, *node;
+ //eom
unsigned int keyindex=key>>1;
- volatile unsigned int * lockptr=&pflookup.larray[keyindex&LOCKMASK].lock;
+ volatile unsigned int * lockptr=&pflookup.larray[keyindex&PRELOCKMASK].lock;
while(!write_trylock(lockptr)) {
sched_yield();
}
prehashlistnode_t *curr = &pflookup.table[keyindex&pflookup.mask];
-
+ //eom
+
for (; curr != NULL; curr = curr->next) {
if (curr->key == key) {
// Find a match in the hash table
int i,index;
unsigned int mask;
- for(i=0;i<NUMLOCKS;i++) {
+ for(i=0;i<PRENUMLOCKS;i++) {
volatile unsigned int * lockptr=&pflookup.larray[i].lock;
while(!write_trylock(lockptr)) {
if (pflookup.numelements < pflookup.threshold) {
//release lock and return
- for(i=0;i<NUMLOCKS;i++) {
+ for(i=0;i<PRENUMLOCKS;i++) {
volatile unsigned int * lockptr=&pflookup.larray[i].lock;
write_unlock(lockptr);
}
pflookup.table = node; //Update the global hashtable upon resize()
pflookup.size = newsize;
pflookup.threshold=newsize*pflookup.loadfactor;
- mask=pflookup.mask = (newsize << 1) -1;
+ mask=pflookup.mask = newsize -1;
for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
prehashlistnode_t * curr = &ptr[i];
}
free(ptr); //Free the memory of the old hash table
- for(i=0;i<NUMLOCKS;i++) {
+ for(i=0;i<PRENUMLOCKS;i++) {
volatile unsigned int * lockptr=&pflookup.larray[i].lock;
write_unlock(lockptr);
}
- return ;
+ return 0;
}
//Note: This is based on the implementation of the inserting a key in the first position of the hashtable
#include "gCollect.h"
-#include "prelookup.h"
+#if 0
+#include "altprelookup.h"
+#else
+#inlcude "prelookup.h"
+#endif
extern pthread_mutex_t prefetchcache_mutex; //Mutex to lock Prefetch Cache
pNodeInfo.newptr->prev=tmp;
pNodeInfo.newptr=tmp;
pNodeInfo.os_count++;
-
+
if (pNodeInfo.os_count>PREFETCH_FLUSH_THRESHOLD) {
//remove oldest from linked list
objstr_t *tofree=pNodeInfo.oldptr;
return ptr;
}
+#if 0
void clearBlock(objstr_t *block) {
+
unsigned long int tmpbegin=(unsigned int)block;
unsigned long int tmpend=(unsigned int)block->top;
int i, j;
prehashlistnode_t *ptr;
- pthread_mutex_lock(&pflookup.lock);
+ //pthread_mutex_lock(&pflookup.lock);
+ /*
+ for(i=0;i<PRENUMLOCKS;i++) {
+ volatile unsigned int * lockptr=&pflookup.larray[i].lock;
+
+ while(!write_trylock(lockptr)) {
+ sched_yield();
+ }
+ }
+ */
+ int lockindex=0;
ptr = pflookup.table;
+ volatile unsigned int * lockptr_current=&pflookup.larray[lockindex].lock;
+ while(!write_trylock(lockptr_current)) {
+ sched_yield();
+ }
+
for(i = 0; i<pflookup.size; i++) {
+
prehashlistnode_t *orig=&ptr[i];
prehashlistnode_t *curr = orig;
prehashlistnode_t *next=curr->next;
}
}
}
+
+ if(((i+1)&(pflookup.mask>>4))==0 && (i+1)<pflookup.size){
+ // try to grab new lock
+ lockindex++;
+ volatile unsigned int * lockptr_new=&pflookup.larray[lockindex].lock;
+ while(!write_trylock(lockptr_new)){
+ sched_yield();
+ }
+ //printf("grab new lock id=%d for %d\n",lockindex,i);
+ write_unlock(lockptr_current);
+ lockptr_current=lockptr_new;
+ }
+
+ }// end of for (pflokup)
+
+ write_unlock(lockptr_current);
+
+}
+#else
+void clearBlock(objstr_t *block) {
+ unsigned long int tmpbegin=(unsigned int)block;
+ unsigned long int tmpend=(unsigned int)block->top;
+ int i, j;
+ prehashlistnode_t *ptr;
+ pthread_mutex_lock(&pflookup.lock);
+
+ ptr = pflookup.table;
+ for(i = 0; i<pflookup.size; i++) {
+ prehashlistnode_t *orig=&ptr[i];
+ prehashlistnode_t *curr = orig;
+ prehashlistnode_t *next=curr->next;
+ for(; next != NULL; curr=next, next = next->next) {
+ unsigned int val=(unsigned int)next->val;
+ if ((val>=tmpbegin)&(val<tmpend)) {
+ prehashlistnode_t *tmp=curr->next=next->next;
+ free(next);
+ next=curr;
+ //loop condition is broken now...need to check before incrementing
+ //if (next==NULL)
+ // break;
+ }
+ }
+ {
+ unsigned int val=(unsigned int)orig->val;
+ if ((val>=tmpbegin)&(val<tmpend)) {
+ if (orig->next==NULL) {
+ orig->key=0;
+ orig->val=NULL;
+ } else {
+ next=orig->next;
+ orig->val=next->val;
+ orig->key=next->key;
+ orig->next=next->next;
+ free(next);
+ }
+ }
+ }
}
pthread_mutex_unlock(&pflookup.lock);
}
+#endif
objstr_t *allocateNew(unsigned int size) {
objstr_t *tmp;