From: bdemsky Date: Tue, 14 Apr 2009 00:52:35 +0000 (+0000) Subject: changes to improve performance X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=58ee45185c4f2f71129f7a874e192823765f323e;p=IRC.git changes to improve performance --- diff --git a/Robust/src/Runtime/STM/stmlookup.c b/Robust/src/Runtime/STM/stmlookup.c index 26da7e5b..024e39de 100644 --- a/Robust/src/Runtime/STM/stmlookup.c +++ b/Robust/src/Runtime/STM/stmlookup.c @@ -8,6 +8,7 @@ __thread unsigned INTPTR 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; @@ -21,7 +22,8 @@ void t_chashCreate(unsigned int size, double loadfactor) { c_loadfactor = loadfactor; c_size = size; c_threshold=size*loadfactor; - c_mask = (size << 3)-1; + c_mask = (size << 4)-1; + c_structs=calloc(1, sizeof(cliststruct_t)); c_numelements = 0; // Initial number of elements in the hash c_list=NULL; } @@ -29,7 +31,8 @@ void t_chashCreate(unsigned int size, double loadfactor) { void t_chashreset() { chashlistnode_t *ptr = c_table; int i; - if (c_numelements<(c_size>>3)) { + + if (c_numelements<(c_size>>4)) { chashlistnode_t *top=&ptr[c_size]; chashlistnode_t *tmpptr=c_list; while(tmpptr!=NULL) { @@ -38,22 +41,18 @@ void t_chashreset() { //zero in list tmpptr->key=0; tmpptr->next=NULL; - } else { - free(tmpptr); } tmpptr=next; } } else { - for(i=0 ; inext; - free(curr); - curr=next; - } - } bzero(c_table, sizeof(chashlistnode_t)*c_size); } + while(c_structs->next!=NULL) { + cliststruct_t *next=c_structs->next; + free(c_structs); + c_structs=next; + } + c_structs->num = 0; c_numelements = 0; c_list=NULL; } @@ -69,7 +68,7 @@ void t_chashInsert(void * key, void *val) { t_chashResize(newsize); } - ptr = &c_table[(((unsigned INTPTR)key)&c_mask)>>3]; + ptr = &c_table[(((unsigned INTPTR)key)&c_mask)>>4]; c_numelements++; if(ptr->key==0) { @@ -78,7 +77,18 @@ void t_chashInsert(void * key, void *val) { ptr->lnext=c_list; c_list=ptr; } else { // Insert in the beginning of linked list - chashlistnode_t * node = calloc(1, sizeof(chashlistnode_t)); + chashlistnode_t * node; + if (c_structs->numarray[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; @@ -91,7 +101,7 @@ void t_chashInsert(void * key, void *val) { // Search for an address for a given oid INLINE void * t_chashSearch(void * key) { //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE - chashlistnode_t *node = &c_table[(((unsigned INTPTR)key) & c_mask)>>3]; + chashlistnode_t *node = &c_table[(((unsigned INTPTR)key) & c_mask)>>4]; do { if(node->key == key) { @@ -102,6 +112,7 @@ INLINE void * t_chashSearch(void * key) { return NULL; } + unsigned int t_chashResize(unsigned int newsize) { chashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list unsigned int oldsize; @@ -121,7 +132,7 @@ unsigned int t_chashResize(unsigned int newsize) { c_table = node; //Update the global hashtable upon resize() c_size = newsize; c_threshold = newsize * c_loadfactor; - mask=c_mask = (newsize << 3)-1; + mask=c_mask = (newsize << 4)-1; for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table curr = &ptr[i]; @@ -133,18 +144,15 @@ 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 = (((unsigned INTPTR)key) & mask) >>3; + index = (((unsigned INTPTR)key) & mask) >>4; 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; tmp->lnext=c_list; c_list=tmp; - if (!isfirst) { - free(curr); - } }/* NOTE: Add this case if you change this... This case currently never happens because of the way things rehash.... @@ -174,17 +182,14 @@ unsigned int t_chashResize(unsigned int newsize) { //Delete the entire hash table void t_chashDelete() { int i; - chashlistnode_t *ptr = c_table; - - for(i=0 ; inext; - 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; c_list=NULL; } diff --git a/Robust/src/Runtime/STM/stmlookup.h b/Robust/src/Runtime/STM/stmlookup.h index 476716e1..c6af2e59 100644 --- a/Robust/src/Runtime/STM/stmlookup.h +++ b/Robust/src/Runtime/STM/stmlookup.h @@ -34,6 +34,13 @@ typedef struct chashtable { double loadfactor; } chashtable_t; +#define NUMCLIST 250 +typedef struct clist { + struct chashlistnode array[NUMCLIST]; + int num; + struct clist *next; +} cliststruct_t; + void t_chashCreate(unsigned int size, double loadfactor); void t_chashInsert(void * key, void *val); @@ -50,5 +57,6 @@ extern __thread unsigned INTPTR c_mask; extern __thread unsigned int c_numelements; extern __thread unsigned int c_threshold; extern __thread double c_loadfactor; +extern __thread cliststruct_t *c_structs; #endif diff --git a/Robust/src/Runtime/STM/tm.h b/Robust/src/Runtime/STM/tm.h index 6910348b..5f701588 100644 --- a/Robust/src/Runtime/STM/tm.h +++ b/Robust/src/Runtime/STM/tm.h @@ -89,7 +89,7 @@ typedef struct objheader { void * inputvalue;\ if ((inputvalue=y)==NULL) x=NULL;\ else { \ -chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>3]; \ +chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>4]; \ do { \ if (cnodetmp->key==inputvalue) {x=cnodetmp->val;break;} \ cnodetmp=cnodetmp->next;\ diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index 3fadff44..9c440563 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -148,7 +148,7 @@ void fixobjlist(struct objlist * ptr) { } void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, unsigned int tc_size) { - unsigned int mask=(tc_size<<3)-1; + unsigned int mask=(tc_size<<4)-1; chashlistnode_t *node=calloc(tc_size, sizeof(chashlistnode_t)); chashlistnode_t *ptr=*tc_table; chashlistnode_t *curr; @@ -200,7 +200,7 @@ void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, unsigned i } next = curr->next; - index = (((unsigned INTPTR)key) & mask) >>3; + index = (((unsigned INTPTR)key) & mask) >>4; curr->key=key; tmp=&node[index]; @@ -210,11 +210,19 @@ void fixtable(chashlistnode_t ** tc_table, chashlistnode_t **tc_list, unsigned i tmp->val = curr->val; tmp->lnext=newlist; newlist=tmp; - if (!isfirst) { - free(curr); - } } else if (isfirst) { - chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t)); + chashlistnode_t *newnode; + if (c_structs->numarray[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; + newnode=&tcl->array[0]; + tcl->num=1; + } newnode->key = curr->key; newnode->val = curr->val; newnode->next = tmp->next;