VMS/VMS_Implementations/SSR_impls/SSR__MC_shared_impl

view SSR.c @ 77:833b31a8abc1

working version (w/ old hash impl)
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 28 Aug 2012 13:40:07 +0200
parents d20b105981b7
children ee8510009267
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 }
253 }
256 /*Frees any memory allocated by SSR__init() then calls VMS_int__shutdown
257 */
258 void
259 SSR__cleanup_after_shutdown()
260 { SSRSemEnv *semanticEnv;
262 semanticEnv = _VMSMasterEnv->semanticEnv;
264 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
265 //UCC
266 FILE* output;
267 int n;
268 char filename[255];
269 for(n=0;n<255;n++)
270 {
271 sprintf(filename, "./counters/UCC.%d",n);
272 output = fopen(filename,"r");
273 if(output)
274 {
275 fclose(output);
276 }else{
277 break;
278 }
279 }
280 if(n<255){
281 printf("Saving UCC to File: %s ...\n", filename);
282 output = fopen(filename,"w+");
283 if(output!=NULL){
284 set_dependency_file(output);
285 //fprintf(output,"digraph Dependencies {\n");
286 //set_dot_file(output);
287 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
288 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
289 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
290 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
291 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
292 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
293 //fprintf(output,"}\n");
294 fflush(output);
296 } else
297 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
298 } else {
299 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
300 }
301 //Loop Graph
302 for(n=0;n<255;n++)
303 {
304 sprintf(filename, "./counters/LoopGraph.%d",n);
305 output = fopen(filename,"r");
306 if(output)
307 {
308 fclose(output);
309 }else{
310 break;
311 }
312 }
313 if(n<255){
314 printf("Saving LoopGraph to File: %s ...\n", filename);
315 output = fopen(filename,"w+");
316 if(output!=NULL){
317 set_dependency_file(output);
318 //fprintf(output,"digraph Dependencies {\n");
319 //set_dot_file(output);
320 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
321 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
322 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
323 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
324 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
325 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
326 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
327 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
328 //fprintf(output,"}\n");
329 fflush(output);
331 } else
332 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
333 } else {
334 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
335 }
338 freeListOfArrays(semanticEnv->unitList);
339 freeListOfArrays(semanticEnv->commDependenciesList);
340 freeListOfArrays(semanticEnv->ctlDependenciesList);
341 freeListOfArrays(semanticEnv->dynDependenciesList);
342 freeListOfArrays(semanticEnv->singletonDependenciesList);
343 #endif
344 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
345 for(n=0;n<255;n++)
346 {
347 sprintf(filename, "./counters/Counters.%d.csv",n);
348 output = fopen(filename,"r");
349 if(output)
350 {
351 fclose(output);
352 }else{
353 break;
354 }
355 }
356 if(n<255){
357 printf("Saving Counter measurements to File: %s ...\n", filename);
358 output = fopen(filename,"w+");
359 if(output!=NULL){
360 set_counter_file(output);
361 int i;
362 for(i=0;i<NUM_CORES;i++){
363 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
364 fflush(output);
365 }
367 } else
368 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
369 } else {
370 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
371 }
373 #endif
374 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
375 * nothing to do here
378 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
379 {
380 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
381 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
382 }
383 VMS_int__free( semanticEnv->readyVPQs );
385 freeHashTable( semanticEnv->commHashTbl );
386 VMS_int__free( _VMSMasterEnv->semanticEnv );
387 */
388 VMS_SS__cleanup_at_end_of_shutdown();
389 }
392 //===========================================================================
394 /*
395 */
396 SlaveVP *
397 SSR__create_procr_with( TopLevelFnPtr fnPtr, void *initData,
398 SlaveVP *creatingPr )
399 { SSRSemReq reqData;
401 //the semantic request data is on the stack and disappears when this
402 // call returns -- it's guaranteed to remain in the VP's stack for as
403 // long as the VP is suspended.
404 reqData.reqType = 0; //know type because in a VMS create req
405 reqData.coreToAssignOnto = -1; //means round-robin assign
406 reqData.fnPtr = fnPtr;
407 reqData.initData = initData;
408 reqData.sendPr = creatingPr;
410 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
412 return creatingPr->dataRetFromReq;
413 }
415 SlaveVP *
416 SSR__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData,
417 SlaveVP *creatingPr, int32 coreToAssignOnto )
418 { SSRSemReq reqData;
420 //the semantic request data is on the stack and disappears when this
421 // call returns -- it's guaranteed to remain in the VP's stack for as
422 // long as the VP is suspended.
423 reqData.reqType = 0; //know type because in a VMS create req
424 reqData.coreToAssignOnto = coreToAssignOnto;
425 reqData.fnPtr = fnPtr;
426 reqData.initData = initData;
427 reqData.sendPr = creatingPr;
429 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
431 return creatingPr->dataRetFromReq;
432 }
435 void
436 SSR__dissipate_procr( SlaveVP *procrToDissipate )
437 {
438 VMS_WL__send_dissipate_req( procrToDissipate );
439 }
442 //===========================================================================
444 void *
445 SSR__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr )
446 { SSRSemReq reqData;
448 reqData.reqType = malloc_req;
449 reqData.sendPr = owningPr;
450 reqData.sizeToMalloc = sizeToMalloc;
452 VMS_WL__send_sem_request( &reqData, owningPr );
454 return owningPr->dataRetFromReq;
455 }
458 /*Sends request to Master, which does the work of freeing
459 */
460 void
461 SSR__free( void *ptrToFree, SlaveVP *owningPr )
462 { SSRSemReq reqData;
464 reqData.reqType = free_req;
465 reqData.sendPr = owningPr;
466 reqData.ptrToFree = ptrToFree;
468 VMS_WL__send_sem_request( &reqData, owningPr );
469 }
472 void
473 SSR__transfer_ownership_of_from_to( void *data, SlaveVP *oldOwnerSlv,
474 SlaveVP *newOwnerPr )
475 {
476 //TODO: put in the ownership system that automatically frees when no
477 // owners of data left -- will need keeper for keeping data around when
478 // future created processors might need it but don't exist yet
479 }
482 void
483 SSR__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data )
484 {
486 }
489 void
490 SSR__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing )
491 {
493 }
496 /*Causes the SSR system to remove internal ownership, so data won't be
497 * freed when SSR shuts down, and will persist in the external program.
498 *
499 *Must be called from the processor that currently owns the data.
500 *
501 *IMPL: Transferring ownership touches two different virtual processor's
502 * state -- which means it has to be done carefully -- the VMS rules for
503 * semantic layers say that a work-unit is only allowed to touch the
504 * virtual processor it is part of, and that only a single work-unit per
505 * virtual processor be assigned to a slave at a time. So, this has to
506 * modify the virtual processor that owns the work-unit that called this
507 * function, then create a request to have the other processor modified.
508 *However, in this case, the TO processor is the outside, and transfers
509 * are only allowed to be called by the giver-upper, so can mark caller of
510 * this function as no longer owner, and return -- done.
511 */
512 void
513 SSR__transfer_ownership_to_outside( void *data )
514 {
515 //TODO: removeAllOwnersFrom( data );
516 }
519 //===========================================================================
521 void
522 SSR__send_of_type_to( SlaveVP *sendPr, void *msg, const int type,
523 SlaveVP *receivePr)
524 { SSRSemReq reqData;
526 reqData.receivePr = receivePr;
527 reqData.sendPr = sendPr;
528 reqData.reqType = send_type;
529 reqData.msgType = type;
530 reqData.msg = msg;
531 reqData.nextReqInHashEntry = NULL;
533 //On ownership -- remove inside the send and let ownership sit in limbo
534 // as a potential in an entry in the hash table, when this receive msg
535 // gets paired to a send, the ownership gets added to the receivePr --
536 // the next work-unit in the receivePr's trace will have ownership.
537 VMS_WL__send_sem_request( &reqData, sendPr );
539 //When come back from suspend, no longer own data reachable from msg
540 //TODO: release ownership here
541 }
543 void
544 SSR__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr )
545 { SSRSemReq reqData;
547 //hash on the receiver, 'cause always know it, but sometimes want to
548 // receive from anonymous sender
550 reqData.receivePr = receivePr;
551 reqData.sendPr = sendPr;
552 reqData.reqType = send_from_to;
553 reqData.msg = msg;
554 reqData.nextReqInHashEntry = NULL;
556 VMS_WL__send_sem_request( &reqData, sendPr );
557 }
560 //===========================================================================
562 void *
563 SSR__receive_any_to( SlaveVP *receivePr )
564 {
566 }
568 void *
569 SSR__receive_type_to( const int type, SlaveVP *receivePr )
570 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to: %d", receivePr->slaveID);
571 SSRSemReq reqData;
573 reqData.receivePr = receivePr;
574 reqData.reqType = receive_type;
575 reqData.msgType = type;
576 reqData.nextReqInHashEntry = NULL;
578 VMS_WL__send_sem_request( &reqData, receivePr );
580 return receivePr->dataRetFromReq;
581 }
585 /*Call this at point receiving virt pr wants in-coming data.
586 *
587 *The reason receivePr must call this is that it modifies the receivPr
588 * loc structure directly -- and the VMS rules state a virtual processor
589 * loc structure can only be modified by itself.
590 */
591 void *
592 SSR__receive_from_to( SlaveVP *sendPr, SlaveVP *receivePr )
593 { DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", sendPr->slaveID, receivePr->slaveID);
594 SSRSemReq reqData;
596 //hash on the receiver, 'cause always know it, but sometimes want to
597 // receive from anonymous sender
599 reqData.receivePr = receivePr;
600 reqData.sendPr = sendPr;
601 reqData.reqType = receive_from_to;
602 reqData.nextReqInHashEntry = NULL;
604 VMS_WL__send_sem_request( &reqData, receivePr );
606 return receivePr->dataRetFromReq;
607 }
610 //===========================================================================
611 //
612 /*A function singleton is a function whose body executes exactly once, on a
613 * single core, no matter how many times the fuction is called and no
614 * matter how many cores or the timing of cores calling it.
615 *
616 *A data singleton is a ticket attached to data. That ticket can be used
617 * to get the data through the function exactly once, no matter how many
618 * times the data is given to the function, and no matter the timing of
619 * trying to get the data through from different cores.
620 */
622 /*asm function declarations*/
623 void asm_save_ret_to_singleton(SSRSingleton *singletonPtrAddr);
624 void asm_write_ret_from_singleton(SSRSingleton *singletonPtrAddr);
626 /*Fn singleton uses ID as index into array of singleton structs held in the
627 * semantic environment.
628 */
629 void
630 SSR__start_fn_singleton( int32 singletonID, SlaveVP *animPr )
631 {
632 SSRSemReq reqData;
634 //
635 reqData.reqType = singleton_fn_start;
636 reqData.singletonID = singletonID;
638 VMS_WL__send_sem_request( &reqData, animPr );
639 if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton
640 {
641 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
642 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
643 }
644 }
646 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
647 * The start_data_singleton makes the structure and puts its addr into the
648 * location.
649 */
650 void
651 SSR__start_data_singleton( SSRSingleton **singletonAddr, SlaveVP *animPr )
652 {
653 SSRSemReq reqData;
655 if( *singletonAddr && (*singletonAddr)->hasFinished )
656 goto JmpToEndSingleton;
658 reqData.reqType = singleton_data_start;
659 reqData.singletonPtrAddr = singletonAddr;
661 VMS_WL__send_sem_request( &reqData, animPr );
662 if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
663 { //Assembly code changes the return addr on the stack to the one
664 // saved into the singleton by the end-singleton-fn
665 //The return addr is at 0x4(%%ebp)
666 JmpToEndSingleton:
667 asm_write_ret_from_singleton(*singletonAddr);
668 }
669 //now, simply return
670 //will exit either from the start singleton call or the end-singleton call
671 }
673 /*Uses ID as index into array of flags. If flag already set, resumes from
674 * end-label. Else, sets flag and resumes normally.
675 *
676 *Note, this call cannot be inlined because the instr addr at the label
677 * inside is shared by all invocations of a given singleton ID.
678 */
679 void
680 SSR__end_fn_singleton( int32 singletonID, SlaveVP *animPr )
681 {
682 SSRSemReq reqData;
684 //don't need this addr until after at least one singleton has reached
685 // this function
686 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
687 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
689 reqData.reqType = singleton_fn_end;
690 reqData.singletonID = singletonID;
692 VMS_WL__send_sem_request( &reqData, animPr );
694 EndSingletonInstrAddr:
695 return;
696 }
698 void
699 SSR__end_data_singleton( SSRSingleton **singletonPtrAddr, SlaveVP *animPr )
700 {
701 SSRSemReq reqData;
703 //don't need this addr until after singleton struct has reached
704 // this function for first time
705 //do assembly that saves the return addr of this fn call into the
706 // data singleton -- that data-singleton can only be given to exactly
707 // one instance in the code of this function. However, can use this
708 // function in different places for different data-singletons.
709 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
712 asm_save_ret_to_singleton(*singletonPtrAddr);
714 reqData.reqType = singleton_data_end;
715 reqData.singletonPtrAddr = singletonPtrAddr;
717 VMS_WL__send_sem_request( &reqData, animPr );
718 }
720 /*This executes the function in the masterVP, so it executes in isolation
721 * from any other copies -- only one copy of the function can ever execute
722 * at a time.
723 *
724 *It suspends to the master, and the request handler takes the function
725 * pointer out of the request and calls it, then resumes the VP.
726 *Only very short functions should be called this way -- for longer-running
727 * isolation, use transaction-start and transaction-end, which run the code
728 * between as work-code.
729 */
730 void
731 SSR__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
732 void *data, SlaveVP *animPr )
733 {
734 SSRSemReq reqData;
736 //
737 reqData.reqType = atomic;
738 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
739 reqData.dataForFn = data;
741 VMS_WL__send_sem_request( &reqData, animPr );
742 }
745 /*This suspends to the master.
746 *First, it looks at the VP's data, to see the highest transactionID that VP
747 * already has entered. If the current ID is not larger, it throws an
748 * exception stating a bug in the code. Otherwise it puts the current ID
749 * there, and adds the ID to a linked list of IDs entered -- the list is
750 * used to check that exits are properly ordered.
751 *Next it is uses transactionID as index into an array of transaction
752 * structures.
753 *If the "VP_currently_executing" field is non-null, then put requesting VP
754 * into queue in the struct. (At some point a holder will request
755 * end-transaction, which will take this VP from the queue and resume it.)
756 *If NULL, then write requesting into the field and resume.
757 */
758 void
759 SSR__start_transaction( int32 transactionID, SlaveVP *animPr )
760 {
761 SSRSemReq reqData;
763 //
764 reqData.sendPr = animPr;
765 reqData.reqType = trans_start;
766 reqData.transID = transactionID;
768 VMS_WL__send_sem_request( &reqData, animPr );
769 }
771 /*This suspends to the master, then uses transactionID as index into an
772 * array of transaction structures.
773 *It looks at VP_currently_executing to be sure it's same as requesting VP.
774 * If different, throws an exception, stating there's a bug in the code.
775 *Next it looks at the queue in the structure.
776 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
777 *If something in, gets it, sets VP_currently_executing to that VP, then
778 * resumes both.
779 */
780 void
781 SSR__end_transaction( int32 transactionID, SlaveVP *animPr )
782 {
783 SSRSemReq reqData;
785 //
786 reqData.sendPr = animPr;
787 reqData.reqType = trans_end;
788 reqData.transID = transactionID;
790 VMS_WL__send_sem_request( &reqData, animPr );
791 }