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