[project @ 2001-11-26 16:54:21 by simonmar]
[ghc-hetmet.git] / ghc / rts / Schedule.c
index 3371bad..b027115 100644 (file)
@@ -1,5 +1,5 @@
 /* ---------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.105 2001/11/08 12:46:31 simonmar Exp $
+ * $Id: Schedule.c,v 1.108 2001/11/26 16:54:22 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
 #include "Stats.h"
 #include "Itimer.h"
 #include "Prelude.h"
+#ifdef PROFILING
+#include "Proftimer.h"
+#include "ProfHeap.h"
+#include "RetainerProfile.h"
+#endif
 #if defined(GRAN) || defined(PAR)
 # include "GranSimRts.h"
 # include "GranSim.h"
@@ -181,7 +186,6 @@ StgTSO *all_threads;
  */
 static StgTSO *suspended_ccalling_threads;
 
-static void GetRoots(evac_fn);
 static StgTSO *threadStackOverflow(StgTSO *tso);
 
 /* KH: The following two flags are shared memory locations.  There is no need
@@ -923,10 +927,14 @@ schedule( void )
      * the user specified "context switch as often as possible", with
      * +RTS -C0
      */
-    if (RtsFlags.ConcFlags.ctxtSwitchTicks == 0
-       && (run_queue_hd != END_TSO_QUEUE
-           || blocked_queue_hd != END_TSO_QUEUE
-           || sleeping_queue != END_TSO_QUEUE))
+    if (
+#ifdef PROFILING
+       RtsFlags.ProfFlags.profileInterval == 0 ||
+#endif
+       (RtsFlags.ConcFlags.ctxtSwitchTicks == 0
+        && (run_queue_hd != END_TSO_QUEUE
+            || blocked_queue_hd != END_TSO_QUEUE
+            || sleeping_queue != END_TSO_QUEUE)))
        context_switch = 1;
     else
        context_switch = 0;
@@ -936,6 +944,10 @@ schedule( void )
     IF_DEBUG(scheduler, sched_belch("-->> Running TSO %ld (%p) %s ...", 
                              t->id, t, whatNext_strs[t->what_next]));
 
+#ifdef PROFILING
+    startHeapProfTimer();
+#endif
+
     /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
     /* Run the current thread 
      */
@@ -961,6 +973,7 @@ schedule( void )
     
     /* Costs for the scheduler are assigned to CCS_SYSTEM */
 #ifdef PROFILING
+    stopHeapProfTimer();
     CCCS = CCS_SYSTEM;
 #endif
     
@@ -1262,6 +1275,15 @@ schedule( void )
     n_free_capabilities++;
 #endif
 
+#ifdef PROFILING
+    if (RtsFlags.ProfFlags.profileInterval==0 || performHeapProfile) {
+       GarbageCollect(GetRoots, rtsTrue);
+       heapCensus();
+       performHeapProfile = rtsFalse;
+       ready_to_gc = rtsFalse; // we already GC'd
+    }
+#endif
+
 #ifdef SMP
     if (ready_to_gc && n_free_capabilities == RtsFlags.ParFlags.nNodes) 
 #else
@@ -1356,9 +1378,13 @@ void deleteAllThreads ( void )
  * ------------------------------------------------------------------------- */
    
 StgInt
-suspendThread( Capability *cap )
+suspendThread( StgRegTable *reg )
 {
   nat tok;
+  Capability *cap;
+
+  // assume that *reg is a pointer to the StgRegTable part of a Capability
+  cap = (Capability *)((void *)reg - sizeof(StgFunTable));
 
   ACQUIRE_LOCK(&sched_mutex);
 
@@ -1382,7 +1408,7 @@ suspendThread( Capability *cap )
   return tok; 
 }
 
-Capability *
+StgRegTable *
 resumeThread( StgInt tok )
 {
   StgTSO *tso, **prev;
@@ -1420,7 +1446,7 @@ resumeThread( StgInt tok )
   cap->r.rCurrentTSO = tso;
 
   RELEASE_LOCK(&sched_mutex);
-  return cap;
+  return &cap->r;
 }
 
 
@@ -2166,7 +2192,7 @@ take_off_run_queue(StgTSO *tso) {
        KH @ 25/10/99
 */
 
-static void
+void
 GetRoots(evac_fn evac)
 {
   StgMainThread *m;