public static final double PROB_DIFF = 0.05; //threshold for difference in probabilities during first phase of analysis
public static final double ANALYSIS_THRESHOLD_PROB = 0.10; //threshold for prefetches to stop propagating during first phase of analysis
public static final double PREFETCH_THRESHOLD_PROB = 0.30;//threshold for prefetches to stop propagating while applying prefetch rules during second phase of analysis
+ public static int prefetchsiteid = 1; //initialized to one because there is a prefetch siteid 0 for starting remote thread
LocalityAnalysis locality;
public PrefetchAnalysis(State state, CallGraph callgraph, TypeUtil typeutil, LocalityAnalysis locality) {
/* This modifies the Flat representation graph */
for(Enumeration e = newprefetchset.keys();e.hasMoreElements();) {
FlatNode fn = (FlatNode) e.nextElement();
- FlatPrefetchNode fpn = new FlatPrefetchNode();
- if(newprefetchset.get(fn).size() > 0) {
- fpn.insAllpp((HashSet)newprefetchset.get(fn));
- if(fn.kind() == FKind.FlatMethod) {
- FlatNode nn = fn.getNext(0);
- fn.setNext(0, fpn);
- fpn.addNext(nn);
- } else {
- /* Check if previous node of this FlatNode is a NEW node
- * If yes, delete this flatnode and its prefetch set from hash table
- * This eliminates prefetches for NULL ptrs*/
- for(int i = 0; i< fn.numPrev(); i++) {
- FlatNode nn = fn.getPrev(i);
- if(nn.kind() == FKind.FlatNew) {
- isFNPresent = true;
- }
- }
- if(!isFNPresent) {
- while(fn.numPrev() > 0) {
- FlatNode nn = fn.getPrev(0);
- for(int j = 0; j<nn.numNext(); j++) {
- if(nn.getNext(j) == fn) {
- nn.setNext(j, fpn);
- }
- }
- }
- fpn.addNext(fn);
- }
- } //end of else
+ FlatPrefetchNode fpn = new FlatPrefetchNode();
+ if(newprefetchset.get(fn).size() > 0) {
+ fpn.insAllpp((HashSet)newprefetchset.get(fn));
+ if(fn.kind() == FKind.FlatMethod) {
+ FlatNode nn = fn.getNext(0);
+ fn.setNext(0, fpn);
+ fpn.addNext(nn);
+ fpn.siteid = prefetchsiteid++;
+ } else {
+ /* Check if previous node of this FlatNode is a NEW node
+ * If yes, delete this flatnode and its prefetch set from hash table
+ * This eliminates prefetches for NULL ptrs*/
+ for(int i = 0; i< fn.numPrev(); i++) {
+ FlatNode nn = fn.getPrev(i);
+ if(nn.kind() == FKind.FlatNew) {
+ isFNPresent = true;
+ }
+ }
+ if(!isFNPresent) {
+ while(fn.numPrev() > 0) {
+ FlatNode nn = fn.getPrev(0);
+ for(int j = 0; j<nn.numNext(); j++) {
+ if(nn.getNext(j) == fn) {
+ nn.setNext(j, fpn);
+ }
+ }
+ }
+ fpn.addNext(fn);
+ fpn.siteid = prefetchsiteid++;
+ }
+ } //end of else
} //End of if
- } //end of while
+ } //end of for
}
}
Hashtable<TempDescriptor, TempDescriptor> backuptable;
Hashtable<LocalityBinding, TempDescriptor> reverttable;
SafetyAnalysis sa;
+ PrefetchAnalysis pa;
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa) {
- this(st, temptovar, typeutil, null, sa);
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
+ this(st, temptovar, typeutil, null, sa, pa);
}
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality) {
- this(st, temptovar, typeutil, locality, null);
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa) {
+ this(st, temptovar, typeutil, locality, null, pa);
}
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa) {
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa) {
this.sa=sa;
+ this.pa=pa;
state=st;
this.temptovar=temptovar;
paramstable=new Hashtable();
private void outputMainMethod(PrintWriter outmethod) {
outmethod.println("int main(int argc, const char *argv[]) {");
outmethod.println(" int i;");
+ outmethod.println("#ifdef TRANSSTATS \n");
+ outmethod.println("handle();\n");
+ outmethod.println("#endif\n");
if (state.THREAD||state.DSM) {
outmethod.println("initializethreads();");
}
outmethod.println("pthread_exit(NULL);");
}
+ outmethod.println("#ifdef TRANSSTATS \n");
+ outmethod.println("printf(\"****** Transaction Stats ******\\n\");");
outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);");
outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);");
+ outmethod.println("#endif\n");
outmethod.println("}");
}
outmethod.println("#include \"methodheaders.h\"");
outmethod.println("#include \"virtualtable.h\"");
outmethod.println("#include \"runtime.h\"");
+ outmethod.println("#include \"dstm.h\"");
if (state.DSM) {
outmethod.println("#include \"localobjects.h\"");
}
outtask.println("struct taskdescriptor {");
outtask.println("void * taskptr;");
outtask.println("int numParameters;");
- outtask.println("int numTotal;");
outtask.println("struct parameterdescriptor **descriptorarray;");
outtask.println("char * name;");
outtask.println("};");
* information. */
private void generateSizeArray(PrintWriter outclassdefs) {
- outclassdefs.print("int numTransAbort = 0;");
- outclassdefs.print("int numTransCommit = 0;");
- outclassdefs.print("int classsize[]={");
+ outclassdefs.print("extern struct prefetchCountStats * evalPrefetch;\n");
+ outclassdefs.print("#ifdef TRANSSTATS \n");
+ outclassdefs.print("extern int numTransAbort;\n");
+ outclassdefs.print("extern int numTransCommit;\n");
+ outclassdefs.print("extern void handle();\n");
+ outclassdefs.print("#endif\n");
+ outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n");
+
+ outclassdefs.print("int classsize[]={");
Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
cdarray=new ClassDescriptor[state.numClasses()];
while(it.hasNext()) {
return;
output.println("{");
output.println("/* prefetch */");
+ output.println("/* prefetchid_" + fpn.siteid + " */");
output.println("void * prefptr;");
output.println("int tmpindex;");
/*Create C code for oid array */
}
output.println("};");
/* make the prefetch call to Runtime */
- output.println(" prefetch("+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);");
+ output.println(" if(evalPrefetch["+fpn.siteid+"].operMode) {");
+ output.println(" prefetch("+fpn.siteid+" ,"+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);");
+ output.println(" } else if(evalPrefetch["+fpn.siteid+"].retrycount <= 0) {");
+ output.println(" prefetch("+fpn.siteid+" ,"+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);");
+ output.println(" evalPrefetch["+fpn.siteid+"].retrycount = RETRYINTERVAL;");
+ output.println(" } else {");
+ output.println(" evalPrefetch["+fpn.siteid+"].retrycount--;");
+ output.println(" }");
output.println("}");
}
}
import Analysis.TaskStateAnalysis.FEdge;
import Analysis.TaskStateAnalysis.FlagState;
import Analysis.TaskStateAnalysis.SafetyAnalysis;
+import Analysis.Prefetch.*;
import IR.ClassDescriptor;
import IR.Descriptor;
import IR.FlagDescriptor;
String otqueueprefix = "___otqueue";
int startupcorenum; // record the core containing startup task, suppose only one core can hava startup object
- public BuildCodeMultiCore(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, Vector<Schedule> scheduling, int coreNum) {
- super(st, temptovar, typeutil, sa);
+ public BuildCodeMultiCore(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, Vector<Schedule> scheduling, int coreNum, PrefetchAnalysis pa) {
+ super(st, temptovar, typeutil, sa, pa);
this.scheduling = scheduling;
this.coreNum = coreNum;
this.currentSchedule = null;
import java.util.*;
public class FlatPrefetchNode extends FlatNode {
+ public Integer siteid;
HashSet<PrefetchPair> hspp;
public FlatPrefetchNode() {
hspp = new HashSet<PrefetchPair>();
+ siteid = new Integer(1);
}
public String toString() {
readSourceFile(state, ClassLibraryPrefix+"gnu/Random.java");
readSourceFile(state, ClassLibraryPrefix+"Vector.java");
readSourceFile(state, ClassLibraryPrefix+"Enumeration.java");
- if(!state.MULTICORE) {
- readSourceFile(state, ClassLibraryPrefix+"Signal.java");
- }
-
if (state.TASK) {
readSourceFile(state, ClassLibraryPrefix+"Object.java");
BuildFlat bf=new BuildFlat(state,tu);
bf.buildFlat();
SafetyAnalysis sa=null;
+ PrefetchAnalysis pa=null;
if (state.TAGSTATE) {
CallGraph callgraph=new CallGraph(state);
if(state.MULTICORE) {
it_scheduling = scheduleAnalysis.getSchedulingsIter();
Vector<Schedule> scheduling = (Vector<Schedule>)it_scheduling.next();
- BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, bf.getMap(), tu, sa, scheduling, scheduleAnalysis.getCoreNum());
+ BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, bf.getMap(), tu, sa, scheduling, scheduleAnalysis.getCoreNum(), pa);
bcm.buildCode();
}
}
if (state.PREFETCH) {
//speed up prefetch generation using locality analysis results
LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
- PrefetchAnalysis pa=new PrefetchAnalysis(state, callgraph, tu, la);
+ pa=new PrefetchAnalysis(state, callgraph, tu, la);
}
LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu);
GenerateConversions gc=new GenerateConversions(la, state);
- BuildCode bc=new BuildCode(state, bf.getMap(), tu, la);
+ BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa);
bc.buildCode();
} else {
- BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa);
+ BuildCode bc=new BuildCode(state, bf.getMap(), tu, sa, pa);
bc.buildCode();
}
}
/***********************************************************
* Macros
**********************************************************/
-#define GET_NTUPLES(x) ((int *)(x))
-#define GET_PTR_OID(x) ((unsigned int *)(x + sizeof(int)))
-#define GET_PTR_EOFF(x,n) ((short *)(x + sizeof(int) + (n*sizeof(unsigned int))))
-#define GET_PTR_ARRYFLD(x,n) ((short *)(x + sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
+#define GET_SITEID(x) ((int *)(x))
+#define GET_NTUPLES(x) ((int *)(x + sizeof(int)))
+#define GET_PTR_OID(x) ((unsigned int *)(x + 2*sizeof(int)))
+#define GET_PTR_EOFF(x,n) ((short *)(x + 2*sizeof(int) + (n*sizeof(unsigned int))))
+#define GET_PTR_ARRYFLD(x,n) ((short *)(x + 2*sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
#define ENDEBUG(s) { printf("Inside %s()\n", s); fflush(stdout);}
#define EXDEBUG(s) {printf("Outside %s()\n", s); fflush(stdout);}
/*****************************************
#define THREAD_NOTIFY_REQUEST 24
#define THREAD_NOTIFY_RESPONSE 25
#define TRANS_UNSUCESSFUL 26
-#define CLOSE_CONNECTION 27
+#define CLOSE_CONNECTION 27
//Max number of objects
#define MAX_OBJECTS 20
#define TID_LEN 20
#define LISTEN_PORT 2156
#define UDP_PORT 2158
-
+//Prefetch tuning paramters
+#define RETRYINTERVAL 100 //N
+#define SHUTDOWNINTERVAL 1 //M
#include <stdlib.h>
#include <stdio.h>
#include "sockpool.h"
#include "prelookup.h"
#include <signal.h>
+#include "addPrefetchEnhance.h"
//bit designations for status field of objheader
#define DIRTY 0x01
int transAbortProcess(local_thread_data_array_t *);
void transAbort(transrecord_t *trans);
void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size);
-void prefetch(int, unsigned int *, unsigned short *, short*);
+void prefetch(int, int, unsigned int *, unsigned short *, short*);
void *transPrefetch(void *);
void *mcqProcess(void *);
prefetchpile_t *foundLocal(char *);// returns node with prefetch elements(oids, offsets)
/* Global Variables */
extern int classsize[];
-
+pfcstats_t *evalPrefetch;
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 */
/* This function is a prefetch call generated by the compiler that
* populates the shared primary prefetch queue*/
-void prefetch(int ntuples, unsigned int *oids, unsigned short *endoffsets, short *arrayfields) {
+void prefetch(int siteid, int ntuples, unsigned int *oids, unsigned short *endoffsets, short *arrayfields) {
/* Allocate for the queue node*/
- int qnodesize = sizeof(int) + ntuples * (sizeof(unsigned short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short);
+ int qnodesize = 2*sizeof(int) + ntuples * (sizeof(unsigned short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short);
char * node= getmemory(qnodesize);
/* Set queue node values */
int len;
int top=endoffsets[ntuples-1];
- *((int *)(node))=ntuples;
- len = sizeof(int);
+ /* TODO: Remove this after testing */
+ evalPrefetch[siteid].callcount++;
+
+ *((int *)(node))=siteid;
+ *((int *)(node + sizeof(int))) = ntuples;
+ len = 2*sizeof(int);
memcpy(node+len, oids, ntuples*sizeof(unsigned int));
memcpy(node+len+ntuples*sizeof(unsigned int), endoffsets, ntuples*sizeof(unsigned short));
memcpy(node+len+ntuples*(sizeof(unsigned int)+sizeof(short)), arrayfields, top*sizeof(short));
//Create and initialize prefetch cache structure
prefetchcache = objstrCreate(PREFETCH_CACHE_SIZE);
initializePCache();
+ if((evalPrefetch = initPrefetchStats()) == NULL) {
+ printf("%s() Error allocating memory at %s, %d\n", __func__, __FILE__, __LINE__);
+ exit(0);
+ }
/* Initialize attributes for mutex */
pthread_mutexattr_init(&prefetchcache_mutex_attr);
tdata = (thread_data_array_t *) threadarg;
/* Send Trans Request */
- if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- perror("Error in socket for TRANS_REQUEST\n");
+ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) <= 0) {
+ printf("transRequest():error %d\n", errno);
+ perror("transRequest() socket error");
pthread_exit(NULL);
}
bzero((char*) &serv_addr, sizeof(serv_addr));
/* Open Connection */
if (connect(sd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
+ printf("transRequest():error %d, sd= %d\n", errno, sd);
perror("transRequest() connect");
close(sd);
pthread_exit(NULL);
}
prefetchpile_t *foundLocal(char *ptr) {
+ int siteid = *(GET_SITEID(ptr));
int ntuples = *(GET_NTUPLES(ptr));
unsigned int * oidarray = GET_PTR_OID(ptr);
unsigned short * endoffsets = GET_PTR_EOFF(ptr, ntuples);
short * arryfields = GET_PTR_ARRYFLD(ptr, ntuples);
prefetchpile_t * head=NULL;
+ int numLocal = 0;
int i;
for(i=0;i<ntuples; i++) {
goto tuple;
}
//Entire prefetch is local
- if (newbase==endindex&&checkoid(oid))
+ if (newbase==endindex&&checkoid(oid)){
+ numLocal++;
goto tuple;
+ }
//Add to remote requests
machinenum=lhashSearch(oid);
insertPile(machinenum, oid, endindex-newbase, &arryfields[newbase], &head);
tuple:
;
}
+
+ /* handle dynamic prefetching */
+ handleDynPrefetching(numLocal, ntuples, siteid);
return head;
}
if ((objheader = (objheader_t *) mhashSearch(oid)) == NULL) {
if ((objheader = (objheader_t *) prehashSearch(oid)) == NULL) {
- prefetch(1, &oid, numoffset, fieldoffset);
+ prefetch(0, 1, &oid, numoffset, fieldoffset);
pthread_mutex_lock(&pflookup.lock);
while ((objheader = (objheader_t *) prehashSearch(oid)) == NULL) {
pthread_cond_wait(&pflookup.cond, &pflookup.lock);
then
EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DTRANSSTATS -DCOMPILER -DDSTM -I$DSMRUNTIME"
fi
-FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c"
+FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/threadnotify.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c $ROBUSTROOT/Runtime/thread.c $DSMRUNTIME/sockpool.c $DSMRUNTIME/addUdpEnhance.c $DSMRUNTIME/signal.c $DSMRUNTIME/gCollect.c $DSMRUNTIME/addPrefetchEnhance.c"
fi
if $RECOVERFLAG