seanhalle@0: /* seanhalle@0: * Copyright 2010 OpenSourceCodeStewardshipFoundation seanhalle@0: * seanhalle@0: * Licensed under BSD seanhalle@0: */ seanhalle@0: seanhalle@0: #include seanhalle@0: #include seanhalle@0: #include seanhalle@0: seanhalle@0: #include "Queue_impl/PrivateQueue.h" seanhalle@0: #include "Hash_impl/PrivateHash.h" seanhalle@0: seanhalle@0: #include "VOMP.h" seanhalle@0: #include "VOMP_Counter_Recording.h" seanhalle@0: seanhalle@0: //========================================================================== seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__init(); seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__init_Helper(); seanhalle@0: //========================================================================== seanhalle@0: seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: seanhalle@0: /*These are the library functions *called in the application* seanhalle@0: * seanhalle@0: *There's a pattern for the outside sequential code to interact with the seanhalle@0: * VMS_HW code. seanhalle@0: *The VMS_HW system is inside a boundary.. every VOMP system is in its seanhalle@0: * own directory that contains the functions for each of the processor types. seanhalle@0: * One of the processor types is the "seed" processor that starts the seanhalle@0: * cascade of creating all the processors that do the work. seanhalle@0: *So, in the directory is a file called "EntryPoint.c" that contains the seanhalle@0: * function, named appropriately to the work performed, that the outside seanhalle@0: * sequential code calls. This function follows a pattern: seanhalle@0: *1) it calls VOMP__init() seanhalle@0: *2) it creates the initial data for the seed processor, which is passed seanhalle@0: * in to the function seanhalle@0: *3) it creates the seed VOMP processor, with the data to start it with. seanhalle@0: *4) it calls startVOMPThenWaitUntilWorkDone seanhalle@0: *5) it gets the returnValue from the transfer struc and returns that seanhalle@0: * from the function seanhalle@0: * seanhalle@0: *For now, a new VOMP system has to be created via VOMP__init every seanhalle@0: * time an entry point function is called -- later, might add letting the seanhalle@0: * VOMP system be created once, and let all the entry points just reuse seanhalle@0: * it -- want to be as simple as possible now, and see by using what makes seanhalle@0: * sense for later.. seanhalle@0: */ seanhalle@0: seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: /*This is the "border crossing" function -- the thing that crosses from the seanhalle@0: * outside world, into the VMS_HW world. It initializes and starts up the seanhalle@0: * VMS system, then creates one processor from the specified function and seanhalle@0: * puts it into the readyQ. From that point, that one function is resp. seanhalle@0: * for creating all the other processors, that then create others, and so seanhalle@0: * forth. seanhalle@0: *When all the processors, including the seed, have dissipated, then this seanhalle@0: * function returns. The results will have been written by side-effect via seanhalle@0: * pointers read from, or written into initData. seanhalle@0: * seanhalle@0: *NOTE: no Threads should exist in the outside program that might touch seanhalle@0: * any of the data reachable from initData passed in to here seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__create_seed_procr_and_do_work( TopLevelFnPtr fnPtr, void *initData ) seanhalle@0: { VOMPSemEnv *semEnv; seanhalle@0: SlaveVP *seedPr; seanhalle@0: seanhalle@0: VOMP__init(); //normal multi-thd seanhalle@0: seanhalle@0: semEnv = _VMSMasterEnv->semanticEnv; seanhalle@0: seanhalle@0: //VOMP starts with one processor, which is put into initial environ, seanhalle@0: // and which then calls create() to create more, thereby expanding work seanhalle@0: seedPr = VOMP__create_procr_helper( fnPtr, initData, seanhalle@0: semEnv, semEnv->nextCoreToGetNewPr++ ); seanhalle@0: seanhalle@0: resume_slaveVP( seedPr, semEnv ); seanhalle@0: seanhalle@0: VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd seanhalle@0: seanhalle@0: VOMP__cleanup_after_shutdown(); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: int32 seanhalle@0: VOMP__giveMinWorkUnitCycles( float32 percentOverhead ) seanhalle@0: { seanhalle@0: return MIN_WORK_UNIT_CYCLES; seanhalle@0: } seanhalle@0: seanhalle@0: int32 seanhalle@0: VOMP__giveIdealNumWorkUnits() seanhalle@0: { seanhalle@0: return NUM_ANIM_SLOTS * NUM_CORES; seanhalle@0: } seanhalle@0: seanhalle@0: int32 seanhalle@0: VOMP__give_number_of_cores_to_schedule_onto() seanhalle@0: { seanhalle@0: return NUM_CORES; seanhalle@0: } seanhalle@0: seanhalle@0: /*For now, use TSC -- later, make these two macros with assembly that first seanhalle@0: * saves jump point, and second jumps back several times to get reliable time seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__start_primitive() seanhalle@0: { saveLowTimeStampCountInto( ((VOMPSemEnv *)(_VMSMasterEnv->semanticEnv))-> seanhalle@0: primitiveStartTime ); seanhalle@0: } seanhalle@0: seanhalle@0: /*Just quick and dirty for now -- make reliable later seanhalle@0: * will want this to jump back several times -- to be sure cache is warm seanhalle@0: * because don't want comm time included in calc-time measurement -- and seanhalle@0: * also to throw out any "weird" values due to OS interrupt or TSC rollover seanhalle@0: */ seanhalle@0: int32 seanhalle@0: VOMP__end_primitive_and_give_cycles() seanhalle@0: { int32 endTime, startTime; seanhalle@0: //TODO: fix by repeating time-measurement seanhalle@0: saveLowTimeStampCountInto( endTime ); seanhalle@0: startTime =((VOMPSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime; seanhalle@0: return (endTime - startTime); seanhalle@0: } seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: /*Initializes all the data-structures for a VOMP system -- but doesn't seanhalle@0: * start it running yet! seanhalle@0: * seanhalle@0: *This runs in the main thread -- before VMS starts up seanhalle@0: * seanhalle@0: *This sets up the semantic layer over the VMS system seanhalle@0: * seanhalle@0: *First, calls VMS_Setup, then creates own environment, making it ready seanhalle@0: * for creating the seed processor and then starting the work. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__init() seanhalle@0: { seanhalle@0: VMS_SS__init(); seanhalle@0: //masterEnv, a global var, now is partially set up by init_VMS seanhalle@0: // after this, have VMS_int__malloc and VMS_int__free available seanhalle@0: seanhalle@0: VOMP__init_Helper(); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: void idle_fn(void* data, SlaveVP *animatingSlv){ seanhalle@0: while(1){ seanhalle@0: VMS_int__suspend_slaveVP_and_send_req(animatingSlv); seanhalle@0: } seanhalle@0: } seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__init_Helper() seanhalle@0: { VOMPSemEnv *semanticEnv; seanhalle@0: PrivQueueStruc **readyVPQs; seanhalle@0: int coreIdx, i, j; seanhalle@0: seanhalle@0: //Hook up the semantic layer's plug-ins to the Master virt procr seanhalle@0: _VMSMasterEnv->requestHandler = &VOMP__Request_Handler; seanhalle@0: _VMSMasterEnv->slaveAssigner = &VOMP__assign_slaveVP_to_slot; seanhalle@0: #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS seanhalle@0: _VMSMasterEnv->counterHandler = &VOMP__counter_handler; seanhalle@0: #endif seanhalle@0: seanhalle@0: //create the semantic layer's environment (all its data) and add to seanhalle@0: // the master environment seanhalle@0: semanticEnv = VMS_int__malloc( sizeof( VOMPSemEnv ) ); seanhalle@0: _VMSMasterEnv->semanticEnv = semanticEnv; seanhalle@0: seanhalle@0: #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS seanhalle@0: VOMP__init_counter_data_structs(); seanhalle@0: #endif seanhalle@0: semanticEnv->shutdownInitiated = FALSE; seanhalle@0: for(i=0;iidlePr[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL); seanhalle@0: semanticEnv->idlePr[i][j]->coreAnimatedBy = i; seanhalle@0: } seanhalle@0: } seanhalle@0: seanhalle@0: #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC seanhalle@0: semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128); seanhalle@0: semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128); seanhalle@0: semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128); seanhalle@0: semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128); seanhalle@0: semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8); seanhalle@0: seanhalle@0: semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128); seanhalle@0: memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit))); seanhalle@0: #endif seanhalle@0: seanhalle@0: //create the ready queue, hash tables used for pairing send to receive seanhalle@0: // and so forth seanhalle@0: //TODO: add hash tables for pairing sends with receives, and seanhalle@0: // initialize the data ownership system seanhalle@0: readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) ); seanhalle@0: seanhalle@0: for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) seanhalle@0: { seanhalle@0: readyVPQs[ coreIdx ] = makeVMSQ(); seanhalle@0: } seanhalle@0: seanhalle@0: semanticEnv->readyVPQs = readyVPQs; seanhalle@0: seanhalle@0: semanticEnv->nextCoreToGetNewPr = 0; seanhalle@0: semanticEnv->numSlaveVP = 0; seanhalle@0: seanhalle@0: semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big seanhalle@0: seanhalle@0: //TODO: bug -- turn these arrays into dyn arrays to eliminate limit seanhalle@0: //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( ); seanhalle@0: //semanticEnv->transactionStrucs = makeDynArrayInfo( ); seanhalle@0: for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ ) seanhalle@0: { seanhalle@0: semanticEnv->fnSingletons[i].endInstrAddr = NULL; seanhalle@0: semanticEnv->fnSingletons[i].hasBeenStarted = FALSE; seanhalle@0: semanticEnv->fnSingletons[i].hasFinished = FALSE; seanhalle@0: semanticEnv->fnSingletons[i].waitQ = makeVMSQ(); seanhalle@0: semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ(); seanhalle@0: } seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: /*Frees any memory allocated by VOMP__init() then calls VMS_int__shutdown seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__cleanup_after_shutdown() seanhalle@0: { VOMPSemEnv *semanticEnv; seanhalle@0: seanhalle@0: semanticEnv = _VMSMasterEnv->semanticEnv; seanhalle@0: seanhalle@0: #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC seanhalle@0: //UCC seanhalle@0: FILE* output; seanhalle@0: int n; seanhalle@0: char filename[255]; seanhalle@0: for(n=0;n<255;n++) seanhalle@0: { seanhalle@0: sprintf(filename, "./counters/UCC.%d",n); seanhalle@0: output = fopen(filename,"r"); seanhalle@0: if(output) seanhalle@0: { seanhalle@0: fclose(output); seanhalle@0: }else{ seanhalle@0: break; seanhalle@0: } seanhalle@0: } seanhalle@0: if(n<255){ seanhalle@0: printf("Saving UCC to File: %s ...\n", filename); seanhalle@0: output = fopen(filename,"w+"); seanhalle@0: if(output!=NULL){ seanhalle@0: set_dependency_file(output); seanhalle@0: //fprintf(output,"digraph Dependencies {\n"); seanhalle@0: //set_dot_file(output); seanhalle@0: //FIXME: first line still depends on counters being enabled, replace w/ unit struct! seanhalle@0: //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); seanhalle@0: forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file); seanhalle@0: forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); seanhalle@0: forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); seanhalle@0: forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file); seanhalle@0: //fprintf(output,"}\n"); seanhalle@0: fflush(output); seanhalle@0: seanhalle@0: } else seanhalle@0: printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); seanhalle@0: } else { seanhalle@0: printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); seanhalle@0: } seanhalle@0: //Loop Graph seanhalle@0: for(n=0;n<255;n++) seanhalle@0: { seanhalle@0: sprintf(filename, "./counters/LoopGraph.%d",n); seanhalle@0: output = fopen(filename,"r"); seanhalle@0: if(output) seanhalle@0: { seanhalle@0: fclose(output); seanhalle@0: }else{ seanhalle@0: break; seanhalle@0: } seanhalle@0: } seanhalle@0: if(n<255){ seanhalle@0: printf("Saving LoopGraph to File: %s ...\n", filename); seanhalle@0: output = fopen(filename,"w+"); seanhalle@0: if(output!=NULL){ seanhalle@0: set_dependency_file(output); seanhalle@0: //fprintf(output,"digraph Dependencies {\n"); seanhalle@0: //set_dot_file(output); seanhalle@0: //FIXME: first line still depends on counters being enabled, replace w/ unit struct! seanhalle@0: //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); seanhalle@0: forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file ); seanhalle@0: forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); seanhalle@0: forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); seanhalle@0: forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file ); seanhalle@0: forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file ); seanhalle@0: //fprintf(output,"}\n"); seanhalle@0: fflush(output); seanhalle@0: seanhalle@0: } else seanhalle@0: printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); seanhalle@0: } else { seanhalle@0: printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: freeListOfArrays(semanticEnv->unitList); seanhalle@0: freeListOfArrays(semanticEnv->commDependenciesList); seanhalle@0: freeListOfArrays(semanticEnv->ctlDependenciesList); seanhalle@0: freeListOfArrays(semanticEnv->dynDependenciesList); seanhalle@0: seanhalle@0: #endif seanhalle@0: #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS seanhalle@0: for(n=0;n<255;n++) seanhalle@0: { seanhalle@0: sprintf(filename, "./counters/Counters.%d.csv",n); seanhalle@0: output = fopen(filename,"r"); seanhalle@0: if(output) seanhalle@0: { seanhalle@0: fclose(output); seanhalle@0: }else{ seanhalle@0: break; seanhalle@0: } seanhalle@0: } seanhalle@0: if(n<255){ seanhalle@0: printf("Saving Counter measurements to File: %s ...\n", filename); seanhalle@0: output = fopen(filename,"w+"); seanhalle@0: if(output!=NULL){ seanhalle@0: set_counter_file(output); seanhalle@0: int i; seanhalle@0: for(i=0;icounterList[i], &print_counter_events_to_file ); seanhalle@0: fflush(output); seanhalle@0: } seanhalle@0: seanhalle@0: } else seanhalle@0: printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); seanhalle@0: } else { seanhalle@0: printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); seanhalle@0: } seanhalle@0: seanhalle@0: #endif seanhalle@0: /* It's all allocated inside VMS's big chunk -- that's about to be freed, so seanhalle@0: * nothing to do here seanhalle@0: seanhalle@0: seanhalle@0: for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) seanhalle@0: { seanhalle@0: VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData ); seanhalle@0: VMS_int__free( semanticEnv->readyVPQs[coreIdx] ); seanhalle@0: } seanhalle@0: VMS_int__free( semanticEnv->readyVPQs ); seanhalle@0: seanhalle@0: freeHashTable( semanticEnv->commHashTbl ); seanhalle@0: VMS_int__free( _VMSMasterEnv->semanticEnv ); seanhalle@0: */ seanhalle@0: VMS_SS__cleanup_at_end_of_shutdown(); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: /* seanhalle@0: */ seanhalle@0: SlaveVP * seanhalle@0: VOMP__create_procr_with( TopLevelFnPtr fnPtr, void *initData, seanhalle@0: SlaveVP *creatingPr ) seanhalle@0: { VOMPSemReq reqData; seanhalle@0: seanhalle@0: //the semantic request data is on the stack and disappears when this seanhalle@0: // call returns -- it's guaranteed to remain in the VP's stack for as seanhalle@0: // long as the VP is suspended. seanhalle@0: reqData.reqType = 0; //know type because in a VMS create req seanhalle@0: reqData.coreToAssignOnto = -1; //means round-robin assign seanhalle@0: reqData.fnPtr = fnPtr; seanhalle@0: reqData.initData = initData; seanhalle@0: reqData.sendPr = creatingPr; seanhalle@0: seanhalle@0: VMS_WL__send_create_slaveVP_req( &reqData, creatingPr ); seanhalle@0: seanhalle@0: return creatingPr->dataRetFromReq; seanhalle@0: } seanhalle@0: seanhalle@0: SlaveVP * seanhalle@0: VOMP__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData, seanhalle@0: SlaveVP *creatingPr, int32 coreToAssignOnto ) seanhalle@0: { VOMPSemReq reqData; seanhalle@0: seanhalle@0: //the semantic request data is on the stack and disappears when this seanhalle@0: // call returns -- it's guaranteed to remain in the VP's stack for as seanhalle@0: // long as the VP is suspended. seanhalle@0: reqData.reqType = 0; //know type because in a VMS create req seanhalle@0: reqData.coreToAssignOnto = coreToAssignOnto; seanhalle@0: reqData.fnPtr = fnPtr; seanhalle@0: reqData.initData = initData; seanhalle@0: reqData.sendPr = creatingPr; seanhalle@0: seanhalle@0: VMS_WL__send_create_slaveVP_req( &reqData, creatingPr ); seanhalle@0: seanhalle@0: return creatingPr->dataRetFromReq; seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__dissipate_procr( SlaveVP *procrToDissipate ) seanhalle@0: { seanhalle@0: VMS_WL__send_dissipate_req( procrToDissipate ); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: void * seanhalle@0: VOMP__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr ) seanhalle@0: { VOMPSemReq reqData; seanhalle@0: seanhalle@0: reqData.reqType = malloc_req; seanhalle@0: reqData.sendPr = owningPr; seanhalle@0: reqData.sizeToMalloc = sizeToMalloc; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, owningPr ); seanhalle@0: seanhalle@0: return owningPr->dataRetFromReq; seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: /*Sends request to Master, which does the work of freeing seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__free( void *ptrToFree, SlaveVP *owningPr ) seanhalle@0: { VOMPSemReq reqData; seanhalle@0: seanhalle@0: reqData.reqType = free_req; seanhalle@0: reqData.sendPr = owningPr; seanhalle@0: reqData.ptrToFree = ptrToFree; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, owningPr ); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv, seanhalle@0: SlaveVP *newOwnerPr ) seanhalle@0: { seanhalle@0: //TODO: put in the ownership system that automatically frees when no seanhalle@0: // owners of data left -- will need keeper for keeping data around when seanhalle@0: // future created processors might need it but don't exist yet seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data ) seanhalle@0: { seanhalle@0: seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing ) seanhalle@0: { seanhalle@0: seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: /*Causes the VOMP system to remove internal ownership, so data won't be seanhalle@0: * freed when VOMP shuts down, and will persist in the external program. seanhalle@0: * seanhalle@0: *Must be called from the processor that currently owns the data. seanhalle@0: * seanhalle@0: *IMPL: Transferring ownership touches two different virtual processor's seanhalle@0: * state -- which means it has to be done carefully -- the VMS rules for seanhalle@0: * semantic layers say that a work-unit is only allowed to touch the seanhalle@0: * virtual processor it is part of, and that only a single work-unit per seanhalle@0: * virtual processor be assigned to a slave at a time. So, this has to seanhalle@0: * modify the virtual processor that owns the work-unit that called this seanhalle@0: * function, then create a request to have the other processor modified. seanhalle@0: *However, in this case, the TO processor is the outside, and transfers seanhalle@0: * are only allowed to be called by the giver-upper, so can mark caller of seanhalle@0: * this function as no longer owner, and return -- done. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__transfer_ownership_to_outside( void *data ) seanhalle@0: { seanhalle@0: //TODO: removeAllOwnersFrom( data ); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__send_of_type_to( SlaveVP *sendPr, void *msg, const int type, seanhalle@0: SlaveVP *receivePr) seanhalle@0: { VOMPSemReq reqData; seanhalle@0: seanhalle@0: reqData.receivePr = receivePr; seanhalle@0: reqData.sendPr = sendPr; seanhalle@0: reqData.reqType = send_type; seanhalle@0: reqData.msgType = type; seanhalle@0: reqData.msg = msg; seanhalle@0: reqData.nextReqInHashEntry = NULL; seanhalle@0: seanhalle@0: //On ownership -- remove inside the send and let ownership sit in limbo seanhalle@0: // as a potential in an entry in the hash table, when this receive msg seanhalle@0: // gets paired to a send, the ownership gets added to the receivePr -- seanhalle@0: // the next work-unit in the receivePr's trace will have ownership. seanhalle@0: VMS_WL__send_sem_request( &reqData, sendPr ); seanhalle@0: seanhalle@0: //When come back from suspend, no longer own data reachable from msg seanhalle@0: //TODO: release ownership here seanhalle@0: } seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr ) seanhalle@0: { VOMPSemReq reqData; seanhalle@0: seanhalle@0: //hash on the receiver, 'cause always know it, but sometimes want to seanhalle@0: // receive from anonymous sender seanhalle@0: seanhalle@0: reqData.receivePr = receivePr; seanhalle@0: reqData.sendPr = sendPr; seanhalle@0: reqData.reqType = send_from_to; seanhalle@0: reqData.msg = msg; seanhalle@0: reqData.nextReqInHashEntry = NULL; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, sendPr ); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: seanhalle@0: void * seanhalle@0: VOMP__receive_any_to( SlaveVP *receivePr ) seanhalle@0: { seanhalle@0: seanhalle@0: } seanhalle@0: seanhalle@0: void * seanhalle@0: VOMP__receive_type_to( const int type, SlaveVP *receivePr ) seanhalle@0: { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID); seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: reqData.receivePr = receivePr; seanhalle@0: reqData.reqType = receive_type; seanhalle@0: reqData.msgType = type; seanhalle@0: reqData.nextReqInHashEntry = NULL; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, receivePr ); seanhalle@0: seanhalle@0: return receivePr->dataRetFromReq; seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: seanhalle@0: /*Call this at point receiving virt pr wants in-coming data. seanhalle@0: * seanhalle@0: *The reason receivePr must call this is that it modifies the receivPr seanhalle@0: * loc structure directly -- and the VMS rules state a virtual processor seanhalle@0: * loc structure can only be modified by itself. seanhalle@0: */ seanhalle@0: void * seanhalle@0: VOMP__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr ) seanhalle@0: { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID); seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: //hash on the receiver, 'cause always know it, but sometimes want to seanhalle@0: // receive from anonymous sender seanhalle@0: seanhalle@0: reqData.receivePr = receivePr; seanhalle@0: reqData.sendPr = sendPr; seanhalle@0: reqData.reqType = receive_from_to; seanhalle@0: reqData.nextReqInHashEntry = NULL; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, receivePr ); seanhalle@0: seanhalle@0: return receivePr->dataRetFromReq; seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: //=========================================================================== seanhalle@0: // seanhalle@0: /*A function singleton is a function whose body executes exactly once, on a seanhalle@0: * single core, no matter how many times the fuction is called and no seanhalle@0: * matter how many cores or the timing of cores calling it. seanhalle@0: * seanhalle@0: *A data singleton is a ticket attached to data. That ticket can be used seanhalle@0: * to get the data through the function exactly once, no matter how many seanhalle@0: * times the data is given to the function, and no matter the timing of seanhalle@0: * trying to get the data through from different cores. seanhalle@0: */ seanhalle@0: seanhalle@0: /*asm function declarations*/ seanhalle@0: void asm_save_ret_to_singleton(VOMPSingleton *singletonPtrAddr); seanhalle@0: void asm_write_ret_from_singleton(VOMPSingleton *singletonPtrAddr); seanhalle@0: seanhalle@0: /*Fn singleton uses ID as index into array of singleton structs held in the seanhalle@0: * semantic environment. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__start_fn_singleton( int32 singletonID, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: // seanhalle@0: reqData.reqType = singleton_fn_start; seanhalle@0: reqData.singletonID = singletonID; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton seanhalle@0: { seanhalle@0: VOMPSemEnv *semEnv = VMS_int__give_sem_env_for( animPr ); seanhalle@0: asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); seanhalle@0: } seanhalle@0: } seanhalle@0: seanhalle@0: /*Data singleton hands addr of loc holding a pointer to a singleton struct. seanhalle@0: * The start_data_singleton makes the structure and puts its addr into the seanhalle@0: * location. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__start_data_singleton( VOMPSingleton **singletonAddr, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: if( *singletonAddr && (*singletonAddr)->hasFinished ) seanhalle@0: goto JmpToEndSingleton; seanhalle@0: seanhalle@0: reqData.reqType = singleton_data_start; seanhalle@0: reqData.singletonPtrAddr = singletonAddr; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr seanhalle@0: { //Assembly code changes the return addr on the stack to the one seanhalle@0: // saved into the singleton by the end-singleton-fn seanhalle@0: //The return addr is at 0x4(%%ebp) seanhalle@0: JmpToEndSingleton: seanhalle@0: asm_write_ret_from_singleton(*singletonAddr); seanhalle@0: } seanhalle@0: //now, simply return seanhalle@0: //will exit either from the start singleton call or the end-singleton call seanhalle@0: } seanhalle@0: seanhalle@0: /*Uses ID as index into array of flags. If flag already set, resumes from seanhalle@0: * end-label. Else, sets flag and resumes normally. seanhalle@0: * seanhalle@0: *Note, this call cannot be inlined because the instr addr at the label seanhalle@0: * inside is shared by all invocations of a given singleton ID. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__end_fn_singleton( int32 singletonID, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: //don't need this addr until after at least one singleton has reached seanhalle@0: // this function seanhalle@0: VOMPSemEnv *semEnv = VMS_int__give_sem_env_for( animPr ); seanhalle@0: asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); seanhalle@0: seanhalle@0: reqData.reqType = singleton_fn_end; seanhalle@0: reqData.singletonID = singletonID; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: seanhalle@0: EndSingletonInstrAddr: seanhalle@0: return; seanhalle@0: } seanhalle@0: seanhalle@0: void seanhalle@0: VOMP__end_data_singleton( VOMPSingleton **singletonPtrAddr, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: //don't need this addr until after singleton struct has reached seanhalle@0: // this function for first time seanhalle@0: //do assembly that saves the return addr of this fn call into the seanhalle@0: // data singleton -- that data-singleton can only be given to exactly seanhalle@0: // one instance in the code of this function. However, can use this seanhalle@0: // function in different places for different data-singletons. seanhalle@0: // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr; seanhalle@0: seanhalle@0: seanhalle@0: asm_save_ret_to_singleton(*singletonPtrAddr); seanhalle@0: seanhalle@0: reqData.reqType = singleton_data_end; seanhalle@0: reqData.singletonPtrAddr = singletonPtrAddr; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: } seanhalle@0: seanhalle@0: /*This executes the function in the masterVP, so it executes in isolation seanhalle@0: * from any other copies -- only one copy of the function can ever execute seanhalle@0: * at a time. seanhalle@0: * seanhalle@0: *It suspends to the master, and the request handler takes the function seanhalle@0: * pointer out of the request and calls it, then resumes the VP. seanhalle@0: *Only very short functions should be called this way -- for longer-running seanhalle@0: * isolation, use transaction-start and transaction-end, which run the code seanhalle@0: * between as work-code. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, seanhalle@0: void *data, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: // seanhalle@0: reqData.reqType = atomic; seanhalle@0: reqData.fnToExecInMaster = ptrToFnToExecInMaster; seanhalle@0: reqData.dataForFn = data; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: } seanhalle@0: seanhalle@0: seanhalle@0: /*This suspends to the master. seanhalle@0: *First, it looks at the VP's data, to see the highest transactionID that VP seanhalle@0: * already has entered. If the current ID is not larger, it throws an seanhalle@0: * exception stating a bug in the code. Otherwise it puts the current ID seanhalle@0: * there, and adds the ID to a linked list of IDs entered -- the list is seanhalle@0: * used to check that exits are properly ordered. seanhalle@0: *Next it is uses transactionID as index into an array of transaction seanhalle@0: * structures. seanhalle@0: *If the "VP_currently_executing" field is non-null, then put requesting VP seanhalle@0: * into queue in the struct. (At some point a holder will request seanhalle@0: * end-transaction, which will take this VP from the queue and resume it.) seanhalle@0: *If NULL, then write requesting into the field and resume. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__start_transaction( int32 transactionID, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: // seanhalle@0: reqData.sendPr = animPr; seanhalle@0: reqData.reqType = trans_start; seanhalle@0: reqData.transID = transactionID; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: } seanhalle@0: seanhalle@0: /*This suspends to the master, then uses transactionID as index into an seanhalle@0: * array of transaction structures. seanhalle@0: *It looks at VP_currently_executing to be sure it's same as requesting VP. seanhalle@0: * If different, throws an exception, stating there's a bug in the code. seanhalle@0: *Next it looks at the queue in the structure. seanhalle@0: *If it's empty, it sets VP_currently_executing field to NULL and resumes. seanhalle@0: *If something in, gets it, sets VP_currently_executing to that VP, then seanhalle@0: * resumes both. seanhalle@0: */ seanhalle@0: void seanhalle@0: VOMP__end_transaction( int32 transactionID, SlaveVP *animPr ) seanhalle@0: { seanhalle@0: VOMPSemReq reqData; seanhalle@0: seanhalle@0: // seanhalle@0: reqData.sendPr = animPr; seanhalle@0: reqData.reqType = trans_end; seanhalle@0: reqData.transID = transactionID; seanhalle@0: seanhalle@0: VMS_WL__send_sem_request( &reqData, animPr ); seanhalle@0: }