VMS/VMS_Implementations/SSR_impls/SSR__MC_shared_impl

view SSR.c @ 84:ce07f1a42ddf

Added skeleton for data tracking assigner + design notes
author Sean Halle <seanhalle@yahoo.com>
date Thu, 10 Jan 2013 11:16:42 -0800
parents 724b5fbcdd57
children
line source
1 /*
2 * Copyright 2010 OpenSourceCodeStewardshipFoundation
3 *
4 * Licensed under BSD
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <malloc.h>
11 #include "Queue_impl/PrivateQueue.h"
12 #include "Hash_impl/PrivateHash.h"
14 #include "SSR.h"
15 #include "SSR_Counter_Recording.h"
17 //==========================================================================
19 void
20 SSR__init();
22 void
23 SSR__init_Helper();
24 //==========================================================================
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 */
43 //===========================================================================
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 */
74 //===========================================================================
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;
94 SSR__init(); //normal multi-thd
96 semEnv = _VMSMasterEnv->semanticEnv;
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++ );
103 resume_slaveVP( seedPr, semEnv );
105 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
107 SSR__cleanup_after_shutdown();
108 }
111 int32
112 SSR__giveMinWorkUnitCycles( float32 percentOverhead )
113 {
114 return MIN_WORK_UNIT_CYCLES;
115 }
117 int32
118 SSR__giveIdealNumWorkUnits()
119 {
120 return NUM_ANIM_SLOTS * NUM_CORES;
121 }
123 int32
124 SSR__give_number_of_cores_to_schedule_onto()
125 {
126 return NUM_CORES;
127 }
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 }
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 }
152 //===========================================================================
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
171 SSR__init_Helper();
172 }
175 void idle_fn(void* data, SlaveVP *animatingSlv){
176 while(1){
177 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
178 }
179 }
181 void
182 SSR__init_Helper()
183 { SSRSemEnv *semanticEnv;
184 PrivQueueStruc **readyVPQs;
185 int coreIdx, i, j;
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
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;
199 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
200 SSR__init_counter_data_structs();
201 #endif
202 #ifdef IDLE_SLAVES
203 semanticEnv->shutdownInitiated = FALSE;
204 for(i=0;i<NUM_CORES;++i){
205 for(j=0;j<NUM_ANIM_SLOTS;++j){
206 semanticEnv->idlePr[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL);
207 semanticEnv->idlePr[i][j]->coreAnimatedBy = i;
208 semanticEnv->idlePr[i][j]->typeOfVP = Idle;
209 }
210 }
211 #endif
212 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
213 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
214 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
215 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
216 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
217 semanticEnv->singletonDependenciesList = makeListOfArrays(sizeof(Dependency),128);
218 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
220 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
221 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
222 #endif
224 //create the ready queue, hash tables used for pairing send to receive
225 // and so forth
226 //TODO: add hash tables for pairing sends with receives, and
227 // initialize the data ownership system
228 readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) );
230 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
231 {
232 readyVPQs[ coreIdx ] = makeVMSQ();
233 }
235 semanticEnv->readyVPQs = readyVPQs;
237 semanticEnv->nextCoreToGetNewPr = 0;
238 semanticEnv->numSlaveVP = 0;
240 semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big
242 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
243 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
244 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
245 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
246 {
247 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
248 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
249 semanticEnv->fnSingletons[i].hasFinished = FALSE;
250 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
251 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
252 }
254 initAssigner( semanticEnv );
255 }
258 /*Frees any memory allocated by SSR__init() then calls VMS_int__shutdown
259 */
260 void
261 SSR__cleanup_after_shutdown()
262 { SSRSemEnv *semanticEnv;
264 semanticEnv = _VMSMasterEnv->semanticEnv;
266 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
267 //UCC
268 FILE* output;
269 int n;
270 char filename[255];
271 for(n=0;n<255;n++)
272 {
273 sprintf(filename, "./counters/UCC.%d",n);
274 output = fopen(filename,"r");
275 if(output)
276 {
277 fclose(output);
278 }else{
279 break;
280 }
281 }
282 if(n<255){
283 printf("Saving UCC to File: %s ...\n", filename);
284 output = fopen(filename,"w+");
285 if(output!=NULL){
286 set_dependency_file(output);
287 //fprintf(output,"digraph Dependencies {\n");
288 //set_dot_file(output);
289 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
290 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
291 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
292 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
293 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
294 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
295 //fprintf(output,"}\n");
296 fflush(output);
298 } else
299 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
300 } else {
301 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
302 }
303 //Loop Graph
304 for(n=0;n<255;n++)
305 {
306 sprintf(filename, "./counters/LoopGraph.%d",n);
307 output = fopen(filename,"r");
308 if(output)
309 {
310 fclose(output);
311 }else{
312 break;
313 }
314 }
315 if(n<255){
316 printf("Saving LoopGraph to File: %s ...\n", filename);
317 output = fopen(filename,"w+");
318 if(output!=NULL){
319 set_dependency_file(output);
320 //fprintf(output,"digraph Dependencies {\n");
321 //set_dot_file(output);
322 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
323 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
324 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
325 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
326 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
327 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
328 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
329 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
330 //fprintf(output,"}\n");
331 fflush(output);
333 } else
334 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
335 } else {
336 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
337 }
340 freeListOfArrays(semanticEnv->unitList);
341 freeListOfArrays(semanticEnv->commDependenciesList);
342 freeListOfArrays(semanticEnv->ctlDependenciesList);
343 freeListOfArrays(semanticEnv->dynDependenciesList);
344 freeListOfArrays(semanticEnv->singletonDependenciesList);
345 #endif
346 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
347 for(n=0;n<255;n++)
348 {
349 sprintf(filename, "./counters/Counters.%d.csv",n);
350 output = fopen(filename,"r");
351 if(output)
352 {
353 fclose(output);
354 }else{
355 break;
356 }
357 }
358 if(n<255){
359 printf("Saving Counter measurements to File: %s ...\n", filename);
360 output = fopen(filename,"w+");
361 if(output!=NULL){
362 set_counter_file(output);
363 int i;
364 for(i=0;i<NUM_CORES;i++){
365 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
366 fflush(output);
367 }
369 } else
370 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
371 } else {
372 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
373 }
375 #endif
376 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
377 * nothing to do here
380 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
381 {
382 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
383 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
384 }
385 VMS_int__free( semanticEnv->readyVPQs );
387 freeHashTable( semanticEnv->commHashTbl );
388 VMS_int__free( _VMSMasterEnv->semanticEnv );
389 */
390 VMS_SS__cleanup_at_end_of_shutdown();
391 }
394 //===========================================================================
396 /*
397 */
398 SlaveVP *
399 SSR__create_procr_with( TopLevelFnPtr fnPtr, void *initData,
400 SlaveVP *creatingPr )
401 { SSRSemReq reqData;
403 //the semantic request data is on the stack and disappears when this
404 // call returns -- it's guaranteed to remain in the VP's stack for as
405 // long as the VP is suspended.
406 reqData.reqType = 0; //know type because in a VMS create req
407 reqData.coreToAssignOnto = -1; //means round-robin assign
408 reqData.fnPtr = fnPtr;
409 reqData.initData = initData;
410 reqData.sendPr = creatingPr;
412 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
414 return creatingPr->dataRetFromReq;
415 }
417 SlaveVP *
418 SSR__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData,
419 SlaveVP *creatingPr, int32 coreToAssignOnto )
420 { SSRSemReq reqData;
422 //the semantic request data is on the stack and disappears when this
423 // call returns -- it's guaranteed to remain in the VP's stack for as
424 // long as the VP is suspended.
425 reqData.reqType = 0; //know type because in a VMS create req
426 reqData.coreToAssignOnto = coreToAssignOnto;
427 reqData.fnPtr = fnPtr;
428 reqData.initData = initData;
429 reqData.sendPr = creatingPr;
431 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
433 return creatingPr->dataRetFromReq;
434 }
437 void
438 SSR__dissipate_procr( SlaveVP *procrToDissipate )
439 {
440 VMS_WL__send_dissipate_req( procrToDissipate );
441 }
444 //===========================================================================
446 void *
447 SSR__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr )
448 { SSRSemReq reqData;
450 reqData.reqType = malloc_req;
451 reqData.sendPr = owningPr;
452 reqData.sizeToMalloc = sizeToMalloc;
454 VMS_WL__send_sem_request( &reqData, owningPr );
456 return owningPr->dataRetFromReq;
457 }
460 /*Sends request to Master, which does the work of freeing
461 */
462 void
463 SSR__free( void *ptrToFree, SlaveVP *owningPr )
464 { SSRSemReq reqData;
466 reqData.reqType = free_req;
467 reqData.sendPr = owningPr;
468 reqData.ptrToFree = ptrToFree;
470 VMS_WL__send_sem_request( &reqData, owningPr );
471 }
474 void
475 SSR__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv,
476 SlaveVP *newOwnerPr )
477 {
478 //TODO: put in the ownership system that automatically frees when no
479 // owners of data left -- will need keeper for keeping data around when
480 // future created processors might need it but don't exist yet
481 }
484 void
485 SSR__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data )
486 {
488 }
491 void
492 SSR__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing )
493 {
495 }
498 /*Causes the SSR system to remove internal ownership, so data won't be
499 * freed when SSR shuts down, and will persist in the external program.
500 *
501 *Must be called from the processor that currently owns the data.
502 *
503 *IMPL: Transferring ownership touches two different virtual processor's
504 * state -- which means it has to be done carefully -- the VMS rules for
505 * semantic layers say that a work-unit is only allowed to touch the
506 * virtual processor it is part of, and that only a single work-unit per
507 * virtual processor be assigned to a slave at a time. So, this has to
508 * modify the virtual processor that owns the work-unit that called this
509 * function, then create a request to have the other processor modified.
510 *However, in this case, the TO processor is the outside, and transfers
511 * are only allowed to be called by the giver-upper, so can mark caller of
512 * this function as no longer owner, and return -- done.
513 */
514 void
515 SSR__transfer_ownership_to_outside( void *data )
516 {
517 //TODO: removeAllOwnersFrom( data );
518 }
521 //===========================================================================
523 void
524 SSR__send_of_type_to( SlaveVP *sendPr, void *msg, const int type,
525 SlaveVP *receivePr)
526 { SSRSemReq reqData;
528 reqData.receivePr = receivePr;
529 reqData.sendPr = sendPr;
530 reqData.reqType = send_type;
531 reqData.msgType = type;
532 reqData.msg = msg;
533 reqData.nextReqInHashEntry = NULL;
535 //On ownership -- remove inside the send and let ownership sit in limbo
536 // as a potential in an entry in the hash table, when this receive msg
537 // gets paired to a send, the ownership gets added to the receivePr --
538 // the next work-unit in the receivePr's trace will have ownership.
539 VMS_WL__send_sem_request( &reqData, sendPr );
541 //When come back from suspend, no longer own data reachable from msg
542 //TODO: release ownership here
543 }
545 void
546 SSR__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr )
547 { SSRSemReq reqData;
549 //hash on the receiver, 'cause always know it, but sometimes want to
550 // receive from anonymous sender
552 reqData.receivePr = receivePr;
553 reqData.sendPr = sendPr;
554 reqData.reqType = send_from_to;
555 reqData.msg = msg;
556 reqData.nextReqInHashEntry = NULL;
558 VMS_WL__send_sem_request( &reqData, sendPr );
559 }
562 //===========================================================================
564 void *
565 SSR__receive_any_to( SlaveVP *receivePr )
566 {
568 }
570 void *
571 SSR__receive_type_to( const int type, SlaveVP *receivePr )
572 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID);
573 SSRSemReq reqData;
575 reqData.receivePr = receivePr;
576 reqData.reqType = receive_type;
577 reqData.msgType = type;
578 reqData.nextReqInHashEntry = NULL;
580 VMS_WL__send_sem_request( &reqData, receivePr );
582 return receivePr->dataRetFromReq;
583 }
587 /*Call this at point receiving virt pr wants in-coming data.
588 *
589 *The reason receivePr must call this is that it modifies the receivPr
590 * loc structure directly -- and the VMS rules state a virtual processor
591 * loc structure can only be modified by itself.
592 */
593 void *
594 SSR__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr )
595 { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID);
596 SSRSemReq reqData;
598 //hash on the receiver, 'cause always know it, but sometimes want to
599 // receive from anonymous sender
601 reqData.receivePr = receivePr;
602 reqData.sendPr = sendPr;
603 reqData.reqType = receive_from_to;
604 reqData.nextReqInHashEntry = NULL;
606 VMS_WL__send_sem_request( &reqData, receivePr );
608 return receivePr->dataRetFromReq;
609 }
612 //===========================================================================
613 //
614 /*A function singleton is a function whose body executes exactly once, on a
615 * single core, no matter how many times the fuction is called and no
616 * matter how many cores or the timing of cores calling it.
617 *
618 *A data singleton is a ticket attached to data. That ticket can be used
619 * to get the data through the function exactly once, no matter how many
620 * times the data is given to the function, and no matter the timing of
621 * trying to get the data through from different cores.
622 */
624 /*asm function declarations*/
625 void asm_save_ret_to_singleton(SSRSingleton *singletonPtrAddr);
626 void asm_write_ret_from_singleton(SSRSingleton *singletonPtrAddr);
628 /*Fn singleton uses ID as index into array of singleton structs held in the
629 * semantic environment.
630 */
631 void
632 SSR__start_fn_singleton( int32 singletonID, SlaveVP *animPr )
633 {
634 SSRSemReq reqData;
636 //
637 reqData.reqType = singleton_fn_start;
638 reqData.singletonID = singletonID;
640 VMS_WL__send_sem_request( &reqData, animPr );
641 if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton
642 {
643 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
644 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
645 }
646 }
648 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
649 * The start_data_singleton makes the structure and puts its addr into the
650 * location.
651 */
652 void
653 SSR__start_data_singleton( SSRSingleton **singletonAddr, SlaveVP *animPr )
654 {
655 SSRSemReq reqData;
657 if( *singletonAddr && (*singletonAddr)->hasFinished )
658 goto JmpToEndSingleton;
660 reqData.reqType = singleton_data_start;
661 reqData.singletonPtrAddr = singletonAddr;
663 VMS_WL__send_sem_request( &reqData, animPr );
664 if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
665 { //Assembly code changes the return addr on the stack to the one
666 // saved into the singleton by the end-singleton-fn
667 //The return addr is at 0x4(%%ebp)
668 JmpToEndSingleton:
669 asm_write_ret_from_singleton(*singletonAddr);
670 }
671 //now, simply return
672 //will exit either from the start singleton call or the end-singleton call
673 }
675 /*Uses ID as index into array of flags. If flag already set, resumes from
676 * end-label. Else, sets flag and resumes normally.
677 *
678 *Note, this call cannot be inlined because the instr addr at the label
679 * inside is shared by all invocations of a given singleton ID.
680 */
681 void
682 SSR__end_fn_singleton( int32 singletonID, SlaveVP *animPr )
683 {
684 SSRSemReq reqData;
686 //don't need this addr until after at least one singleton has reached
687 // this function
688 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
689 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
691 reqData.reqType = singleton_fn_end;
692 reqData.singletonID = singletonID;
694 VMS_WL__send_sem_request( &reqData, animPr );
696 EndSingletonInstrAddr:
697 return;
698 }
700 void
701 SSR__end_data_singleton( SSRSingleton **singletonPtrAddr, SlaveVP *animPr )
702 {
703 SSRSemReq reqData;
705 //don't need this addr until after singleton struct has reached
706 // this function for first time
707 //do assembly that saves the return addr of this fn call into the
708 // data singleton -- that data-singleton can only be given to exactly
709 // one instance in the code of this function. However, can use this
710 // function in different places for different data-singletons.
711 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
714 asm_save_ret_to_singleton(*singletonPtrAddr);
716 reqData.reqType = singleton_data_end;
717 reqData.singletonPtrAddr = singletonPtrAddr;
719 VMS_WL__send_sem_request( &reqData, animPr );
720 }
722 /*This executes the function in the masterVP, so it executes in isolation
723 * from any other copies -- only one copy of the function can ever execute
724 * at a time.
725 *
726 *It suspends to the master, and the request handler takes the function
727 * pointer out of the request and calls it, then resumes the VP.
728 *Only very short functions should be called this way -- for longer-running
729 * isolation, use transaction-start and transaction-end, which run the code
730 * between as work-code.
731 */
732 void
733 SSR__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
734 void *data, SlaveVP *animPr )
735 {
736 SSRSemReq reqData;
738 //
739 reqData.reqType = atomic;
740 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
741 reqData.dataForFn = data;
743 VMS_WL__send_sem_request( &reqData, animPr );
744 }
747 /*This suspends to the master.
748 *First, it looks at the VP's data, to see the highest transactionID that VP
749 * already has entered. If the current ID is not larger, it throws an
750 * exception stating a bug in the code. Otherwise it puts the current ID
751 * there, and adds the ID to a linked list of IDs entered -- the list is
752 * used to check that exits are properly ordered.
753 *Next it is uses transactionID as index into an array of transaction
754 * structures.
755 *If the "VP_currently_executing" field is non-null, then put requesting VP
756 * into queue in the struct. (At some point a holder will request
757 * end-transaction, which will take this VP from the queue and resume it.)
758 *If NULL, then write requesting into the field and resume.
759 */
760 void
761 SSR__start_transaction( int32 transactionID, SlaveVP *animPr )
762 {
763 SSRSemReq reqData;
765 //
766 reqData.sendPr = animPr;
767 reqData.reqType = trans_start;
768 reqData.transID = transactionID;
770 VMS_WL__send_sem_request( &reqData, animPr );
771 }
773 /*This suspends to the master, then uses transactionID as index into an
774 * array of transaction structures.
775 *It looks at VP_currently_executing to be sure it's same as requesting VP.
776 * If different, throws an exception, stating there's a bug in the code.
777 *Next it looks at the queue in the structure.
778 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
779 *If something in, gets it, sets VP_currently_executing to that VP, then
780 * resumes both.
781 */
782 void
783 SSR__end_transaction( int32 transactionID, SlaveVP *animPr )
784 {
785 SSRSemReq reqData;
787 //
788 reqData.sendPr = animPr;
789 reqData.reqType = trans_end;
790 reqData.transID = transactionID;
792 VMS_WL__send_sem_request( &reqData, animPr );
793 }