switch to spaces only..
[IRC.git] / Robust / src / Runtime / DSTM / interface / addPrefetchEnhance.c
index e86b860e6377797339342d079756284e56549f60..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,6 +7,19 @@ extern objstr_t *prefetchcache; //Global Prefetch cache
 extern pthread_mutex_t prefetchcache_mutex; //Mutex to lock Prefetch Cache
 extern unsigned int myIpAddr;
 
+//#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() {
@@ -44,76 +57,104 @@ char getOperationMode(int siteid) {
  * 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) {
-       evalPrefetch[siteid].operMode = 0;
+        LOGEVENT('O');
+        evalPrefetch[siteid].operMode = 0;
       }
     }
   }
 }
 
+#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)
-       break;
+        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);
+        /* Remove from prefetch cache */
+        prehashRemove(curr->key);
       }
       curr = curr->next;
     }
   }
 }
+#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
+ * entries from the transaction cache when a
  * transaction commits
  * Return -1 on error else returns 0 */
-int updatePrefetchCache(thread_data_array_t* tdata) {
+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;
@@ -135,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;
 }