# HG changeset patch # User Sean Halle # Date 1362386438 28800 # Node ID 1d7ea1b0f1762c0a2697e878fd4a5c5f0942aa76 # Parent 7ab0d5bf16cb9f57736bf176dab4c2689d7fd14e Dev_ML Working in sequential mode diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 AnimationMaster.c --- a/AnimationMaster.c Sat Mar 02 09:54:19 2013 -0800 +++ b/AnimationMaster.c Mon Mar 04 00:40:38 2013 -0800 @@ -516,6 +516,8 @@ (*protoLangEnv->shutdownHdlr)( langEnv ); PR_int__remove_lang_env_from_process_and_free( langEnv ); //removes from process and frees + + PR_PI__resume_slave_in_PRServ( requestingSlv ); } diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 CoreController.c --- a/CoreController.c Sat Mar 02 09:54:19 2013 -0800 +++ b/CoreController.c Mon Mar 04 00:40:38 2013 -0800 @@ -369,7 +369,9 @@ if( numRepetitionsWithNoWork > NUM_REPS_W_NO_WORK_BEFORE_BACKOFF) doBackoff_for_TooLongWithNoWork( numRepetitionsWithNoWork, &seed1, &seed2 ); if( numRepetitionsWithNoWork > NUM_REPS_W_NO_WORK_BEFORE_YIELD ) - { numRepetitionsWithNoWork = 0; pthread_yield(); } + { //This is sequential mode.. just return + return; + } //Try to get the lock diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 PR.c --- a/PR.c Sat Mar 02 09:54:19 2013 -0800 +++ b/PR.c Mon Mar 04 00:40:38 2013 -0800 @@ -10,7 +10,6 @@ #include #include #include -#include #include "PR.h" @@ -117,7 +116,8 @@ process->langEnvs = langEnvs; process->protoLangEnvsList = langEnvsList; process->numLangEnvs = 0; - + process->hasWaitingToEnd = FALSE; + //A Process starts with one slave, the seed slave seedSlv = PR_int__create_slaveVP( seed_Fn, seedData, process ); seedSlv->typeOfVP = SeedSlv; @@ -212,14 +212,23 @@ } +/*This should only be called from main. It makes the OS thread that is animating + * main to suspend until the process completes shutdown. + */ void PR__wait_for_process_to_end( PRProcess *process ) { + process->hasWaitingToEnd = TRUE; + #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE // call the one and only core ctlr (sequential version), in the main thread. - coreCtlr_Seq( NULL ); - flushRegisters(); //Not sure why here, but leaving to be safe - + if( process->executionIsComplete ) + return; + else + { coreCtlr_Seq( NULL ); + flushRegisters(); //Not sure why here, but leaving to be safe + process->executionIsComplete = TRUE; + } #else //First get the "ACK" lock, then do normal wait for signal, then release // ACK lock, to let end-process know it can free the process struct @@ -244,6 +253,11 @@ void PR__wait_for_all_activity_to_end() { + #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE + //In sequential mode, can't reach this call unless all activity has + // already completed, so just return. + return; + #else pthread_mutex_lock( &(_PRTopEnv->activityDoneLock) ); while( !(_PRTopEnv->allActivityIsDone) ) { @@ -251,6 +265,7 @@ &(_PRTopEnv->activityDoneLock) ); } pthread_mutex_unlock( &(_PRTopEnv->activityDoneLock) ); + #endif } diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 PR__SS.c --- a/PR__SS.c Sat Mar 02 09:54:19 2013 -0800 +++ b/PR__SS.c Mon Mar 04 00:40:38 2013 -0800 @@ -72,15 +72,7 @@ //Make the animation slots and similar per-core structs.. for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) { - //readyToAnimateQs[ coreIdx ] = makePRQ(); - -/* //Q: should give masterVP core-specific info as its init data? - Don't have masterVPs anymore -- the pinned pthread takes that role - masterVPs[ coreIdx ] = PR_int__create_slaveVP_helper( (TopLevelFnPtr)&animationMaster, (void*)_PRTopEnv ); - masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx; - masterVPs[ coreIdx ]->typeOfVP = Master; - */ - allAnimSlots[ coreIdx ] = PR_SS__create_anim_slots( coreIdx ); //makes for one core +// allAnimSlots[ coreIdx ] = PR_SS__create_anim_slots( coreIdx ); //makes for one core } //For each animation slot, there is an idle slave, and an initial @@ -91,23 +83,25 @@ for( coreNum = 0; coreNum < NUM_CORES; coreNum++ ) { //langEnv->coreIsDone[coreNum] = FALSE; //use during shutdown //Still have multiple slots -- left over from prev incarnation - for( slotNum = 0; slotNum < NUM_ANIM_SLOTS; ++slotNum ) - { idleSlv = PR_int__create_slaveVP_helper( &idle_fn, NULL ); - idleSlv->coreAnimatedBy = coreNum; - idleSlv->typeOfVP = IdleVP; - idleSlv->animSlotAssignedTo = - _PRTopEnv->allAnimSlots[coreNum][slotNum]; - _PRTopEnv->idleSlv[coreNum][slotNum] = idleSlv; + allAnimSlots[ coreNum ] = PR_SS__create_anim_slots( coreNum ); //makes for one core + + slotNum = 0; //quick fix -- remove last vestiges of multiple slots per core + idleSlv = PR_int__create_slaveVP_helper( &idle_fn, NULL ); + idleSlv->coreAnimatedBy = coreNum; + idleSlv->typeOfVP = IdleVP; + idleSlv->animSlotAssignedTo = allAnimSlots[coreNum][slotNum]; + //start with all slots filled by the idle slaves + (allAnimSlots[coreNum][slotNum])->slaveAssignedToSlot = idleSlv; + _PRTopEnv->idleSlv[coreNum][slotNum] = idleSlv; - slotTaskSlv = PR_int__create_slot_slave( ); - slotTaskSlv->coreAnimatedBy = coreNum; - slotTaskSlv->animSlotAssignedTo = - _PRTopEnv->allAnimSlots[coreNum][slotNum]; + slotTaskSlv = PR_int__create_slot_slave( ); + slotTaskSlv->coreAnimatedBy = coreNum; + slotTaskSlv->animSlotAssignedTo = allAnimSlots[coreNum][slotNum]; - slotTaskSlv->typeOfVP = SlotTaskSlv; - _PRTopEnv->slotTaskSlvs[coreNum][slotNum] = slotTaskSlv; - } + slotTaskSlv->typeOfVP = SlotTaskSlv; + _PRTopEnv->slotTaskSlvs[coreNum][slotNum] = slotTaskSlv; + } _PRTopEnv->slaveRecycleQ = makePRQ(); @@ -251,26 +245,26 @@ */ void PR_SS__register_assigner( SlaveAssigner assigner, SlaveVP *seedVP, int32 magicNum ) - { PRLangEnv *langEnv; + { PRLangEnv *protoLangEnv; - langEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); - langEnv->workAssigner = assigner; + protoLangEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); + protoLangEnv->workAssigner = assigner; } void PR_SS__register_lang_shutdown_handler( LangShutdownHdlr shutdownHdlr, SlaveVP *seedVP, int32 magicNum ) - { PRLangEnv *langEnv; + { PRLangEnv *protoLangEnv; - langEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); - langEnv->shutdownHdlr = shutdownHdlr; + protoLangEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); + protoLangEnv->shutdownHdlr = shutdownHdlr; } void PR_SS__register_lang_data_creator( LangDataCreator langDataCreator, SlaveVP *seedVP, int32 magicNum ) - { PRLangEnv *langEnv; + { PRLangEnv *protoLangEnv; - langEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); - langEnv->langDataCreator = langDataCreator; + protoLangEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); + protoLangEnv->langDataCreator = langDataCreator; } void PR_SS__register_lang_meta_task_creator( LangMetaTaskCreator langMetaTaskCreator, @@ -283,18 +277,18 @@ void PR_SS__register_make_slave_ready_fn( MakeSlaveReadyFn fn, SlaveVP *seedVP, int32 magicNum ) - { PRLangEnv *langEnv; + { PRLangEnv *protoLangEnv; - langEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); - langEnv->makeSlaveReadyFn = fn; + protoLangEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); + protoLangEnv->makeSlaveReadyFn = fn; } void PR_SS__register_make_task_ready_fn( MakeTaskReadyFn fn, SlaveVP *seedVP, int32 magicNum ) - { PRLangEnv *langEnv; + { PRLangEnv *protoLangEnv; - langEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); - langEnv->makeTaskReadyFn = fn; + protoLangEnv = PR_SS__give_proto_lang_env_for_slave( seedVP, magicNum ); + protoLangEnv->makeTaskReadyFn = fn; } //======== @@ -331,12 +325,12 @@ //Then free the lang env PRLangEnv *protoLangEnv; for( i = 0; i < process->numLangEnvs; i++ ) - { protoLangEnv = PR_int__give_proto_lang_env(process->protoLangEnvsList[i]); + { protoLangEnv = process->protoLangEnvsList[i]; //The lang shutdowns should free any slaves or tasks in the langEnv (*protoLangEnv->shutdownHdlr)(&(protoLangEnv[1])); - PR_int__free( protoLangEnv ); + PR_int__free( protoLangEnv ); //don't need to remove from process! } - PR_int__free( process->protoLangEnvsList ); //list array + PR_int__free( process->protoLangEnvsList ); //array of Envs empty so free it PR_int__free( &(((int32 *)process->langEnvs)[-1]) ); //the collection array //any slaves from this process still in slots will finish executing, but @@ -360,15 +354,25 @@ //cause resume of "PR__wait_for_process_to_end()" call if( process->hasWaitingToEnd ) { + #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE + process->executionIsComplete = TRUE; + PR_int__free(process); + //The "wait for process to end" call started the PR activity that + // happens inside that process. That leads to here, running inside the + // master.. so just return, and let the core ctlr detect no work and + // return. + return; + #else pthread_mutex_lock( &(process->doneLock) ); process->executionIsComplete = TRUE; pthread_mutex_unlock( &(process->doneLock) ); - pthread_cond_broadcast( &(process->doneCond) ); - //now wait for woken waiter to Ack, then free the process struct - pthread_mutex_lock( &(process->doneAckLock) ); //BUG:? may be a race - pthread_mutex_unlock( &(process->doneAckLock) ); - PR_int__free(process); - } + pthread_cond_broadcast( &(process->doneCond) ); + //now wait for woken waiter to Ack, then free the process struct + pthread_mutex_lock( &(process->doneAckLock) ); //BUG:? may be a race + pthread_mutex_unlock( &(process->doneAckLock) ); + PR_int__free(process); + #endif + } //if no more processes, cause resume of "PR__wait_for_all_activity_to_end" if( _PRTopEnv->numProcesses == 0) { diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 PR__WL.h --- a/PR__WL.h Sat Mar 02 09:54:19 2013 -0800 +++ b/PR__WL.h Mon Mar 04 00:40:38 2013 -0800 @@ -53,7 +53,6 @@ void PR__wait_for_process_to_end( PRProcess *process ); -fixme; //process->hasWaitingToEnd void PR__wait_for_all_activity_to_end(); diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 PR__int.c --- a/PR__int.c Sat Mar 02 09:54:19 2013 -0800 +++ b/PR__int.c Mon Mar 04 00:40:38 2013 -0800 @@ -359,6 +359,7 @@ idx = protoLangEnv->idxInProcess; count = (process->numLangEnvs - idx) * sizeof(PRLangEnv *);//idx starts at 0 memmove( &(langEnvsList[idx]), &(langEnvsList[idx+1]), count); + process->numLangEnvs -= 1; PR_int__free( protoLangEnv ); } diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 Services_Offered_by_PR/Services_Language/PRServ_Request_Handlers.c --- a/Services_Offered_by_PR/Services_Language/PRServ_Request_Handlers.c Sat Mar 02 09:54:19 2013 -0800 +++ b/Services_Offered_by_PR/Services_Language/PRServ_Request_Handlers.c Mon Mar 04 00:40:38 2013 -0800 @@ -320,11 +320,11 @@ } void -PRServ__handleDissipateSeed(void *langReq, SlaveVP *seedSlv, VSsLangEnv *langEnv ) +PRServ__handleDissipateSeed(void *langReq, SlaveVP *seedSlv, PRServLangEnv *langEnv ) { DEBUG__printf1(dbgRqstHdlr,"Dissipate in PRServ %d", - requestingSlv->slaveNum); + seedSlv->slaveNum); //This should only ever be called for the seed slave -- for which there's // nothing to do.. if( seedSlv->typeOfVP != SeedSlv ) diff -r 7ab0d5bf16cb -r 1d7ea1b0f176 Services_Offered_by_PR/Services_Language/PRServ_SS.c --- a/Services_Offered_by_PR/Services_Language/PRServ_SS.c Sat Mar 02 09:54:19 2013 -0800 +++ b/Services_Offered_by_PR/Services_Language/PRServ_SS.c Mon Mar 04 00:40:38 2013 -0800 @@ -12,7 +12,7 @@ #include "Hash_impl/PrivateHash.h" #include "PRServ.h" -#include "PR_impl/Services_Offered_by_PR/Measurement_and_Stats/PR_MEAS__Counter_Recording.h" +#include "PR_impl/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h" //========================================================================== @@ -41,11 +41,11 @@ // PR_SS__register_lang_meta_task_creator( &PRServ__create_empty_lang_meta_task_in_slave, seedSlv, PRServ_MAGIC_NUMBER ); PR_SS__register_make_slave_ready_fn( &PRServ__resume_slave, seedSlv, PRServ_MAGIC_NUMBER ); PR_SS__register_make_task_ready_fn( &PRServ__make_task_ready, seedSlv, PRServ_MAGIC_NUMBER ); - - #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS + + #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS _PRTopEnv->counterHandler = &PR_MEAS__counter_handler; PR_MEAS__init_counter_data_structs_for_lang( seedSlv, PRServ_MAGIC_NUMBER ); - #endif + #endif //TODO: bug -- turn these arrays into dyn arrays to eliminate limit @@ -225,8 +225,8 @@ freePrivQ( langEnv->fnSingletons[i].waitQ ); freePrivQ( langEnv->transactionStrucs[i].waitingVPQ ); } - - PR_int__remove_lang_env_from_process_and_free( langEnv ); + //note, PR handles removing the langEnv from the process and freeing + // the langEnv chunk of memory }