Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VOMP_impls > VOMP__MC_shared_impl
comparison VOMP.c @ 0:b311282ec174
Initial add -- copies of code from SSR
| author | Some Random Person <seanhalle@yahoo.com> |
|---|---|
| date | Sun, 20 May 2012 22:07:52 -0700 |
| parents | |
| children | 21cf36019f0d |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d6c589a42ab4 |
|---|---|
| 1 /* | |
| 2 * Copyright 2010 OpenSourceCodeStewardshipFoundation | |
| 3 * | |
| 4 * Licensed under BSD | |
| 5 */ | |
| 6 | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <malloc.h> | |
| 10 | |
| 11 #include "Queue_impl/PrivateQueue.h" | |
| 12 #include "Hash_impl/PrivateHash.h" | |
| 13 | |
| 14 #include "SSR.h" | |
| 15 #include "SSR_Counter_Recording.h" | |
| 16 | |
| 17 //========================================================================== | |
| 18 | |
| 19 void | |
| 20 SSR__init(); | |
| 21 | |
| 22 void | |
| 23 SSR__init_Helper(); | |
| 24 //========================================================================== | |
| 25 | |
| 26 | |
| 27 /*TODO: Q: dealing with library f()s and DKU vs WT vs FoR | |
| 28 * (still want to do FoR, with time-lines as syntax, could be super cool) | |
| 29 * A: thinking pin the coreCtlrs for all of BLIS -- let Master arbitrate | |
| 30 * among library, DKU, WT, FoR -- all the patterns in terms of virtual | |
| 31 * processors (or equivalently work-units), so Master picks which virt procr | |
| 32 * from which portions of app (DKU, WT, FoR) onto which anim slots | |
| 33 *Might even do hierarchy of masters -- group of anim slots for each core | |
| 34 * has its own master, that keeps generated work local | |
| 35 * single-reader-single-writer sync everywhere -- no atomic primitives | |
| 36 * Might have the different assigners talk to each other, to negotiate | |
| 37 * larger-grain sharing of resources, according to predicted critical | |
| 38 * path, and expansion of work | |
| 39 */ | |
| 40 | |
| 41 | |
| 42 | |
| 43 //=========================================================================== | |
| 44 | |
| 45 | |
| 46 /*These are the library functions *called in the application* | |
| 47 * | |
| 48 *There's a pattern for the outside sequential code to interact with the | |
| 49 * VMS_HW code. | |
| 50 *The VMS_HW system is inside a boundary.. every SSR system is in its | |
| 51 * own directory that contains the functions for each of the processor types. | |
| 52 * One of the processor types is the "seed" processor that starts the | |
| 53 * cascade of creating all the processors that do the work. | |
| 54 *So, in the directory is a file called "EntryPoint.c" that contains the | |
| 55 * function, named appropriately to the work performed, that the outside | |
| 56 * sequential code calls. This function follows a pattern: | |
| 57 *1) it calls SSR__init() | |
| 58 *2) it creates the initial data for the seed processor, which is passed | |
| 59 * in to the function | |
| 60 *3) it creates the seed SSR processor, with the data to start it with. | |
| 61 *4) it calls startSSRThenWaitUntilWorkDone | |
| 62 *5) it gets the returnValue from the transfer struc and returns that | |
| 63 * from the function | |
| 64 * | |
| 65 *For now, a new SSR system has to be created via SSR__init every | |
| 66 * time an entry point function is called -- later, might add letting the | |
| 67 * SSR system be created once, and let all the entry points just reuse | |
| 68 * it -- want to be as simple as possible now, and see by using what makes | |
| 69 * sense for later.. | |
| 70 */ | |
| 71 | |
| 72 | |
| 73 | |
| 74 //=========================================================================== | |
| 75 | |
| 76 /*This is the "border crossing" function -- the thing that crosses from the | |
| 77 * outside world, into the VMS_HW world. It initializes and starts up the | |
| 78 * VMS system, then creates one processor from the specified function and | |
| 79 * puts it into the readyQ. From that point, that one function is resp. | |
| 80 * for creating all the other processors, that then create others, and so | |
| 81 * forth. | |
| 82 *When all the processors, including the seed, have dissipated, then this | |
| 83 * function returns. The results will have been written by side-effect via | |
| 84 * pointers read from, or written into initData. | |
| 85 * | |
| 86 *NOTE: no Threads should exist in the outside program that might touch | |
| 87 * any of the data reachable from initData passed in to here | |
| 88 */ | |
| 89 void | |
| 90 SSR__create_seed_procr_and_do_work( TopLevelFnPtr fnPtr, void *initData ) | |
| 91 { SSRSemEnv *semEnv; | |
| 92 SlaveVP *seedPr; | |
| 93 | |
| 94 SSR__init(); //normal multi-thd | |
| 95 | |
| 96 semEnv = _VMSMasterEnv->semanticEnv; | |
| 97 | |
| 98 //SSR starts with one processor, which is put into initial environ, | |
| 99 // and which then calls create() to create more, thereby expanding work | |
| 100 seedPr = SSR__create_procr_helper( fnPtr, initData, | |
| 101 semEnv, semEnv->nextCoreToGetNewPr++ ); | |
| 102 | |
| 103 resume_slaveVP( seedPr, semEnv ); | |
| 104 | |
| 105 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd | |
| 106 | |
| 107 SSR__cleanup_after_shutdown(); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 int32 | |
| 112 SSR__giveMinWorkUnitCycles( float32 percentOverhead ) | |
| 113 { | |
| 114 return MIN_WORK_UNIT_CYCLES; | |
| 115 } | |
| 116 | |
| 117 int32 | |
| 118 SSR__giveIdealNumWorkUnits() | |
| 119 { | |
| 120 return NUM_ANIM_SLOTS * NUM_CORES; | |
| 121 } | |
| 122 | |
| 123 int32 | |
| 124 SSR__give_number_of_cores_to_schedule_onto() | |
| 125 { | |
| 126 return NUM_CORES; | |
| 127 } | |
| 128 | |
| 129 /*For now, use TSC -- later, make these two macros with assembly that first | |
| 130 * saves jump point, and second jumps back several times to get reliable time | |
| 131 */ | |
| 132 void | |
| 133 SSR__start_primitive() | |
| 134 { saveLowTimeStampCountInto( ((SSRSemEnv *)(_VMSMasterEnv->semanticEnv))-> | |
| 135 primitiveStartTime ); | |
| 136 } | |
| 137 | |
| 138 /*Just quick and dirty for now -- make reliable later | |
| 139 * will want this to jump back several times -- to be sure cache is warm | |
| 140 * because don't want comm time included in calc-time measurement -- and | |
| 141 * also to throw out any "weird" values due to OS interrupt or TSC rollover | |
| 142 */ | |
| 143 int32 | |
| 144 SSR__end_primitive_and_give_cycles() | |
| 145 { int32 endTime, startTime; | |
| 146 //TODO: fix by repeating time-measurement | |
| 147 saveLowTimeStampCountInto( endTime ); | |
| 148 startTime =((SSRSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime; | |
| 149 return (endTime - startTime); | |
| 150 } | |
| 151 | |
| 152 //=========================================================================== | |
| 153 | |
| 154 /*Initializes all the data-structures for a SSR system -- but doesn't | |
| 155 * start it running yet! | |
| 156 * | |
| 157 *This runs in the main thread -- before VMS starts up | |
| 158 * | |
| 159 *This sets up the semantic layer over the VMS system | |
| 160 * | |
| 161 *First, calls VMS_Setup, then creates own environment, making it ready | |
| 162 * for creating the seed processor and then starting the work. | |
| 163 */ | |
| 164 void | |
| 165 SSR__init() | |
| 166 { | |
| 167 VMS_SS__init(); | |
| 168 //masterEnv, a global var, now is partially set up by init_VMS | |
| 169 // after this, have VMS_int__malloc and VMS_int__free available | |
| 170 | |
| 171 SSR__init_Helper(); | |
| 172 } | |
| 173 | |
| 174 | |
| 175 void idle_fn(void* data, SlaveVP *animatingSlv){ | |
| 176 while(1){ | |
| 177 VMS_int__suspend_slaveVP_and_send_req(animatingSlv); | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 void | |
| 182 SSR__init_Helper() | |
| 183 { SSRSemEnv *semanticEnv; | |
| 184 PrivQueueStruc **readyVPQs; | |
| 185 int coreIdx, i, j; | |
| 186 | |
| 187 //Hook up the semantic layer's plug-ins to the Master virt procr | |
| 188 _VMSMasterEnv->requestHandler = &SSR__Request_Handler; | |
| 189 _VMSMasterEnv->slaveAssigner = &SSR__assign_slaveVP_to_slot; | |
| 190 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS | |
| 191 _VMSMasterEnv->counterHandler = &SSR__counter_handler; | |
| 192 #endif | |
| 193 | |
| 194 //create the semantic layer's environment (all its data) and add to | |
| 195 // the master environment | |
| 196 semanticEnv = VMS_int__malloc( sizeof( SSRSemEnv ) ); | |
| 197 _VMSMasterEnv->semanticEnv = semanticEnv; | |
| 198 | |
| 199 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS | |
| 200 SSR__init_counter_data_structs(); | |
| 201 #endif | |
| 202 semanticEnv->shutdownInitiated = FALSE; | |
| 203 for(i=0;i<NUM_CORES;++i){ | |
| 204 for(j=0;j<NUM_ANIM_SLOTS;++j){ | |
| 205 semanticEnv->idlePr[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL); | |
| 206 semanticEnv->idlePr[i][j]->coreAnimatedBy = i; | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC | |
| 211 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128); | |
| 212 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128); | |
| 213 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128); | |
| 214 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128); | |
| 215 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8); | |
| 216 | |
| 217 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128); | |
| 218 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit))); | |
| 219 #endif | |
| 220 | |
| 221 //create the ready queue, hash tables used for pairing send to receive | |
| 222 // and so forth | |
| 223 //TODO: add hash tables for pairing sends with receives, and | |
| 224 // initialize the data ownership system | |
| 225 readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) ); | |
| 226 | |
| 227 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) | |
| 228 { | |
| 229 readyVPQs[ coreIdx ] = makeVMSQ(); | |
| 230 } | |
| 231 | |
| 232 semanticEnv->readyVPQs = readyVPQs; | |
| 233 | |
| 234 semanticEnv->nextCoreToGetNewPr = 0; | |
| 235 semanticEnv->numSlaveVP = 0; | |
| 236 | |
| 237 semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big | |
| 238 | |
| 239 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit | |
| 240 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( ); | |
| 241 //semanticEnv->transactionStrucs = makeDynArrayInfo( ); | |
| 242 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ ) | |
| 243 { | |
| 244 semanticEnv->fnSingletons[i].endInstrAddr = NULL; | |
| 245 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE; | |
| 246 semanticEnv->fnSingletons[i].hasFinished = FALSE; | |
| 247 semanticEnv->fnSingletons[i].waitQ = makeVMSQ(); | |
| 248 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ(); | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 | |
| 253 /*Frees any memory allocated by SSR__init() then calls VMS_int__shutdown | |
| 254 */ | |
| 255 void | |
| 256 SSR__cleanup_after_shutdown() | |
| 257 { SSRSemEnv *semanticEnv; | |
| 258 | |
| 259 semanticEnv = _VMSMasterEnv->semanticEnv; | |
| 260 | |
| 261 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC | |
| 262 //UCC | |
| 263 FILE* output; | |
| 264 int n; | |
| 265 char filename[255]; | |
| 266 for(n=0;n<255;n++) | |
| 267 { | |
| 268 sprintf(filename, "./counters/UCC.%d",n); | |
| 269 output = fopen(filename,"r"); | |
| 270 if(output) | |
| 271 { | |
| 272 fclose(output); | |
| 273 }else{ | |
| 274 break; | |
| 275 } | |
| 276 } | |
| 277 if(n<255){ | |
| 278 printf("Saving UCC to File: %s ...\n", filename); | |
| 279 output = fopen(filename,"w+"); | |
| 280 if(output!=NULL){ | |
| 281 set_dependency_file(output); | |
| 282 //fprintf(output,"digraph Dependencies {\n"); | |
| 283 //set_dot_file(output); | |
| 284 //FIXME: first line still depends on counters being enabled, replace w/ unit struct! | |
| 285 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); | |
| 286 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file); | |
| 287 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); | |
| 288 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); | |
| 289 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file); | |
| 290 //fprintf(output,"}\n"); | |
| 291 fflush(output); | |
| 292 | |
| 293 } else | |
| 294 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); | |
| 295 } else { | |
| 296 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); | |
| 297 } | |
| 298 //Loop Graph | |
| 299 for(n=0;n<255;n++) | |
| 300 { | |
| 301 sprintf(filename, "./counters/LoopGraph.%d",n); | |
| 302 output = fopen(filename,"r"); | |
| 303 if(output) | |
| 304 { | |
| 305 fclose(output); | |
| 306 }else{ | |
| 307 break; | |
| 308 } | |
| 309 } | |
| 310 if(n<255){ | |
| 311 printf("Saving LoopGraph to File: %s ...\n", filename); | |
| 312 output = fopen(filename,"w+"); | |
| 313 if(output!=NULL){ | |
| 314 set_dependency_file(output); | |
| 315 //fprintf(output,"digraph Dependencies {\n"); | |
| 316 //set_dot_file(output); | |
| 317 //FIXME: first line still depends on counters being enabled, replace w/ unit struct! | |
| 318 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info ); | |
| 319 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file ); | |
| 320 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file ); | |
| 321 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file ); | |
| 322 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file ); | |
| 323 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file ); | |
| 324 //fprintf(output,"}\n"); | |
| 325 fflush(output); | |
| 326 | |
| 327 } else | |
| 328 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); | |
| 329 } else { | |
| 330 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); | |
| 331 } | |
| 332 | |
| 333 | |
| 334 freeListOfArrays(semanticEnv->unitList); | |
| 335 freeListOfArrays(semanticEnv->commDependenciesList); | |
| 336 freeListOfArrays(semanticEnv->ctlDependenciesList); | |
| 337 freeListOfArrays(semanticEnv->dynDependenciesList); | |
| 338 | |
| 339 #endif | |
| 340 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS | |
| 341 for(n=0;n<255;n++) | |
| 342 { | |
| 343 sprintf(filename, "./counters/Counters.%d.csv",n); | |
| 344 output = fopen(filename,"r"); | |
| 345 if(output) | |
| 346 { | |
| 347 fclose(output); | |
| 348 }else{ | |
| 349 break; | |
| 350 } | |
| 351 } | |
| 352 if(n<255){ | |
| 353 printf("Saving Counter measurements to File: %s ...\n", filename); | |
| 354 output = fopen(filename,"w+"); | |
| 355 if(output!=NULL){ | |
| 356 set_counter_file(output); | |
| 357 int i; | |
| 358 for(i=0;i<NUM_CORES;i++){ | |
| 359 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file ); | |
| 360 fflush(output); | |
| 361 } | |
| 362 | |
| 363 } else | |
| 364 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n"); | |
| 365 } else { | |
| 366 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n"); | |
| 367 } | |
| 368 | |
| 369 #endif | |
| 370 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so | |
| 371 * nothing to do here | |
| 372 | |
| 373 | |
| 374 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) | |
| 375 { | |
| 376 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData ); | |
| 377 VMS_int__free( semanticEnv->readyVPQs[coreIdx] ); | |
| 378 } | |
| 379 VMS_int__free( semanticEnv->readyVPQs ); | |
| 380 | |
| 381 freeHashTable( semanticEnv->commHashTbl ); | |
| 382 VMS_int__free( _VMSMasterEnv->semanticEnv ); | |
| 383 */ | |
| 384 VMS_SS__cleanup_at_end_of_shutdown(); | |
| 385 } | |
| 386 | |
| 387 | |
| 388 //=========================================================================== | |
| 389 | |
| 390 /* | |
| 391 */ | |
| 392 SlaveVP * | |
| 393 SSR__create_procr_with( TopLevelFnPtr fnPtr, void *initData, | |
| 394 SlaveVP *creatingPr ) | |
| 395 { SSRSemReq reqData; | |
| 396 | |
| 397 //the semantic request data is on the stack and disappears when this | |
| 398 // call returns -- it's guaranteed to remain in the VP's stack for as | |
| 399 // long as the VP is suspended. | |
| 400 reqData.reqType = 0; //know type because in a VMS create req | |
| 401 reqData.coreToAssignOnto = -1; //means round-robin assign | |
| 402 reqData.fnPtr = fnPtr; | |
| 403 reqData.initData = initData; | |
| 404 reqData.sendPr = creatingPr; | |
| 405 | |
| 406 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr ); | |
| 407 | |
| 408 return creatingPr->dataRetFromReq; | |
| 409 } | |
| 410 | |
| 411 SlaveVP * | |
| 412 SSR__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData, | |
| 413 SlaveVP *creatingPr, int32 coreToAssignOnto ) | |
| 414 { SSRSemReq reqData; | |
| 415 | |
| 416 //the semantic request data is on the stack and disappears when this | |
| 417 // call returns -- it's guaranteed to remain in the VP's stack for as | |
| 418 // long as the VP is suspended. | |
| 419 reqData.reqType = 0; //know type because in a VMS create req | |
| 420 reqData.coreToAssignOnto = coreToAssignOnto; | |
| 421 reqData.fnPtr = fnPtr; | |
| 422 reqData.initData = initData; | |
| 423 reqData.sendPr = creatingPr; | |
| 424 | |
| 425 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr ); | |
| 426 | |
| 427 return creatingPr->dataRetFromReq; | |
| 428 } | |
| 429 | |
| 430 | |
| 431 void | |
| 432 SSR__dissipate_procr( SlaveVP *procrToDissipate ) | |
| 433 { | |
| 434 VMS_WL__send_dissipate_req( procrToDissipate ); | |
| 435 } | |
| 436 | |
| 437 | |
| 438 //=========================================================================== | |
| 439 | |
| 440 void * | |
| 441 SSR__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr ) | |
| 442 { SSRSemReq reqData; | |
| 443 | |
| 444 reqData.reqType = malloc_req; | |
| 445 reqData.sendPr = owningPr; | |
| 446 reqData.sizeToMalloc = sizeToMalloc; | |
| 447 | |
| 448 VMS_WL__send_sem_request( &reqData, owningPr ); | |
| 449 | |
| 450 return owningPr->dataRetFromReq; | |
| 451 } | |
| 452 | |
| 453 | |
| 454 /*Sends request to Master, which does the work of freeing | |
| 455 */ | |
| 456 void | |
| 457 SSR__free( void *ptrToFree, SlaveVP *owningPr ) | |
| 458 { SSRSemReq reqData; | |
| 459 | |
| 460 reqData.reqType = free_req; | |
| 461 reqData.sendPr = owningPr; | |
| 462 reqData.ptrToFree = ptrToFree; | |
| 463 | |
| 464 VMS_WL__send_sem_request( &reqData, owningPr ); | |
| 465 } | |
| 466 | |
| 467 | |
| 468 void | |
| 469 SSR__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv, | |
| 470 SlaveVP *newOwnerPr ) | |
| 471 { | |
| 472 //TODO: put in the ownership system that automatically frees when no | |
| 473 // owners of data left -- will need keeper for keeping data around when | |
| 474 // future created processors might need it but don't exist yet | |
| 475 } | |
| 476 | |
| 477 | |
| 478 void | |
| 479 SSR__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data ) | |
| 480 { | |
| 481 | |
| 482 } | |
| 483 | |
| 484 | |
| 485 void | |
| 486 SSR__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing ) | |
| 487 { | |
| 488 | |
| 489 } | |
| 490 | |
| 491 | |
| 492 /*Causes the SSR system to remove internal ownership, so data won't be | |
| 493 * freed when SSR shuts down, and will persist in the external program. | |
| 494 * | |
| 495 *Must be called from the processor that currently owns the data. | |
| 496 * | |
| 497 *IMPL: Transferring ownership touches two different virtual processor's | |
| 498 * state -- which means it has to be done carefully -- the VMS rules for | |
| 499 * semantic layers say that a work-unit is only allowed to touch the | |
| 500 * virtual processor it is part of, and that only a single work-unit per | |
| 501 * virtual processor be assigned to a slave at a time. So, this has to | |
| 502 * modify the virtual processor that owns the work-unit that called this | |
| 503 * function, then create a request to have the other processor modified. | |
| 504 *However, in this case, the TO processor is the outside, and transfers | |
| 505 * are only allowed to be called by the giver-upper, so can mark caller of | |
| 506 * this function as no longer owner, and return -- done. | |
| 507 */ | |
| 508 void | |
| 509 SSR__transfer_ownership_to_outside( void *data ) | |
| 510 { | |
| 511 //TODO: removeAllOwnersFrom( data ); | |
| 512 } | |
| 513 | |
| 514 | |
| 515 //=========================================================================== | |
| 516 | |
| 517 void | |
| 518 SSR__send_of_type_to( SlaveVP *sendPr, void *msg, const int type, | |
| 519 SlaveVP *receivePr) | |
| 520 { SSRSemReq reqData; | |
| 521 | |
| 522 reqData.receivePr = receivePr; | |
| 523 reqData.sendPr = sendPr; | |
| 524 reqData.reqType = send_type; | |
| 525 reqData.msgType = type; | |
| 526 reqData.msg = msg; | |
| 527 reqData.nextReqInHashEntry = NULL; | |
| 528 | |
| 529 //On ownership -- remove inside the send and let ownership sit in limbo | |
| 530 // as a potential in an entry in the hash table, when this receive msg | |
| 531 // gets paired to a send, the ownership gets added to the receivePr -- | |
| 532 // the next work-unit in the receivePr's trace will have ownership. | |
| 533 VMS_WL__send_sem_request( &reqData, sendPr ); | |
| 534 | |
| 535 //When come back from suspend, no longer own data reachable from msg | |
| 536 //TODO: release ownership here | |
| 537 } | |
| 538 | |
| 539 void | |
| 540 SSR__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr ) | |
| 541 { SSRSemReq reqData; | |
| 542 | |
| 543 //hash on the receiver, 'cause always know it, but sometimes want to | |
| 544 // receive from anonymous sender | |
| 545 | |
| 546 reqData.receivePr = receivePr; | |
| 547 reqData.sendPr = sendPr; | |
| 548 reqData.reqType = send_from_to; | |
| 549 reqData.msg = msg; | |
| 550 reqData.nextReqInHashEntry = NULL; | |
| 551 | |
| 552 VMS_WL__send_sem_request( &reqData, sendPr ); | |
| 553 } | |
| 554 | |
| 555 | |
| 556 //=========================================================================== | |
| 557 | |
| 558 void * | |
| 559 SSR__receive_any_to( SlaveVP *receivePr ) | |
| 560 { | |
| 561 | |
| 562 } | |
| 563 | |
| 564 void * | |
| 565 SSR__receive_type_to( const int type, SlaveVP *receivePr ) | |
| 566 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID); | |
| 567 SSRSemReq reqData; | |
| 568 | |
| 569 reqData.receivePr = receivePr; | |
| 570 reqData.reqType = receive_type; | |
| 571 reqData.msgType = type; | |
| 572 reqData.nextReqInHashEntry = NULL; | |
| 573 | |
| 574 VMS_WL__send_sem_request( &reqData, receivePr ); | |
| 575 | |
| 576 return receivePr->dataRetFromReq; | |
| 577 } | |
| 578 | |
| 579 | |
| 580 | |
| 581 /*Call this at point receiving virt pr wants in-coming data. | |
| 582 * | |
| 583 *The reason receivePr must call this is that it modifies the receivPr | |
| 584 * loc structure directly -- and the VMS rules state a virtual processor | |
| 585 * loc structure can only be modified by itself. | |
| 586 */ | |
| 587 void * | |
| 588 SSR__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr ) | |
| 589 { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID); | |
| 590 SSRSemReq reqData; | |
| 591 | |
| 592 //hash on the receiver, 'cause always know it, but sometimes want to | |
| 593 // receive from anonymous sender | |
| 594 | |
| 595 reqData.receivePr = receivePr; | |
| 596 reqData.sendPr = sendPr; | |
| 597 reqData.reqType = receive_from_to; | |
| 598 reqData.nextReqInHashEntry = NULL; | |
| 599 | |
| 600 VMS_WL__send_sem_request( &reqData, receivePr ); | |
| 601 | |
| 602 return receivePr->dataRetFromReq; | |
| 603 } | |
| 604 | |
| 605 | |
| 606 //=========================================================================== | |
| 607 // | |
| 608 /*A function singleton is a function whose body executes exactly once, on a | |
| 609 * single core, no matter how many times the fuction is called and no | |
| 610 * matter how many cores or the timing of cores calling it. | |
| 611 * | |
| 612 *A data singleton is a ticket attached to data. That ticket can be used | |
| 613 * to get the data through the function exactly once, no matter how many | |
| 614 * times the data is given to the function, and no matter the timing of | |
| 615 * trying to get the data through from different cores. | |
| 616 */ | |
| 617 | |
| 618 /*asm function declarations*/ | |
| 619 void asm_save_ret_to_singleton(SSRSingleton *singletonPtrAddr); | |
| 620 void asm_write_ret_from_singleton(SSRSingleton *singletonPtrAddr); | |
| 621 | |
| 622 /*Fn singleton uses ID as index into array of singleton structs held in the | |
| 623 * semantic environment. | |
| 624 */ | |
| 625 void | |
| 626 SSR__start_fn_singleton( int32 singletonID, SlaveVP *animPr ) | |
| 627 { | |
| 628 SSRSemReq reqData; | |
| 629 | |
| 630 // | |
| 631 reqData.reqType = singleton_fn_start; | |
| 632 reqData.singletonID = singletonID; | |
| 633 | |
| 634 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 635 if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton | |
| 636 { | |
| 637 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr ); | |
| 638 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); | |
| 639 } | |
| 640 } | |
| 641 | |
| 642 /*Data singleton hands addr of loc holding a pointer to a singleton struct. | |
| 643 * The start_data_singleton makes the structure and puts its addr into the | |
| 644 * location. | |
| 645 */ | |
| 646 void | |
| 647 SSR__start_data_singleton( SSRSingleton **singletonAddr, SlaveVP *animPr ) | |
| 648 { | |
| 649 SSRSemReq reqData; | |
| 650 | |
| 651 if( *singletonAddr && (*singletonAddr)->hasFinished ) | |
| 652 goto JmpToEndSingleton; | |
| 653 | |
| 654 reqData.reqType = singleton_data_start; | |
| 655 reqData.singletonPtrAddr = singletonAddr; | |
| 656 | |
| 657 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 658 if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr | |
| 659 { //Assembly code changes the return addr on the stack to the one | |
| 660 // saved into the singleton by the end-singleton-fn | |
| 661 //The return addr is at 0x4(%%ebp) | |
| 662 JmpToEndSingleton: | |
| 663 asm_write_ret_from_singleton(*singletonAddr); | |
| 664 } | |
| 665 //now, simply return | |
| 666 //will exit either from the start singleton call or the end-singleton call | |
| 667 } | |
| 668 | |
| 669 /*Uses ID as index into array of flags. If flag already set, resumes from | |
| 670 * end-label. Else, sets flag and resumes normally. | |
| 671 * | |
| 672 *Note, this call cannot be inlined because the instr addr at the label | |
| 673 * inside is shared by all invocations of a given singleton ID. | |
| 674 */ | |
| 675 void | |
| 676 SSR__end_fn_singleton( int32 singletonID, SlaveVP *animPr ) | |
| 677 { | |
| 678 SSRSemReq reqData; | |
| 679 | |
| 680 //don't need this addr until after at least one singleton has reached | |
| 681 // this function | |
| 682 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr ); | |
| 683 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); | |
| 684 | |
| 685 reqData.reqType = singleton_fn_end; | |
| 686 reqData.singletonID = singletonID; | |
| 687 | |
| 688 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 689 | |
| 690 EndSingletonInstrAddr: | |
| 691 return; | |
| 692 } | |
| 693 | |
| 694 void | |
| 695 SSR__end_data_singleton( SSRSingleton **singletonPtrAddr, SlaveVP *animPr ) | |
| 696 { | |
| 697 SSRSemReq reqData; | |
| 698 | |
| 699 //don't need this addr until after singleton struct has reached | |
| 700 // this function for first time | |
| 701 //do assembly that saves the return addr of this fn call into the | |
| 702 // data singleton -- that data-singleton can only be given to exactly | |
| 703 // one instance in the code of this function. However, can use this | |
| 704 // function in different places for different data-singletons. | |
| 705 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr; | |
| 706 | |
| 707 | |
| 708 asm_save_ret_to_singleton(*singletonPtrAddr); | |
| 709 | |
| 710 reqData.reqType = singleton_data_end; | |
| 711 reqData.singletonPtrAddr = singletonPtrAddr; | |
| 712 | |
| 713 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 714 } | |
| 715 | |
| 716 /*This executes the function in the masterVP, so it executes in isolation | |
| 717 * from any other copies -- only one copy of the function can ever execute | |
| 718 * at a time. | |
| 719 * | |
| 720 *It suspends to the master, and the request handler takes the function | |
| 721 * pointer out of the request and calls it, then resumes the VP. | |
| 722 *Only very short functions should be called this way -- for longer-running | |
| 723 * isolation, use transaction-start and transaction-end, which run the code | |
| 724 * between as work-code. | |
| 725 */ | |
| 726 void | |
| 727 SSR__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, | |
| 728 void *data, SlaveVP *animPr ) | |
| 729 { | |
| 730 SSRSemReq reqData; | |
| 731 | |
| 732 // | |
| 733 reqData.reqType = atomic; | |
| 734 reqData.fnToExecInMaster = ptrToFnToExecInMaster; | |
| 735 reqData.dataForFn = data; | |
| 736 | |
| 737 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 738 } | |
| 739 | |
| 740 | |
| 741 /*This suspends to the master. | |
| 742 *First, it looks at the VP's data, to see the highest transactionID that VP | |
| 743 * already has entered. If the current ID is not larger, it throws an | |
| 744 * exception stating a bug in the code. Otherwise it puts the current ID | |
| 745 * there, and adds the ID to a linked list of IDs entered -- the list is | |
| 746 * used to check that exits are properly ordered. | |
| 747 *Next it is uses transactionID as index into an array of transaction | |
| 748 * structures. | |
| 749 *If the "VP_currently_executing" field is non-null, then put requesting VP | |
| 750 * into queue in the struct. (At some point a holder will request | |
| 751 * end-transaction, which will take this VP from the queue and resume it.) | |
| 752 *If NULL, then write requesting into the field and resume. | |
| 753 */ | |
| 754 void | |
| 755 SSR__start_transaction( int32 transactionID, SlaveVP *animPr ) | |
| 756 { | |
| 757 SSRSemReq reqData; | |
| 758 | |
| 759 // | |
| 760 reqData.sendPr = animPr; | |
| 761 reqData.reqType = trans_start; | |
| 762 reqData.transID = transactionID; | |
| 763 | |
| 764 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 765 } | |
| 766 | |
| 767 /*This suspends to the master, then uses transactionID as index into an | |
| 768 * array of transaction structures. | |
| 769 *It looks at VP_currently_executing to be sure it's same as requesting VP. | |
| 770 * If different, throws an exception, stating there's a bug in the code. | |
| 771 *Next it looks at the queue in the structure. | |
| 772 *If it's empty, it sets VP_currently_executing field to NULL and resumes. | |
| 773 *If something in, gets it, sets VP_currently_executing to that VP, then | |
| 774 * resumes both. | |
| 775 */ | |
| 776 void | |
| 777 SSR__end_transaction( int32 transactionID, SlaveVP *animPr ) | |
| 778 { | |
| 779 SSRSemReq reqData; | |
| 780 | |
| 781 // | |
| 782 reqData.sendPr = animPr; | |
| 783 reqData.reqType = trans_end; | |
| 784 reqData.transID = transactionID; | |
| 785 | |
| 786 VMS_WL__send_sem_request( &reqData, animPr ); | |
| 787 } |
