1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
%
% (c) Kevin Hammond, Parade/AQUA Projects, Glasgow University, February 15th. 1995
%
% This is for GUM only.
%
%************************************************************************
%* *
\section[Parallel.lh]{Definitions for parallel machines}
%* *
%************************************************************************
Multi-slurp protection:
\begin{code}
#ifndef Parallel_H
#define Parallel_H
\end{code}
This section contains definitions applicable only to programs compiled
to run on a parallel machine. Some of these things can probably be
ripped out now that we don't store GAs in closures, but beware that
this {\em might} break GranSim, so check first! KH
These basic definitions need to be around, one way or the other:
\begin{code}
#define PAR_FIXED_HDR (GA_HDR_SIZE)
#define PAR_HDR_POSN AFTER_INFO_HDR
#define AFTER_PAR_HDR (PAR_HDR_POSN+PAR_FIXED_HDR)
#define SET_PAR_HDR(closure,ga) /* nothing */
#define SET_STATIC_PAR_HDR(closure) /* nothing */
\end{code}
\begin{code}
# ifdef PAR
# define MAX_PES 256 /* Maximum number of processors */
/* MAX_PES is enforced by SysMan, which does not
allow more than this many "processors".
This is important because PackGA [GlobAddr.lc]
**assumes** that a PE# can fit in 8+ bits.
*/
extern I_ do_sp_profile;
extern P_ PendingFetches;
extern GLOBAL_TASK_ID *PEs;
extern rtsBool IAmMainThread, GlobalStopPending;
extern rtsBool fishing;
extern GLOBAL_TASK_ID SysManTask;
extern int seed; /*pseudo-random-number generator seed:*/
/*Initialised in ParInit*/
extern I_ threadId; /*Number of Threads that have existed on a PE*/
extern GLOBAL_TASK_ID mytid;
extern int nPEs;
extern rtsBool InGlobalGC; /* Are we in the midst of performing global GC */
extern HashTable *pGAtoGALAtable;
extern HashTable *LAtoGALAtable;
extern GALA *freeIndirections;
extern GALA *liveIndirections;
extern GALA *freeGALAList;
extern GALA *liveRemoteGAs;
extern int thisPE;
void RunParallelSystem PROTO((StgPtr program_closure));
void initParallelSystem(STG_NO_ARGS);
void SynchroniseSystem(STG_NO_ARGS);
void registerTask PROTO((GLOBAL_TASK_ID gtid));
globalAddr *LAGAlookup PROTO((P_ addr));
P_ GALAlookup PROTO((globalAddr *ga));
globalAddr *MakeGlobal PROTO((P_ addr, rtsBool preferred));
globalAddr *setRemoteGA PROTO((P_ addr, globalAddr *ga, rtsBool preferred));
void splitWeight PROTO((globalAddr *to, globalAddr *from));
globalAddr *addWeight PROTO((globalAddr *ga));
void initGAtables(STG_NO_ARGS);
W_ taskIDtoPE PROTO((GLOBAL_TASK_ID gtid));
void RebuildLAGAtable(STG_NO_ARGS);
void *lookupHashTable PROTO((HashTable *table, StgWord key));
void insertHashTable PROTO((HashTable *table, StgWord key, void *data));
void freeHashTable PROTO((HashTable *table, void (*freeDataFun) PROTO((void *data))));
HashTable *allocHashTable(STG_NO_ARGS);
void *removeHashTable PROTO((HashTable *table, StgWord key, void *data));
extern void myexit PROTO((I_));
# define EXIT myexit
# define exit : error : Wrong exit!
# else
# define EXIT exit
# endif
\end{code}
%************************************************************************
%* *
\subsection[anti-parallel-SM]{But if we're {\em not} compiling for a parallel system...}
%* *
%************************************************************************
Get this out of the way. These are all null definitions.
\begin{code}
# if !(defined(GRAN) || defined(PAR))
# define GA_HDR_SIZE 0
# define GA(closure) /*nothing*/
# define SET_GA(closure,ga) /* nothing */
# define SET_STATIC_GA(closure) /* nothing */
# define SET_GRAN_HDR(closure,pe) /* nothing */
# define SET_STATIC_PROCS(closure) /* nothing */
# define SET_TASK_ACTIVITY(act) /* nothing */
#endif
#if defined(GRAN)
# define GA_HDR_SIZE 1
# define PROCS_HDR_POSN PAR_HDR_POSN
# define PROCS_HDR_SIZE 1
/* Accessing components of the field */
# define PROCS(closure) (*((P_)(closure)+PROCS_HDR_POSN))
# define SET_PROCS(closure, procs) \
PROCS(closure) = (W_)(procs) /* Set closure's location */
# define SET_GRAN_HDR(closure,pe) SET_PROCS(closure,pe)
# define SET_STATIC_PROCS(closure) , (W_) (Everywhere)
# define SET_TASK_ACTIVITY(act) /* nothing */
#endif
\end{code}
%************************************************************************
%* *
\subsection[parallel-GAs]{Parallel-only part of fixed headers (global addresses)}
%* *
%************************************************************************
Definitions relating to the entire parallel-only fixed-header field.
On GUM, the global addresses for each local closure are stored in a separate
hash table, rather then with the closure in the heap. We call @getGA@ to
look up the global address associated with a local closure (0 is returned
for local closures that have no global address), and @setGA@ to store a new
global address for a local closure which did not previously have one.
\begin{code}
#if defined(PAR)
# define GA_HDR_SIZE 0
# define GA(closure) getGA(closure)
# define SET_GA(closure, ga) setGA(closure,ga)
# define SET_STATIC_GA(closure)
# define SET_GRAN_HDR(closure,pe)
# define SET_STATIC_PROCS(closure)
# define MAX_GA_WEIGHT 0 /* Treat as 2^n */
W_ PackGA PROTO((W_, int));
/* There was a PACK_GA macro here; but we turned it into the PackGA
routine [GlobAddr.lc] (because it needs to do quite a bit of
paranoia checking. Phil & Will (95/08)
*/
\end{code}
At the moment, there is no activity profiling for GUM. This may change.
\begin{code}
# define SET_TASK_ACTIVITY(act)
\end{code}
%************************************************************************
%* *
\subsection[parallel-heap-objs]{Special parallel-only heap objects (`closures')}
%* *
%************************************************************************
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NB: The following definitons are BOTH for GUM and GrAnSim -- HWL
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The rest of this file contains definitions for {\it GUM and GrAnSim}.
Although we don't create FetchMe nodes in GrAnSim (we simulate it by
bitmask twiddling) we use FetchMe_info when converting nodes into RBHs
(mainly to keep the code as close to GUM as possible). So, we define all
the FetchMe related stuff in GrAnSim, too. % -- HWL
%************************************************************************
%* *
\subsubsection[FETCHME-closures]{@FETCHME@ heap objects (`closures')}
%* *
%************************************************************************
FetchMes are pointers into the global heap. When evaluated, the value
they point to is read from the global heap.
A FetchMe closure has the form:
\begin{onlylatex}
\begin{center}
\end{onlylatex}
\begin{tabular}{||l|l||}\hline
\tr{FETCHME_info} & junk \\ \hline
\end{tabular}
\begin{onlylatex}
\end{center}
\end{onlylatex}
The argument word is a pointer (outside of the heap) to a globalAddr structure...
in particular, the one corresponding to the object to be fetched. Note that
we can't just used the LAGA table, because weight-splitting may force us to
reassign a local GA to the @FetchMe@ so that we can give out new references.
A @FetchMe@ must have a valid @MUT_LINK@ field, because it may act as
a transition between an RBH on the OldMutables list and a BQ still on
the OldMutables list.
\begin{code}
# define FETCHME_VHS IND_VHS
# define FETCHME_HS IND_HS
# define FETCHME_GA_LOCN FETCHME_HS
# define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
# define FETCHME_CLOSURE_NoPTRS(closure) 0L
# define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
# define SET_FETCHME_HDR(closure,infolbl,cc,size,ptrs) \
{ SET_FIXED_HDR(closure,FetchMe_info,<bogus CC>); \
SET_MUT_RESERVED_WORDS(closure); \
}
# define FETCHME_GA(closure) (((globalAddr **)(closure))[FETCHME_GA_LOCN])
EXTFUN(FetchMe_entry);
EXTDATA_RO(FetchMe_info);
\end{code}
%************************************************************************
%* *
\subsubsection[BlockedFetch-closures]{@BlockedFetch@ heap objects (`closures')}
%* *
%************************************************************************
@BlockedFetch@s are inbound fetch messages blocked on local closures.
They arise as entries in a local blocking queue when a fetch has been
received for a local black hole. When awakened, we look at their
contents to figure out where to send a resume.
A @BlockedFetch@ closure has the form:
\begin{onlylatex}
\begin{center}
\end{onlylatex}
\begin{tabular}{||l|l|l||}\hline
\tr{BF_info} & link & node & gtid & slot & weight \\ \hline
\end{tabular}
\begin{onlylatex}
\end{center}
\end{onlylatex}
\begin{code}
# define BF_VHS (GC_MUT_RESERVED_WORDS)
# define BF_HS (FIXED_HS + BF_VHS)
# define BF_LINK_LOCN (BF_HS)
# define BF_NODE_LOCN (BF_HS + 1)
# define BF_GTID_LOCN (BF_HS + 2)
# define BF_SLOT_LOCN (BF_HS + 3)
# define BF_WEIGHT_LOCN (BF_HS + 4)
# define BF_CLOSURE_NoPTRS(closure) 2
# define BF_CLOSURE_NoNONPTRS(closure) 3
# define BF_CLOSURE_SIZE(closure) (BF_VHS + 5)
# define BF_LINK(closure) (((PP_)closure)[BF_LINK_LOCN])
# define BF_NODE(closure) (((PP_)closure)[BF_NODE_LOCN])
# define BF_GTID(closure) (((P_)closure)[BF_GTID_LOCN])
# define BF_SLOT(closure) (((P_)closure)[BF_SLOT_LOCN])
# define BF_WEIGHT(closure) (((P_)closure)[BF_WEIGHT_LOCN])
# define BF_CLOSURE_PTR(closure, no) (((P_)(closure))[BF_HS + (no) - 1])
/* std start-filling-in macro: */
# define SET_BF_HDR(closure,infolbl,cc) \
{ SET_FIXED_HDR(closure,infolbl,cc); \
SET_MUT_RESERVED_WORDS(closure); \
}
EXTFUN(BF_entry);
EXTDATA_RO(BF_info);
\end{code}
%************************************************************************
%* *
\subsubsection[FMBQ-closures]{@FMBQ@ (FetchMe with blocking queue) heap objects (`closures')}
%* *
%************************************************************************
FetchMe's with blocking queues are @Fetchme@ nodes which have been entered
(and therefore a fetch has been sent), but for which we have not yet received
a @Resume@ message. They look just like normal blocking queues, but have
a distinguished info pointer.
\begin{code}
# define FMBQ_VHS BQ_VHS
# define FMBQ_HS BQ_HS
# define FMBQ_CLOSURE_SIZE(closure) BQ_CLOSURE_SIZE(closure)
# define FMBQ_CLOSURE_NoPTRS(closure) BQ_CLOSURE_NoPTRS(closure)
# define FMBQ_CLOSURE_NoNONPTRS(closure) BQ_CLOSURE_NoNONPTRS(closure)
# define FMBQ_CLOSURE_PTR(closure, no) BQ_CLOSURE_PTR(closure, no)
# define FMBQ_ENTRIES(closure) BQ_ENTRIES(closure)
# define FMBQ_LINK(closure) BQ_LINK(closure)
EXTFUN(FMBQ_entry);
EXTDATA_RO(FMBQ_info);
\end{code}
%************************************************************************
%* *
\subsection[parallel-info-tables]{Special parallel-only info-table stuff}
%* *
%************************************************************************
%************************************************************************
%* *
\subsubsection[FETCHME_ITBL]{@FETCHME_ITBL@}
%* *
%************************************************************************
ToDo: delete FetchMe CAT (because we don't profile and parallelize at
the same time...) Even better...set things up so that we can profile
and parallelize at the same time!
\begin{code}
# define FETCHME_ITBL(itbl_name,entry_code) \
CAT_DECLARE(FetchMe,INTERNAL_KIND,"FetchMe","<FetchMe>") \
EXTFUN(entry_code); \
EXTDATA_RO(MK_REP_LBL(FetchMe,,)); \
const W_ itbl_name[] = { \
(W_) entry_code \
,(W_) INFO_OTHER_TAG \
,(W_) MK_REP_REF(FetchMe,,) \
INCLUDE_PROFILING_INFO(FetchMe) \
}
# define FETCHME_RTBL() \
const W_ MK_REP_LBL(FetchMe,,)[] = { \
INCLUDE_TYPE_INFO(FETCHME) \
INCLUDE_SIZE_INFO(MIN_UPD_SIZE, 0L) \
INCLUDE_PAR_INFO \
INCLUDE_COPYING_INFO(_Evacuate_FetchMe,_Scavenge_FetchMe) \
INCLUDE_COMPACTING_INFO(_ScanLink_FetchMe,_PRStart_FetchMe,_ScanMove_FetchMe,_PRIn_Error) \
}
\end{code}
%************************************************************************
%* *
\subsubsection[BF_ITBL]{@BF_ITBL@}
%* *
%************************************************************************
The special info table used for thread state objects (BlockedFetchs).
\begin{code}
# define BF_ITBL() \
CAT_DECLARE(BF,INTERNAL_KIND,"BlockedFetch","<BlockedFetch>") \
EXTFUN(BF_entry); \
EXTDATA_RO(MK_REP_LBL(BF,,)); \
const W_ BF_info[] = { \
(W_) BF_entry \
,(W_) INFO_OTHER_TAG \
,(W_) MK_REP_REF(BF,,) \
INCLUDE_PROFILING_INFO(BF) \
}
# define BF_RTBL() \
const W_ MK_REP_LBL(BF,,)[] = { \
INCLUDE_TYPE_INFO(BF) \
INCLUDE_SIZE_INFO(BF_CLOSURE_SIZE(dummy),BF_CLOSURE_NoPTRS(dummy)) \
INCLUDE_PAR_INFO \
INCLUDE_COPYING_INFO(_Evacuate_BF,_Scavenge_BF) \
INCLUDE_COMPACTING_INFO(_ScanLink_BF,_PRStart_BF,_ScanMove_BF,_PRIn_BF) \
}
\end{code}
%************************************************************************
%* *
\subsubsection[FMBQ_ITBL]{@FMBQ_ITBL@}
%* *
%************************************************************************
Special info-table for local blocking queues.
\begin{code}
# define FMBQ_ITBL() \
CAT_DECLARE(FMBQ,INTERNAL_KIND,"FMBQ","<FMBQ>") \
EXTFUN(FMBQ_entry); \
EXTDATA_RO(MK_REP_LBL(FMBQ,,)); \
const W_ FMBQ_info[] = { \
(W_) FMBQ_entry \
,(W_) INFO_OTHER_TAG \
,(W_) MK_REP_REF(FMBQ,,) \
INCLUDE_PROFILING_INFO(FMBQ) \
}
# define FMBQ_RTBL() \
const W_ MK_REP_LBL(FMBQ,,)[] = { \
INCLUDE_TYPE_INFO(FMBQ) \
INCLUDE_SIZE_INFO(MIN_UPD_SIZE,INFO_UNUSED) \
INCLUDE_PAR_INFO \
INCLUDE_COPYING_INFO(_Evacuate_BQ,_Scavenge_BQ) \
SPEC_COMPACTING_INFO(_ScanLink_BQ,_PRStart_BQ,_ScanMove_BQ,_PRIn_BQ) \
}
\end{code}
%************************************************************************
%* *
\subsection[parallel-spark-pool-defs]{Parallel-only Spark pool definitions}
%* *
%************************************************************************
\begin{code}
# define HAVE_SPARK ((PendingSparksHd[REQUIRED_POOL] < PendingSparksTl[REQUIRED_POOL]) \
|| (PendingSparksHd[ADVISORY_POOL] < PendingSparksTl[ADVISORY_POOL]))
# define HAVE_WORK (RUNNING_THREAD || HAVE_SPARK)
# define RUNNING_THREAD (CurrentTSO != NULL)
\end{code}
%************************************************************************
%* *
\subsection[parallel-pack-defs]{Parallel-only Packing definitions}
%* *
%************************************************************************
Symbolic constants for the packing code.
This constant defines how many words of data we can pack into a single
packet in the parallel (GUM) system.
\begin{code}
void InitPackBuffer(STG_NO_ARGS);
P_ PackTSO PROTO((P_ tso, W_ *size));
P_ PackStkO PROTO((P_ stko, W_ *size));
P_ AllocateHeap PROTO((W_ size)); /* Doesn't belong */
void InitClosureQueue (STG_NO_ARGS);
P_ DeQueueClosure(STG_NO_ARGS);
void QueueClosure PROTO((P_ closure));
rtsBool QueueEmpty(STG_NO_ARGS);
void PrintPacket PROTO((P_ buffer));
P_ get_closure_info PROTO((P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type));
rtsBool isOffset PROTO((globalAddr *ga)),
isFixed PROTO((globalAddr *ga));
void doGlobalGC(STG_NO_ARGS);
P_ PackNearbyGraph PROTO((P_ closure,W_ *size));
P_ UnpackGraph PROTO((W_ *buffer, globalAddr **gamap, W_ *nGAs));
\end{code}
\begin{code}
# define PACK_HEAP_REQUIRED \
((RTSflags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (SPEC_HS + 2))
extern W_ *PackBuffer; /* size: can be set via option */
extern long *buffer; /* HWL_ */
extern W_ *freeBuffer; /* HWL_ */
extern W_ *packBuffer; /* HWL_ */
extern void InitPackBuffer(STG_NO_ARGS);
extern void InitMoreBuffers(STG_NO_ARGS);
extern void InitPendingGABuffer(W_ size);
extern void AllocClosureQueue(W_ size);
# define MAX_GAS (RTSflags.ParFlags.packBufferSize / PACK_GA_SIZE)
# define PACK_GA_SIZE 3 /* Size of a packed GA in words */
/* Size of a packed fetch-me in words */
# define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
# define PACK_HDR_SIZE 1 /* Words of header in a packet */
# define PACK_PLC_SIZE 2 /* Size of a packed PLC in words */
#endif
\end{code}
\begin{code}
#if defined(GRAN)
/* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
void InitPackBuffer(STG_NO_ARGS);
P_ AllocateHeap PROTO((W_ size)); /* Doesn't belong */
P_ PackNearbyGraph PROTO((P_ closure, P_ tso, W_ *packbuffersize));
P_ PackOneNode PROTO((P_ closure, P_ tso, W_ *packbuffersize));
P_ UnpackGraph PROTO((P_ buffer));
void InitClosureQueue (STG_NO_ARGS);
P_ DeQueueClosure(STG_NO_ARGS);
void QueueClosure PROTO((P_ closure));
rtsBool QueueEmpty(STG_NO_ARGS);
void PrintPacket PROTO((P_ buffer));
P_ get_closure_info PROTO((P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type));
/* These are needed in the packing code to get the size of the packet
right. The closures itself are never built in GrAnSim. */
# define FETCHME_VHS IND_VHS
# define FETCHME_HS IND_HS
# define FETCHME_GA_LOCN FETCHME_HS
# define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
# define FETCHME_CLOSURE_NoPTRS(closure) 0L
# define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
# define MAX_GAS (RTSflags.GranFlags.packBufferSize / PACK_GA_SIZE)
# define PACK_GA_SIZE 3 /* Size of a packed GA in words */
/* Size of a packed fetch-me in words */
# define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
# define PACK_HDR_SIZE 4 /* Words of header in a packet */
# define PACK_HEAP_REQUIRED \
((RTSflags.GranFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE \
+ _FHS) * (SPEC_HS + 2))
# define PACK_FLAG_LOCN 0
# define PACK_TSO_LOCN 1
# define PACK_UNPACKED_SIZE_LOCN 2
# define PACK_SIZE_LOCN 3
# define MAGIC_PACK_FLAG 0xfabc
#endif
#endif /* Parallel_H */
\end{code}
|