comparison MasterLoop.c @ 169:d1dd9e6ee72c

VMS preprocessor definitions moved to VMS_defs.h and changes to measurement
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 16 Dec 2011 20:00:21 +0100
parents fe5ec83f1baf
children c3f458403cd6
comparison
equal deleted inserted replaced
24:e52cd378a27f 45:98465da51254
14 14
15 15
16 //=========================================================================== 16 //===========================================================================
17 void inline 17 void inline
18 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ, 18 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ,
19 VirtProcr *masterPr ); 19 VirtProcr *masterVP );
20 20
21 //=========================================================================== 21 //===========================================================================
22 22
23 23
24 24
82 SlaveScheduler slaveScheduler; 82 SlaveScheduler slaveScheduler;
83 RequestHandler requestHandler; 83 RequestHandler requestHandler;
84 void *semanticEnv; 84 void *semanticEnv;
85 85
86 int32 thisCoresIdx; 86 int32 thisCoresIdx;
87 VirtProcr *masterPr; 87 VirtProcr *masterVP;
88 volatile VirtProcr *volatileMasterPr; 88 volatile VirtProcr *volatilemasterVP;
89 89
90 volatileMasterPr = animatingPr; 90 volatilemasterVP = animatingPr;
91 masterPr = (VirtProcr*)volatileMasterPr; //used to force re-define after jmp 91 masterVP = (VirtProcr*)volatilemasterVP; //used to force re-define after jmp
92 92
93 //First animation of each MasterVP will in turn animate this part 93 //====================== Measurement =====================
94 // of setup code.. (VP creator sets up the stack as if this function 94 TSCountLowHigh endMaster;
95 // was called normally, but actually get here by jmp) 95 uint64 numCycles;
96 //So, setup values about stack ptr, jmp pt and all that 96 //==========================================================
97 //masterPr->nextInstrPt = &&masterLoopStartPt;
98
99
100 //Note, got rid of writing the stack and frame ptr up here, because
101 // only one
102 // core can ever animate a given MasterVP, so don't need to communicate
103 // new frame and stack ptr to the MasterVP storage before a second
104 // version of that MasterVP can get animated on a different core.
105 //Also got rid of the busy-wait.
106
107 97
108 //masterLoopStartPt: 98 //masterLoopStartPt:
109 while(1){ 99 while(1){ //switch to core_loop and back to here is at end of loop
110 100
111 //============================= MEASUREMENT STUFF ======================== 101 //============================= MEASUREMENT STUFF =======================
112 #ifdef MEAS__TIME_MASTER 102 #ifdef MEAS__TIME_MASTER
113 //Total Master time includes one coreloop time -- just assume the core 103 //Total Master time includes one coreloop time -- just assume the core
114 // loop time is same for Master as for AppVPs, even though it may be 104 // loop time is same for Master as for AppVPs, even though it may be
115 // smaller due to higher predictability of the fixed jmp. 105 // smaller due to higher predictability of the fixed jmp.
116 saveLowTimeStampCountInto( masterPr->startMasterTSCLow ); 106 saveLowTimeStampCountInto( masterVP->startMasterTSCLow );
117 #endif 107 #endif
118 //======================================================================== 108 //=======================================================================
119 109
120 masterEnv = (MasterEnv*)_VMSMasterEnv; 110 masterEnv = (MasterEnv*)_VMSMasterEnv;
121 111
122 //GCC may optimize so doesn't always re-define from frame-storage 112 //GCC may optimize so doesn't always re-define from frame-storage
123 masterPr = (VirtProcr*)volatileMasterPr; //just to make sure after jmp 113 masterVP = (VirtProcr*)volatilemasterVP; //just to make sure after jmp
124 thisCoresIdx = masterPr->coreAnimatedBy; 114 thisCoresIdx = masterVP->coreAnimatedBy;
125 readyToAnimateQ = masterEnv->readyToAnimateQs[thisCoresIdx]; 115 readyToAnimateQ = masterEnv->readyToAnimateQs[thisCoresIdx];
126 schedSlots = masterEnv->allSchedSlots[thisCoresIdx]; 116 schedSlots = masterEnv->allSchedSlots[thisCoresIdx];
127 117
128 requestHandler = masterEnv->requestHandler; 118 requestHandler = masterEnv->requestHandler;
129 slaveScheduler = masterEnv->slaveScheduler; 119 slaveScheduler = masterEnv->slaveScheduler;
130 semanticEnv = masterEnv->semanticEnv; 120 semanticEnv = masterEnv->semanticEnv;
131 121
132 122
133 //Poll each slot's Done flag 123 //Poll each slot's Done flag
134 numSlotsFilled = 0; 124 numSlotsFilled = 0;
125 Meas_startMasterLoop
135 for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++) 126 for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++)
136 { 127 {
137 currSlot = schedSlots[ slotIdx ]; 128 currSlot = schedSlots[ slotIdx ];
138 129
139 if( currSlot->workIsDone ) 130 if( currSlot->workIsDone )
140 { 131 {
141 currSlot->workIsDone = FALSE; 132 currSlot->workIsDone = FALSE;
142 currSlot->needsProcrAssigned = TRUE; 133 currSlot->needsProcrAssigned = TRUE;
143 134
144 //process requests from slave to master 135 //process requests from slave to master
145 //====================== MEASUREMENT STUFF =================== 136 Meas_startReqHdlr
146 #ifdef MEAS__TIME_PLUGIN
147 int32 startStamp1, endStamp1;
148 saveLowTimeStampCountInto( startStamp1 );
149 #endif
150 //============================================================
151 (*requestHandler)( currSlot->procrAssignedToSlot, semanticEnv ); 137 (*requestHandler)( currSlot->procrAssignedToSlot, semanticEnv );
152 //====================== MEASUREMENT STUFF =================== 138 Meas_endReqHdlr
153 #ifdef MEAS__TIME_PLUGIN
154 saveLowTimeStampCountInto( endStamp1 );
155 addIntervalToHist( startStamp1, endStamp1,
156 _VMSMasterEnv->reqHdlrLowTimeHist );
157 addIntervalToHist( startStamp1, endStamp1,
158 _VMSMasterEnv->reqHdlrHighTimeHist );
159 #endif
160 //============================================================
161 } 139 }
162 if( currSlot->needsProcrAssigned ) 140 if( currSlot->needsProcrAssigned )
163 { //give slot a new virt procr 141 { //give slot a new virt procr
164 schedVirtPr = 142 schedVirtPr =
165 (*slaveScheduler)( semanticEnv, thisCoresIdx ); 143 (*slaveScheduler)( semanticEnv, thisCoresIdx );
172 150
173 writeVMSQ( schedVirtPr, readyToAnimateQ ); 151 writeVMSQ( schedVirtPr, readyToAnimateQ );
174 } 152 }
175 } 153 }
176 } 154 }
177 155 Meas_endMasterLoop
178 156
179 #ifdef USE_WORK_STEALING 157 #ifdef USE_WORK_STEALING
180 //If no slots filled, means no more work, look for work to steal. 158 //If no slots filled, means no more work, look for work to steal.
181 if( numSlotsFilled == 0 ) 159 if( numSlotsFilled == 0 )
182 { gateProtected_stealWorkInto( currSlot, readyToAnimateQ, masterPr ); 160 { gateProtected_stealWorkInto( currSlot, readyToAnimateQ, masterVP );
183 } 161 }
184 #endif 162 #endif
185 163
186 164
187 #ifdef MEAS__TIME_MASTER 165
188 saveLowTimeStampCountInto( masterPr->endMasterTSCLow ); 166 //=================== Meas =======================
189 #endif 167 #ifdef MEAS__TIME_MASTER
190 168 saveLowTimeStampCountInto( masterVP->endMasterTSCLow );
191 masterSwitchToCoreLoop(animatingPr); 169 #endif
170 #ifdef MEAS__TIME_2011_SYS
171 //Take meas here, to get cycles since entered Master
172 saveTSCLowHigh(endMaster);
173 numCycles = endMaster.longVal - _VMSMasterEnv->startMaster.longVal;
174
175 if( numCycles < 200000 ) //sanity check against swap thd out)
176 { masterEnv->totalMasterCycles += numCycles;
177 masterEnv->numMasterAnimations++;
178 }
179 #endif
180 //==================================================
181 masterSwitchToCoreLoop(animatingPr); //"finishes" when switch back to Master
192 flushRegisters(); 182 flushRegisters();
193 }//MasterLoop 183 }//MasterLoop
194 184
195
196 } 185 }
197 186
198 187
199 188
200 /*This has a race condition -- the coreloops are accessing their own queues 189 /*This has a race condition -- the coreloops are accessing their own queues
201 * at the same time that this work-stealer on a different core is trying to 190 * at the same time that this work-stealer on a different core is trying to
202 */ 191 */
203 void inline 192 void inline
204 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ, 193 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ,
205 VirtProcr *masterPr ) 194 VirtProcr *masterVP )
206 { 195 {
207 VirtProcr *stolenPr; 196 VirtProcr *stolenPr;
208 int32 coreIdx, i; 197 int32 coreIdx, i;
209 VMSQueueStruc *currQ; 198 VMSQueueStruc *currQ;
210 199
211 stolenPr = NULL; 200 stolenPr = NULL;
212 coreIdx = masterPr->coreAnimatedBy; 201 coreIdx = masterVP->coreAnimatedBy;
213 for( i = 0; i < NUM_CORES -1; i++ ) 202 for( i = 0; i < NUM_CORES -1; i++ )
214 { 203 {
215 if( coreIdx >= NUM_CORES -1 ) 204 if( coreIdx >= NUM_CORES -1 )
216 { coreIdx = 0; 205 { coreIdx = 0;
217 } 206 }
304 * 293 *
305 */ 294 */
306 void inline 295 void inline
307 gateProtected_stealWorkInto( SchedSlot *currSlot, 296 gateProtected_stealWorkInto( SchedSlot *currSlot,
308 VMSQueueStruc *myReadyToAnimateQ, 297 VMSQueueStruc *myReadyToAnimateQ,
309 VirtProcr *masterPr ) 298 VirtProcr *masterVP )
310 { 299 {
311 VirtProcr *stolenPr; 300 VirtProcr *stolenPr;
312 int32 coreIdx, i, haveAVictim, gotLock; 301 int32 coreIdx, i, haveAVictim, gotLock;
313 VMSQueueStruc *victimsQ; 302 VMSQueueStruc *victimsQ;
314 303
317 306
318 307
319 308
320 //see if any other cores have work available to steal 309 //see if any other cores have work available to steal
321 haveAVictim = FALSE; 310 haveAVictim = FALSE;
322 coreIdx = masterPr->coreAnimatedBy; 311 coreIdx = masterVP->coreAnimatedBy;
323 for( i = 0; i < NUM_CORES -1; i++ ) 312 for( i = 0; i < NUM_CORES -1; i++ )
324 { 313 {
325 if( coreIdx >= NUM_CORES -1 ) 314 if( coreIdx >= NUM_CORES -1 )
326 { coreIdx = 0; 315 { coreIdx = 0;
327 } 316 }