From 5eee97bccbbc2e74962ed386e931bac84d278b1a Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 25 Dec 2009 08:15:58 +0000 Subject: [PATCH] changes to support create logs of events for STM --- Robust/src/IR/Flat/BuildCode.java | 17 +++++++++ Robust/src/IR/State.java | 1 + Robust/src/Main/Main.java | 2 + Robust/src/Runtime/STM/array.h | 10 +++++ Robust/src/Runtime/STM/commit.c | 15 +++++++- Robust/src/Runtime/STM/monitor.c | 40 +++++++++++++++----- Robust/src/Runtime/STM/monitor.h | 29 ++++++--------- Robust/src/Runtime/STM/stm.c | 12 ++++++ Robust/src/Runtime/runtime.c | 62 ++++++++++--------------------- Robust/src/Runtime/runtime.h | 43 +++++++++++++++++++++ Robust/src/Runtime/thread.c | 9 +++++ Robust/src/buildscript | 12 ++++++ 12 files changed, 182 insertions(+), 70 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index a51e86de..8fbd6599 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -181,6 +181,9 @@ public class BuildCode { if (state.SANDBOX) { outmethodheader.println("#include \"sandbox.h\""); } + if (state.EVENTMONITOR) { + outmethodheader.println("#include \"monitor.h\""); + } if (state.SINGLETM) { outmethodheader.println("#include \"tm.h\""); outmethodheader.println("#include \"delaycomp.h\""); @@ -406,6 +409,10 @@ public class BuildCode { outmethod.println("#endif\n"); } + if (state.EVENTMONITOR) { + outmethod.println("dumpdata();"); + } + if (state.THREAD||state.SINGLETM) outmethod.println("pthread_exit(NULL);"); @@ -617,6 +624,9 @@ public class BuildCode { //Print out definition for array type outclassdefs.println("struct "+arraytype+" {"); outclassdefs.println(" int type;"); + if (state.EVENTMONITOR) { + outclassdefs.println(" int objuid;"); + } if (state.THREAD) { outclassdefs.println(" pthread_t tid;"); outclassdefs.println(" void * lockentry;"); @@ -1351,6 +1361,9 @@ public class BuildCode { /* Output class structure */ classdefout.println("struct "+cn.getSafeSymbol()+" {"); classdefout.println(" int type;"); + if (state.EVENTMONITOR) { + classdefout.println(" int objuid;"); + } if (state.THREAD) { classdefout.println(" pthread_t tid;"); classdefout.println(" void * lockentry;"); @@ -1630,6 +1643,7 @@ public class BuildCode { ar.liveout=liveout; ar.liveoutvirtualread=liveoutvirtualread; + for(Iterator it=liveinto.iterator(); it.hasNext();) { TempDescriptor tmp=it.next(); //remove the pointers @@ -3859,6 +3873,9 @@ public class BuildCode { } if (wb.needBarrier(fsfn)&& locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) { + if (state.EVENTMONITOR) { + output.println("if ("+dst+"->___objstatus___&DIRTY) EVLOGEVENTOBJ(EV_WRITE,"+dst+"->objuid)"); + } output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;"); } if (srcptr&!fsfn.getSrc().getType().isNull()) { diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index bc7e742b..90c50fe5 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -103,6 +103,7 @@ public class State { public boolean DSMTASK=false; public static boolean ABORTREADERS=false; //STM options + public boolean EVENTMONITOR=false; public static boolean STMARRAY=false; public static boolean SINGLETM=false; public static boolean READSET=false; diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 1487ff8a..ed7b5cf5 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -122,6 +122,8 @@ public class Main { state.TAGSTATE=true; else if (option.equals("-stmarray")) state.STMARRAY=true; + else if (option.equals("-eventmonitor")) + state.EVENTMONITOR=true; else if (option.equals("-dualview")) state.DUALVIEW=true; else if (option.equals("-hybrid")) diff --git a/Robust/src/Runtime/STM/array.h b/Robust/src/Runtime/STM/array.h index d4ecd73f..db8ead43 100644 --- a/Robust/src/Runtime/STM/array.h +++ b/Robust/src/Runtime/STM/array.h @@ -33,6 +33,14 @@ version=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int)); \ } +#ifdef EVENTMONITOR +#define EVGETARRAY(array, index) EVLOGEVENTARRAY(EV_ARRAYREAD,array->objuid,index) +#define EVSETARRAY(cond, array, index) if (cond!=STMDIRTY) EVLOGEVENTARRAY(EV_ARRAYWRITE,array->objuid,index) +#else +#define EVGETARRAY(array, index) +#define EVSETARRAY(cond, array, index) +#endif + #define STMGETARRAY(dst, array, index, type) { \ if (((char *)array)!=((char *)array->___objlocation___)) { \ if(!(array->___objstatus___&NEW)) { \ @@ -42,6 +50,7 @@ GETLOCKPTR(status, array, metaindex); \ if (metaindexlowindex||metaindex>array->highindex \ ||(*status)==STMNONE) { \ + EVGETARRAY(array, metaindex); \ arraycopy(array, byteindex); \ (*status)=STMCLEAN;} \ } \ @@ -59,6 +68,7 @@ ||(*status)==STMNONE) { \ arraycopy(array, byteindex); \ } \ + EVSETARRAY(*status, array, metaindex); \ (*status)=STMDIRTY; \ } \ ((type *)(((char *) &array->___length___)+sizeof(int)))[index]=src; \ diff --git a/Robust/src/Runtime/STM/commit.c b/Robust/src/Runtime/STM/commit.c index 39c399ff..4585eff9 100644 --- a/Robust/src/Runtime/STM/commit.c +++ b/Robust/src/Runtime/STM/commit.c @@ -2,6 +2,9 @@ #ifdef DELAYCOMP #include #endif +#ifdef EVENTMONITOR +#include"monitor.h" +#endif #ifdef TRANSSTATS #define TRANSWRAP(x) x @@ -91,7 +94,9 @@ int transCommit() { #ifdef SANDBOX abortenabled=1; #endif - +#ifdef EVENTMONITOR + EVLOGEVENT(EV_ABORT); +#endif return TRANS_ABORT; } if(finalResponse == TRANS_COMMIT) { @@ -111,6 +116,9 @@ int transCommit() { #if defined(STMARRAY)&&!defined(DUALVIEW) arraystack.count=0; #endif +#endif +#ifdef EVENTMONITOR + EVLOGEVENT(EV_COMMIT); #endif return 0; } @@ -140,6 +148,9 @@ int transCommit() { #if defined(STMARRAY)&&!defined(DUALVIEW) arraystack.count=0; #endif +#endif +#ifdef EVENTMONITOR + EVLOGEVENT(EV_ABORT); #endif return TRANS_ABORT; } @@ -1202,7 +1213,7 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) { int j; int addwrobject=0, addrdobject=0; int elementsize=classsize[type]; - int baseoffset=(lowoffset<___length___)); + int baseoffset=(lowoffset<___length___)); char *dstptr=((char *)dst)+baseoffset; char *srcptr=((char *)src)+baseoffset; for(j=lowoffset; j<=highoffset;j++, srcptr+=INDEXLENGTH,dstptr+=INDEXLENGTH) { diff --git a/Robust/src/Runtime/STM/monitor.c b/Robust/src/Runtime/STM/monitor.c index 84f10e43..eb4e1820 100644 --- a/Robust/src/Runtime/STM/monitor.c +++ b/Robust/src/Runtime/STM/monitor.c @@ -1,18 +1,40 @@ +#include "runtime.h" #include "monitor.h" #include #include #include +#include + +__thread struct eventmonitor * events; +struct eventmonitor * eventlist; +static volatile int threadcount=0; +__thread int threadnum; + +static inline int atomicinc(volatile int *lock) { + int retval=1; + __asm__ __volatile__("lock; xadd %0,%1" + : "=r"(retval) + : "m"(*lock), "0"(retval) + : "memory"); + return retval; +} //Need to have global lock before calling this method void createmonitor() { struct eventmonitor *event=calloc(1, sizeof(struct eventmonitor)); //add new eventmonitor to list event->next=eventlist; - eventlist=events; + eventlist=event; + int ourcount=atomicinc(&threadcount); + threadnum=ourcount; + if (threadnum>=MAXEVTHREADS) { + printf("ERROR: Threads exceeds MAXEVTHREADS\n"); + } + //point thread lock variable to eventmonitor events=event; - EVLOGEVENT(EM_THREAD); + EVLOGEVENT(EV_THREAD); } void writedata(int fd, char * buffer, int count) { @@ -25,21 +47,21 @@ void writedata(int fd, char * buffer, int count) { } void dumpdata() { - int fd=open("logdata",O_RDWR|O_CREAT); + int fd=open("logdata",O_RDWR|O_CREAT,S_IRWXU); int count=0; struct eventmonitor * ptr=eventlist; while(ptr!=NULL) { count++; + if (ptr->index>MAXEVENTS) { + printf("ERROR: EVENT COUNT EXCEEDED\n"); + } ptr=ptr->next; } - writedata(fd, &count, sizeof(int)); + writedata(fd, (char *)&count, sizeof(int)); ptr=eventlist; - if (ptr->index>MAXEVENTS) { - printf("ERROR: EVENT COUNT EXCEEDED\n") - } while(ptr!=NULL) { - writedata(fd, &ptr->index, sizeof(int)); - writedata(fd, ptr->value, sizeof(int)*ptr->index); + writedata(fd, (char *) &ptr->index, sizeof(int)); + writedata(fd, (char *) ptr->value, sizeof(int)*ptr->index); ptr=ptr->next; } close(fd); diff --git a/Robust/src/Runtime/STM/monitor.h b/Robust/src/Runtime/STM/monitor.h index 90eeb875..588795cf 100644 --- a/Robust/src/Runtime/STM/monitor.h +++ b/Robust/src/Runtime/STM/monitor.h @@ -11,6 +11,8 @@ #define EV_START 4 #define EV_COMMIT 5 #define EV_ABORT 6 +#define EV_ARRAYREAD 7 +#define EV_ARRAYWRITE 8 struct eventmonitor { int index; @@ -18,27 +20,14 @@ struct eventmonitor { unsigned int value[MAXEVENTS]; }; +#define MAXEVTHREADS 16 +#define EVTHREADSHIFT 4 +extern __thread int threadnum; extern __thread struct eventmonitor * events; extern struct eventmonitor * eventlist; void createmonitor(); void dumpdata(); -#if defined(__i386__) -static __inline__ unsigned long long rdtsc(void) -{ - unsigned long long int x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} -#elif defined(__x86_64__) -static __inline__ unsigned long long rdtsc(void) -{ - unsigned hi, lo; - __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); - return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); -} -#endif - #define LOGTIME *((long long *)&events->value[events->index])=rdtsc(); \ events->index+=2; @@ -47,8 +36,14 @@ static __inline__ unsigned long long rdtsc(void) } #define EVLOGEVENTOBJ(x,o) { events->value[events->index++]=x; \ - events->value[events->index++]=o; \ + events->value[events->index++]=o; \ LOGTIME \ } +#define EVLOGEVENTARRAY(x,o,i) { events->value[events->index++]=x; \ + events->value[events->index++]=o; \ + events->value[events->index++]=i; \ + LOGTIME \ + } + #endif diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index b9b2935c..c491c570 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -12,6 +12,9 @@ #include "tm.h" #include "garbage.h" +#ifdef EVENTMONITOR +#include "monitor.h" +#endif /* Per thread transaction variables */ __thread objstr_t *t_cache; @@ -83,6 +86,9 @@ int stmStartup() { */ void transStart() { //Transaction start is currently free...commit and aborting is not +#ifdef EVENTMONITOR + EVLOGEVENT(EV_START); +#endif } /* ======================================================= @@ -189,12 +195,18 @@ void *transRead(void * oid, void *gl) { size += sizeof(objheader_t); objcopy = (objheader_t *) objstrAlloc(size); A_memcpy(objcopy, header, size); +#ifdef EVENTMONITOR + EVLOGEVENTOBJ(EV_READ, ((struct ___Object___ *)oid)->objuid); +#endif } #else GETSIZE(size, header); size += sizeof(objheader_t); objcopy = (objheader_t *) objstrAlloc(size); A_memcpy(objcopy, header, size); +#ifdef EVENTMONITOR + EVLOGEVENTOBJ(EV_READ, ((struct ___Object___ *) oid)->objuid); +#endif #endif #ifdef STMSTATS /* keep track of the object's access sequence in a transaction */ diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 7a339cf3..83d221e6 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -29,6 +29,16 @@ __thread unsigned long long clkticks[ARRAY_LENGTH]; unsigned long long beginClock=0; #define FILENAME "log" #endif +#ifdef EVENTMONITOR +#include "monitor.h" +__thread int objcount=0; +#define ASSIGNUID(x) { \ + int number=((objcount++)<objuid=number; \ + } +#else +#define ASSIGNUID(x) +#endif #if defined(THREADS)||defined(STM) /* Global barrier for STM */ @@ -227,52 +237,13 @@ void CALL11(___System______exit____I,int ___status___, int ___status___) { } #endif #endif +#endif +#ifdef EVENTMONITOR + dumpdata(); #endif exit(___status___); } -#if defined(__i386__) - -static __inline__ unsigned long long rdtsc(void) -{ - unsigned long long int x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} -#elif defined(__x86_64__) - -static __inline__ unsigned long long rdtsc(void) -{ - unsigned hi, lo; - __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); - return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); -} - -#elif defined(__powerpc__) - -typedef unsigned long long int unsigned long long; - -static __inline__ unsigned long long rdtsc(void) -{ - unsigned long long int result=0; - unsigned long int upper, lower,tmp; - __asm__ volatile( - "0: \n" - "\tmftbu %0 \n" - "\tmftb %1 \n" - "\tmftbu %2 \n" - "\tcmpw %2,%0 \n" - "\tbne 0b \n" - : "=r"(upper),"=r"(lower),"=r"(tmp) - ); - result = upper; - result = result<<32; - result = result|lower; - - return(result); -} -#endif - void CALL11(___System______logevent____I,int ___event___, int ___event___) { #ifdef STMLOG event[counter] = ___event___; @@ -453,6 +424,9 @@ void CALL00(___Barrier______enterBarrier____) { printf("%s() Could not wait on barrier: error %d in %s\n", __func__, errno, __FILE__); exit(-1); } +#ifdef EVENTMONITOR + EVLOGEVENT(EV_BARRIER); +#endif } #endif @@ -501,6 +475,7 @@ __attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) { #else struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]); #endif + ASSIGNUID(v); v->type=type; v->___objlocation___=v; return v; @@ -525,6 +500,7 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, #else struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]); #endif + ASSIGNUID(v); if (length<0) { printf("ERROR: negative array\n"); return NULL; @@ -538,6 +514,7 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, __attribute__((malloc)) void * allocate_new(void * ptr, int type) { objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t)); struct ___Object___ * v=(struct ___Object___ *) &tmp[1]; + ASSIGNUID(v); initdsmlocks(&tmp->lock); tmp->version = 1; v->___objlocation___=v; @@ -573,6 +550,7 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t initdsmlocks(&tmp->lock); #endif tmp->version=1; + ASSIGNUID(v); v->type=type; if (length<0) { printf("ERROR: negative array %d\n", length); diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 8290d3ee..37af2b7e 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -223,4 +223,47 @@ int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *pr #endif +#if defined(__i386__) + +static __inline__ unsigned long long rdtsc(void) +{ + unsigned long long int x; + __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); + return x; +} +#elif defined(__x86_64__) + +static __inline__ unsigned long long rdtsc(void) +{ + unsigned hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); +} + +#elif defined(__powerpc__) + +typedef unsigned long long int unsigned long long; + +static __inline__ unsigned long long rdtsc(void) +{ + unsigned long long int result=0; + unsigned long int upper, lower,tmp; + __asm__ volatile( + "0: \n" + "\tmftbu %0 \n" + "\tmftb %1 \n" + "\tmftbu %2 \n" + "\tcmpw %2,%0 \n" + "\tbne 0b \n" + : "=r"(upper),"=r"(lower),"=r"(tmp) + ); + result = upper; + result = result<<32; + result = result|lower; + + return(result); +} +#endif + + #endif diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index b5e9a789..44950b4a 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -25,6 +25,9 @@ #include "tm.h" #endif #include +#ifdef EVENTMONITOR +#include "monitor.h" +#endif int threadcount; @@ -252,6 +255,9 @@ void initializethreads() { list->prev=&litem; list=&litem; #endif +#ifdef EVENTMONITOR + createmonitor(); +#endif } #if defined(THREADS)||defined(STM) @@ -259,6 +265,9 @@ void initthread(struct ___Thread___ * ___this___) { #ifdef AFFINITY set_affinity(); #endif +#ifdef EVENTMONITOR + createmonitor(); +#endif #ifdef SANDBOX struct sigaction sig; abortenabled=0; diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 9fa2ce5a..b7001715 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -14,6 +14,7 @@ echo "-stmarray partial array treatment" echo "-dualview dual view of arrays" echo "-hybrid use fission only when it looks like a good choice" echo "-numa numa aware" +echo "-eventmonitor turn on transaction event trace recording" echo echo DSM options echo -dsm distributed shared memory @@ -97,6 +98,7 @@ FASTMEMCPY=false STMARRAY=false DUALVIEW=false STM=false +EVENTMONITOR=false NOJAVA=false CHECKFLAG=false RECOVERFLAG=false @@ -173,6 +175,11 @@ shift elif [[ $1 = '-nojava' ]] then NOJAVA=true +elif [[ $1 = '-eventmonitor' ]] +then +JAVAOPTS="$JAVAOPTS -eventmonitor" +EVENTMONITOR=true +EXTRAOPTIONS="$EXTRAOPTIONS -DEVENTMONITOR" elif [[ $1 = '-garbagestats' ]] then EXTRAOPTIONS="$EXTRAOPTIONS -DGARBAGESTATS" @@ -731,6 +738,11 @@ then FILES="$FILES $ROBUSTROOT/Runtime/affinity.c" fi +if $EVENTMONITOR +then +FILES="$FILES $ROBUSTROOT/Runtime/STM/monitor.c" +fi + if $FASTMEMCPY then FILES="$FILES $ROBUSTROOT/Runtime/memcpy32.o $ROBUSTROOT/Runtime/instrset32.o" -- 2.34.1