From: bdemsky <bdemsky>
Date: Tue, 3 Aug 2010 09:46:00 +0000 (+0000)
Subject: bug fixes for coreprof
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e0e6d5cc51dc3c73d95b798e12e4db20dda43f56;p=IRC.git

bug fixes for coreprof
---

diff --git a/Robust/src/Benchmarks/oooJava/sor/SORRunner.java b/Robust/src/Benchmarks/oooJava/sor/SORRunner.java
index a66568d9..deb5bfbe 100644
--- a/Robust/src/Benchmarks/oooJava/sor/SORRunner.java
+++ b/Robust/src/Benchmarks/oooJava/sor/SORRunner.java
@@ -19,7 +19,7 @@
  *                                                                         *
  **************************************************************************/
 
-class SORRunner extends Thread {
+class SORRunner {
 
   int id, num_iterations;
   double G[][],omega;
diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java
index 3bd86e8d..479fc596 100644
--- a/Robust/src/IR/Flat/BuildCode.java
+++ b/Robust/src/IR/Flat/BuildCode.java
@@ -329,6 +329,7 @@ public class BuildCode {
 
     if (state.MLP || state.OOOJAVA) {
       //outmethod.println("  pthread_once( &mlpOnceObj, mlpInitOncePerThread );");
+
       outmethod.println("  workScheduleInit( "+state.MLP_NUMCORES+", invokeSESEmethod );");
     }
 
@@ -524,7 +525,9 @@ public class BuildCode {
       outmethod.println("#include \"mlp_runtime.h\"");
       outmethod.println("#include \"psemaphore.h\"");
     }
-
+    if (state.COREPROF) {
+      outmethod.println("#include \"coreprof.h\"");
+    }
 
     //Store the sizes of classes & array elements
     generateSizeArray(outmethod);
@@ -2342,6 +2345,10 @@ public class BuildCode {
           (state.OOOJAVA && fsen.equals( oooa.getMainSESE() ))
       ) {
 	outmethod.println(  "      /* work scheduler works forever, explicitly exit */");
+	if (state.COREPROF) {
+	  outmethod.println("EXITPROFILER();");
+	  outmethod.println("DUMPPROFILER();");
+	}
 	outmethod.println(  "      exit( 0 );");
       }
 
diff --git a/Robust/src/Runtime/coreprof/coreprof.c b/Robust/src/Runtime/coreprof/coreprof.c
index 7b61c8a6..3c5f8760 100644
--- a/Robust/src/Runtime/coreprof/coreprof.c
+++ b/Robust/src/Runtime/coreprof/coreprof.c
@@ -1,18 +1,32 @@
 #include "runtime.h"
 #include "coreprof.h"
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "mlp_lock.h"
 
-__thread struct coreprofmonitor * cp_events;
+__thread struct coreprofmonitor * cp_events=NULL;
 struct coreprofmonitor * cp_eventlist=NULL;
 static volatile int cp_threadcount=0;
-__thread int threadnum;
+__thread int cp_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 createprofiler() {
+  if (cp_events!=NULL)
+    return;
   struct coreprofmonitor *event=calloc(1, sizeof(struct coreprofmonitor));
   //add new eventmonitor to list
   struct coreprofmonitor *tmp;
@@ -21,19 +35,19 @@ void createprofiler() {
   do {
     tmp=cp_eventlist;
     event->next=tmp;
-  } while(CAS(&cp_eventlist, tmp, event)!=tmp);
+  } while(CAS(&cp_eventlist, (INTPTR) tmp, (INTPTR) event)!=((INTPTR)tmp));
 
-  int ourcount=atomic_inc(&cp_threadcount);
+  int ourcount=atomicinc(&cp_threadcount);
   cp_threadnum=ourcount;
 
   //point thread lock variable to eventmonitor
   cp_events=event;
-  CPLOGEVENT(CP_START, CP_BEGIN);
+  CPLOGEVENT(CP_MAIN, CP_BEGIN);
 }
 
 //Place to do shutdown stuff
 void exitprofiler() {
-  CPLOGEVENT(CP_START, CP_END);
+  CPLOGEVENT(CP_MAIN, CP_END);
 }
 
 void cpwritedata(int fd, char * buffer, int count) {
@@ -49,9 +63,9 @@ void dumpprofiler() {
   int fd=open("logdata",O_RDWR|O_CREAT,S_IRWXU);
   int count=0;
   struct coreprofmonitor * ptr=cp_eventlist;
-  int VERSION=0;
+  int version=0;
   //Write version number
-  cpwritedata(fd, &version, sizeof(int));
+  cpwritedata(fd, (char *)&version, sizeof(int));
   while(ptr!=NULL) {
     count++;
     if (ptr->index>CPMAXEVENTS) {
@@ -66,7 +80,7 @@ void dumpprofiler() {
   //Write the number of events for each thread
   ptr=cp_eventlist;
   while(ptr!=NULL) {
-    cpwritedata(fd, &ptr->index, sizeof(int));
+    cpwritedata(fd, (char *)&ptr->index, sizeof(int));
     ptr=ptr->next;
   }
 
diff --git a/Robust/src/Runtime/coreprof/coreprof.h b/Robust/src/Runtime/coreprof/coreprof.h
index 8cc6d33b..bc50df18 100644
--- a/Robust/src/Runtime/coreprof/coreprof.h
+++ b/Robust/src/Runtime/coreprof/coreprof.h
@@ -1,12 +1,16 @@
 #ifndef COREPROF_H
 #define COREPROF_H
 #ifndef COREPROF
+
 //Core Prof turned off
 #define CREATEPROFILER() ;
 #define EXITPROFILER() ;
 #define DUMPPROFILER() ;
 #define CPLOGEVENT(x,y) ;
 #else
+#include <stdlib.h>
+#include "runtime.h"
+
 //Core Prof defined
 #ifndef CPMAXEVENTS
 #define CPMAXEVENTS (1024*1024*128)
@@ -15,7 +19,7 @@
 #define EXITPROFILER() exitprofiler();
 #define DUMPPROFILER() dumpprofiler();
 
-#define CPLOGEVENT(x,y) { CP_events->value[cp_events->index++]=((x<<CP_BASE_SHIFT)|y); \
+#define CPLOGEVENT(x,y) { cp_events->value[cp_events->index++]=((x<<CP_BASE_SHIFT)|y); \
     CPLOGTIME								\
       }
 
@@ -36,7 +40,7 @@
 struct coreprofmonitor {
   int index;
   struct coreprofmonitor * next;
-  unsigned int value[MAXEVENTS];
+  unsigned int value[CPMAXEVENTS];
 };
 
 extern __thread int cp_threadnum;
@@ -47,16 +51,16 @@ void exitprofiler();
 void dumpprofiler();
 
 static inline void *cp_calloc(int size) {
-  CP_LOGEVENT(CP_RUNMALLOC, CP_BEGIN);
+  CPLOGEVENT(CP_RUNMALLOC, CP_BEGIN);
   void *mem=calloc(1,size);
-  CP_LOGEVENT(CP_RUNMALLOC, CP_END);
+  CPLOGEVENT(CP_RUNMALLOC, CP_END);
   return mem;
 }
 
 static inline void cp_free(void *ptr) {
-  CP_LOGEVENT(CP_RUNFREE, CP_BEGIN);
+  CPLOGEVENT(CP_RUNFREE, CP_BEGIN);
   free(ptr);
-  CP_LOGEVENT(CP_RUNFREE, CP_END);
+  CPLOGEVENT(CP_RUNFREE, CP_END);
 }
 #endif
 #endif
diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c
index 093dacba..48b41e51 100644
--- a/Robust/src/Runtime/workschedule.c
+++ b/Robust/src/Runtime/workschedule.c
@@ -109,7 +109,7 @@ void* workerMain( void* arg ) {
 void workScheduleInit( int numProcessors,
                        void(*func)(void*) ) {
   int i, status;
-
+  CREATEPROFILER();
   pthread_mutex_init(&gclock, NULL);
   pthread_mutex_init(&gclistlock, NULL);
   pthread_cond_init(&gccond, NULL);
@@ -165,5 +165,4 @@ void workScheduleBegin() {
   for( i = 0; i < numWorkers; ++i ) {
     pthread_join( workerDataArray[i].workerThread, NULL );
   }
-  DUMPPROFILER();
 }