[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / rts / gum / FetchMe.c
1 /* -----------------------------------------------------------------------------
2  * $Id: FetchMe.c,v 1.2 1998/12/02 13:29:03 simonm Exp $
3  *
4  * Entry code for a FETCH_ME closure
5  *
6  * ---------------------------------------------------------------------------*/
7  
8 #ifdef PAR /* all of it */
9
10 #include "Rts.h"
11 #include "FetchMe.h"
12 #include "HLC.h"
13
14 /* -----------------------------------------------------------------------------
15    FETCH_ME closures.
16
17    A FETCH_ME closure represents data that currently resides on
18    another PE.  We issue a fetch message, and wait for the data to be
19    retrieved.
20    -------------------------------------------------------------------------- */
21
22 INFO_TABLE(FETCH_ME_info, FETCH_ME_entry, 0,2, FETCH_ME, const, EF_,0,0);
23
24 STGFUN(FETCH_ME_entry)
25 {
26     globalAddr *rGA;
27     globalAddr *lGA;
28     globalAddr fmbqGA;
29
30 # if defined(GRAN)
31     STGCALL0(void,(),GranSimBlock);     /* Do this before losing its TSO_LINK */
32 # endif
33
34     rGA = FETCHME_GA(R1);
35     ASSERT(rGA->loc.gc.gtid != mytid);
36
37     /* Turn the FETCH_ME into a FETCH_ME_BQ, and place the current thread
38      * on the blocking queue.
39      */
40     R1.cl->header.info = FETCH_ME_BQ_info;
41     CurrentTSO->link = END_TSO_QUEUE;
42     ((StgBlackHole *)R1.cl)->blocking_queue = CurrentTSO;
43
44 #ifdef 0 /* unknown junk... needed? --SDM */
45     if (DO_QP_PROF) {
46         QP_Event1("GR", CurrentTSO);
47     }
48
49     if (RTSflags.ParFlags.granSimStats) {
50         /* Note that CURRENT_TIME may perform an unsafe call */
51         TIME now = CURRENT_TIME;
52         TSO_EXECTIME(CurrentTSO) += now - TSO_BLOCKEDAT(CurrentTSO);
53         TSO_FETCHCOUNT(CurrentTSO)++;
54         TSO_QUEUE(CurrentTSO) = Q_FETCHING;
55         TSO_BLOCKEDAT(CurrentTSO) = now;
56         /* DumpGranEventAndNode(GR_FETCH, CurrentTSO, (SAVE_R1).p, 
57            taskIDtoPE(rGA->loc.gc.gtid)); */
58         DumpRawGranEvent(CURRENT_PROC,taskIDtoPE(rGA->loc.gc.gtid),GR_FETCH,
59                          CurrentTSO,(SAVE_R1).p,0);
60     }
61
62     /* Phil T. claims that this was a workaround for a hard-to-find
63      * bug, hence I'm leaving it out for now --SDM 
64      */
65     /* Assign a brand-new global address to the newly created FMBQ */
66     lGA = MakeGlobal((SAVE_R1).p, rtsFalse);
67     splitWeight(&fmbqGA, lGA);
68     ASSERT(fmbqGA.weight == 1L << (BITS_IN(unsigned) - 1));
69 #endif
70
71     /* I *hope* it's ok to call this from STG land. --SDM */
72     STGCALL3(sendFetch, rGA, &fmbqGA, 0/*load*/);
73
74     BLOCK_NP(1); /* back to the scheduler */
75
76     FE_
77 }
78
79 /* -----------------------------------------------------------------------------
80    FETCH_ME_BQ
81    
82    On the first entry of a FETCH_ME closure, we turn the closure into
83    a FETCH_ME_BQ, which behaves just like a black hole.  Any thread
84    entering the FETCH_ME_BQ will be placed in the blocking queue.
85    When the data arrives from the remote PE, all waiting threads are
86    woken up and the FETCH_ME_BQ is overwritten with the fetched data.
87    -------------------------------------------------------------------------- */
88
89 INFO_TABLE(FETCH_ME_BQ_info, BLACKHOLE_entry,0,2,BLACKHOLE,const,EF_,0,0);
90
91 #endif /* PAR */