# HG changeset patch # User Sean Halle # Date 1371071526 25200 # Node ID 7b6f8cf08b1f7650cf3618da91e6edee1e620076 # Parent 72ffdb11ad8e92b5b019128f82befa59eac7c68f Minor -- gave malloc its own lock and renamed TopLevelFn to BirthFn diff -r 72ffdb11ad8e -r 7b6f8cf08b1f AnimationMaster.c --- a/AnimationMaster.c Wed May 22 17:40:23 2013 -0700 +++ b/AnimationMaster.c Wed Jun 12 14:12:06 2013 -0700 @@ -34,6 +34,9 @@ inline void handleThrowException( PRServiceReq *langReq, PRLangEnv *protoLangEnv ); +void +debug_print_req(AnimSlot *slot, PRReqst *req); + //=========================================================================== /*Note: there used to be a coreController that was another animation @@ -73,7 +76,6 @@ if( slot->workIsDone ) { slot->workIsDone = FALSE; slot->needsWorkAssigned = TRUE; -printf("top handle request: %d | reqType: %d\n", slot->coreSlotIsOn, (int32)req->reqType );fflush(stdin); //An Idle VP has no request to handle, so skip to assign.. if( slot->slaveAssignedToSlot->typeOfVP != IdleVP && @@ -86,6 +88,7 @@ //process the request made by the slave (held inside slave struc) slave = slot->slaveAssignedToSlot; req = slave->request; + debug_print_req(slot, req); //If the requesting slave is a slot slave, and request is not // task-end, then turn it into a free task slave & continue @@ -592,3 +595,27 @@ (*protoLangEnv->makeSlaveReadyFn)( langReq->requestingSlv, PR_int__give_lang_env(protoLangEnv) ); } +void +debug_print_req(AnimSlot *slot, PRReqst *req) + { + if(dbgMaster) + { printf("top handle request: %d | reqType: ", slot->coreSlotIsOn ); + switch(req->reqType) + { case TaskCreate: printf("TaskCreate \n"); break; + case TaskEnd: printf("TaskEnd \n"); break; + case SlvCreate: printf("SlvCreate \n"); break; + case SlvDissipate: printf("SlvDissipate \n"); break; + case Language: printf("Language \n"); break; + case Service: printf("Service \n"); break; + case Hardware: printf("Hardware \n"); break; + case IO: printf("IO \n"); break; + case OSCall: printf("OSCall \n"); break; + case LangShutdown: printf("LangShutdown \n"); break; + case ProcessEnd: printf("ProcessEnd \n"); break; + case PRShutdown: printf("PRShutdown \n"); break; + } + fflush(stdin); + } + } + + diff -r 72ffdb11ad8e -r 7b6f8cf08b1f HW_Dependent_Primitives/PR__primitives.c --- a/HW_Dependent_Primitives/PR__primitives.c Wed May 22 17:40:23 2013 -0700 +++ b/HW_Dependent_Primitives/PR__primitives.c Wed Jun 12 14:12:06 2013 -0700 @@ -18,14 +18,14 @@ * carefully that it's safe) */ inline void -PR_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr, +PR_int__reset_slaveVP_to_BirthFn( SlaveVP *slaveVP, BirthFnPtr fnPtr, void *dataParam) { void *stackPtr; // Start of Hardware dependent part //Set slave's instr pointer to a helper Fn that copies params from stack - slaveVP->resumeInstrPtr = (TopLevelFnPtr)&startUpTopLevelFn; + slaveVP->resumeInstrPtr = (BirthFnPtr)&startUpBirthFn; //fnPtr takes two params -- void *dataParam & void *animSlv // Stack grows *down*, so start it at highest stack addr, minus room @@ -81,7 +81,7 @@ *((void**)stackPtr - 1) = (void*)fnPtr; //what helper jmps to //Set slave's instr pointer to a helper Fn that copies params from stack - slaveVP->resumeInstrPtr = (TopLevelFnPtr)&jmpToOneParamFn; + slaveVP->resumeInstrPtr = (BirthFnPtr)&jmpToOneParamFn; // end of Hardware dependent part @@ -123,7 +123,7 @@ *((void**)stackPtr - 1) = (void*)fnPtr; //what helper jmps to //Set slave's instr pointer to a helper Fn that copies params from stack - slaveVP->resumeInstrPtr = (TopLevelFnPtr)&jmpToTwoParamFn; + slaveVP->resumeInstrPtr = (BirthFnPtr)&jmpToTwoParamFn; // end of Hardware dependent part diff -r 72ffdb11ad8e -r 7b6f8cf08b1f HW_Dependent_Primitives/PR__primitives.h --- a/HW_Dependent_Primitives/PR__primitives.h Wed May 22 17:40:23 2013 -0700 +++ b/HW_Dependent_Primitives/PR__primitives.h Wed Jun 12 14:12:06 2013 -0700 @@ -23,7 +23,7 @@ masterSwitchToCoreCtlr(SlaveVP *nextSlave); void -startUpTopLevelFn(); +startUpBirthFn(); void jmpToOneParamFn(); diff -r 72ffdb11ad8e -r 7b6f8cf08b1f HW_Dependent_Primitives/PR__primitives_asm.s --- a/HW_Dependent_Primitives/PR__primitives_asm.s Wed May 22 17:40:23 2013 -0700 +++ b/HW_Dependent_Primitives/PR__primitives_asm.s Wed Jun 12 14:12:06 2013 -0700 @@ -14,8 +14,8 @@ //Trick for 64 bit arch -- copies args from stack into regs, then does jmp to // the top-level function, which was pointed to by the stack-ptr -.globl startUpTopLevelFn -startUpTopLevelFn: +.globl startUpBirthFn +startUpBirthFn: movq %rdi , %rsi #get second argument from first argument of switchSlv movq 0x08(%rsp), %rdi #get first argument from stack movq (%rsp) , %rax #get top-level function's addr from stack diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR.c --- a/PR.c Wed May 22 17:40:23 2013 -0700 +++ b/PR.c Wed Jun 12 14:12:06 2013 -0700 @@ -65,7 +65,7 @@ PR_SS__create_topEnv(); #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE - printf( "\n\n Running in SEQUENTIAL mode \n\n" ); + printf( "\n\n Running in SEQUENTIAL mode -- NUM_CORES: %d \n\n", NUM_CORES ); //Only difference between version with an OS thread pinned to each core and // the sequential version of PR is PR__init_Seq, this, and coreCtlr_Seq. @@ -100,7 +100,7 @@ * */ PRProcess * -PR__create_process( TopLevelFnPtr seed_Fn, void *seedData ) +PR__create_process( BirthFnPtr seed_Fn, void *seedData ) { SlaveVP *seedSlv; PRProcess *process; PRLangEnv **langEnvs, **langEnvsList; diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__PI.c --- a/PR__PI.c Wed May 22 17:40:23 2013 -0700 +++ b/PR__PI.c Wed Jun 12 14:12:06 2013 -0700 @@ -48,6 +48,14 @@ } } } +/*Make slave ready, without having to know the lang env.. just the magic num + */ +void +PR_PI__make_slave_ready_for_lang( SlaveVP *slave, int32 magicNum ) + { void *langEnv; + langEnv = PR_PI__give_lang_env_for_slave( slave, magicNum ); + PR_PI__make_slave_ready( slave, langEnv ); + } /*Any langlet can transfer slaves over to be resumed in PRServ.. the resume Fn * is registered in the PRServ lang env during process creation. diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__SS.c --- a/PR__SS.c Wed May 22 17:40:23 2013 -0700 +++ b/PR__SS.c Wed Jun 12 14:12:06 2013 -0700 @@ -402,7 +402,7 @@ AnimSlot **animSlots; //create the shutdown processors, one for each core controller -- put them // directly into the slots - PR_int__get_master_lock(); + PR_int__get_wrapper_lock(); for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) { //Note, this is running in the master shutDownSlv = PR_SS__create_shutdown_slave(); diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__WL.c --- a/PR__WL.c Wed May 22 17:40:23 2013 -0700 +++ b/PR__WL.c Wed Jun 12 14:12:06 2013 -0700 @@ -116,7 +116,7 @@ inline void -PR_WL__send_create_task_req( TopLevelFn fn, void *initData, void *langReq, +PR_WL__send_create_task_req( BirthFn fn, void *initData, void *langReq, int32 *taskID, CreateHandler handler, SlaveVP *animSlv, int32 magicNumber) { PRReqst req; diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__WL.h --- a/PR__WL.h Wed May 22 17:40:23 2013 -0700 +++ b/PR__WL.h Wed Jun 12 14:12:06 2013 -0700 @@ -40,7 +40,7 @@ PR__start(); PRProcess * -PR__create_process( TopLevelFnPtr seed_Fn, void *seedData ); +PR__create_process( BirthFnPtr seed_Fn, void *seedData ); void PR__end_seedVP( SlaveVP *seedSlv ); diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__int.c --- a/PR__int.c Wed May 22 17:40:23 2013 -0700 +++ b/PR__int.c Wed Jun 12 14:12:06 2013 -0700 @@ -30,7 +30,7 @@ */ inline SlaveVP * -PR_int__create_slaveVP_helper( TopLevelFnPtr fnPtr, void *dataParam ) +PR_int__create_slaveVP_helper( BirthFnPtr fnPtr, void *dataParam ) { SlaveVP *newSlv; void *stackLocs; @@ -46,10 +46,14 @@ newSlv->numTimesAssignedToASlot = 0; - newSlv->langDatas = NULL; - newSlv->metaTasks = NULL; + + newSlv->langDatas = + (PRLangData **)PR_int__make_collection_of_size( NUM_IN_COLLECTION ); + + newSlv->metaTasks = + (PRMetaTask **) PR_int__make_collection_of_size( NUM_IN_COLLECTION ); - PR_int__reset_slaveVP_to_TopLvlFn( newSlv, fnPtr, dataParam ); + PR_int__reset_slaveVP_to_BirthFn( newSlv, fnPtr, dataParam ); //============================= MEASUREMENT STUFF ======================== #ifdef PROBES__TURN_ON_STATS_PROBES @@ -68,16 +72,10 @@ inline SlaveVP * -PR_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam, PRProcess *process ) +PR_int__create_slaveVP( BirthFnPtr fnPtr, void *dataParam, PRProcess *process ) { SlaveVP *newSlv; newSlv = PR_int__create_slaveVP_helper( fnPtr, dataParam ); - - newSlv->langDatas = - (PRLangData **)PR_int__make_collection_of_size( NUM_IN_COLLECTION ); - - newSlv->metaTasks = - (PRMetaTask **) PR_int__make_collection_of_size( NUM_IN_COLLECTION ); process->numLiveGenericSlvs += 1; @@ -441,7 +439,7 @@ //if work found, put into slot, and adjust flags and state slot->slaveAssignedToSlot = slave; slave->animSlotAssignedTo = slot; - slot->needsWorkAssigned = FALSE; + slot->needsWorkAssigned = FALSE; #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC //have a slave to be assigned to the slot @@ -486,7 +484,7 @@ slotSlv = _PRTopEnv->slotTaskSlvs[coreNum][slotNum]; //point slave to task's function - PR_int__reset_slaveVP_to_TopLvlFn( slotSlv, protoMetaTask->topLevelFn, protoMetaTask->initData ); + PR_int__reset_slaveVP_to_BirthFn( slotSlv, protoMetaTask->topLevelFn, protoMetaTask->initData ); PR_int__insert_meta_task_into_slave( protoMetaTask, slotSlv ); slotSlv->processSlaveIsIn = protoMetaTask->processTaskIsIn; PR_int__put_slave_into_slot( slotSlv, slot ); @@ -696,7 +694,7 @@ { protoLangEnv = PR_int__give_proto_lang_env_for_slave( slave, magicNum ); if(protoLangEnv->langDataCreator == NULL) PR_int__error("register a lang data creator"); - //This will call PR_PI__create_lang_data_in_slave + //This will call PR_PI__create_lang_data_in_slave -- puts it into slave return (*protoLangEnv->langDataCreator)( slave ); } } @@ -865,14 +863,46 @@ PR_int__backoff_for_TooLongToGetLock( int32 numTriesToGetLock ); inline void -PR_int__get_master_lock() - { int32 *addrOfMasterLock; +PR_int__get_wrapper_lock() + { int32 *addrOfWrapperLock; #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE return; #endif - addrOfMasterLock = &(_PRTopEnv->masterLock); + addrOfWrapperLock = &(_PRTopEnv->wrapperLock); + + int numTriesToGetLock = 0; + int gotLock = 0; + +// MEAS__Capture_Pre_Master_Lock_Point; + while( !gotLock ) //keep going until get master lock + { + numTriesToGetLock++; //if too many, means too much contention + if( numTriesToGetLock > NUM_TRIES_BEFORE_DO_BACKOFF ) + { PR_int__backoff_for_TooLongToGetLock( numTriesToGetLock ); + } + if( numTriesToGetLock > MASTERLOCK_RETRIES_BEFORE_YIELD ) + { numTriesToGetLock = 0; + pthread_yield(); + } + + //try to get the lock + gotLock = __sync_bool_compare_and_swap( addrOfWrapperLock, + UNLOCKED, LOCKED ); + } +// MEAS__Capture_Post_Master_Lock_Point; + } + +inline void +PR_int__get_malloc_lock() + { int32 *addrOfMallocLock; + + #ifdef DEBUG__TURN_ON_SEQUENTIAL_MODE + return; + #endif + + addrOfMallocLock = &(_PRTopEnv->mallocLock); int numTriesToGetLock = 0; int gotLock = 0; @@ -890,7 +920,7 @@ } //try to get the lock - gotLock = __sync_bool_compare_and_swap( addrOfMasterLock, + gotLock = __sync_bool_compare_and_swap( addrOfMallocLock, UNLOCKED, LOCKED ); } MEAS__Capture_Post_Master_Lock_Point; diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__int.h --- a/PR__int.h Wed May 22 17:40:23 2013 -0700 +++ b/PR__int.h Wed Jun 12 14:12:06 2013 -0700 @@ -21,7 +21,7 @@ inline void -PR_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr, +PR_int__reset_slaveVP_to_BirthFn( SlaveVP *slaveVP, BirthFnPtr fnPtr, void *dataParam); inline @@ -39,11 +39,11 @@ //=========================================================================== inline SlaveVP * -PR_int__create_slaveVP_helper( TopLevelFnPtr fnPtr, void *dataParam ); +PR_int__create_slaveVP_helper( BirthFnPtr fnPtr, void *dataParam ); inline SlaveVP * -PR_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam, PRProcess *process ); +PR_int__create_slaveVP( BirthFnPtr fnPtr, void *dataParam, PRProcess *process ); SlaveVP * PR_int__get_recycled_slot_slave( ); @@ -223,9 +223,16 @@ PR_int__strDup( char *str ); inline void -PR_int__get_master_lock(); +PR_int__get_wrapper_lock(); -#define PR_int__release_master_lock() _PRTopEnv->masterLock = UNLOCKED +inline void +PR_int__get_malloc_lock(); + +#define PR_int__release_master_lock() _PRTopEnv->masterLock = UNLOCKED + +#define PR_int__release_wrapper_lock() _PRTopEnv->wrapperLock = UNLOCKED + +#define PR_int__release_malloc_lock() _PRTopEnv->mallocLock = UNLOCKED inline uint32_t PR_int__randomNumber(); diff -r 72ffdb11ad8e -r 7b6f8cf08b1f PR__structs.h --- a/PR__structs.h Wed May 22 17:40:23 2013 -0700 +++ b/PR__structs.h Wed Jun 12 14:12:06 2013 -0700 @@ -43,8 +43,8 @@ typedef void (*LangMetaTaskFreer) ( void * ); //lang meta task to free typedef void (*MakeSlaveReadyFn) ( SlaveVP *, void * ); //slave and langEnv typedef void (*MakeTaskReadyFn) ( void *, void * ); //langTask and langEnv -typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv -typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv +typedef void (*BirthFnPtr) ( void *, SlaveVP * ); //initData, animSlv +typedef void BirthFn ( void *, SlaveVP * ); //initData, animSlv typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * ); //=========== MEASUREMENT STUFF ========== MEAS__Insert_Counter_Handler @@ -121,17 +121,17 @@ enum PRReqstType //avoid starting enums at 0, for debug reasons { TaskCreate = 1, - TaskEnd = 2, - SlvCreate = 3, - SlvDissipate = 4, - Language = 5, - Service = 6, //To invoke a PR provided equivalent of a language request (ex: probe) - Hardware = 7, - IO = 8, - OSCall = 9, - LangShutdown = 10, - ProcessEnd = 11, - PRShutdown = 12 + TaskEnd, + SlvCreate, + SlvDissipate, + Language, + Service, //To invoke a PR provided equivalent of a language request (ex: probe) + Hardware, + IO, + OSCall, + LangShutdown, + ProcessEnd, + PRShutdown }; @@ -143,7 +143,7 @@ int32 langMagicNumber; SlaveVP *requestingSlave; - TopLevelFnPtr topLevelFn; + BirthFnPtr topLevelFn; void *initData; int32 *ID; @@ -152,6 +152,7 @@ // fn directly into the request.. might change to this for all requests RequestHandler handler; //pointer to handler fn CreateHandler createHdlr; //special because returns something + int32 createSuspendedGroup; //must be non-zero PRReqst *nextReqst; }; @@ -263,6 +264,10 @@ int8 falseSharePad1[256 - sizeof(void*)]; int32 masterLock; //offset to this field used in asm int8 falseSharePad2[256 - sizeof(int32)]; + int32 wrapperLock; //offset to this field used in asm + int8 falseSharePad3[256 - sizeof(int32)]; + int32 mallocLock; //offset to this field used in asm + int8 falseSharePad4[256 - sizeof(int32)]; //============ below this, no fields are used in asm ============= //Basic PR infrastructure @@ -373,7 +378,7 @@ int32 *ID; //is standard PR ID PRProcess *processTaskIsIn; SlaveVP *slaveAssignedTo; //not valid until task animated - TopLevelFnPtr topLevelFn; //This is the Fn executes as the task + BirthFnPtr topLevelFn; //This is the Fn executes as the task void *initData; //The data taken by the function LangMetaTaskFreer freer; bool32 goAheadAndFree; diff -r 72ffdb11ad8e -r 7b6f8cf08b1f Services_Offered_by_PR/Measurement_and_Stats/probes.c --- a/Services_Offered_by_PR/Measurement_and_Stats/probes.c Wed May 22 17:40:23 2013 -0700 +++ b/Services_Offered_by_PR/Measurement_and_Stats/probes.c Wed Jun 12 14:12:06 2013 -0700 @@ -163,11 +163,11 @@ PR_impl__index_probe_by_its_name( int32 probeID, SlaveVP *animSlv ) { IntervalProbe *probe; - PR_int__get_master_lock(); + PR_int__get_wrapper_lock(); probe = _PRTopEnv->intervalProbes[ probeID ]; addValueIntoTable(probe->nameStr, probe, _PRTopEnv->probeNameHashTbl); - PR_int__release_master_lock(); + PR_int__release_wrapper_lock(); } diff -r 72ffdb11ad8e -r 7b6f8cf08b1f Services_Offered_by_PR/Memory_Handling/vmalloc.c --- a/Services_Offered_by_PR/Memory_Handling/vmalloc.c Wed May 22 17:40:23 2013 -0700 +++ b/Services_Offered_by_PR/Memory_Handling/vmalloc.c Wed Jun 12 14:12:06 2013 -0700 @@ -291,9 +291,9 @@ PR_WL__malloc( int32 sizeRequested ) { void *ret; - PR_int__get_master_lock(); + PR_int__get_malloc_lock(); ret = PR_int__malloc( sizeRequested ); - PR_int__release_master_lock(); + PR_int__release_malloc_lock(); return ret; } @@ -354,9 +354,9 @@ void PR_WL__free( void *ptrToFree ) { - PR_int__get_master_lock(); + PR_int__get_malloc_lock(); PR_int__free( ptrToFree ); - PR_int__release_master_lock(); + PR_int__release_malloc_lock(); } /* diff -r 72ffdb11ad8e -r 7b6f8cf08b1f Services_Offered_by_PR/Services_Language/PRServ_SS.c --- a/Services_Offered_by_PR/Services_Language/PRServ_SS.c Wed May 22 17:40:23 2013 -0700 +++ b/Services_Offered_by_PR/Services_Language/PRServ_SS.c Wed Jun 12 14:12:06 2013 -0700 @@ -12,7 +12,7 @@ #include "Hash_impl/PrivateHash.h" #include "PRServ.h" -#include "PR_impl/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h" +//#include "PR_impl/Services_Offered_by_PR/Measurement_and_Stats/MEAS__Counter_Recording.h" //==========================================================================