[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / runtime / main / GranSim.lc
index f8531ae..cdaee56 100644 (file)
@@ -2,7 +2,7 @@
 % (c) The GRASP/AQUA Project, Glasgow University, 1995 - 1996
 %     Hans Wolfgang Loidl
 %
-% Time-stamp: <Wed Jun 19 1996 16:38:25 Stardate: [-31]7683.25 hwloidl>
+% Time-stamp: <Sun Oct 19 1997 23:39:59 Stardate: [-30]0119.72 hwloidl>
 %
 %************************************************************************
 %*                                                                      *
@@ -20,7 +20,9 @@ which should be <= the length of a word in bits.  -- HWL
 \begin{code}
 #if defined(GRAN) || defined(PAR)
 
+#ifndef _AIX
 #define NON_POSIX_SOURCE    /* gettimeofday */
+#endif
 
 #include "rtsdefs.h" 
 
@@ -77,6 +79,9 @@ char *proc_status_names[] = {
 unsigned CurrentProc = 0;
 rtsBool IgnoreEvents = rtsFalse; /* HACK only for testing */
 
+#if 0 && (defined(GCap) || defined(GCgn))
+closq ex_RBH_q = NULL;
+#endif
 #endif  /* GRAN */
 \end{code}
 
@@ -300,7 +305,7 @@ get_next_event()
 
   if(EventHd == NULL)
     {
-      fprintf(stderr,"No next event\n");
+      fprintf(stderr,"No next event. This may be caused by a circular data dependency in the program.\n");
       EXIT(EXIT_FAILURE);
     }
 
@@ -432,7 +437,7 @@ grab_event()             /* undo prepend_event i.e. get the event */
  eventq event = EventHd;
 
  if(EventHd == NULL) {
-   fprintf(stderr,"No next event (in grab_event)\n");
+   fprintf(stderr,"No next event (in grab_event). This may be caused by a circular data dependency in the program.\n");
    EXIT(EXIT_FAILURE);
  }
 
@@ -440,6 +445,50 @@ grab_event()             /* undo prepend_event i.e. get the event */
  return (event);
 }
 
+void 
+traverse_eventq_for_gc()
+{
+ eventq event = EventHd;
+ W_ bufsize;
+ P_ closure, tso, buffer, bufptr;
+ PROC proc, creator;
+
+ /* Traverse eventq and replace every FETCHREPLY by a FETCHNODE for the
+    orig closure (root of packed graph). This means that a graph, which is
+    between processors at the time of GC is fetched again at the time when
+    it would have arrived, had there been no GC. Slightly inaccurate but
+    safe for GC.
+    This is only needed for GUM style fetchng. */
+ if (!RTSflags.GranFlags.DoGUMMFetching)
+   return;
+
+ for(event = EventHd; event!=NULL; event=EVENT_NEXT(event)) {
+   if (EVENT_TYPE(event)==FETCHREPLY) {
+     buffer = EVENT_NODE(event);
+     ASSERT(buffer[PACK_FLAG_LOCN]==MAGIC_PACK_FLAG);  /* It's a pack buffer */
+     bufsize = buffer[PACK_SIZE_LOCN];
+     closure= (P_)buffer[PACK_HDR_SIZE];
+     tso = (P_)buffer[PACK_TSO_LOCN];
+     proc = EVENT_PROC(event);
+     creator = EVENT_CREATOR(event);                 /* similar to unpacking */
+     for (bufptr=buffer+PACK_HDR_SIZE; bufptr<(buffer+bufsize);
+         bufptr++) {
+        if ( (INFO_TYPE(INFO_PTR(*bufptr)) == INFO_SPEC_RBH_TYPE) ||
+             (INFO_TYPE(INFO_PTR(*bufptr)) == INFO_GEN_RBH_TYPE) ) {
+            convertFromRBH((P_)*bufptr);
+        }
+     }
+     free(buffer);
+     EVENT_TYPE(event) = FETCHNODE;
+     EVENT_PROC(event) = creator;
+     EVENT_CREATOR(event) = proc;
+     EVENT_NODE(event) = closure;
+     EVENT_TSO(event) = tso;
+     EVENT_GC_INFO(event) =  0;
+   }
+ }
+}
+
 void
 print_event(event)
 eventq event;
@@ -447,9 +496,9 @@ eventq event;
 
   char str_tso[16], str_node[16];
 
-  sprintf(str_tso,((EVENT_TSO(event)==Prelude_Z91Z93_closure) ? "______" : "%#6lx"), 
+  sprintf(str_tso,((EVENT_TSO(event)==PrelBase_Z91Z93_closure) ? "______" : "%#6lx"), 
                   EVENT_TSO(event));
-  sprintf(str_node,((EVENT_NODE(event)==Prelude_Z91Z93_closure) ? "______" : "%#6lx"), 
+  sprintf(str_node,((EVENT_NODE(event)==PrelBase_Z91Z93_closure) ? "______" : "%#6lx"), 
                     EVENT_NODE(event));
 
   if (event==NULL)
@@ -481,7 +530,7 @@ print_spark(spark)
 { 
   char str[16];
 
-  sprintf(str,((SPARK_NODE(spark)==Prelude_Z91Z93_closure) ? "______" : "%#6lx"), 
+  sprintf(str,((SPARK_NODE(spark)==PrelBase_Z91Z93_closure) ? "______" : "%#6lx"), 
               (W_) SPARK_NODE(spark));
 
   if (spark==NULL)
@@ -530,18 +579,18 @@ First some auxiliary routines.
 void 
 ActivateNextThread (PROC proc)
 {
-  ASSERT(RunnableThreadsHd[proc]!=Prelude_Z91Z93_closure);
+  ASSERT(RunnableThreadsHd[proc]!=PrelBase_Z91Z93_closure);
 
   RunnableThreadsHd[proc] = TSO_LINK(RunnableThreadsHd[proc]);
-  if(RunnableThreadsHd[proc]==Prelude_Z91Z93_closure) {
+  if(RunnableThreadsHd[proc]==PrelBase_Z91Z93_closure) {
     MAKE_IDLE(proc);
-    RunnableThreadsTl[proc] = Prelude_Z91Z93_closure;
+    RunnableThreadsTl[proc] = PrelBase_Z91Z93_closure;
   } else {
     CurrentTime[proc] += RTSflags.GranFlags.gran_threadcontextswitchtime;
     if (RTSflags.GranFlags.granSimStats && 
        (!RTSflags.GranFlags.Light || (RTSflags.GranFlags.debug & 0x20000))) 
       DumpRawGranEvent(proc,0,GR_SCHEDULE,RunnableThreadsHd[proc],
-                       Prelude_Z91Z93_closure,0);
+                       PrelBase_Z91Z93_closure,0);
   }
 }
 \end{code}
@@ -568,7 +617,7 @@ W_ liveness;
 
   if (RTSflags.GranFlags.granSimStats_Heap) {
       DumpRawGranEvent(CurrentProc,0,GR_ALLOC,CurrentTSO,
-                       Prelude_Z91Z93_closure,n);
+                       PrelBase_Z91Z93_closure,n);
   }
   
   TSO_EXECTIME(CurrentTSO) += RTSflags.GranFlags.gran_heapalloc_cost;
@@ -696,8 +745,8 @@ P_ node;
                     }
                   }
 #  endif
-                  TSO_LINK(CurrentTSO) = Prelude_Z91Z93_closure;
-                  /* CurrentTSO = Prelude_Z91Z93_closure; */
+                  TSO_LINK(CurrentTSO) = PrelBase_Z91Z93_closure;
+                  /* CurrentTSO = PrelBase_Z91Z93_closure; */
 
                   /* ThreadQueueHd is now the next TSO to schedule or NULL */
                   /* CurrentTSO is pointed to by the FETCHNODE event */
@@ -725,7 +774,7 @@ P_ node;
                 } else {
                   TSO_TYPE(CurrentTSO) |= FETCH_MASK_TSO;
                 }
-                CurrentTSO = Prelude_Z91Z93_closure;
+                CurrentTSO = PrelBase_Z91Z93_closure;
               }
 #  endif
             }
@@ -747,13 +796,13 @@ P_ node;
 {
   /* ++SparksAvail;  Nope; do that in add_to_spark_queue */
   if(RTSflags.GranFlags.granSimStats_Sparks)
-    DumpRawGranEvent(CurrentProc,(PROC)0,SP_SPARK,Prelude_Z91Z93_closure,node,
+    DumpRawGranEvent(CurrentProc,(PROC)0,SP_SPARK,PrelBase_Z91Z93_closure,node,
                       spark_queue_len(CurrentProc,ADVISORY_POOL)-1);
 
   /* Force the PE to take notice of the spark */
   if(RTSflags.GranFlags.DoAlwaysCreateThreads) {
     new_event(CurrentProc,CurrentProc,CurrentTime[CurrentProc],
-             FINDWORK,Prelude_Z91Z93_closure,Prelude_Z91Z93_closure,NULL);
+             FINDWORK,PrelBase_Z91Z93_closure,PrelBase_Z91Z93_closure,NULL);
     if (CurrentTime[CurrentProc]<TimeOfNextEvent)
       TimeOfNextEvent = CurrentTime[CurrentProc];
   }
@@ -787,7 +836,7 @@ I_ identifier;
 
   /* ++SparksAvail; Nope; do that in add_to_spark_queue */
   if(RTSflags.GranFlags.granSimStats_Sparks)
-    DumpRawGranEvent(proc,0,SP_SPARKAT,Prelude_Z91Z93_closure,SPARK_NODE(spark),
+    DumpRawGranEvent(proc,0,SP_SPARKAT,PrelBase_Z91Z93_closure,SPARK_NODE(spark),
                     spark_queue_len(proc,ADVISORY_POOL));
 
   if (proc!=CurrentProc) {
@@ -803,10 +852,10 @@ I_ identifier;
     /* Need CurrentTSO in event field to associate costs with creating
        spark even in a GrAnSim Light setup */
     new_event(proc,CurrentProc,exporttime,
-            MOVESPARK,CurrentTSO,Prelude_Z91Z93_closure,spark);
+            MOVESPARK,CurrentTSO,PrelBase_Z91Z93_closure,spark);
   else
     new_event(proc,CurrentProc,exporttime,
-            MOVESPARK,Prelude_Z91Z93_closure,Prelude_Z91Z93_closure,spark);
+            MOVESPARK,PrelBase_Z91Z93_closure,PrelBase_Z91Z93_closure,spark);
   /* Bit of a hack to treat placed sparks the same as stolen sparks */
   ++OutstandingFishes[proc];
 
@@ -814,7 +863,7 @@ I_ identifier;
      MOVESPARK into the sparkq!) */
   if(RTSflags.GranFlags.DoAlwaysCreateThreads) {
     new_event(CurrentProc,CurrentProc,exporttime+1,
-              FINDWORK,Prelude_Z91Z93_closure,Prelude_Z91Z93_closure,NULL);
+              FINDWORK,PrelBase_Z91Z93_closure,PrelBase_Z91Z93_closure,NULL);
   }
 
   if (exporttime<TimeOfNextEvent)
@@ -848,7 +897,7 @@ GranSimBlock(P_ tso, PROC proc, P_ node)
 
   CurrentTime[proc] += RTSflags.GranFlags.gran_threadqueuetime;
   ActivateNextThread(proc);
-  TSO_LINK(tso) = Prelude_Z91Z93_closure;  /* not really necessary; only for testing */
+  TSO_LINK(tso) = PrelBase_Z91Z93_closure;  /* not really necessary; only for testing */
 }
 
 #endif  /* GRAN */
@@ -918,7 +967,7 @@ DumpGranEvent(name, tso)
 enum gran_event_types name;
 P_ tso;
 {
-    DumpRawGranEvent(CURRENT_PROC, (PROC)0, name, tso, Prelude_Z91Z93_closure, 0);
+    DumpRawGranEvent(CURRENT_PROC, (PROC)0, name, tso, PrelBase_Z91Z93_closure, 0);
 }
 
 void
@@ -937,8 +986,8 @@ I_ len;
 #endif
 
   id = tso == NULL ? -1 : TSO_ID(tso);
-  if (node==Prelude_Z91Z93_closure)
-      strcpy(node_str,"________");  /* "Prelude_Z91Z93_closure"); */
+  if (node==PrelBase_Z91Z93_closure)
+      strcpy(node_str,"________");  /* "PrelBase_Z91Z93_closure"); */
   else
       sprintf(node_str,"0x%-6lx",node);
 
@@ -984,7 +1033,7 @@ I_ len;
         fprintf(gr_file,"PE %2u [%s]: %-9s\t%lx\t%s\t[SN %u]\n", 
        /* using spark name as optional argument     ^^^^^^ */
                proc,time_string,gran_event_names[name],
-               id,node_str,(len & NEW_SPARKNAME_MASK));
+               id,node_str,len);
         break;
      case GR_FETCH:
      case GR_REPLY:
@@ -1035,8 +1084,8 @@ I_ len;
     return;
 
   id = tso == NULL ? -1 : TSO_ID(tso);
-  if (node==Nil_closure)
-      strcpy(node_str,"________");  /* "Nil_closure"); */
+  if (node==PrelBase_Z91Z93_closure)
+      strcpy(node_str,"________");  /* "Z91Z93_closure"); */
   else
       sprintf(node_str,"0x%-6lx",node);
 
@@ -1068,7 +1117,7 @@ I_ len;
         fprintf(gr_file,"PE %2u [%s]: %-9s\t%lx\t%s\t[SN %u]\n", 
        /* using spark name as optional argument     ^^^^^^ */
                proc,time_string,gran_event_names[name],
-               id,node_str,(len & NEW_SPARKNAME_MASK));
+               id,node_str,len);
         break;
      default:
         fprintf(stderr,"Error in DumpStartEventAt: event %s is not a START event\n",
@@ -1206,7 +1255,7 @@ TIME v;
       return;
 #endif
 
-    DumpGranEvent(GR_TERMINATE, Prelude_Z91Z93_closure);
+    DumpGranEvent(GR_TERMINATE, PrelBase_Z91Z93_closure);
 
     if (sizeof(TIME) == 4) {
        putc('\0', gr_file);