Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VSs_impls > VSs__MC_shared_impl
diff VSs.c @ 0:67a3a05a39c0
Initial add -- copied code, just junk still
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Wed, 23 May 2012 13:17:07 -0700 |
| parents | |
| children | f2ed1c379fe7 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/VSs.c Wed May 23 13:17:07 2012 -0700 1.3 @@ -0,0 +1,772 @@ 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 "VOMP.h" 1.18 +#include "VOMP_Counter_Recording.h" 1.19 + 1.20 +//========================================================================== 1.21 + 1.22 +void 1.23 +VOMP__init(); 1.24 + 1.25 +void 1.26 +VOMP__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 VOMP 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 VOMP__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 VOMP processor, with the data to start it with. 1.49 + *4) it calls startVOMPThenWaitUntilWorkDone 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 VOMP system has to be created via VOMP__init every 1.54 + * time an entry point function is called -- later, might add letting the 1.55 + * VOMP 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 +VOMP__create_seed_procr_and_do_work( TopLevelFnPtr fnPtr, void *initData ) 1.79 + { VOMPSemEnv *semEnv; 1.80 + SlaveVP *seedPr; 1.81 + 1.82 + VOMP__init(); //normal multi-thd 1.83 + 1.84 + semEnv = _VMSMasterEnv->semanticEnv; 1.85 + 1.86 + //VOMP starts with one processor, which is put into initial environ, 1.87 + // and which then calls create() to create more, thereby expanding work 1.88 + seedPr = VOMP__create_procr_helper( fnPtr, initData, 1.89 + semEnv, semEnv->nextCoreToGetNewPr++ ); 1.90 + 1.91 + resume_slaveVP( seedPr, semEnv ); 1.92 + 1.93 + VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd 1.94 + 1.95 + VOMP__cleanup_after_shutdown(); 1.96 + } 1.97 + 1.98 + 1.99 +int32 1.100 +VOMP__giveMinWorkUnitCycles( float32 percentOverhead ) 1.101 + { 1.102 + return MIN_WORK_UNIT_CYCLES; 1.103 + } 1.104 + 1.105 +int32 1.106 +VOMP__giveIdealNumWorkUnits() 1.107 + { 1.108 + return NUM_ANIM_SLOTS * NUM_CORES; 1.109 + } 1.110 + 1.111 +int32 1.112 +VOMP__give_number_of_cores_to_schedule_onto() 1.113 + { 1.114 + return NUM_CORES; 1.115 + } 1.116 + 1.117 +/*For now, use TSC -- later, make these two macros with assembly that first 1.118 + * saves jump point, and second jumps back several times to get reliable time 1.119 + */ 1.120 +void 1.121 +VOMP__start_primitive() 1.122 + { saveLowTimeStampCountInto( ((VOMPSemEnv *)(_VMSMasterEnv->semanticEnv))-> 1.123 + primitiveStartTime ); 1.124 + } 1.125 + 1.126 +/*Just quick and dirty for now -- make reliable later 1.127 + * will want this to jump back several times -- to be sure cache is warm 1.128 + * because don't want comm time included in calc-time measurement -- and 1.129 + * also to throw out any "weird" values due to OS interrupt or TSC rollover 1.130 + */ 1.131 +int32 1.132 +VOMP__end_primitive_and_give_cycles() 1.133 + { int32 endTime, startTime; 1.134 + //TODO: fix by repeating time-measurement 1.135 + saveLowTimeStampCountInto( endTime ); 1.136 + startTime =((VOMPSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime; 1.137 + return (endTime - startTime); 1.138 + } 1.139 + 1.140 +//=========================================================================== 1.141 + 1.142 +/*Initializes all the data-structures for a VOMP system -- but doesn't 1.143 + * start it running yet! 1.144 + * 1.145 + *This runs in the main thread -- before VMS starts up 1.146 + * 1.147 + *This sets up the semantic layer over the VMS system 1.148 + * 1.149 + *First, calls VMS_Setup, then creates own environment, making it ready 1.150 + * for creating the seed processor and then starting the work. 1.151 + */ 1.152 +void 1.153 +VOMP__init() 1.154 + { 1.155 + VMS_SS__init(); 1.156 + //masterEnv, a global var, now is partially set up by init_VMS 1.157 + // after this, have VMS_int__malloc and VMS_int__free available 1.158 + 1.159 + VOMP__init_Helper(); 1.160 + } 1.161 + 1.162 + 1.163 +void idle_fn(void* data, SlaveVP *animatingSlv){ 1.164 + while(1){ 1.165 + VMS_int__suspend_slaveVP_and_send_req(animatingSlv); 1.166 + } 1.167 +} 1.168 + 1.169 +void 1.170 +VOMP__init_Helper() 1.171 + { VOMPSemEnv *semanticEnv; 1.172 + PrivQueueStruc **readyVPQs; 1.173 + int coreIdx, i, j; 1.174 + 1.175 + //Hook up the semantic layer's plug-ins to the Master virt procr 1.176 + _VMSMasterEnv->requestHandler = &VOMP__Request_Handler; 1.177 + _VMSMasterEnv->slaveAssigner = &VOMP__assign_slaveVP_to_slot; 1.178 + #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS 1.179 + _VMSMasterEnv->counterHandler = &VOMP__counter_handler; 1.180 + #endif 1.181 + 1.182 + //create the semantic layer's environment (all its data) and add to 1.183 + // the master environment 1.184 + semanticEnv = VMS_int__malloc( sizeof( VOMPSemEnv ) ); 1.185 + _VMSMasterEnv->semanticEnv = semanticEnv; 1.186 + 1.187 + #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS 1.188 + VOMP__init_counter_data_structs(); 1.189 + #endif 1.190 + semanticEnv->shutdownInitiated = FALSE; 1.191 + for(i=0;i<NUM_CORES;++i){ 1.192 + for(j=0;j<NUM_ANIM_SLOTS;++j){ 1.193 + semanticEnv->idlePr[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL); 1.194 + semanticEnv->idlePr[i][j]->coreAnimatedBy = i; 1.195 + } 1.196 + } 1.197 + 1.198 + #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC 1.199 + semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128); 1.200 + semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128); 1.201 + semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128); 1.202 + semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128); 1.203 + semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8); 1.204 + 1.205 + semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128); 1.206 + memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit))); 1.207 + #endif 1.208 + 1.209 + //create the ready queue, hash tables used for pairing send to receive 1.210 + // and so forth 1.211 + //TODO: add hash tables for pairing sends with receives, and 1.212 + // initialize the data ownership system 1.213 + readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) ); 1.214 + 1.215 + for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) 1.216 + { 1.217 + readyVPQs[ coreIdx ] = makeVMSQ(); 1.218 + } 1.219 + 1.220 + semanticEnv->readyVPQs = readyVPQs; 1.221 + 1.222 + semanticEnv->nextCoreToGetNewPr = 0; 1.223 + semanticEnv->numSlaveVP = 0; 1.224 + 1.225 + semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big 1.226 + 1.227 + //TODO: bug -- turn these arrays into dyn arrays to eliminate limit 1.228 + //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( ); 1.229 + //semanticEnv->transactionStrucs = makeDynArrayInfo( ); 1.230 + for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ ) 1.231 + { 1.232 + semanticEnv->fnSingletons[i].endInstrAddr = NULL; 1.233 + semanticEnv->fnSingletons[i].hasBeenStarted = FALSE; 1.234 + semanticEnv->fnSingletons[i].hasFinished = FALSE; 1.235 + semanticEnv->fnSingletons[i].waitQ = makeVMSQ(); 1.236 + semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ(); 1.237 + } 1.238 + } 1.239 + 1.240 + 1.241 +/*Frees any memory allocated by VOMP__init() then calls VMS_int__shutdown 1.242 + */ 1.243 +void 1.244 +VOMP__cleanup_after_shutdown() 1.245 + { VOMPSemEnv *semanticEnv; 1.246 + 1.247 + semanticEnv = _VMSMasterEnv->semanticEnv; 1.248 + 1.249 + #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC 1.250 + //UCC 1.251 + FILE* output; 1.252 + int n; 1.253 + char filename[255]; 1.254 + for(n=0;n<255;n++) 1.255 + { 1.256 + sprintf(filename, "./counters/UCC.%d",n); 1.257 + output = fopen(filename,"r"); 1.258 + if(output) 1.259 + { 1.260 + fclose(output); 1.261 + }else{ 1.262 + break; 1.263 + } 1.264 + } 1.265 + if(n<255){ 1.266 + printf("Saving UCC to File: %s ...\n", filename); 1.267 + output = fopen(filename,"w+"); 1.268 + if(output!=NULL){ 1.269 + set_dependency_file(output); 1.270 + //fprintf(output,"digraph Dependencies {\n"); 1.271 + //set_dot_file(output); 1.272 + //FIXME: first line still depends on counters being enabled, replace w/ unit struct! 1.273 + //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); 1.274 + forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file); 1.275 + forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); 1.276 + forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); 1.277 + forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file); 1.278 + //fprintf(output,"}\n"); 1.279 + fflush(output); 1.280 + 1.281 + } else 1.282 + printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); 1.283 + } else { 1.284 + printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); 1.285 + } 1.286 + //Loop Graph 1.287 + for(n=0;n<255;n++) 1.288 + { 1.289 + sprintf(filename, "./counters/LoopGraph.%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 LoopGraph 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 + forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file ); 1.311 + forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file ); 1.312 + //fprintf(output,"}\n"); 1.313 + fflush(output); 1.314 + 1.315 + } else 1.316 + printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); 1.317 + } else { 1.318 + printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); 1.319 + } 1.320 + 1.321 + 1.322 + freeListOfArrays(semanticEnv->unitList); 1.323 + freeListOfArrays(semanticEnv->commDependenciesList); 1.324 + freeListOfArrays(semanticEnv->ctlDependenciesList); 1.325 + freeListOfArrays(semanticEnv->dynDependenciesList); 1.326 + 1.327 + #endif 1.328 +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS 1.329 + for(n=0;n<255;n++) 1.330 + { 1.331 + sprintf(filename, "./counters/Counters.%d.csv",n); 1.332 + output = fopen(filename,"r"); 1.333 + if(output) 1.334 + { 1.335 + fclose(output); 1.336 + }else{ 1.337 + break; 1.338 + } 1.339 + } 1.340 + if(n<255){ 1.341 + printf("Saving Counter measurements to File: %s ...\n", filename); 1.342 + output = fopen(filename,"w+"); 1.343 + if(output!=NULL){ 1.344 + set_counter_file(output); 1.345 + int i; 1.346 + for(i=0;i<NUM_CORES;i++){ 1.347 + forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file ); 1.348 + fflush(output); 1.349 + } 1.350 + 1.351 + } else 1.352 + printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); 1.353 + } else { 1.354 + printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); 1.355 + } 1.356 + 1.357 +#endif 1.358 +/* It's all allocated inside VMS's big chunk -- that's about to be freed, so 1.359 + * nothing to do here 1.360 + 1.361 + 1.362 + for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) 1.363 + { 1.364 + VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData ); 1.365 + VMS_int__free( semanticEnv->readyVPQs[coreIdx] ); 1.366 + } 1.367 + VMS_int__free( semanticEnv->readyVPQs ); 1.368 + 1.369 + freeHashTable( semanticEnv->commHashTbl ); 1.370 + VMS_int__free( _VMSMasterEnv->semanticEnv ); 1.371 + */ 1.372 + VMS_SS__cleanup_at_end_of_shutdown(); 1.373 + } 1.374 + 1.375 + 1.376 +//=========================================================================== 1.377 + 1.378 +/* 1.379 + */ 1.380 + SlaveVP * 1.381 +VOMP__create_procr_with( TopLevelFnPtr fnPtr, void *initData, 1.382 + SlaveVP *creatingPr ) 1.383 + { VOMPSemReq reqData; 1.384 + 1.385 + //the semantic request data is on the stack and disappears when this 1.386 + // call returns -- it's guaranteed to remain in the VP's stack for as 1.387 + // long as the VP is suspended. 1.388 + reqData.reqType = 0; //know type because in a VMS create req 1.389 + reqData.coreToAssignOnto = -1; //means round-robin assign 1.390 + reqData.fnPtr = fnPtr; 1.391 + reqData.initData = initData; 1.392 + reqData.sendPr = creatingPr; 1.393 + 1.394 + VMS_WL__send_create_slaveVP_req( &reqData, creatingPr ); 1.395 + 1.396 + return creatingPr->dataRetFromReq; 1.397 + } 1.398 + 1.399 + SlaveVP * 1.400 +VOMP__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData, 1.401 + SlaveVP *creatingPr, int32 coreToAssignOnto ) 1.402 + { VOMPSemReq reqData; 1.403 + 1.404 + //the semantic request data is on the stack and disappears when this 1.405 + // call returns -- it's guaranteed to remain in the VP's stack for as 1.406 + // long as the VP is suspended. 1.407 + reqData.reqType = 0; //know type because in a VMS create req 1.408 + reqData.coreToAssignOnto = coreToAssignOnto; 1.409 + reqData.fnPtr = fnPtr; 1.410 + reqData.initData = initData; 1.411 + reqData.sendPr = creatingPr; 1.412 + 1.413 + VMS_WL__send_create_slaveVP_req( &reqData, creatingPr ); 1.414 + 1.415 + return creatingPr->dataRetFromReq; 1.416 + } 1.417 + 1.418 + 1.419 + void 1.420 +VOMP__dissipate_procr( SlaveVP *procrToDissipate ) 1.421 + { 1.422 + VMS_WL__send_dissipate_req( procrToDissipate ); 1.423 + } 1.424 + 1.425 + 1.426 +//=========================================================================== 1.427 + 1.428 +void * 1.429 +VOMP__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr ) 1.430 + { VOMPSemReq reqData; 1.431 + 1.432 + reqData.reqType = malloc_req; 1.433 + reqData.sendPr = owningPr; 1.434 + reqData.sizeToMalloc = sizeToMalloc; 1.435 + 1.436 + VMS_WL__send_sem_request( &reqData, owningPr ); 1.437 + 1.438 + return owningPr->dataRetFromReq; 1.439 + } 1.440 + 1.441 + 1.442 +/*Sends request to Master, which does the work of freeing 1.443 + */ 1.444 +void 1.445 +VOMP__free( void *ptrToFree, SlaveVP *owningPr ) 1.446 + { VOMPSemReq reqData; 1.447 + 1.448 + reqData.reqType = free_req; 1.449 + reqData.sendPr = owningPr; 1.450 + reqData.ptrToFree = ptrToFree; 1.451 + 1.452 + VMS_WL__send_sem_request( &reqData, owningPr ); 1.453 + } 1.454 + 1.455 + 1.456 +void 1.457 +VOMP__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv, 1.458 + SlaveVP *newOwnerPr ) 1.459 + { 1.460 + //TODO: put in the ownership system that automatically frees when no 1.461 + // owners of data left -- will need keeper for keeping data around when 1.462 + // future created processors might need it but don't exist yet 1.463 + } 1.464 + 1.465 + 1.466 +void 1.467 +VOMP__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data ) 1.468 + { 1.469 + 1.470 + } 1.471 + 1.472 + 1.473 +void 1.474 +VOMP__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing ) 1.475 + { 1.476 + 1.477 + } 1.478 + 1.479 + 1.480 +/*Causes the VOMP system to remove internal ownership, so data won't be 1.481 + * freed when VOMP shuts down, and will persist in the external program. 1.482 + * 1.483 + *Must be called from the processor that currently owns the data. 1.484 + * 1.485 + *IMPL: Transferring ownership touches two different virtual processor's 1.486 + * state -- which means it has to be done carefully -- the VMS rules for 1.487 + * semantic layers say that a work-unit is only allowed to touch the 1.488 + * virtual processor it is part of, and that only a single work-unit per 1.489 + * virtual processor be assigned to a slave at a time. So, this has to 1.490 + * modify the virtual processor that owns the work-unit that called this 1.491 + * function, then create a request to have the other processor modified. 1.492 + *However, in this case, the TO processor is the outside, and transfers 1.493 + * are only allowed to be called by the giver-upper, so can mark caller of 1.494 + * this function as no longer owner, and return -- done. 1.495 + */ 1.496 +void 1.497 +VOMP__transfer_ownership_to_outside( void *data ) 1.498 + { 1.499 + //TODO: removeAllOwnersFrom( data ); 1.500 + } 1.501 + 1.502 + 1.503 +//=========================================================================== 1.504 + 1.505 +void 1.506 +VOMP__send_of_type_to( SlaveVP *sendPr, void *msg, const int type, 1.507 + SlaveVP *receivePr) 1.508 + { VOMPSemReq reqData; 1.509 + 1.510 + reqData.receivePr = receivePr; 1.511 + reqData.sendPr = sendPr; 1.512 + reqData.reqType = send_type; 1.513 + reqData.msgType = type; 1.514 + reqData.msg = msg; 1.515 + reqData.nextReqInHashEntry = NULL; 1.516 + 1.517 + //On ownership -- remove inside the send and let ownership sit in limbo 1.518 + // as a potential in an entry in the hash table, when this receive msg 1.519 + // gets paired to a send, the ownership gets added to the receivePr -- 1.520 + // the next work-unit in the receivePr's trace will have ownership. 1.521 + VMS_WL__send_sem_request( &reqData, sendPr ); 1.522 + 1.523 + //When come back from suspend, no longer own data reachable from msg 1.524 + //TODO: release ownership here 1.525 + } 1.526 + 1.527 +void 1.528 +VOMP__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr ) 1.529 + { VOMPSemReq reqData; 1.530 + 1.531 + //hash on the receiver, 'cause always know it, but sometimes want to 1.532 + // receive from anonymous sender 1.533 + 1.534 + reqData.receivePr = receivePr; 1.535 + reqData.sendPr = sendPr; 1.536 + reqData.reqType = send_from_to; 1.537 + reqData.msg = msg; 1.538 + reqData.nextReqInHashEntry = NULL; 1.539 + 1.540 + VMS_WL__send_sem_request( &reqData, sendPr ); 1.541 + } 1.542 + 1.543 + 1.544 +//=========================================================================== 1.545 + 1.546 +void * 1.547 +VOMP__receive_any_to( SlaveVP *receivePr ) 1.548 + { 1.549 + 1.550 + } 1.551 + 1.552 +void * 1.553 +VOMP__receive_type_to( const int type, SlaveVP *receivePr ) 1.554 + { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID); 1.555 + VOMPSemReq reqData; 1.556 + 1.557 + reqData.receivePr = receivePr; 1.558 + reqData.reqType = receive_type; 1.559 + reqData.msgType = type; 1.560 + reqData.nextReqInHashEntry = NULL; 1.561 + 1.562 + VMS_WL__send_sem_request( &reqData, receivePr ); 1.563 + 1.564 + return receivePr->dataRetFromReq; 1.565 + } 1.566 + 1.567 + 1.568 + 1.569 +/*Call this at point receiving virt pr wants in-coming data. 1.570 + * 1.571 + *The reason receivePr must call this is that it modifies the receivPr 1.572 + * loc structure directly -- and the VMS rules state a virtual processor 1.573 + * loc structure can only be modified by itself. 1.574 + */ 1.575 +void * 1.576 +VOMP__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr ) 1.577 + { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID); 1.578 + VOMPSemReq reqData; 1.579 + 1.580 + //hash on the receiver, 'cause always know it, but sometimes want to 1.581 + // receive from anonymous sender 1.582 + 1.583 + reqData.receivePr = receivePr; 1.584 + reqData.sendPr = sendPr; 1.585 + reqData.reqType = receive_from_to; 1.586 + reqData.nextReqInHashEntry = NULL; 1.587 + 1.588 + VMS_WL__send_sem_request( &reqData, receivePr ); 1.589 + 1.590 + return receivePr->dataRetFromReq; 1.591 + } 1.592 + 1.593 + 1.594 +//=========================================================================== 1.595 +// 1.596 +/*A function singleton is a function whose body executes exactly once, on a 1.597 + * single core, no matter how many times the fuction is called and no 1.598 + * matter how many cores or the timing of cores calling it. 1.599 + * 1.600 + *A data singleton is a ticket attached to data. That ticket can be used 1.601 + * to get the data through the function exactly once, no matter how many 1.602 + * times the data is given to the function, and no matter the timing of 1.603 + * trying to get the data through from different cores. 1.604 + */ 1.605 + 1.606 +/*asm function declarations*/ 1.607 +void asm_save_ret_to_singleton(VOMPSingleton *singletonPtrAddr); 1.608 +void asm_write_ret_from_singleton(VOMPSingleton *singletonPtrAddr); 1.609 + 1.610 +/*Fn singleton uses ID as index into array of singleton structs held in the 1.611 + * semantic environment. 1.612 + */ 1.613 +void 1.614 +VOMP__start_fn_singleton( int32 singletonID, SlaveVP *animPr ) 1.615 + { 1.616 + VOMPSemReq reqData; 1.617 + 1.618 + // 1.619 + reqData.reqType = singleton_fn_start; 1.620 + reqData.singletonID = singletonID; 1.621 + 1.622 + VMS_WL__send_sem_request( &reqData, animPr ); 1.623 + if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton 1.624 + { 1.625 + VOMPSemEnv *semEnv = VMS_int__give_sem_env_for( animPr ); 1.626 + asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); 1.627 + } 1.628 + } 1.629 + 1.630 +/*Data singleton hands addr of loc holding a pointer to a singleton struct. 1.631 + * The start_data_singleton makes the structure and puts its addr into the 1.632 + * location. 1.633 + */ 1.634 +void 1.635 +VOMP__start_data_singleton( VOMPSingleton **singletonAddr, SlaveVP *animPr ) 1.636 + { 1.637 + VOMPSemReq reqData; 1.638 + 1.639 + if( *singletonAddr && (*singletonAddr)->hasFinished ) 1.640 + goto JmpToEndSingleton; 1.641 + 1.642 + reqData.reqType = singleton_data_start; 1.643 + reqData.singletonPtrAddr = singletonAddr; 1.644 + 1.645 + VMS_WL__send_sem_request( &reqData, animPr ); 1.646 + if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr 1.647 + { //Assembly code changes the return addr on the stack to the one 1.648 + // saved into the singleton by the end-singleton-fn 1.649 + //The return addr is at 0x4(%%ebp) 1.650 + JmpToEndSingleton: 1.651 + asm_write_ret_from_singleton(*singletonAddr); 1.652 + } 1.653 + //now, simply return 1.654 + //will exit either from the start singleton call or the end-singleton call 1.655 + } 1.656 + 1.657 +/*Uses ID as index into array of flags. If flag already set, resumes from 1.658 + * end-label. Else, sets flag and resumes normally. 1.659 + * 1.660 + *Note, this call cannot be inlined because the instr addr at the label 1.661 + * inside is shared by all invocations of a given singleton ID. 1.662 + */ 1.663 +void 1.664 +VOMP__end_fn_singleton( int32 singletonID, SlaveVP *animPr ) 1.665 + { 1.666 + VOMPSemReq reqData; 1.667 + 1.668 + //don't need this addr until after at least one singleton has reached 1.669 + // this function 1.670 + VOMPSemEnv *semEnv = VMS_int__give_sem_env_for( animPr ); 1.671 + asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); 1.672 + 1.673 + reqData.reqType = singleton_fn_end; 1.674 + reqData.singletonID = singletonID; 1.675 + 1.676 + VMS_WL__send_sem_request( &reqData, animPr ); 1.677 + 1.678 +EndSingletonInstrAddr: 1.679 + return; 1.680 + } 1.681 + 1.682 +void 1.683 +VOMP__end_data_singleton( VOMPSingleton **singletonPtrAddr, SlaveVP *animPr ) 1.684 + { 1.685 + VOMPSemReq reqData; 1.686 + 1.687 + //don't need this addr until after singleton struct has reached 1.688 + // this function for first time 1.689 + //do assembly that saves the return addr of this fn call into the 1.690 + // data singleton -- that data-singleton can only be given to exactly 1.691 + // one instance in the code of this function. However, can use this 1.692 + // function in different places for different data-singletons. 1.693 +// (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr; 1.694 + 1.695 + 1.696 + asm_save_ret_to_singleton(*singletonPtrAddr); 1.697 + 1.698 + reqData.reqType = singleton_data_end; 1.699 + reqData.singletonPtrAddr = singletonPtrAddr; 1.700 + 1.701 + VMS_WL__send_sem_request( &reqData, animPr ); 1.702 + } 1.703 + 1.704 +/*This executes the function in the masterVP, so it executes in isolation 1.705 + * from any other copies -- only one copy of the function can ever execute 1.706 + * at a time. 1.707 + * 1.708 + *It suspends to the master, and the request handler takes the function 1.709 + * pointer out of the request and calls it, then resumes the VP. 1.710 + *Only very short functions should be called this way -- for longer-running 1.711 + * isolation, use transaction-start and transaction-end, which run the code 1.712 + * between as work-code. 1.713 + */ 1.714 +void 1.715 +VOMP__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, 1.716 + void *data, SlaveVP *animPr ) 1.717 + { 1.718 + VOMPSemReq reqData; 1.719 + 1.720 + // 1.721 + reqData.reqType = atomic; 1.722 + reqData.fnToExecInMaster = ptrToFnToExecInMaster; 1.723 + reqData.dataForFn = data; 1.724 + 1.725 + VMS_WL__send_sem_request( &reqData, animPr ); 1.726 + } 1.727 + 1.728 + 1.729 +/*This suspends to the master. 1.730 + *First, it looks at the VP's data, to see the highest transactionID that VP 1.731 + * already has entered. If the current ID is not larger, it throws an 1.732 + * exception stating a bug in the code. Otherwise it puts the current ID 1.733 + * there, and adds the ID to a linked list of IDs entered -- the list is 1.734 + * used to check that exits are properly ordered. 1.735 + *Next it is uses transactionID as index into an array of transaction 1.736 + * structures. 1.737 + *If the "VP_currently_executing" field is non-null, then put requesting VP 1.738 + * into queue in the struct. (At some point a holder will request 1.739 + * end-transaction, which will take this VP from the queue and resume it.) 1.740 + *If NULL, then write requesting into the field and resume. 1.741 + */ 1.742 +void 1.743 +VOMP__start_transaction( int32 transactionID, SlaveVP *animPr ) 1.744 + { 1.745 + VOMPSemReq reqData; 1.746 + 1.747 + // 1.748 + reqData.sendPr = animPr; 1.749 + reqData.reqType = trans_start; 1.750 + reqData.transID = transactionID; 1.751 + 1.752 + VMS_WL__send_sem_request( &reqData, animPr ); 1.753 + } 1.754 + 1.755 +/*This suspends to the master, then uses transactionID as index into an 1.756 + * array of transaction structures. 1.757 + *It looks at VP_currently_executing to be sure it's same as requesting VP. 1.758 + * If different, throws an exception, stating there's a bug in the code. 1.759 + *Next it looks at the queue in the structure. 1.760 + *If it's empty, it sets VP_currently_executing field to NULL and resumes. 1.761 + *If something in, gets it, sets VP_currently_executing to that VP, then 1.762 + * resumes both. 1.763 + */ 1.764 +void 1.765 +VOMP__end_transaction( int32 transactionID, SlaveVP *animPr ) 1.766 + { 1.767 + VOMPSemReq reqData; 1.768 + 1.769 + // 1.770 + reqData.sendPr = animPr; 1.771 + reqData.reqType = trans_end; 1.772 + reqData.transID = transactionID; 1.773 + 1.774 + VMS_WL__send_sem_request( &reqData, animPr ); 1.775 + }
