-#ifndef _UDP_H
-#define _UDP_H
+#ifndef _ADDUDPENHANCE_H
+#define _ADDUDPENHANCE_H
#include "dstm.h"
#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;
}
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;
+ }
}
}
}
}
//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;
}
}
-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);
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) {
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));
+}
#define _GCOLLECT_H
#include "dstm.h"
-//#include "prelookup.h"
/***********************************
****** Global constants **********
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
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;
}
#include "dstm.h"
-extern objstr_t *prefetchcache;
objstr_t *objstrCreate(unsigned int size) {
objstr_t *tmp;
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));
#include "threadnotify.h"
#include "queue.h"
#include "addUdpEnhance.h"
+#include "gCollect.h"
#ifdef COMPILER
#include "thread.h"
#endif
/* 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 */
/***********************************
* 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 *);
if (numbytes==0)
return 0;
if (numbytes == -1) {
+ perror("recv");
return -1;
}
buffer += numbytes;
int retval;
//Create and initialize prefetch cache structure
prefetchcache = objstrCreate(PREFETCH_CACHE_SIZE);
+ initializePCache();
/* Initialize attributes for mutex */
pthread_mutexattr_init(&prefetchcache_mutex_attr);
if(treplyctrl == TRANS_ABORT) {
#ifdef TRANSSTATS
- ++numTransAbort;
+ numTransAbort++;
#endif
/* Free Resources */
objstrDelete(record->cache);
return TRANS_ABORT;
} else if(treplyctrl == TRANS_COMMIT) {
#ifdef TRANSSTATS
- ++numTransCommit;
+ numTransCommit++;
#endif
/* Free Resources */
objstrDelete(record->cache);
/* 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);
}
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);
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);
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;