--- /dev/null
+#include "dstm.h"
+#include "addPrefetchEnhance.h"
+
+extern int numprefetchsites;
+//pfcstats_t evalPrefetch[numprefetchsites]; //Global array for all prefetch sites in the executable
+extern pfcstats_t *evalPrefetch;
+
+pfcstats_t *initPrefetchStats() {
+ pfcstats_t *ptr;
+ if((ptr = calloc(numprefetchsites, sizeof(pfcstats_t))) == NULL) {
+ printf("%s() Calloc error in %s at line %d\n", __func__, __FILE__, __LINE__);
+ return NULL;
+ }
+ int i;
+ /* Enable prefetching at the beginning */
+ for(i=0; i<numprefetchsites; i++) {
+ ptr[i].operMode = 1;
+ ptr[i].callcount = 0;
+ ptr[i].retrycount = RETRYINTERVAL; //N
+ ptr[i].uselesscount = SHUTDOWNINTERVAL; //M
+ }
+ return ptr;
+}
+
+int getRetryCount(int siteid) {
+ return evalPrefetch[siteid].retrycount;
+}
+
+int getUselessCount(int siteid) {
+ return evalPrefetch[siteid].uselesscount;
+}
+
+char getOperationMode(int siteid) {
+ return evalPrefetch[siteid].operMode;
+}
+
+void handleDynPrefetching(int numLocal, int ntuples, int siteid) {
+ if(numLocal < ntuples) {
+ /* prefetch not found locally(miss in cache) */
+ evalPrefetch[siteid].operMode = 1;
+ evalPrefetch[siteid].uselesscount = SHUTDOWNINTERVAL;
+ } else {
+ if(getOperationMode(siteid) != 0) {
+ evalPrefetch[siteid].uselesscount--;
+ if(evalPrefetch[siteid].uselesscount <= 0)
+ evalPrefetch[siteid].operMode = 0;
+ }
+ }
+}
--- /dev/null
+#ifndef _ADDPREFETCHENHANCE_H_
+#define _ADDPREFETCHENHANCE_H_
+
+typedef struct prefetchCountStats {
+ int retrycount; /* keeps track of when to retry and check if we can turn on this prefetch site */
+ int uselesscount; /* keeps track of how long was the prefetching at site useles */
+ char operMode; /* 1 = on , 0 = off */
+ int callcount;
+} pfcstats_t;
+
+pfcstats_t *initPrefetchStats();
+int getRetryCount(int siteid);
+int getUselessCount(int siteid);
+char getOperationMode(int);
+void handleDynPrefetching(int, int, int);
+
+#endif
--- /dev/null
+#include "dstm.h"
+#include <signal.h>
+
+extern int numTransAbort;
+extern int numTransCommit;
+extern int numprefetchsites;
+void handle();
+extern pfcstats_t *evalPrefetch;
+
+void transStatsHandler(int sig, siginfo_t* info, void *context) {
+#ifdef TRANSSTATS
+ printf("****** Transaction Stats ******\n");
+ printf("numTransAbort = %d\n", numTransAbort);
+ printf("numTransCommit = %d\n", numTransCommit);
+ int i;
+ for(i=0; i<numprefetchsites; i++) {
+ printf("siteid = %d, callCount = %d\n", i, evalPrefetch[i].callcount);
+ }
+ exit(0);
+#endif
+}
+
+void handle() {
+#ifdef TRANSSTATS
+ struct sigaction siga;
+ siga.sa_handler = NULL;
+ siga.sa_flags = SA_SIGINFO;
+ siga.sa_flags = 0;
+ siga.sa_sigaction = &transStatsHandler;
+ sigemptyset(&siga.sa_mask);
+ sigaction(SIGUSR1, &siga, 0);
+#endif
+}