VMS/VMS_Implementations/SSR_impls/SSR__MC_shared_impl

view SSR.c @ 72:d20b105981b7

make idle VPs optional
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Wed, 28 Mar 2012 18:02:38 +0200
parents 8882e795016d
children b73e4a6f3497
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->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
219 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
220 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
221 #endif
223 //create the ready queue, hash tables used for pairing send to receive
224 // and so forth
225 //TODO: add hash tables for pairing sends with receives, and
226 // initialize the data ownership system
227 readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) );
229 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
230 {
231 readyVPQs[ coreIdx ] = makeVMSQ();
232 }
234 semanticEnv->readyVPQs = readyVPQs;
236 semanticEnv->nextCoreToGetNewPr = 0;
237 semanticEnv->numSlaveVP = 0;
239 semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big
241 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
242 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
243 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
244 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
245 {
246 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
247 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
248 semanticEnv->fnSingletons[i].hasFinished = FALSE;
249 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
250 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
251 }
252 }
255 /*Frees any memory allocated by SSR__init() then calls VMS_int__shutdown
256 */
257 void
258 SSR__cleanup_after_shutdown()
259 { SSRSemEnv *semanticEnv;
261 semanticEnv = _VMSMasterEnv->semanticEnv;
263 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
264 //UCC
265 FILE* output;
266 int n;
267 char filename[255];
268 for(n=0;n<255;n++)
269 {
270 sprintf(filename, "./counters/UCC.%d",n);
271 output = fopen(filename,"r");
272 if(output)
273 {
274 fclose(output);
275 }else{
276 break;
277 }
278 }
279 if(n<255){
280 printf("Saving UCC to File: %s ...\n", filename);
281 output = fopen(filename,"w+");
282 if(output!=NULL){
283 set_dependency_file(output);
284 //fprintf(output,"digraph Dependencies {\n");
285 //set_dot_file(output);
286 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
287 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
288 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
289 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
290 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
291 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
292 //fprintf(output,"}\n");
293 fflush(output);
295 } else
296 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
297 } else {
298 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
299 }
300 //Loop Graph
301 for(n=0;n<255;n++)
302 {
303 sprintf(filename, "./counters/LoopGraph.%d",n);
304 output = fopen(filename,"r");
305 if(output)
306 {
307 fclose(output);
308 }else{
309 break;
310 }
311 }
312 if(n<255){
313 printf("Saving LoopGraph to File: %s ...\n", filename);
314 output = fopen(filename,"w+");
315 if(output!=NULL){
316 set_dependency_file(output);
317 //fprintf(output,"digraph Dependencies {\n");
318 //set_dot_file(output);
319 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
320 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
321 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
322 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
323 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
324 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
325 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
326 //fprintf(output,"}\n");
327 fflush(output);
329 } else
330 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
331 } else {
332 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
333 }
336 freeListOfArrays(semanticEnv->unitList);
337 freeListOfArrays(semanticEnv->commDependenciesList);
338 freeListOfArrays(semanticEnv->ctlDependenciesList);
339 freeListOfArrays(semanticEnv->dynDependenciesList);
341 #endif
342 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
343 for(n=0;n<255;n++)
344 {
345 sprintf(filename, "./counters/Counters.%d.csv",n);
346 output = fopen(filename,"r");
347 if(output)
348 {
349 fclose(output);
350 }else{
351 break;
352 }
353 }
354 if(n<255){
355 printf("Saving Counter measurements to File: %s ...\n", filename);
356 output = fopen(filename,"w+");
357 if(output!=NULL){
358 set_counter_file(output);
359 int i;
360 for(i=0;i<NUM_CORES;i++){
361 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
362 fflush(output);
363 }
365 } else
366 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
367 } else {
368 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
369 }
371 #endif
372 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
373 * nothing to do here
376 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
377 {
378 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
379 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
380 }
381 VMS_int__free( semanticEnv->readyVPQs );
383 freeHashTable( semanticEnv->commHashTbl );
384 VMS_int__free( _VMSMasterEnv->semanticEnv );
385 */
386 VMS_SS__cleanup_at_end_of_shutdown();
387 }
390 //===========================================================================
392 /*
393 */
394 SlaveVP *
395 SSR__create_procr_with( TopLevelFnPtr fnPtr, void *initData,
396 SlaveVP *creatingPr )
397 { SSRSemReq reqData;
399 //the semantic request data is on the stack and disappears when this
400 // call returns -- it's guaranteed to remain in the VP's stack for as
401 // long as the VP is suspended.
402 reqData.reqType = 0; //know type because in a VMS create req
403 reqData.coreToAssignOnto = -1; //means round-robin assign
404 reqData.fnPtr = fnPtr;
405 reqData.initData = initData;
406 reqData.sendPr = creatingPr;
408 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
410 return creatingPr->dataRetFromReq;
411 }
413 SlaveVP *
414 SSR__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData,
415 SlaveVP *creatingPr, int32 coreToAssignOnto )
416 { SSRSemReq reqData;
418 //the semantic request data is on the stack and disappears when this
419 // call returns -- it's guaranteed to remain in the VP's stack for as
420 // long as the VP is suspended.
421 reqData.reqType = 0; //know type because in a VMS create req
422 reqData.coreToAssignOnto = coreToAssignOnto;
423 reqData.fnPtr = fnPtr;
424 reqData.initData = initData;
425 reqData.sendPr = creatingPr;
427 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
429 return creatingPr->dataRetFromReq;
430 }
433 void
434 SSR__dissipate_procr( SlaveVP *procrToDissipate )
435 {
436 VMS_WL__send_dissipate_req( procrToDissipate );
437 }
440 //===========================================================================
442 void *
443 SSR__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr )
444 { SSRSemReq reqData;
446 reqData.reqType = malloc_req;
447 reqData.sendPr = owningPr;
448 reqData.sizeToMalloc = sizeToMalloc;
450 VMS_WL__send_sem_request( &reqData, owningPr );
452 return owningPr->dataRetFromReq;
453 }
456 /*Sends request to Master, which does the work of freeing
457 */
458 void
459 SSR__free( void *ptrToFree, SlaveVP *owningPr )
460 { SSRSemReq reqData;
462 reqData.reqType = free_req;
463 reqData.sendPr = owningPr;
464 reqData.ptrToFree = ptrToFree;
466 VMS_WL__send_sem_request( &reqData, owningPr );
467 }
470 void
471 SSR__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv,
472 SlaveVP *newOwnerPr )
473 {
474 //TODO: put in the ownership system that automatically frees when no
475 // owners of data left -- will need keeper for keeping data around when
476 // future created processors might need it but don't exist yet
477 }
480 void
481 SSR__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data )
482 {
484 }
487 void
488 SSR__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing )
489 {
491 }
494 /*Causes the SSR system to remove internal ownership, so data won't be
495 * freed when SSR shuts down, and will persist in the external program.
496 *
497 *Must be called from the processor that currently owns the data.
498 *
499 *IMPL: Transferring ownership touches two different virtual processor's
500 * state -- which means it has to be done carefully -- the VMS rules for
501 * semantic layers say that a work-unit is only allowed to touch the
502 * virtual processor it is part of, and that only a single work-unit per
503 * virtual processor be assigned to a slave at a time. So, this has to
504 * modify the virtual processor that owns the work-unit that called this
505 * function, then create a request to have the other processor modified.
506 *However, in this case, the TO processor is the outside, and transfers
507 * are only allowed to be called by the giver-upper, so can mark caller of
508 * this function as no longer owner, and return -- done.
509 */
510 void
511 SSR__transfer_ownership_to_outside( void *data )
512 {
513 //TODO: removeAllOwnersFrom( data );
514 }
517 //===========================================================================
519 void
520 SSR__send_of_type_to( SlaveVP *sendPr, void *msg, const int type,
521 SlaveVP *receivePr)
522 { SSRSemReq reqData;
524 reqData.receivePr = receivePr;
525 reqData.sendPr = sendPr;
526 reqData.reqType = send_type;
527 reqData.msgType = type;
528 reqData.msg = msg;
529 reqData.nextReqInHashEntry = NULL;
531 //On ownership -- remove inside the send and let ownership sit in limbo
532 // as a potential in an entry in the hash table, when this receive msg
533 // gets paired to a send, the ownership gets added to the receivePr --
534 // the next work-unit in the receivePr's trace will have ownership.
535 VMS_WL__send_sem_request( &reqData, sendPr );
537 //When come back from suspend, no longer own data reachable from msg
538 //TODO: release ownership here
539 }
541 void
542 SSR__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr )
543 { SSRSemReq reqData;
545 //hash on the receiver, 'cause always know it, but sometimes want to
546 // receive from anonymous sender
548 reqData.receivePr = receivePr;
549 reqData.sendPr = sendPr;
550 reqData.reqType = send_from_to;
551 reqData.msg = msg;
552 reqData.nextReqInHashEntry = NULL;
554 VMS_WL__send_sem_request( &reqData, sendPr );
555 }
558 //===========================================================================
560 void *
561 SSR__receive_any_to( SlaveVP *receivePr )
562 {
564 }
566 void *
567 SSR__receive_type_to( const int type, SlaveVP *receivePr )
568 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID);
569 SSRSemReq reqData;
571 reqData.receivePr = receivePr;
572 reqData.reqType = receive_type;
573 reqData.msgType = type;
574 reqData.nextReqInHashEntry = NULL;
576 VMS_WL__send_sem_request( &reqData, receivePr );
578 return receivePr->dataRetFromReq;
579 }
583 /*Call this at point receiving virt pr wants in-coming data.
584 *
585 *The reason receivePr must call this is that it modifies the receivPr
586 * loc structure directly -- and the VMS rules state a virtual processor
587 * loc structure can only be modified by itself.
588 */
589 void *
590 SSR__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr )
591 { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID);
592 SSRSemReq reqData;
594 //hash on the receiver, 'cause always know it, but sometimes want to
595 // receive from anonymous sender
597 reqData.receivePr = receivePr;
598 reqData.sendPr = sendPr;
599 reqData.reqType = receive_from_to;
600 reqData.nextReqInHashEntry = NULL;
602 VMS_WL__send_sem_request( &reqData, receivePr );
604 return receivePr->dataRetFromReq;
605 }
608 //===========================================================================
609 //
610 /*A function singleton is a function whose body executes exactly once, on a
611 * single core, no matter how many times the fuction is called and no
612 * matter how many cores or the timing of cores calling it.
613 *
614 *A data singleton is a ticket attached to data. That ticket can be used
615 * to get the data through the function exactly once, no matter how many
616 * times the data is given to the function, and no matter the timing of
617 * trying to get the data through from different cores.
618 */
620 /*asm function declarations*/
621 void asm_save_ret_to_singleton(SSRSingleton *singletonPtrAddr);
622 void asm_write_ret_from_singleton(SSRSingleton *singletonPtrAddr);
624 /*Fn singleton uses ID as index into array of singleton structs held in the
625 * semantic environment.
626 */
627 void
628 SSR__start_fn_singleton( int32 singletonID, SlaveVP *animPr )
629 {
630 SSRSemReq reqData;
632 //
633 reqData.reqType = singleton_fn_start;
634 reqData.singletonID = singletonID;
636 VMS_WL__send_sem_request( &reqData, animPr );
637 if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton
638 {
639 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
640 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
641 }
642 }
644 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
645 * The start_data_singleton makes the structure and puts its addr into the
646 * location.
647 */
648 void
649 SSR__start_data_singleton( SSRSingleton **singletonAddr, SlaveVP *animPr )
650 {
651 SSRSemReq reqData;
653 if( *singletonAddr && (*singletonAddr)->hasFinished )
654 goto JmpToEndSingleton;
656 reqData.reqType = singleton_data_start;
657 reqData.singletonPtrAddr = singletonAddr;
659 VMS_WL__send_sem_request( &reqData, animPr );
660 if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
661 { //Assembly code changes the return addr on the stack to the one
662 // saved into the singleton by the end-singleton-fn
663 //The return addr is at 0x4(%%ebp)
664 JmpToEndSingleton:
665 asm_write_ret_from_singleton(*singletonAddr);
666 }
667 //now, simply return
668 //will exit either from the start singleton call or the end-singleton call
669 }
671 /*Uses ID as index into array of flags. If flag already set, resumes from
672 * end-label. Else, sets flag and resumes normally.
673 *
674 *Note, this call cannot be inlined because the instr addr at the label
675 * inside is shared by all invocations of a given singleton ID.
676 */
677 void
678 SSR__end_fn_singleton( int32 singletonID, SlaveVP *animPr )
679 {
680 SSRSemReq reqData;
682 //don't need this addr until after at least one singleton has reached
683 // this function
684 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
685 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
687 reqData.reqType = singleton_fn_end;
688 reqData.singletonID = singletonID;
690 VMS_WL__send_sem_request( &reqData, animPr );
692 EndSingletonInstrAddr:
693 return;
694 }
696 void
697 SSR__end_data_singleton( SSRSingleton **singletonPtrAddr, SlaveVP *animPr )
698 {
699 SSRSemReq reqData;
701 //don't need this addr until after singleton struct has reached
702 // this function for first time
703 //do assembly that saves the return addr of this fn call into the
704 // data singleton -- that data-singleton can only be given to exactly
705 // one instance in the code of this function. However, can use this
706 // function in different places for different data-singletons.
707 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
710 asm_save_ret_to_singleton(*singletonPtrAddr);
712 reqData.reqType = singleton_data_end;
713 reqData.singletonPtrAddr = singletonPtrAddr;
715 VMS_WL__send_sem_request( &reqData, animPr );
716 }
718 /*This executes the function in the masterVP, so it executes in isolation
719 * from any other copies -- only one copy of the function can ever execute
720 * at a time.
721 *
722 *It suspends to the master, and the request handler takes the function
723 * pointer out of the request and calls it, then resumes the VP.
724 *Only very short functions should be called this way -- for longer-running
725 * isolation, use transaction-start and transaction-end, which run the code
726 * between as work-code.
727 */
728 void
729 SSR__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
730 void *data, SlaveVP *animPr )
731 {
732 SSRSemReq reqData;
734 //
735 reqData.reqType = atomic;
736 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
737 reqData.dataForFn = data;
739 VMS_WL__send_sem_request( &reqData, animPr );
740 }
743 /*This suspends to the master.
744 *First, it looks at the VP's data, to see the highest transactionID that VP
745 * already has entered. If the current ID is not larger, it throws an
746 * exception stating a bug in the code. Otherwise it puts the current ID
747 * there, and adds the ID to a linked list of IDs entered -- the list is
748 * used to check that exits are properly ordered.
749 *Next it is uses transactionID as index into an array of transaction
750 * structures.
751 *If the "VP_currently_executing" field is non-null, then put requesting VP
752 * into queue in the struct. (At some point a holder will request
753 * end-transaction, which will take this VP from the queue and resume it.)
754 *If NULL, then write requesting into the field and resume.
755 */
756 void
757 SSR__start_transaction( int32 transactionID, SlaveVP *animPr )
758 {
759 SSRSemReq reqData;
761 //
762 reqData.sendPr = animPr;
763 reqData.reqType = trans_start;
764 reqData.transID = transactionID;
766 VMS_WL__send_sem_request( &reqData, animPr );
767 }
769 /*This suspends to the master, then uses transactionID as index into an
770 * array of transaction structures.
771 *It looks at VP_currently_executing to be sure it's same as requesting VP.
772 * If different, throws an exception, stating there's a bug in the code.
773 *Next it looks at the queue in the structure.
774 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
775 *If something in, gets it, sets VP_currently_executing to that VP, then
776 * resumes both.
777 */
778 void
779 SSR__end_transaction( int32 transactionID, SlaveVP *animPr )
780 {
781 SSRSemReq reqData;
783 //
784 reqData.sendPr = animPr;
785 reqData.reqType = trans_end;
786 reqData.transID = transactionID;
788 VMS_WL__send_sem_request( &reqData, animPr );
789 }