Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > DKU_impls > DKU__MC_shared_impl
diff DKU.c @ 0:9f2a7bd26dd9
Initial add -- code is straight copy of VSs implementation.. to be modified
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Mon, 27 Aug 2012 02:14:35 -0700 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/DKU.c Mon Aug 27 02:14:35 2012 -0700 1.3 @@ -0,0 +1,853 @@ 1.4 +/* 1.5 + * Copyright 2010 OpenSourceCodeStewardshipFoundation 1.6 + * 1.7 + * Licensed under BSD 1.8 + */ 1.9 + 1.10 +#include <stdio.h> 1.11 +#include <stdlib.h> 1.12 +#include <malloc.h> 1.13 + 1.14 +#include "Queue_impl/PrivateQueue.h" 1.15 +#include "Hash_impl/PrivateHash.h" 1.16 + 1.17 +#include "VSs.h" 1.18 +#include "Measurement/VSs_Counter_Recording.h" 1.19 + 1.20 +//========================================================================== 1.21 + 1.22 +void 1.23 +VSs__init(); 1.24 + 1.25 +void 1.26 +VSs__init_Helper(); 1.27 +//========================================================================== 1.28 + 1.29 + 1.30 + 1.31 +//=========================================================================== 1.32 + 1.33 + 1.34 +/*These are the library functions *called in the application* 1.35 + * 1.36 + *There's a pattern for the outside sequential code to interact with the 1.37 + * VMS_HW code. 1.38 + *The VMS_HW system is inside a boundary.. every VSs system is in its 1.39 + * own directory that contains the functions for each of the processor types. 1.40 + * One of the processor types is the "seed" processor that starts the 1.41 + * cascade of creating all the processors that do the work. 1.42 + *So, in the directory is a file called "EntryPoint.c" that contains the 1.43 + * function, named appropriately to the work performed, that the outside 1.44 + * sequential code calls. This function follows a pattern: 1.45 + *1) it calls VSs__init() 1.46 + *2) it creates the initial data for the seed processor, which is passed 1.47 + * in to the function 1.48 + *3) it creates the seed VSs processor, with the data to start it with. 1.49 + *4) it calls startVSsThenWaitUntilWorkDone 1.50 + *5) it gets the returnValue from the transfer struc and returns that 1.51 + * from the function 1.52 + * 1.53 + *For now, a new VSs system has to be created via VSs__init every 1.54 + * time an entry point function is called -- later, might add letting the 1.55 + * VSs system be created once, and let all the entry points just reuse 1.56 + * it -- want to be as simple as possible now, and see by using what makes 1.57 + * sense for later.. 1.58 + */ 1.59 + 1.60 + 1.61 + 1.62 +//=========================================================================== 1.63 + 1.64 +/*This is the "border crossing" function -- the thing that crosses from the 1.65 + * outside world, into the VMS_HW world. It initializes and starts up the 1.66 + * VMS system, then creates one processor from the specified function and 1.67 + * puts it into the readyQ. From that point, that one function is resp. 1.68 + * for creating all the other processors, that then create others, and so 1.69 + * forth. 1.70 + *When all the processors, including the seed, have dissipated, then this 1.71 + * function returns. The results will have been written by side-effect via 1.72 + * pointers read from, or written into initData. 1.73 + * 1.74 + *NOTE: no Threads should exist in the outside program that might touch 1.75 + * any of the data reachable from initData passed in to here 1.76 + */ 1.77 +void 1.78 +VSs__create_seed_slave_and_do_work( TopLevelFnPtr fnPtr, void *initData ) 1.79 + { VSsSemEnv *semEnv; 1.80 + SlaveVP *seedSlv; 1.81 + VSsSemData *semData; 1.82 + VSsTaskStub *threadTaskStub, *parentTaskStub; 1.83 + 1.84 + VSs__init(); //normal multi-thd 1.85 + 1.86 + semEnv = _VMSMasterEnv->semanticEnv; 1.87 + 1.88 + //VSs starts with one processor, which is put into initial environ, 1.89 + // and which then calls create() to create more, thereby expanding work 1.90 + seedSlv = VSs__create_slave_helper( fnPtr, initData, 1.91 + semEnv, semEnv->nextCoreToGetNewSlv++ ); 1.92 + 1.93 + //seed slave is a thread slave, so make a thread's task stub for it 1.94 + // and then make another to stand for the seed's parent task. Make 1.95 + // the parent be already ended, and have one child (the seed). This 1.96 + // will make the dissipate handler do the right thing when the seed 1.97 + // is dissipated. 1.98 + threadTaskStub = create_thread_task_stub( initData ); 1.99 + parentTaskStub = create_thread_task_stub( NULL ); 1.100 + parentTaskStub->isEnded = TRUE; 1.101 + parentTaskStub->numLiveChildThreads = 1; //so dissipate works for seed 1.102 + threadTaskStub->parentTaskStub = parentTaskStub; 1.103 + 1.104 + semData = (VSsSemData *)seedSlv->semanticData; 1.105 + //seedVP is a thread, so has a permanent task 1.106 + semData->needsTaskAssigned = FALSE; 1.107 + semData->taskStub = threadTaskStub; 1.108 + semData->slaveType = ThreadSlv; 1.109 + 1.110 + resume_slaveVP( seedSlv, semEnv ); //returns right away, just queues Slv 1.111 + 1.112 + VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd 1.113 + 1.114 + VSs__cleanup_after_shutdown(); 1.115 + } 1.116 + 1.117 + 1.118 +int32 1.119 +VSs__giveMinWorkUnitCycles( float32 percentOverhead ) 1.120 + { 1.121 + return MIN_WORK_UNIT_CYCLES; 1.122 + } 1.123 + 1.124 +int32 1.125 +VSs__giveIdealNumWorkUnits() 1.126 + { 1.127 + return NUM_ANIM_SLOTS * NUM_CORES; 1.128 + } 1.129 + 1.130 +int32 1.131 +VSs__give_number_of_cores_to_schedule_onto() 1.132 + { 1.133 + return NUM_CORES; 1.134 + } 1.135 + 1.136 +/*For now, use TSC -- later, make these two macros with assembly that first 1.137 + * saves jump point, and second jumps back several times to get reliable time 1.138 + */ 1.139 +void 1.140 +VSs__start_primitive() 1.141 + { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))-> 1.142 + primitiveStartTime ); 1.143 + } 1.144 + 1.145 +/*Just quick and dirty for now -- make reliable later 1.146 + * will want this to jump back several times -- to be sure cache is warm 1.147 + * because don't want comm time included in calc-time measurement -- and 1.148 + * also to throw out any "weird" values due to OS interrupt or TSC rollover 1.149 + */ 1.150 +int32 1.151 +VSs__end_primitive_and_give_cycles() 1.152 + { int32 endTime, startTime; 1.153 + //TODO: fix by repeating time-measurement 1.154 + saveLowTimeStampCountInto( endTime ); 1.155 + startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime; 1.156 + return (endTime - startTime); 1.157 + } 1.158 + 1.159 +//=========================================================================== 1.160 + 1.161 +/*Initializes all the data-structures for a VSs system -- but doesn't 1.162 + * start it running yet! 1.163 + * 1.164 + *This runs in the main thread -- before VMS starts up 1.165 + * 1.166 + *This sets up the semantic layer over the VMS system 1.167 + * 1.168 + *First, calls VMS_Setup, then creates own environment, making it ready 1.169 + * for creating the seed processor and then starting the work. 1.170 + */ 1.171 +void 1.172 +VSs__init() 1.173 + { 1.174 + VMS_SS__init(); 1.175 + //masterEnv, a global var, now is partially set up by init_VMS 1.176 + // after this, have VMS_int__malloc and VMS_int__free available 1.177 + 1.178 + VSs__init_Helper(); 1.179 + } 1.180 + 1.181 + 1.182 +void idle_fn(void* data, SlaveVP *animatingSlv){ 1.183 + while(1){ 1.184 + VMS_int__suspend_slaveVP_and_send_req(animatingSlv); 1.185 + } 1.186 +} 1.187 + 1.188 +void 1.189 +VSs__init_Helper() 1.190 + { VSsSemEnv *semanticEnv; 1.191 + int32 i, coreNum, slotNum; 1.192 + VSsSemData *semData; 1.193 + 1.194 + //Hook up the semantic layer's plug-ins to the Master virt procr 1.195 + _VMSMasterEnv->requestHandler = &VSs__Request_Handler; 1.196 + _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot; 1.197 + 1.198 + //create the semantic layer's environment (all its data) and add to 1.199 + // the master environment 1.200 + semanticEnv = VMS_int__malloc( sizeof( VSsSemEnv ) ); 1.201 + _VMSMasterEnv->semanticEnv = semanticEnv; 1.202 + 1.203 + #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS 1.204 + _VMSMasterEnv->counterHandler = &VSs__counter_handler; 1.205 + VSs__init_counter_data_structs(); 1.206 + #endif 1.207 + 1.208 + semanticEnv->shutdownInitiated = FALSE; 1.209 + semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) ); 1.210 + //For each animation slot, there is an idle slave, and an initial 1.211 + // slave assigned as the current-task-slave. Create them here. 1.212 + SlaveVP *idleSlv, *slotTaskSlv; 1.213 + for( coreNum = 0; coreNum < NUM_CORES; coreNum++ ) 1.214 + { semanticEnv->coreIsDone[coreNum] = FALSE; //use during shutdown 1.215 + 1.216 + for( slotNum = 0; slotNum < NUM_ANIM_SLOTS; ++slotNum ) 1.217 + { idleSlv = VSs__create_slave_helper( &idle_fn, NULL, semanticEnv, 0); 1.218 + idleSlv->coreAnimatedBy = coreNum; 1.219 + idleSlv->animSlotAssignedTo = 1.220 + _VMSMasterEnv->allAnimSlots[coreNum][slotNum]; 1.221 + semanticEnv->idleSlv[coreNum][slotNum] = idleSlv; 1.222 + 1.223 + slotTaskSlv = VSs__create_slave_helper( &idle_fn, NULL, semanticEnv, 0); 1.224 + slotTaskSlv->coreAnimatedBy = coreNum; 1.225 + slotTaskSlv->animSlotAssignedTo = 1.226 + _VMSMasterEnv->allAnimSlots[coreNum][slotNum]; 1.227 + 1.228 + semData = slotTaskSlv->semanticData; 1.229 + semData->needsTaskAssigned = TRUE; 1.230 + semData->slaveType = SlotTaskSlv; 1.231 + semanticEnv->slotTaskSlvs[coreNum][slotNum] = slotTaskSlv; 1.232 + } 1.233 + } 1.234 + 1.235 + //create the ready queues, hash tables used for matching and so forth 1.236 + semanticEnv->slavesReadyToResumeQ = makeVMSQ(); 1.237 + semanticEnv->freeExtraTaskSlvQ = makeVMSQ(); 1.238 + semanticEnv->taskReadyQ = makeVMSQ(); 1.239 + 1.240 + semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free ); 1.241 + semanticEnv->commHashTbl = makeHashTable32( 16, &VMS_int__free ); 1.242 + 1.243 + semanticEnv->nextCoreToGetNewSlv = 0; 1.244 + 1.245 + 1.246 + //TODO: bug -- turn these arrays into dyn arrays to eliminate limit 1.247 + //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( ); 1.248 + //semanticEnv->transactionStrucs = makeDynArrayInfo( ); 1.249 + for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ ) 1.250 + { 1.251 + semanticEnv->fnSingletons[i].endInstrAddr = NULL; 1.252 + semanticEnv->fnSingletons[i].hasBeenStarted = FALSE; 1.253 + semanticEnv->fnSingletons[i].hasFinished = FALSE; 1.254 + semanticEnv->fnSingletons[i].waitQ = makeVMSQ(); 1.255 + semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ(); 1.256 + } 1.257 + 1.258 + semanticEnv->numLiveExtraTaskSlvs = 0; //must be last 1.259 + semanticEnv->numLiveThreadSlvs = 1; //must be last, counts the seed 1.260 + 1.261 + #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC 1.262 + semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128); 1.263 + semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128); 1.264 + semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128); 1.265 + semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128); 1.266 + semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8); 1.267 + 1.268 + semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128); 1.269 + memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit))); 1.270 + #endif 1.271 + } 1.272 + 1.273 + 1.274 +/*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown 1.275 + */ 1.276 +void 1.277 +VSs__cleanup_after_shutdown() 1.278 + { VSsSemEnv *semanticEnv; 1.279 + 1.280 + semanticEnv = _VMSMasterEnv->semanticEnv; 1.281 + 1.282 + #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC 1.283 + //UCC 1.284 + FILE* output; 1.285 + int n; 1.286 + char filename[255]; 1.287 + for(n=0;n<255;n++) 1.288 + { 1.289 + sprintf(filename, "./counters/UCC.%d",n); 1.290 + output = fopen(filename,"r"); 1.291 + if(output) 1.292 + { 1.293 + fclose(output); 1.294 + }else{ 1.295 + break; 1.296 + } 1.297 + } 1.298 + if(n<255){ 1.299 + printf("Saving UCC to File: %s ...\n", filename); 1.300 + output = fopen(filename,"w+"); 1.301 + if(output!=NULL){ 1.302 + set_dependency_file(output); 1.303 + //fprintf(output,"digraph Dependencies {\n"); 1.304 + //set_dot_file(output); 1.305 + //FIXME: first line still depends on counters being enabled, replace w/ unit struct! 1.306 + //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); 1.307 + forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file); 1.308 + forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); 1.309 + forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); 1.310 + forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file); 1.311 + //fprintf(output,"}\n"); 1.312 + fflush(output); 1.313 + 1.314 + } else 1.315 + printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); 1.316 + } else { 1.317 + printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); 1.318 + } 1.319 + //Loop Graph 1.320 + for(n=0;n<255;n++) 1.321 + { 1.322 + sprintf(filename, "./counters/LoopGraph.%d",n); 1.323 + output = fopen(filename,"r"); 1.324 + if(output) 1.325 + { 1.326 + fclose(output); 1.327 + }else{ 1.328 + break; 1.329 + } 1.330 + } 1.331 + if(n<255){ 1.332 + printf("Saving LoopGraph to File: %s ...\n", filename); 1.333 + output = fopen(filename,"w+"); 1.334 + if(output!=NULL){ 1.335 + set_dependency_file(output); 1.336 + //fprintf(output,"digraph Dependencies {\n"); 1.337 + //set_dot_file(output); 1.338 + //FIXME: first line still depends on counters being enabled, replace w/ unit struct! 1.339 + //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); 1.340 + forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file ); 1.341 + forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); 1.342 + forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); 1.343 + forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file ); 1.344 + forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file ); 1.345 + //fprintf(output,"}\n"); 1.346 + fflush(output); 1.347 + 1.348 + } else 1.349 + printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); 1.350 + } else { 1.351 + printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); 1.352 + } 1.353 + 1.354 + 1.355 + freeListOfArrays(semanticEnv->unitList); 1.356 + freeListOfArrays(semanticEnv->commDependenciesList); 1.357 + freeListOfArrays(semanticEnv->ctlDependenciesList); 1.358 + freeListOfArrays(semanticEnv->dynDependenciesList); 1.359 + 1.360 + #endif 1.361 +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS 1.362 + for(n=0;n<255;n++) 1.363 + { 1.364 + sprintf(filename, "./counters/Counters.%d.csv",n); 1.365 + output = fopen(filename,"r"); 1.366 + if(output) 1.367 + { 1.368 + fclose(output); 1.369 + }else{ 1.370 + break; 1.371 + } 1.372 + } 1.373 + if(n<255){ 1.374 + printf("Saving Counter measurements to File: %s ...\n", filename); 1.375 + output = fopen(filename,"w+"); 1.376 + if(output!=NULL){ 1.377 + set_counter_file(output); 1.378 + int i; 1.379 + for(i=0;i<NUM_CORES;i++){ 1.380 + forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file ); 1.381 + fflush(output); 1.382 + } 1.383 + 1.384 + } else 1.385 + printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); 1.386 + } else { 1.387 + printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); 1.388 + } 1.389 + 1.390 +#endif 1.391 +/* It's all allocated inside VMS's big chunk -- that's about to be freed, so 1.392 + * nothing to do here 1.393 + 1.394 + 1.395 + for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) 1.396 + { 1.397 + VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData ); 1.398 + VMS_int__free( semanticEnv->readyVPQs[coreIdx] ); 1.399 + } 1.400 + VMS_int__free( semanticEnv->readyVPQs ); 1.401 + 1.402 + freeHashTable( semanticEnv->commHashTbl ); 1.403 + VMS_int__free( _VMSMasterEnv->semanticEnv ); 1.404 + */ 1.405 + VMS_SS__cleanup_at_end_of_shutdown(); 1.406 + } 1.407 + 1.408 + 1.409 +//=========================================================================== 1.410 + 1.411 +SlaveVP * 1.412 +VSs__create_thread( TopLevelFnPtr fnPtr, void *initData, 1.413 + SlaveVP *creatingThd ) 1.414 + { VSsSemReq reqData; 1.415 + 1.416 + //the semantic request data is on the stack and disappears when this 1.417 + // call returns -- it's guaranteed to remain in the VP's stack for as 1.418 + // long as the VP is suspended. 1.419 + reqData.reqType = 0; //know type because in a VMS create req 1.420 + reqData.fnPtr = fnPtr; 1.421 + reqData.initData = initData; 1.422 + reqData.callingSlv = creatingThd; 1.423 + 1.424 + VMS_WL__send_create_slaveVP_req( &reqData, creatingThd ); 1.425 + 1.426 + return creatingThd->dataRetFromReq; 1.427 + } 1.428 + 1.429 +/*This is always the last thing done in the code animated by a thread VP. 1.430 + * Normally, this would be the last line of the thread's top level function. 1.431 + * But, if the thread exits from any point, it has to do so by calling 1.432 + * this. 1.433 + * 1.434 + *It simply sends a dissipate request, which handles all the state cleanup. 1.435 + */ 1.436 +void 1.437 +VSs__end_thread( SlaveVP *thdToEnd ) 1.438 + { VSsSemData *semData; 1.439 + 1.440 + VMS_WL__send_dissipate_req( thdToEnd ); 1.441 + } 1.442 + 1.443 + 1.444 + 1.445 +//=========================================================================== 1.446 + 1.447 + 1.448 +//======================= task submit and end ============================== 1.449 +/* 1.450 + */ 1.451 +void 1.452 +VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv) 1.453 + { VSsSemReq reqData; 1.454 + 1.455 + reqData.reqType = submit_task; 1.456 + 1.457 + reqData.taskType = taskType; 1.458 + reqData.args = args; 1.459 + reqData.callingSlv = animSlv; 1.460 + 1.461 + reqData.taskID = NULL; 1.462 + 1.463 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.464 + } 1.465 + 1.466 +inline int32 * 1.467 +VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv ) 1.468 + { int32 *taskID; 1.469 + 1.470 + taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) ); 1.471 + taskID[0] = numInts; 1.472 + return taskID; 1.473 + } 1.474 + 1.475 +void 1.476 +VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID, 1.477 + SlaveVP *animSlv) 1.478 + { VSsSemReq reqData; 1.479 + 1.480 + reqData.reqType = submit_task; 1.481 + 1.482 + reqData.taskType = taskType; 1.483 + reqData.args = args; 1.484 + reqData.taskID = taskID; 1.485 + reqData.callingSlv = animSlv; 1.486 + 1.487 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.488 + } 1.489 + 1.490 + 1.491 +/*This call is the last to happen in every task. It causes the slave to 1.492 + * suspend and get the next task out of the task-queue. Notice there is no 1.493 + * assigner here.. only one slave, no slave ReadyQ, and so on.. 1.494 + *Can either make the assigner take the next task out of the taskQ, or can 1.495 + * leave all as it is, and make task-end take the next task. 1.496 + *Note: this fits the case in the new VMS for no-context tasks, so will use 1.497 + * the built-in taskQ of new VMS, and should be local and much faster. 1.498 + * 1.499 + *The task-stub is saved in the animSlv, so the request handler will get it 1.500 + * from there, along with the task-type which has arg types, and so on.. 1.501 + * 1.502 + * NOTE: if want, don't need to send the animating SlaveVP around.. 1.503 + * instead, can make a single slave per core, and coreCtrlr looks up the 1.504 + * slave from having the core number. 1.505 + * 1.506 + *But, to stay compatible with all the other VMS languages, leave it in.. 1.507 + */ 1.508 +void 1.509 +VSs__end_task( SlaveVP *animSlv ) 1.510 + { VSsSemReq reqData; 1.511 + 1.512 + reqData.reqType = end_task; 1.513 + reqData.callingSlv = animSlv; 1.514 + 1.515 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.516 + } 1.517 + 1.518 + 1.519 +void 1.520 +VSs__taskwait(SlaveVP *animSlv) 1.521 +{ 1.522 + VSsSemReq reqData; 1.523 + 1.524 + reqData.reqType = taskwait; 1.525 + reqData.callingSlv = animSlv; 1.526 + 1.527 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.528 +} 1.529 + 1.530 + 1.531 + 1.532 +//========================== send and receive ============================ 1.533 +// 1.534 + 1.535 +inline int32 * 1.536 +VSs__give_self_taskID( SlaveVP *animSlv ) 1.537 + { 1.538 + return ((VSsSemData*)animSlv->semanticData)->taskStub->taskID; 1.539 + } 1.540 + 1.541 +//================================ send =================================== 1.542 + 1.543 +void 1.544 +VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID, 1.545 + SlaveVP *senderSlv ) 1.546 + { VSsSemReq reqData; 1.547 + 1.548 + reqData.reqType = send_type_to; 1.549 + 1.550 + reqData.msg = msg; 1.551 + reqData.msgType = type; 1.552 + reqData.receiverID = receiverID; 1.553 + reqData.senderSlv = senderSlv; 1.554 + 1.555 + reqData.nextReqInHashEntry = NULL; 1.556 + 1.557 + VMS_WL__send_sem_request( &reqData, senderSlv ); 1.558 + 1.559 + //When come back from suspend, no longer own data reachable from msg 1.560 + } 1.561 + 1.562 +void 1.563 +VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv ) 1.564 + { VSsSemReq reqData; 1.565 + 1.566 + reqData.reqType = send_from_to; 1.567 + 1.568 + reqData.msg = msg; 1.569 + reqData.senderID = senderID; 1.570 + reqData.receiverID = receiverID; 1.571 + reqData.senderSlv = senderSlv; 1.572 + 1.573 + reqData.nextReqInHashEntry = NULL; 1.574 + 1.575 + VMS_WL__send_sem_request( &reqData, senderSlv ); 1.576 + } 1.577 + 1.578 + 1.579 +//================================ receive ================================ 1.580 + 1.581 +/*The "type" version of send and receive creates a many-to-one relationship. 1.582 + * The sender is anonymous, and many sends can stack up, waiting to be 1.583 + * received. The same receiver can also have send from-to's 1.584 + * waiting for it, and those will be kept separate from the "type" 1.585 + * messages. 1.586 + */ 1.587 +void * 1.588 +VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv ) 1.589 + { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] ); 1.590 + VSsSemReq reqData; 1.591 + 1.592 + reqData.reqType = receive_type_to; 1.593 + 1.594 + reqData.msgType = type; 1.595 + reqData.receiverID = receiverID; 1.596 + reqData.receiverSlv = receiverSlv; 1.597 + 1.598 + reqData.nextReqInHashEntry = NULL; 1.599 + 1.600 + VMS_WL__send_sem_request( &reqData, receiverSlv ); 1.601 + 1.602 + return receiverSlv->dataRetFromReq; 1.603 + } 1.604 + 1.605 + 1.606 + 1.607 +/*Call this at the point a receiving task wants in-coming data. 1.608 + * Use this from-to form when know senderID -- it makes a direct channel 1.609 + * between sender and receiver. 1.610 + */ 1.611 +void * 1.612 +VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv ) 1.613 + { 1.614 + VSsSemReq reqData; 1.615 + 1.616 + reqData.reqType = receive_from_to; 1.617 + 1.618 + reqData.senderID = senderID; 1.619 + reqData.receiverID = receiverID; 1.620 + reqData.receiverSlv = receiverSlv; 1.621 + 1.622 + reqData.nextReqInHashEntry = NULL; 1.623 + DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]); 1.624 + 1.625 + VMS_WL__send_sem_request( &reqData, receiverSlv ); 1.626 + 1.627 + return receiverSlv->dataRetFromReq; 1.628 + } 1.629 + 1.630 + 1.631 + 1.632 + 1.633 +//========================================================================== 1.634 +// 1.635 +/*A function singleton is a function whose body executes exactly once, on a 1.636 + * single core, no matter how many times the fuction is called and no 1.637 + * matter how many cores or the timing of cores calling it. 1.638 + * 1.639 + *A data singleton is a ticket attached to data. That ticket can be used 1.640 + * to get the data through the function exactly once, no matter how many 1.641 + * times the data is given to the function, and no matter the timing of 1.642 + * trying to get the data through from different cores. 1.643 + */ 1.644 + 1.645 +/*asm function declarations*/ 1.646 +void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr); 1.647 +void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr); 1.648 + 1.649 +/*Fn singleton uses ID as index into array of singleton structs held in the 1.650 + * semantic environment. 1.651 + */ 1.652 +void 1.653 +VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv ) 1.654 + { 1.655 + VSsSemReq reqData; 1.656 + 1.657 + // 1.658 + reqData.reqType = singleton_fn_start; 1.659 + reqData.singletonID = singletonID; 1.660 + 1.661 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.662 + if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton 1.663 + { 1.664 + VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv ); 1.665 + asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); 1.666 + } 1.667 + } 1.668 + 1.669 +/*Data singleton hands addr of loc holding a pointer to a singleton struct. 1.670 + * The start_data_singleton makes the structure and puts its addr into the 1.671 + * location. 1.672 + */ 1.673 +void 1.674 +VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv ) 1.675 + { 1.676 + VSsSemReq reqData; 1.677 + 1.678 + if( *singletonAddr && (*singletonAddr)->hasFinished ) 1.679 + goto JmpToEndSingleton; 1.680 + 1.681 + reqData.reqType = singleton_data_start; 1.682 + reqData.singletonPtrAddr = singletonAddr; 1.683 + 1.684 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.685 + if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr 1.686 + { //Assembly code changes the return addr on the stack to the one 1.687 + // saved into the singleton by the end-singleton-fn 1.688 + //The return addr is at 0x4(%%ebp) 1.689 + JmpToEndSingleton: 1.690 + asm_write_ret_from_singleton(*singletonAddr); 1.691 + } 1.692 + //now, simply return 1.693 + //will exit either from the start singleton call or the end-singleton call 1.694 + } 1.695 + 1.696 +/*Uses ID as index into array of flags. If flag already set, resumes from 1.697 + * end-label. Else, sets flag and resumes normally. 1.698 + * 1.699 + *Note, this call cannot be inlined because the instr addr at the label 1.700 + * inside is shared by all invocations of a given singleton ID. 1.701 + */ 1.702 +void 1.703 +VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv ) 1.704 + { 1.705 + VSsSemReq reqData; 1.706 + 1.707 + //don't need this addr until after at least one singleton has reached 1.708 + // this function 1.709 + VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv ); 1.710 + asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); 1.711 + 1.712 + reqData.reqType = singleton_fn_end; 1.713 + reqData.singletonID = singletonID; 1.714 + 1.715 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.716 + 1.717 +EndSingletonInstrAddr: 1.718 + return; 1.719 + } 1.720 + 1.721 +void 1.722 +VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv ) 1.723 + { 1.724 + VSsSemReq reqData; 1.725 + 1.726 + //don't need this addr until after singleton struct has reached 1.727 + // this function for first time 1.728 + //do assembly that saves the return addr of this fn call into the 1.729 + // data singleton -- that data-singleton can only be given to exactly 1.730 + // one instance in the code of this function. However, can use this 1.731 + // function in different places for different data-singletons. 1.732 +// (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr; 1.733 + 1.734 + 1.735 + asm_save_ret_to_singleton(*singletonPtrAddr); 1.736 + 1.737 + reqData.reqType = singleton_data_end; 1.738 + reqData.singletonPtrAddr = singletonPtrAddr; 1.739 + 1.740 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.741 + } 1.742 + 1.743 +/*This executes the function in the masterVP, so it executes in isolation 1.744 + * from any other copies -- only one copy of the function can ever execute 1.745 + * at a time. 1.746 + * 1.747 + *It suspends to the master, and the request handler takes the function 1.748 + * pointer out of the request and calls it, then resumes the VP. 1.749 + *Only very short functions should be called this way -- for longer-running 1.750 + * isolation, use transaction-start and transaction-end, which run the code 1.751 + * between as work-code. 1.752 + */ 1.753 +void 1.754 +VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, 1.755 + void *data, SlaveVP *animSlv ) 1.756 + { 1.757 + VSsSemReq reqData; 1.758 + 1.759 + // 1.760 + reqData.reqType = atomic; 1.761 + reqData.fnToExecInMaster = ptrToFnToExecInMaster; 1.762 + reqData.dataForFn = data; 1.763 + 1.764 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.765 + } 1.766 + 1.767 + 1.768 +/*This suspends to the master. 1.769 + *First, it looks at the VP's data, to see the highest transactionID that VP 1.770 + * already has entered. If the current ID is not larger, it throws an 1.771 + * exception stating a bug in the code. Otherwise it puts the current ID 1.772 + * there, and adds the ID to a linked list of IDs entered -- the list is 1.773 + * used to check that exits are properly ordered. 1.774 + *Next it is uses transactionID as index into an array of transaction 1.775 + * structures. 1.776 + *If the "VP_currently_executing" field is non-null, then put requesting VP 1.777 + * into queue in the struct. (At some point a holder will request 1.778 + * end-transaction, which will take this VP from the queue and resume it.) 1.779 + *If NULL, then write requesting into the field and resume. 1.780 + */ 1.781 +void 1.782 +VSs__start_transaction( int32 transactionID, SlaveVP *animSlv ) 1.783 + { 1.784 + VSsSemReq reqData; 1.785 + 1.786 + // 1.787 + reqData.callingSlv = animSlv; 1.788 + reqData.reqType = trans_start; 1.789 + reqData.transID = transactionID; 1.790 + 1.791 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.792 + } 1.793 + 1.794 +/*This suspends to the master, then uses transactionID as index into an 1.795 + * array of transaction structures. 1.796 + *It looks at VP_currently_executing to be sure it's same as requesting VP. 1.797 + * If different, throws an exception, stating there's a bug in the code. 1.798 + *Next it looks at the queue in the structure. 1.799 + *If it's empty, it sets VP_currently_executing field to NULL and resumes. 1.800 + *If something in, gets it, sets VP_currently_executing to that VP, then 1.801 + * resumes both. 1.802 + */ 1.803 +void 1.804 +VSs__end_transaction( int32 transactionID, SlaveVP *animSlv ) 1.805 + { 1.806 + VSsSemReq reqData; 1.807 + 1.808 + // 1.809 + reqData.callingSlv = animSlv; 1.810 + reqData.reqType = trans_end; 1.811 + reqData.transID = transactionID; 1.812 + 1.813 + VMS_WL__send_sem_request( &reqData, animSlv ); 1.814 + } 1.815 + 1.816 +//======================== Internal ================================== 1.817 +/* 1.818 + */ 1.819 +SlaveVP * 1.820 +VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData, 1.821 + SlaveVP *creatingSlv ) 1.822 + { VSsSemReq reqData; 1.823 + 1.824 + //the semantic request data is on the stack and disappears when this 1.825 + // call returns -- it's guaranteed to remain in the VP's stack for as 1.826 + // long as the VP is suspended. 1.827 + reqData.reqType = 0; //know type because in a VMS create req 1.828 + reqData.coreToAssignOnto = -1; //means round-robin assign 1.829 + reqData.fnPtr = fnPtr; 1.830 + reqData.initData = initData; 1.831 + reqData.callingSlv = creatingSlv; 1.832 + 1.833 + VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv ); 1.834 + 1.835 + return creatingSlv->dataRetFromReq; 1.836 + } 1.837 + 1.838 +SlaveVP * 1.839 +VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData, 1.840 + SlaveVP *creatingSlv, int32 coreToAssignOnto ) 1.841 + { VSsSemReq reqData; 1.842 + 1.843 + //the semantic request data is on the stack and disappears when this 1.844 + // call returns -- it's guaranteed to remain in the VP's stack for as 1.845 + // long as the VP is suspended. 1.846 + reqData.reqType = create_slave_w_aff; //not used, May 2012 1.847 + reqData.coreToAssignOnto = coreToAssignOnto; 1.848 + reqData.fnPtr = fnPtr; 1.849 + reqData.initData = initData; 1.850 + reqData.callingSlv = creatingSlv; 1.851 + 1.852 + VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv ); 1.853 + 1.854 + return creatingSlv->dataRetFromReq; 1.855 + } 1.856 +
