new files for dynamic prefetch enabling
[IRC.git] / Robust / src / Runtime / DSTM / interface / addPrefetchEnhance.c
1 #include "dstm.h"
2 #include "addPrefetchEnhance.h"
3
4 extern int numprefetchsites;
5 //pfcstats_t evalPrefetch[numprefetchsites]; //Global array for all prefetch sites in the executable
6 extern pfcstats_t *evalPrefetch;
7
8 pfcstats_t *initPrefetchStats() {
9   pfcstats_t *ptr;
10   if((ptr = calloc(numprefetchsites, sizeof(pfcstats_t))) == NULL) {
11     printf("%s() Calloc error in %s at line %d\n", __func__, __FILE__, __LINE__);
12     return NULL;
13   }
14   int i;
15   /* Enable prefetching at the beginning */
16   for(i=0; i<numprefetchsites; i++) {
17     ptr[i].operMode = 1;
18     ptr[i].callcount = 0;
19     ptr[i].retrycount = RETRYINTERVAL; //N
20     ptr[i].uselesscount = SHUTDOWNINTERVAL; //M
21   }
22   return ptr;
23 }
24
25 int getRetryCount(int siteid) {
26   return evalPrefetch[siteid].retrycount;
27 }
28
29 int getUselessCount(int siteid) {
30   return evalPrefetch[siteid].uselesscount;
31 }
32
33 char getOperationMode(int siteid) {
34   return evalPrefetch[siteid].operMode;
35 }
36
37 void handleDynPrefetching(int numLocal, int ntuples, int siteid) {
38   if(numLocal < ntuples) {
39     /* prefetch not found locally(miss in cache) */
40     evalPrefetch[siteid].operMode = 1;
41     evalPrefetch[siteid].uselesscount = SHUTDOWNINTERVAL;
42   } else {
43     if(getOperationMode(siteid) != 0) {
44       evalPrefetch[siteid].uselesscount--;
45       if(evalPrefetch[siteid].uselesscount <= 0)
46         evalPrefetch[siteid].operMode = 0;
47     }
48   }
49 }