1 /* --------------------------------------------------------------------------
2 Time-stamp: <Tue Mar 06 2001 00:18:30 Stardate: [-30]6285.06 hwloidl>
3 $Id: GranSimRts.h,v 1.4 2001/03/22 03:51:11 hwloidl Exp $
5 Variables and functions specific to GranSim.
6 ----------------------------------------------------------------------- */
11 //@node Headers for GranSim objs used only in the RTS internally, , ,
12 //@section Headers for GranSim objs used only in the RTS internally
16 //* Spark handling routines::
17 //* Processor related stuff::
19 //* Statistics gathering::
24 //@node Event queue, Spark handling routines, Headers for GranSim objs used only in the RTS internally, Headers for GranSim objs used only in the RTS internally
25 //@subsection Event queue
27 #if defined(GRAN) || defined(PAR)
28 /* Granularity event types for output (see DumpGranEvent) */
29 typedef enum GranEventType_ {
30 GR_START = 0, GR_STARTQ,
31 GR_STEALING, GR_STOLEN, GR_STOLENQ,
32 GR_FETCH, GR_REPLY, GR_BLOCK, GR_RESUME, GR_RESUMEQ,
33 GR_SCHEDULE, GR_DESCHEDULE,
35 SP_SPARK, SP_SPARKAT, SP_USED, SP_PRUNED, SP_EXPORTED, SP_ACQUIRED, SP_REQUESTED,
38 GR_SYSTEM_START, GR_SYSTEM_END, /* only for debugging */
42 extern char *gran_event_names[];
45 #if defined(GRAN) /* whole file */
47 /* Event Types (internal use only) */
48 typedef enum rtsEventType_ {
49 ContinueThread = 0, /* Continue running the first thread in the queue */
50 StartThread, /* Start a newly created thread */
51 ResumeThread, /* Resume a previously running thread */
52 MoveSpark, /* Move a spark from one PE to another */
53 MoveThread, /* Move a thread from one PE to another */
54 FindWork, /* Search for work */
55 FetchNode, /* Fetch a node */
56 FetchReply, /* Receive a node */
57 GlobalBlock, /* Block a TSO on a remote node */
58 UnblockThread /* Make a TSO runnable */
61 /* Number of last event type */
64 typedef struct rtsEvent_ {
65 PEs proc; /* Processor id */
66 PEs creator; /* Processor id of PE that created the event */
67 rtsEventType evttype; /* rtsEvent type */
68 rtsTime time; /* Time at which event happened */
69 StgTSO *tso; /* Associated TSO, if relevant */
70 StgClosure *node; /* Associated node, if relevant */
71 rtsSpark *spark; /* Associated SPARK, if relevant */
72 StgInt gc_info; /* Counter of heap objects to mark (used in GC only)*/
73 struct rtsEvent_ *next;
76 typedef rtsEvent *rtsEventQ;
78 extern rtsEventQ EventHd;
80 /* Interface for ADT of Event Queue */
81 rtsEvent *get_next_event(void);
82 rtsTime get_time_of_next_event(void);
83 void insert_event(rtsEvent *newentry);
84 void new_event(PEs proc, PEs creator, rtsTime time,
85 rtsEventType evttype, StgTSO *tso,
86 StgClosure *node, rtsSpark *spark);
87 void print_event(rtsEvent *event);
88 void print_eventq(rtsEvent *hd);
89 void prepend_event(rtsEvent *event);
90 rtsEventQ grab_event(void);
91 void prune_eventq(StgTSO *tso, StgClosure *node);
93 void traverse_eventq_for_gc(void);
94 void markEventQueue(void);
96 //@node Spark handling routines, Processor related stuff, Event queue, Headers for GranSim objs used only in the RTS internally
97 //@subsection Spark handling routines
99 /* These functions are only used in the RTS internally; see GranSim.h for rest */
100 void disposeSpark(rtsSpark *spark);
101 void disposeSparkQ(rtsSparkQ spark);
102 void print_spark(rtsSpark *spark);
103 void print_sparkq(PEs proc);
104 void print_sparkq_stats(void);
105 nat spark_queue_len(PEs proc);
106 rtsSpark *delete_from_sparkq (rtsSpark *spark, PEs p, rtsBool dispose_too);
107 void markSparkQueue(void);
109 //@node Processor related stuff, Local types, Spark handling routines, Headers for GranSim objs used only in the RTS internally
110 //@subsection Processor related stuff
112 typedef enum rtsProcStatus_ {
113 Idle = 0, /* empty threadq */
114 Sparking, /* non-empty sparkq; FINDWORK has been issued */
115 Starting, /* STARTTHREAD has been issue */
116 Fetching, /* waiting for remote data (only if block-on-fetch) */
117 Fishing, /* waiting for remote spark/thread */
118 Busy /* non-empty threadq, with head of queue active */
122 #define IS_IDLE(proc) (procStatus[proc] == Idle)
123 #define IS_SPARKING(proc) (procStatus[proc] == Sparking)
124 #define IS_STARTING(proc) (procStatus[proc] == Starting)
125 #define IS_FETCHING(proc) (procStatus[proc] == Fetching)
126 #define IS_FISHING(proc) (procStatus[proc] == Fishing)
127 #define IS_BUSY(proc) (procStatus[proc] == Busy)
128 #define ANY_IDLE (any_idle())
129 #define MAKE_IDLE(proc) procStatus[proc] = Idle
130 #define MAKE_SPARKING(proc) procStatus[proc] = Sparking
131 #define MAKE_STARTING(proc) procStatus[proc] = Starting
132 #define MAKE_FETCHING(proc) procStatus[proc] = Fetching
133 #define MAKE_FISHING(proc) procStatus[proc] = Fishing
134 #define MAKE_BUSY(proc) procStatus[proc] = Busy
137 //@node Local types, Statistics gathering, Processor related stuff, Headers for GranSim objs used only in the RTS internally
138 //@subsection Local types
140 /* Return codes of HandleFetchRequest:
141 0 ... ok (FETCHREPLY event with a buffer containing addresses of the
142 nearby graph has been scheduled)
143 1 ... node is already local (fetched by somebody else; no event is
145 2 ... fetch request has been forwrded to the PE that now contains the
147 3 ... node is a black hole (BH, BQ or RBH); no event is scheduled, and
148 the current TSO is put into the blocking queue of that node
149 4 ... out of heap in PackNearbyGraph; GC should be triggered in calling
150 function to guarantee that the tso and node inputs are valid
151 (they may be moved during GC).
152 Return codes of blockFetch:
153 0 ... ok; tso is now at beginning of BQ attached to the bh closure
154 1 ... the bh closure is no BH any more; tso is immediately unblocked
157 typedef enum rtsFetchReturnCode_ {
164 } rtsFetchReturnCode;
166 //@node Statistics gathering, Prototypes, Local types, Headers for GranSim objs used only in the RTS internally
167 //@subsection Statistics gathering
169 extern unsigned int /* nat */ OutstandingFetches[], OutstandingFishes[];
170 extern rtsProcStatus procStatus[];
171 extern StgTSO *BlockedOnFetch[];
173 /* global structure for collecting statistics */
174 typedef struct GlobalGranStats_ {
177 nat event_counts[MAX_EVENT];
179 /* communication stats */
181 nat tot_fake_fetches; // GranSim internal; faked Fetches are a kludge!!
182 nat tot_low_pri_sparks;
184 /* load distribution statistics */
185 nat rs_sp_count, rs_t_count, ntimes_total, fl_total,
186 no_of_steals, no_of_migrates;
188 /* spark queue stats */
189 nat tot_sq_len, tot_sq_probes, tot_sparks;
190 nat tot_add_threads, tot_tq_len, non_end_add_threads;
192 /* packet statistics */
193 nat tot_packets, tot_packet_size, tot_cuts, tot_thunks;
196 nat tot_threads_created, threads_created_on_PE[MAX_PROC],
200 nat pruned_sparks, withered_sparks;
201 nat tot_sparks_created, sparks_created_on_PE[MAX_PROC];
203 /* scheduling stats */
204 nat tot_yields, tot_stackover, tot_heapover;
206 /* blocking queue statistics */
207 rtsTime tot_bq_processing_time;
208 nat tot_bq_len, tot_bq_len_local, tot_awbq, tot_FMBQs;
211 extern GlobalGranStats globalGranStats;
213 //@node Prototypes, , Statistics gathering, Headers for GranSim objs used only in the RTS internally
214 //@subsection Prototypes
216 /* Generally useful fcts */
217 PEs where_is(StgClosure *node);
218 rtsBool is_unique(StgClosure *node);
220 /* Prototypes of event handling functions; needed in Schedule.c:ReSchedule() */
221 void do_the_globalblock (rtsEvent* event);
222 void do_the_unblock (rtsEvent* event);
223 void do_the_fetchnode (rtsEvent* event);
224 void do_the_fetchreply (rtsEvent* event);
225 void do_the_movethread (rtsEvent* event);
226 void do_the_movespark (rtsEvent* event);
227 void do_the_startthread(rtsEvent *event);
228 void do_the_findwork(rtsEvent* event);
229 void gimme_spark (rtsEvent *event, rtsBool *found_res, rtsSparkQ *spark_res);
230 rtsBool munch_spark (rtsEvent *event, rtsSparkQ spark);
232 /* GranSimLight routines */
233 void GranSimLight_enter_system(rtsEvent *event, StgTSO **ActiveTSOp);
234 void GranSimLight_leave_system(rtsEvent *event, StgTSO **ActiveTSOp);
236 /* Communication related routines */
237 rtsFetchReturnCode fetchNode(StgClosure* node, PEs from, PEs to);
238 rtsFetchReturnCode handleFetchRequest(StgClosure* node, PEs curr_proc, PEs p, StgTSO* tso);
239 void handleIdlePEs(void);
241 long int random(void); /* used in stealSpark() and stealThread() in GranSim.c */
243 /* Scheduling fcts defined in GranSim.c */
244 void insertThread(StgTSO *tso, PEs proc);
245 void endThread(StgTSO *tso, PEs proc);
246 rtsBool GranSimLight_insertThread(StgTSO *tso, PEs proc);
247 nat thread_queue_len(PEs proc);
250 rtsBool is_on_queue (StgTSO *tso, PEs proc);
253 #if defined(GRAN) || defined(PAR)
255 Interface for dumping routines (i.e. writing to log file).
256 These routines are shared with GUM (and could also be used for SMP).
258 void DumpGranEvent(GranEventType name, StgTSO *tso);
259 void DumpEndEvent(PEs proc, StgTSO *tso, rtsBool mandatory_thread);
260 void DumpTSO(StgTSO *tso);
261 void DumpRawGranEvent(PEs proc, PEs p, GranEventType name,
262 StgTSO *tso, StgClosure *node,
263 StgInt sparkname, StgInt len);
264 void DumpVeryRawGranEvent(rtsTime time, PEs proc, PEs p, GranEventType name,
265 StgTSO *tso, StgClosure *node,
266 StgInt sparkname, StgInt len);
269 #endif /* GRANSIM_RTS_H */