Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison MasterLoop.c @ 121:73acc2140742
merged Stefans test head
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 07 Sep 2011 12:02:56 +0200 |
| parents | efb55f1b5fb9 |
| children | d4c881c7f03a 7cff4e13d5c4 |
comparison
equal
deleted
inserted
replaced
| 25:d63d59a2c6bb | 32:5197c66f356b |
|---|---|
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include "VMS.h" | 12 #include "VMS.h" |
| 13 #include "ProcrContext.h" | 13 #include "ProcrContext.h" |
| 14 | 14 #include "Master_Request_Handlers.h" |
| 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 *masterPr ); |
| 104 // version of that MasterVP can get animated on a different core. | 104 // version of that MasterVP can get animated on a different core. |
| 105 //Also got rid of the busy-wait. | 105 //Also got rid of the busy-wait. |
| 106 | 106 |
| 107 | 107 |
| 108 //masterLoopStartPt: | 108 //masterLoopStartPt: |
| 109 //The animating materVP suspends at end of this loop, then later resumes and | |
| 110 // comes back here | |
| 109 while(1){ | 111 while(1){ |
| 110 | 112 |
| 111 //============================= MEASUREMENT STUFF ======================== | 113 //============================= MEASUREMENT STUFF ======================== |
| 112 #ifdef MEAS__TIME_MASTER | 114 #ifdef MEAS__TIME_MASTER |
| 113 //Total Master time includes one coreloop time -- just assume the core | 115 //Total Master time includes one coreloop time -- just assume the core |
| 118 //======================================================================== | 120 //======================================================================== |
| 119 | 121 |
| 120 masterEnv = (MasterEnv*)_VMSMasterEnv; | 122 masterEnv = (MasterEnv*)_VMSMasterEnv; |
| 121 | 123 |
| 122 //GCC may optimize so doesn't always re-define from frame-storage | 124 //GCC may optimize so doesn't always re-define from frame-storage |
| 123 masterPr = (VirtProcr*)volatileMasterPr; //just to make sure after jmp | 125 masterPr = (VirtProcr*)volatileMasterPr; //on stack, to be sure after jmp |
| 124 thisCoresIdx = masterPr->coreAnimatedBy; | 126 thisCoresIdx = masterPr->coreAnimatedBy; |
| 125 readyToAnimateQ = masterEnv->readyToAnimateQs[thisCoresIdx]; | 127 readyToAnimateQ = masterEnv->readyToAnimateQs[thisCoresIdx]; |
| 126 schedSlots = masterEnv->allSchedSlots[thisCoresIdx]; | 128 schedSlots = masterEnv->allSchedSlots[thisCoresIdx]; |
| 127 | 129 |
| 128 requestHandler = masterEnv->requestHandler; | 130 requestHandler = masterEnv->requestHandler; |
| 129 slaveScheduler = masterEnv->slaveScheduler; | 131 slaveScheduler = masterEnv->slaveScheduler; |
| 130 semanticEnv = masterEnv->semanticEnv; | 132 semanticEnv = masterEnv->semanticEnv; |
| 131 | 133 |
| 132 | 134 //First, check for requests from other MasterVPs, and handle them |
| 133 //Poll each slot's Done flag | 135 if( masterEnv->requestsWaitingFor[thisCoresIdx] ) |
| 136 { masterReqQ = masterEnv->masterReqQs[thisCoresIdx]; | |
| 137 while( currReq = readVMSQ(masterReqQ) ) | |
| 138 { handleMasterReq( currReq, semanticEnv, masterPr ); | |
| 139 } | |
| 140 } | |
| 141 //Now, take care of the SlaveVPs | |
| 142 //Go through the slots -- if Slave there newly suspended, handle its request | |
| 143 // then, either way, ask assigner to fill each slot | |
| 134 numSlotsFilled = 0; | 144 numSlotsFilled = 0; |
| 135 for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++) | 145 for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++) |
| 136 { | 146 { |
| 137 currSlot = schedSlots[ slotIdx ]; | 147 currSlot = schedSlots[ slotIdx ]; |
| 138 | 148 |
| 188 saveLowTimeStampCountInto( masterPr->endMasterTSCLow ); | 198 saveLowTimeStampCountInto( masterPr->endMasterTSCLow ); |
| 189 #endif | 199 #endif |
| 190 | 200 |
| 191 masterSwitchToCoreLoop(animatingPr); | 201 masterSwitchToCoreLoop(animatingPr); |
| 192 flushRegisters(); | 202 flushRegisters(); |
| 193 }//MasterLoop | 203 }//while(1) MasterLoop |
| 194 | |
| 195 | |
| 196 } | 204 } |
| 197 | 205 |
| 198 | 206 /*This is for inter-master communication. Either the master itself or |
| 199 | 207 * the plugin sends one of these requests. Some are handled here, by the |
| 200 /*This has a race condition -- the coreloops are accessing their own queues | 208 * master_loop, others are handed off to the plugin. |
| 201 * at the same time that this work-stealer on a different core is trying to | 209 */ |
| 210 void inline | |
| 211 handleMasterReq( MasterReq *currReq, void *_semEnv, VirtProcr *masterPr ) | |
| 212 { | |
| 213 switch( currReq->reqType ) | |
| 214 { case interVMSReq: | |
| 215 handleInterVMSReq( (InterVMSCoreReq *)currReq, masterPr); | |
| 216 break; | |
| 217 case interPluginReq: | |
| 218 (*interPluginReqHdlr)( (InterPluginReq *)currReq, _semEnv ); | |
| 219 break; | |
| 220 default: | |
| 221 break; | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 void inline | |
| 226 handleInterVMSReq( InterVMSCoreReq *currReq, VirtProcr *masterPr ) | |
| 227 { | |
| 228 switch( currReq->reqType ) | |
| 229 { | |
| 230 case transfer_free: handleTransferFree( currReq, masterPr ); | |
| 231 break; | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 | |
| 236 /*Work Stealing Alg -- racy one | |
| 237 *This algorithm has a race condition -- the coreloops are accessing their | |
| 238 * own queues at the same time that this work-stealer on a different core | |
| 239 * is trying to. | |
| 240 *The second stealing alg, below, protects against this. | |
| 202 */ | 241 */ |
| 203 void inline | 242 void inline |
| 204 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ, | 243 stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ, |
| 205 VirtProcr *masterPr ) | 244 VirtProcr *masterPr ) |
| 206 { | 245 { |
| 232 | 271 |
| 233 writeVMSQ( stolenPr, readyToAnimateQ ); | 272 writeVMSQ( stolenPr, readyToAnimateQ ); |
| 234 } | 273 } |
| 235 } | 274 } |
| 236 | 275 |
| 237 /*This algorithm makes the common case fast. Make the coreloop passive, | 276 /*Work Stealing alg -- protected one |
| 277 *This algorithm makes the common case fast. Make the coreloop passive, | |
| 238 * and show its progress. Make the stealer control a gate that coreloop | 278 * and show its progress. Make the stealer control a gate that coreloop |
| 239 * has to pass. | 279 * has to pass. |
| 240 *To avoid interference, only one stealer at a time. Use a global | 280 *To avoid interference, only one stealer at a time. Use a global |
| 241 * stealer-lock. | 281 * stealer-lock. |
| 242 * | 282 * |
| 358 | 398 |
| 359 vicGate->gateClosed = FALSE; | 399 vicGate->gateClosed = FALSE; |
| 360 //======= End Gate-protection ======= | 400 //======= End Gate-protection ======= |
| 361 | 401 |
| 362 | 402 |
| 363 if( stolenPr != NULL ) //victim could have been in protected and taken | 403 if( stolenPr != NULL ) //victim could have been in protected and took it |
| 364 { currSlot->procrAssignedToSlot = stolenPr; | 404 { currSlot->procrAssignedToSlot = stolenPr; |
| 365 stolenPr->schedSlot = currSlot; | 405 stolenPr->schedSlot = currSlot; |
| 366 currSlot->needsProcrAssigned = FALSE; | 406 currSlot->needsProcrAssigned = FALSE; |
| 367 | 407 |
| 368 writeVMSQ( stolenPr, myReadyToAnimateQ ); | 408 writeVMSQ( stolenPr, myReadyToAnimateQ ); |
