switch to spaces only..
[IRC.git] / Robust / src / Runtime / DSTM / interface / addPrefetchEnhance.c
index 30da7aa2309b77b6ea12e42f4ed2c72ef0ff07a7..eda8cc3f19729ad08de58712d82b019056afa8a2 100644 (file)
@@ -1,5 +1,5 @@
 #include "addPrefetchEnhance.h"
-#include "prelookup.h"
+#include "altprelookup.h"
 
 extern int numprefetchsites; // Number of prefetch sites
 extern pfcstats_t *evalPrefetch; //Global array that keeps track of operation mode (ON/OFF) for each prefetch site
@@ -7,7 +7,20 @@ extern objstr_t *prefetchcache; //Global Prefetch cache
 extern pthread_mutex_t prefetchcache_mutex; //Mutex to lock Prefetch Cache
 extern unsigned int myIpAddr;
 
-/* This function creates and initializes the 
+//#define LOGEVENTS
+#ifdef LOGEVENTS
+extern char bigarray[16*1024*1024];
+extern int bigindex;
+#define LOGEVENT(x) { \
+    int tmp=bigindex ++;                         \
+    bigarray[tmp]=x;                            \
+}
+#else
+#define LOGEVENT(x)
+#endif
+
+
+/* This function creates and initializes the
  * evalPrefetch global array */
 pfcstats_t *initPrefetchStats() {
   pfcstats_t *ptr;
@@ -38,39 +51,42 @@ char getOperationMode(int siteid) {
   return evalPrefetch[siteid].operMode;
 }
 
-/* This function updates counters and mode of operation of a 
+/* This function updates counters and mode of operation of a
  * prefetch site during runtime. When the prefetch call at a site
  * generates oids that are found/not found in the prefetch cache,
  * we take action accordingly */
 void handleDynPrefetching(int numLocal, int ntuples, int siteid) {
   if(numLocal < ntuples) {
-    /* prefetch not found locally(miss in cache) */
+    /* prefetch not found locally(miss in cache); turn on prefetching*/
     evalPrefetch[siteid].operMode = 1;
     evalPrefetch[siteid].uselesscount = SHUTDOWNINTERVAL;
   } else {
+    //Turn off prefetch site
     if(getOperationMode(siteid) != 0) {
       evalPrefetch[siteid].uselesscount--;
-      if(evalPrefetch[siteid].uselesscount <= 0)
+      if(evalPrefetch[siteid].uselesscount <= 0) {
+        LOGEVENT('O');
         evalPrefetch[siteid].operMode = 0;
+      }
     }
   }
 }
 
-/* This function clears from prefetch cache those 
+#if 1
+/* This function clears from prefetch cache those
  * entries that caused a transaction abort */
-void cleanPCache(thread_data_array_t *tdata) {
-  transrecord_t *rec = tdata->rec;
-  unsigned int size = rec->lookupTable->size;
-  chashlistnode_t *ptr = rec->lookupTable->table;
+void cleanPCache() {
+  unsigned int size = c_size;
+  chashlistnode_t *ptr = c_table;
   int i;
   for(i = 0; i < size; i++) {
     chashlistnode_t *curr = &ptr[i]; //for each entry in the cache lookupTable
     while(curr != NULL) {
-      if(curr->key == 0) 
+      if(curr->key == 0)
         break;
       objheader_t *header1, *header2;
+      /* Not found in local machine's object store and found in prefetch cache */
       if((header1 = mhashSearch(curr->key)) == NULL && ((header2 = prehashSearch(curr->key)) != NULL)) {
-        /* Not found in local machine's object store and found in prefetch cache */
         /* Remove from prefetch cache */
         prehashRemove(curr->key);
       }
@@ -78,41 +94,67 @@ void cleanPCache(thread_data_array_t *tdata) {
     }
   }
 }
+#else
+/* This function clears from prefetch cache those
+ * entries that caused a transaction abort */
+void cleanPCache() {
+  unsigned int size = c_size;
+  struct chashentry *ptr = c_table;
+  int i;
+  for(i = 0; i < size; i++) {
+    struct chashentry *curr = &ptr[i]; //for each entry in the cache lookupTable
+    if(curr->key == 0)
+      continue;
+    objheader_t *header1, *header2;
+    /* Not found in local machine's object store and found in prefetch cache */
+    if((header1 = mhashSearch(curr->key)) == NULL && ((header2 = prehashSearch(curr->key)) != NULL)) {
+      /* Remove from prefetch cache */
+      prehashRemove(curr->key);
+    }
+  }
+}
+#endif
 
 /* This function updates the prefetch cache with
- * entires from the transaction cache when a 
- * transaction commits 
- * Return -1 on error else returns 0 */ 
-int updatePrefetchCache(thread_data_array_t* tdata) {
+ * entries from the transaction cache when a
+ * transaction commits
+ * Return -1 on error else returns 0 */
+int updatePrefetchCache(trans_req_data_t *tdata) {
   int retval;
   char oidType;
-  oidType = 'R';
-  if((retval = copyToCache(tdata->buffer->f.numread, (unsigned int *)(tdata->buffer->objread), tdata, oidType)) != 0) {
-    printf("%s(): Error in copying objects read at %s, %d\n", __func__, __FILE__, __LINE__);
-    return -1;
-  }
-  oidType = 'M';
-  if((retval = copyToCache(tdata->buffer->f.nummod, tdata->buffer->oidmod, tdata, oidType)) != 0) {
-    printf("%s(): Error in copying objects read at %s, %d\n", __func__, __FILE__, __LINE__);
-    return -1;
+  /*//TODO comment it for now because objects read are already in the prefetch cache
+     oidType = 'R';
+     if(tdata->f.numread > 0) {
+     if((retval = copyToCache(tdata->f.numread, (unsigned int *)(tdata->objread), oidType)) != 0) {
+      printf("%s(): Error in copying objects read at %s, %d\n", __func__, __FILE__, __LINE__);
+      return -1;
+     }
+     }
+   */
+  if(tdata->f.nummod > 0) {
+    oidType = 'M';
+    if((retval = copyToCache(tdata->f.nummod, tdata->oidmod, oidType)) != 0) {
+      printf("%s(): Error in copying objects read at %s, %d\n", __func__, __FILE__, __LINE__);
+      return -1;
+    }
   }
   return 0;
 }
 
-int copyToCache(int numoid, unsigned int *oidarray, thread_data_array_t *tdata, char oidType) { 
+int copyToCache(int numoid, unsigned int *oidarray, char oidType) {
   int i;
   for (i = 0; i < numoid; i++) {
     unsigned int oid;
-    if(oidType == 'R') {
-      char * objread = (char *) oidarray;
-      oid = *((unsigned int *)(objread+(sizeof(unsigned int)+
-              sizeof(unsigned short))*i));
-    } else {
-      oid = oidarray[i];
-    }
+    //if(oidType == 'R') {
+    //  char * objread = (char *) oidarray;
+    //  oid = *((unsigned int *)(objread+(sizeof(unsigned int)+
+    //                                    sizeof(unsigned short))*i));
+    //} else {
+    oid = oidarray[i];
+    //}
     pthread_mutex_lock(&prefetchcache_mutex);
     objheader_t * header;
-    if((header = (objheader_t *) chashSearch(tdata->rec->lookupTable, oid)) == NULL) {
+    if((header = (objheader_t *) t_chashSearch(oid)) == NULL) {
       printf("%s() obj %x is no longer in transaction cache at %s , %d\n", __func__, oid,__FILE__, __LINE__);
       fflush(stdout);
       return -1;
@@ -122,8 +164,8 @@ int copyToCache(int numoid, unsigned int *oidarray, thread_data_array_t *tdata,
     GETSIZE(size, header);
     objheader_t * newAddr;
     if((newAddr = prefetchobjstrAlloc(size + sizeof(objheader_t))) == NULL) {
-      printf("%s(): Error in getting memory from prefetch cache at %s, %d\n", __func__, 
-          __FILE__, __LINE__);
+      printf("%s(): Error in getting memory from prefetch cache at %s, %d\n", __func__,
+             __FILE__, __LINE__);
       pthread_mutex_unlock(&prefetchcache_mutex);
       return -1;
     }
@@ -134,14 +176,10 @@ int copyToCache(int numoid, unsigned int *oidarray, thread_data_array_t *tdata,
       newAddr->version += 1;
       newAddr->notifylist = NULL;
     }
+    STATUS(newAddr)=0;
+
     //make an entry in prefetch lookup hashtable
-    void *oldptr;
-    if((oldptr = prehashSearch(oid)) != NULL) {
-      prehashRemove(oid);
-      prehashInsert(oid, newAddr);
-    } else {
-      prehashInsert(oid, newAddr);
-    }
+    prehashInsert(oid, newAddr);
   } //end of for
   return 0;
 }