# HG changeset patch # User Me@portablequad # Date 1314766504 25200 # Node ID ac11b50220bd1e82394377612a316a247ecc4d9b # Parent 4700896a5666347a2186c0ba6f2fb4c4c8637e54 Added inter-master requests diff -r 4700896a5666 -r ac11b50220bd MasterLoop.c --- a/MasterLoop.c Tue Jul 26 16:28:47 2011 +0200 +++ b/MasterLoop.c Tue Aug 30 21:55:04 2011 -0700 @@ -11,7 +11,7 @@ #include "VMS.h" #include "ProcrContext.h" - +#include "Master_Request_Handlers.h" //=========================================================================== void inline @@ -106,6 +106,8 @@ //masterLoopStartPt: + //The animating materVP suspends at end of this loop, then later resumes and + // comes back here while(1){ //============================= MEASUREMENT STUFF ======================== @@ -120,7 +122,7 @@ masterEnv = (MasterEnv*)_VMSMasterEnv; //GCC may optimize so doesn't always re-define from frame-storage - masterPr = (VirtProcr*)volatileMasterPr; //just to make sure after jmp + masterPr = (VirtProcr*)volatileMasterPr; //on stack, to be sure after jmp thisCoresIdx = masterPr->coreAnimatedBy; readyToAnimateQ = masterEnv->readyToAnimateQs[thisCoresIdx]; schedSlots = masterEnv->allSchedSlots[thisCoresIdx]; @@ -129,8 +131,16 @@ slaveScheduler = masterEnv->slaveScheduler; semanticEnv = masterEnv->semanticEnv; - - //Poll each slot's Done flag + //First, check for requests from other MasterVPs, and handle them + if( masterEnv->requestsWaitingFor[thisCoresIdx] ) + { masterReqQ = masterEnv->masterReqQs[thisCoresIdx]; + while( currReq = readVMSQ(masterReqQ) ) + { handleMasterReq( currReq, semanticEnv, masterPr ); + } + } + //Now, take care of the SlaveVPs + //Go through the slots -- if Slave there newly suspended, handle its request + // then, either way, ask assigner to fill each slot numSlotsFilled = 0; for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++) { @@ -190,15 +200,44 @@ masterSwitchToCoreLoop(animatingPr); flushRegisters(); - }//MasterLoop - - + }//while(1) MasterLoop } +/*This is for inter-master communication. Either the master itself or + * the plugin sends one of these requests. Some are handled here, by the + * master_loop, others are handed off to the plugin. + */ +void inline +handleMasterReq( MasterReq *currReq, void *_semEnv, VirtProcr *masterPr ) + { + switch( currReq->reqType ) + { case interVMSReq: + handleInterVMSReq( (InterVMSCoreReq *)currReq, masterPr); + break; + case interPluginReq: + (*interPluginReqHdlr)( (InterPluginReq *)currReq, _semEnv ); + break; + default: + break; + } + } +void inline +handleInterVMSReq( InterVMSCoreReq *currReq, VirtProcr *masterPr ) + { + switch( currReq->reqType ) + { + case transfer_free: handleTransferFree( currReq, masterPr ); + break; + } + } + -/*This has a race condition -- the coreloops are accessing their own queues - * at the same time that this work-stealer on a different core is trying to +/*Work Stealing Alg -- racy one + *This algorithm has a race condition -- the coreloops are accessing their + * own queues at the same time that this work-stealer on a different core + * is trying to. + *The second stealing alg, below, protects against this. */ void inline stealWorkInto( SchedSlot *currSlot, VMSQueueStruc *readyToAnimateQ, @@ -234,7 +273,8 @@ } } -/*This algorithm makes the common case fast. Make the coreloop passive, +/*Work Stealing alg -- protected one + *This algorithm makes the common case fast. Make the coreloop passive, * and show its progress. Make the stealer control a gate that coreloop * has to pass. *To avoid interference, only one stealer at a time. Use a global @@ -360,7 +400,7 @@ //======= End Gate-protection ======= - if( stolenPr != NULL ) //victim could have been in protected and taken + if( stolenPr != NULL ) //victim could have been in protected and took it { currSlot->procrAssignedToSlot = stolenPr; stolenPr->schedSlot = currSlot; currSlot->needsProcrAssigned = FALSE; diff -r 4700896a5666 -r ac11b50220bd inter_VMS_request_handlers.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inter_VMS_request_handlers.c Tue Aug 30 21:55:04 2011 -0700 @@ -0,0 +1,27 @@ +/* + * Copyright 2011 OpenSourceCodeStewardshipFoundation + * + * Licensed under GNU GPL version 2 + */ + +#include +#include + +#include "VMS/VMS.h" +#include "VMS/Queue_impl/PrivateQueue.h" +#include "VMS/Hash_impl/PrivateHash.h" +#include "VMS/vmalloc.h" + + + +//=============================== ================================= +/*The VMS__free in a different masterVP discovered the chunk it was + * given was originally allocated by this masterVP, so it sent the + * chunk over. Simply call VMS__free here. + */ +inline void +handleTransferFree( MasterReq *masterReq, VirtProcr *masterPr ) + { + VMS__free( masterReq->ptrToFree ); + } + diff -r 4700896a5666 -r ac11b50220bd inter_VMS_request_handlers.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inter_VMS_request_handlers.h Tue Aug 30 21:55:04 2011 -0700 @@ -0,0 +1,23 @@ +/* + * Copyright 2011 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author(s): seanhalle@yahoo.com + * + */ + +#ifndef _MASTER_REQ_H +#define _MASTER_REQ_H + +/*Defines everything specific to inter-master requests that + * are internal to VMS. + *The plugin has its own handlers for inter-master requests + * sent between plugin instances. + */ + +inline void +handleMakeMutex( VPThdSemReq *semReq, VPThdSemEnv *semEnv); + + +#endif /* _MASTER_REQ_H */ +