| rev |
line source |
|
seanhalle@230
|
1 /*
|
|
seanhalle@230
|
2 * Copyright 2010 OpenSourceStewardshipFoundation
|
|
seanhalle@230
|
3 *
|
|
seanhalle@230
|
4 * Licensed under BSD
|
|
seanhalle@230
|
5 */
|
|
seanhalle@230
|
6
|
|
seanhalle@230
|
7
|
|
seanhalle@230
|
8
|
|
seanhalle@230
|
9 #include <stdio.h>
|
|
seanhalle@230
|
10 #include <stddef.h>
|
|
seanhalle@230
|
11
|
|
seanhalle@230
|
12 #include "VMS.h"
|
|
seanhalle@230
|
13
|
|
seanhalle@230
|
14
|
|
seanhalle@230
|
15 //========================= Local Fn Prototypes =============================
|
|
seanhalle@230
|
16 void inline
|
|
seanhalle@230
|
17 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ,
|
|
seanhalle@230
|
18 SlaveVP *masterVP );
|
|
seanhalle@230
|
19
|
|
seanhalle@230
|
20 //===========================================================================
|
|
seanhalle@230
|
21
|
|
seanhalle@230
|
22
|
|
seanhalle@230
|
23
|
|
seanhalle@230
|
24 /*The animationMaster embodies most of the animator of the language. The
|
|
seanhalle@230
|
25 * animator is what emodies the behavior of language constructs.
|
|
seanhalle@230
|
26 * As such, it is the animationMaster, in combination with the plugin
|
|
seanhalle@230
|
27 * functions, that make the language constructs do their behavior.
|
|
seanhalle@230
|
28 *
|
|
seanhalle@230
|
29 *Within the code, this is the top-level-function of the masterVPs, and
|
|
seanhalle@230
|
30 * runs when the coreController has no more slave VPs. It's job is to
|
|
seanhalle@230
|
31 * refill the animation slots with slaves.
|
|
seanhalle@230
|
32 *
|
|
seanhalle@230
|
33 *To do this, it scans the animation slots for just-completed slaves.
|
|
seanhalle@230
|
34 * Each of these has a request in it. So, the master hands each to the
|
|
seanhalle@230
|
35 * plugin's request handler.
|
|
seanhalle@230
|
36 *Each request represents a language construct that has been encountered
|
|
seanhalle@230
|
37 * by the application code in the slave. Passing the request to the
|
|
seanhalle@230
|
38 * request handler is how that language construct's behavior gets invoked.
|
|
seanhalle@230
|
39 * The request handler then performs the actions of the construct's
|
|
seanhalle@230
|
40 * behavior. So, the request handler encodes the behavior of the
|
|
seanhalle@230
|
41 * language's parallelism constructs, and performs that when the master
|
|
seanhalle@230
|
42 * hands it a slave containing a request to perform that construct.
|
|
seanhalle@230
|
43 *
|
|
seanhalle@230
|
44 *On a shared-memory machine, the behavior of parallelism constructs
|
|
seanhalle@230
|
45 * equals control, over order of execution of code. Hence, the behavior
|
|
seanhalle@230
|
46 * of the language constructs performed by the request handler is to
|
|
seanhalle@230
|
47 * choose the order that slaves get animated, and thereby control the
|
|
seanhalle@230
|
48 * order that application code in the slaves executes.
|
|
seanhalle@230
|
49 *
|
|
seanhalle@230
|
50 *To control order of animation of slaves, the request handler has a
|
|
seanhalle@230
|
51 * semantic environment that holds data structures used to hold slaves
|
|
seanhalle@230
|
52 * and choose when they're ready to be animated.
|
|
seanhalle@230
|
53 *
|
|
seanhalle@230
|
54 *Once a slave is marked as ready to be animated by the request handler,
|
|
seanhalle@230
|
55 * it is the second plugin function, the Assigner, which chooses the core
|
|
seanhalle@230
|
56 * the slave gets assigned to for animation. Hence, the Assigner doesn't
|
|
seanhalle@230
|
57 * perform any of the semantic behavior of language constructs, rather
|
|
seanhalle@230
|
58 * it gives the language a chance to improve performance. The performance
|
|
seanhalle@230
|
59 * of application code is strongly related to communication between
|
|
seanhalle@230
|
60 * cores. On shared-memory machines, communication is caused during
|
|
seanhalle@230
|
61 * execution of code, by memory accesses, and how much depends on contents
|
|
seanhalle@230
|
62 * of caches connected to the core executing the code. So, the placement
|
|
seanhalle@230
|
63 * of slaves determines the communication caused during execution of the
|
|
seanhalle@230
|
64 * slave's code.
|
|
seanhalle@230
|
65 *The point of the Assigner, then, is to use application information during
|
|
seanhalle@230
|
66 * execution of the program, to make choices about slave placement onto
|
|
seanhalle@230
|
67 * cores, with the aim to put slaves close to caches containing the data
|
|
seanhalle@230
|
68 * used by the slave's code.
|
|
seanhalle@230
|
69 *
|
|
seanhalle@230
|
70 *==========================================================================
|
|
seanhalle@230
|
71 *In summary, the animationMaster scans the slots, finds slaves
|
|
seanhalle@230
|
72 * just-finished, which hold requests, pass those to the request handler,
|
|
seanhalle@230
|
73 * along with the semantic environment, and the request handler then manages
|
|
seanhalle@230
|
74 * the structures in the semantic env, which controls the order of
|
|
seanhalle@230
|
75 * animation of slaves, and so embodies the behavior of the language
|
|
seanhalle@230
|
76 * constructs.
|
|
seanhalle@230
|
77 *The animationMaster then rescans the slots, offering each empty one to
|
|
seanhalle@230
|
78 * the Assigner, along with the semantic environment. The Assigner chooses
|
|
seanhalle@230
|
79 * among the ready slaves in the semantic Env, finding the one best suited
|
|
seanhalle@230
|
80 * to be animated by that slot's associated core.
|
|
seanhalle@230
|
81 *
|
|
seanhalle@230
|
82 *==========================================================================
|
|
seanhalle@230
|
83 *Implementation Details:
|
|
seanhalle@230
|
84 *
|
|
seanhalle@230
|
85 *There is a separate masterVP for each core, but a single semantic
|
|
seanhalle@230
|
86 * environment shared by all cores. Each core also has its own scheduling
|
|
seanhalle@230
|
87 * slots, which are used to communicate slaves between animationMaster and
|
|
seanhalle@230
|
88 * coreController. There is only one global variable, _VMSMasterEnv, which
|
|
seanhalle@230
|
89 * holds the semantic env and other things shared by the different
|
|
seanhalle@230
|
90 * masterVPs. The request handler and Assigner are registered with
|
|
seanhalle@230
|
91 * the animationMaster by the language's init function, and a pointer to
|
|
seanhalle@230
|
92 * each is in the _VMSMasterEnv. (There are also some pthread related global
|
|
seanhalle@230
|
93 * vars, but they're only used during init of VMS).
|
|
seanhalle@230
|
94 *VMS gains control over the cores by essentially "turning off" the OS's
|
|
seanhalle@230
|
95 * scheduler, using pthread pin-to-core commands.
|
|
seanhalle@230
|
96 *
|
|
seanhalle@230
|
97 *The masterVPs are created during init, with this animationMaster as their
|
|
seanhalle@230
|
98 * top level function. The masterVPs use the same SlaveVP data structure,
|
|
seanhalle@230
|
99 * even though they're not slave VPs.
|
|
seanhalle@230
|
100 *A "seed slave" is also created during init -- this is equivalent to the
|
|
seanhalle@230
|
101 * "main" function in C, and acts as the entry-point to the VMS-language-
|
|
seanhalle@230
|
102 * based application.
|
|
seanhalle@230
|
103 *The masterVPs shared a single system-wide master-lock, so only one
|
|
seanhalle@230
|
104 * masterVP may be animated at a time.
|
|
seanhalle@230
|
105 *The core controllers access _VMSMasterEnv to get the masterVP, and when
|
|
seanhalle@230
|
106 * they start, the slots are all empty, so they run their associated core's
|
|
seanhalle@230
|
107 * masterVP. The first of those to get the master lock sees the seed slave
|
|
seanhalle@230
|
108 * in the shared semantic environment, so when it runs the Assigner, that
|
|
seanhalle@230
|
109 * returns the seed slave, which the animationMaster puts into a scheduling
|
|
seanhalle@230
|
110 * slot then switches to the core controller. That then switches the core
|
|
seanhalle@230
|
111 * over to the seed slave, which then proceeds to execute language
|
|
seanhalle@230
|
112 * constructs to create more slaves, and so on. Each of those constructs
|
|
seanhalle@230
|
113 * causes the seed slave to suspend, switching over to the core controller,
|
|
seanhalle@230
|
114 * which eventually switches to the masterVP, which executes the
|
|
seanhalle@230
|
115 * request handler, which uses VMS primitives to carry out the creation of
|
|
seanhalle@230
|
116 * new slave VPs, which are marked as ready for the Assigner, and so on..
|
|
seanhalle@230
|
117 *
|
|
seanhalle@230
|
118 *On animation slots, and system behavior:
|
|
seanhalle@230
|
119 * A request may linger in a animation slot for a long time while
|
|
seanhalle@230
|
120 * the slaves in the other slots are animated. This only becomes a problem
|
|
seanhalle@230
|
121 * when such a request is a choke-point in the constraints, and is needed
|
|
seanhalle@230
|
122 * to free work for *other* cores. To reduce this occurance, the number
|
|
seanhalle@230
|
123 * of animation slots should be kept low. In balance, having multiple
|
|
seanhalle@230
|
124 * animation slots amortizes the overhead of switching to the masterVP and
|
|
seanhalle@230
|
125 * executing the animationMaster code, which drives for more than one. In
|
|
seanhalle@230
|
126 * practice, the best balance should be discovered by profiling.
|
|
seanhalle@230
|
127 */
|
|
seanhalle@230
|
128 void animationMaster( void *initData, SlaveVP *masterVP )
|
|
seanhalle@230
|
129 {
|
|
seanhalle@230
|
130 //Used while scanning and filling animation slots
|
|
seanhalle@230
|
131 int32 slotIdx, numSlotsFilled;
|
|
seanhalle@230
|
132 SchedSlot *currSlot, **schedSlots;
|
|
seanhalle@230
|
133 SlaveVP *assignedSlaveVP; //the slave chosen by the assigner
|
|
seanhalle@230
|
134
|
|
seanhalle@230
|
135 //Local copies, for performance
|
|
seanhalle@230
|
136 MasterEnv *masterEnv;
|
|
seanhalle@230
|
137 SlaveAssigner slaveAssigner;
|
|
seanhalle@230
|
138 RequestHandler requestHandler;
|
|
seanhalle@230
|
139 void *semanticEnv;
|
|
seanhalle@230
|
140 int32 thisCoresIdx;
|
|
seanhalle@230
|
141
|
|
seanhalle@230
|
142 //======================== Initializations ========================
|
|
seanhalle@230
|
143 masterEnv = (MasterEnv*)_VMSMasterEnv;
|
|
seanhalle@230
|
144
|
|
seanhalle@230
|
145 thisCoresIdx = masterVP->coreAnimatedBy;
|
|
seanhalle@230
|
146 schedSlots = masterEnv->allSchedSlots[thisCoresIdx];
|
|
seanhalle@230
|
147
|
|
seanhalle@230
|
148 requestHandler = masterEnv->requestHandler;
|
|
seanhalle@230
|
149 slaveAssigner = masterEnv->slaveAssigner;
|
|
seanhalle@230
|
150 semanticEnv = masterEnv->semanticEnv;
|
|
seanhalle@230
|
151
|
|
seanhalle@230
|
152
|
|
seanhalle@230
|
153 //======================== animationMaster ========================
|
|
seanhalle@230
|
154 while(1){
|
|
seanhalle@230
|
155
|
|
seanhalle@230
|
156 MEAS__Capture_Pre_Master_Point
|
|
seanhalle@230
|
157
|
|
seanhalle@230
|
158 //Scan the animation slots
|
|
seanhalle@230
|
159 numSlotsFilled = 0;
|
|
seanhalle@230
|
160 for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
|
|
seanhalle@230
|
161 {
|
|
seanhalle@230
|
162 currSlot = schedSlots[ slotIdx ];
|
|
seanhalle@230
|
163
|
|
seanhalle@230
|
164 //Check if newly-done slave in slot, which will need request handld
|
|
seanhalle@230
|
165 if( currSlot->workIsDone )
|
|
seanhalle@230
|
166 {
|
|
seanhalle@230
|
167 currSlot->workIsDone = FALSE;
|
|
seanhalle@230
|
168 currSlot->needsSlaveAssigned = TRUE;
|
|
seanhalle@230
|
169
|
|
seanhalle@230
|
170 MEAS__startReqHdlr;
|
|
seanhalle@230
|
171
|
|
seanhalle@230
|
172 //process the requests made by the slave (held inside slave struc)
|
|
seanhalle@230
|
173 (*requestHandler)( currSlot->slaveAssignedToSlot, semanticEnv );
|
|
seanhalle@230
|
174
|
|
seanhalle@230
|
175 MEAS__endReqHdlr;
|
|
seanhalle@230
|
176 }
|
|
seanhalle@230
|
177 //If slot empty, hand to Assigner to fill with a slave
|
|
seanhalle@230
|
178 if( currSlot->needsSlaveAssigned )
|
|
seanhalle@230
|
179 { //Call plugin's Assigner to give slot a new slave
|
|
seanhalle@230
|
180 assignedSlaveVP =
|
|
seanhalle@230
|
181 (*slaveAssigner)( semanticEnv, currSlot );
|
|
seanhalle@230
|
182
|
|
seanhalle@230
|
183 //put the chosen slave into slot, and adjust flags and state
|
|
seanhalle@230
|
184 if( assignedSlaveVP != NULL )
|
|
seanhalle@230
|
185 { currSlot->slaveAssignedToSlot = assignedSlaveVP;
|
|
seanhalle@233
|
186 assignedSlaveVP->schedSlotAssignedTo = currSlot;
|
|
seanhalle@230
|
187 currSlot->needsSlaveAssigned = FALSE;
|
|
seanhalle@230
|
188 numSlotsFilled += 1;
|
|
seanhalle@230
|
189 }
|
|
seanhalle@230
|
190 }
|
|
seanhalle@230
|
191 }
|
|
seanhalle@230
|
192
|
|
seanhalle@230
|
193 MEAS__Capture_Post_Master_Point;
|
|
seanhalle@230
|
194
|
|
seanhalle@231
|
195 masterSwitchToCoreCtlr( masterVP );
|
|
seanhalle@230
|
196 flushRegisters();
|
|
seanhalle@232
|
197 }//while(1)
|
|
seanhalle@230
|
198 }
|
|
seanhalle@230
|
199
|