Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > SSR_impls > SSR__MC_shared_impl
view SSR.c @ 66:ce95c4d84fcd
integrating holistic model in common ancestor - not finished yet
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Thu, 15 Mar 2012 18:28:43 +0100 |
| parents | bd5ab695145c |
| children | 81a0f076b12e |
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 sched slots
33 *Might even do hierarchy of masters -- group of sched 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_SCHED_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;
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 semanticEnv->shutdownInitiated = FALSE;
203 for(i=0;i<NUM_CORES;++i){
204 for(j=0;j<NUM_SCHED_SLOTS;++j){
205 semanticEnv->idlePr[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL);
206 semanticEnv->idlePr[i][j]->coreAnimatedBy = i;
207 }
208 }
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);
217 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
218 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_SCHED_SLOTS * sizeof(Unit)));
219 #endif
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 *) );
227 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
228 {
229 readyVPQs[ coreIdx ] = makeVMSQ();
230 }
232 semanticEnv->readyVPQs = readyVPQs;
234 semanticEnv->nextCoreToGetNewPr = 0;
235 semanticEnv->numSlaveVP = 0;
237 semanticEnv->commHashTbl = makeHashTable( 1<<16, &VMS_int__free );//start big
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 }
253 /*Frees any memory allocated by SSR__init() then calls VMS_int__shutdown
254 */
255 void
256 SSR__cleanup_after_shutdown()
257 { SSRSemEnv *semanticEnv;
259 semanticEnv = _VMSMasterEnv->semanticEnv;
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);
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);
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 }
334 freeListOfArrays(semanticEnv->unitList);
335 freeListOfArrays(semanticEnv->commDependenciesList);
336 freeListOfArrays(semanticEnv->ctlDependenciesList);
337 freeListOfArrays(semanticEnv->dynDependenciesList);
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 }
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 }
369 #endif
370 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
371 * nothing to do here
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 );
381 freeHashTable( semanticEnv->commHashTbl );
382 VMS_int__free( _VMSMasterEnv->semanticEnv );
383 */
384 VMS_SS__cleanup_at_end_of_shutdown();
385 }
388 //===========================================================================
390 /*
391 */
392 SlaveVP *
393 SSR__create_procr_with( TopLevelFnPtr fnPtr, void *initData,
394 SlaveVP *creatingPr )
395 { SSRSemReq reqData;
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;
406 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
408 return creatingPr->dataRetFromReq;
409 }
411 SlaveVP *
412 SSR__create_procr_with_affinity( TopLevelFnPtr fnPtr, void *initData,
413 SlaveVP *creatingPr, int32 coreToAssignOnto )
414 { SSRSemReq reqData;
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;
425 VMS_WL__send_create_slaveVP_req( &reqData, creatingPr );
427 return creatingPr->dataRetFromReq;
428 }
431 void
432 SSR__dissipate_procr( SlaveVP *procrToDissipate )
433 {
434 VMS_WL__send_dissipate_req( procrToDissipate );
435 }
438 //===========================================================================
440 void *
441 SSR__malloc_to( int32 sizeToMalloc, SlaveVP *owningPr )
442 { SSRSemReq reqData;
444 reqData.reqType = malloc_req;
445 reqData.sendPr = owningPr;
446 reqData.sizeToMalloc = sizeToMalloc;
448 VMS_WL__send_sem_request( &reqData, owningPr );
450 return owningPr->dataRetFromReq;
451 }
454 /*Sends request to Master, which does the work of freeing
455 */
456 void
457 SSR__free( void *ptrToFree, SlaveVP *owningPr )
458 { SSRSemReq reqData;
460 reqData.reqType = free_req;
461 reqData.sendPr = owningPr;
462 reqData.ptrToFree = ptrToFree;
464 VMS_WL__send_sem_request( &reqData, owningPr );
465 }
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 }
478 void
479 SSR__add_ownership_by_to( SlaveVP *newOwnerSlv, void *data )
480 {
482 }
485 void
486 SSR__remove_ownership_by_from( SlaveVP *loserSlv, void *dataLosing )
487 {
489 }
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 }
515 //===========================================================================
517 void
518 SSR__send_of_type_to( SlaveVP *sendPr, void *msg, const int type,
519 SlaveVP *receivePr)
520 { SSRSemReq reqData;
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;
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 );
535 //When come back from suspend, no longer own data reachable from msg
536 //TODO: release ownership here
537 }
539 void
540 SSR__send_from_to( void *msg, SlaveVP *sendPr, SlaveVP *receivePr )
541 { SSRSemReq reqData;
543 //hash on the receiver, 'cause always know it, but sometimes want to
544 // receive from anonymous sender
546 reqData.receivePr = receivePr;
547 reqData.sendPr = sendPr;
548 reqData.reqType = send_from_to;
549 reqData.msg = msg;
550 reqData.nextReqInHashEntry = NULL;
552 VMS_WL__send_sem_request( &reqData, sendPr );
553 }
556 //===========================================================================
558 void *
559 SSR__receive_any_to( SlaveVP *receivePr )
560 {
562 }
564 void *
565 SSR__receive_type_to( const int type, SlaveVP *receivePr )
566 {
567 SSRSemReq reqData;
569 reqData.receivePr = receivePr;
570 reqData.reqType = receive_type;
571 reqData.msgType = type;
572 reqData.nextReqInHashEntry = NULL;
574 VMS_WL__send_sem_request( &reqData, receivePr );
576 return receivePr->dataRetFromReq;
577 }
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 { SSRSemReq reqData;
591 //hash on the receiver, 'cause always know it, but sometimes want to
592 // receive from anonymous sender
594 reqData.receivePr = receivePr;
595 reqData.sendPr = sendPr;
596 reqData.reqType = receive_from_to;
597 reqData.nextReqInHashEntry = NULL;
599 VMS_WL__send_sem_request( &reqData, receivePr );
601 return receivePr->dataRetFromReq;
602 }
605 //===========================================================================
606 //
607 /*A function singleton is a function whose body executes exactly once, on a
608 * single core, no matter how many times the fuction is called and no
609 * matter how many cores or the timing of cores calling it.
610 *
611 *A data singleton is a ticket attached to data. That ticket can be used
612 * to get the data through the function exactly once, no matter how many
613 * times the data is given to the function, and no matter the timing of
614 * trying to get the data through from different cores.
615 */
617 /*asm function declarations*/
618 void asm_save_ret_to_singleton(SSRSingleton *singletonPtrAddr);
619 void asm_write_ret_from_singleton(SSRSingleton *singletonPtrAddr);
621 /*Fn singleton uses ID as index into array of singleton structs held in the
622 * semantic environment.
623 */
624 void
625 SSR__start_fn_singleton( int32 singletonID, SlaveVP *animPr )
626 {
627 SSRSemReq reqData;
629 //
630 reqData.reqType = singleton_fn_start;
631 reqData.singletonID = singletonID;
633 VMS_WL__send_sem_request( &reqData, animPr );
634 if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton
635 {
636 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
637 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
638 }
639 }
641 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
642 * The start_data_singleton makes the structure and puts its addr into the
643 * location.
644 */
645 void
646 SSR__start_data_singleton( SSRSingleton **singletonAddr, SlaveVP *animPr )
647 {
648 SSRSemReq reqData;
650 if( *singletonAddr && (*singletonAddr)->hasFinished )
651 goto JmpToEndSingleton;
653 reqData.reqType = singleton_data_start;
654 reqData.singletonPtrAddr = singletonAddr;
656 VMS_WL__send_sem_request( &reqData, animPr );
657 if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
658 { //Assembly code changes the return addr on the stack to the one
659 // saved into the singleton by the end-singleton-fn
660 //The return addr is at 0x4(%%ebp)
661 JmpToEndSingleton:
662 asm_write_ret_from_singleton(*singletonAddr);
663 }
664 //now, simply return
665 //will exit either from the start singleton call or the end-singleton call
666 }
668 /*Uses ID as index into array of flags. If flag already set, resumes from
669 * end-label. Else, sets flag and resumes normally.
670 *
671 *Note, this call cannot be inlined because the instr addr at the label
672 * inside is shared by all invocations of a given singleton ID.
673 */
674 void
675 SSR__end_fn_singleton( int32 singletonID, SlaveVP *animPr )
676 {
677 SSRSemReq reqData;
679 //don't need this addr until after at least one singleton has reached
680 // this function
681 SSRSemEnv *semEnv = VMS_int__give_sem_env_for( animPr );
682 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
684 reqData.reqType = singleton_fn_end;
685 reqData.singletonID = singletonID;
687 VMS_WL__send_sem_request( &reqData, animPr );
689 EndSingletonInstrAddr:
690 return;
691 }
693 void
694 SSR__end_data_singleton( SSRSingleton **singletonPtrAddr, SlaveVP *animPr )
695 {
696 SSRSemReq reqData;
698 //don't need this addr until after singleton struct has reached
699 // this function for first time
700 //do assembly that saves the return addr of this fn call into the
701 // data singleton -- that data-singleton can only be given to exactly
702 // one instance in the code of this function. However, can use this
703 // function in different places for different data-singletons.
704 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
707 asm_save_ret_to_singleton(*singletonPtrAddr);
709 reqData.reqType = singleton_data_end;
710 reqData.singletonPtrAddr = singletonPtrAddr;
712 VMS_WL__send_sem_request( &reqData, animPr );
713 }
715 /*This executes the function in the masterVP, so it executes in isolation
716 * from any other copies -- only one copy of the function can ever execute
717 * at a time.
718 *
719 *It suspends to the master, and the request handler takes the function
720 * pointer out of the request and calls it, then resumes the VP.
721 *Only very short functions should be called this way -- for longer-running
722 * isolation, use transaction-start and transaction-end, which run the code
723 * between as work-code.
724 */
725 void
726 SSR__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
727 void *data, SlaveVP *animPr )
728 {
729 SSRSemReq reqData;
731 //
732 reqData.reqType = atomic;
733 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
734 reqData.dataForFn = data;
736 VMS_WL__send_sem_request( &reqData, animPr );
737 }
740 /*This suspends to the master.
741 *First, it looks at the VP's data, to see the highest transactionID that VP
742 * already has entered. If the current ID is not larger, it throws an
743 * exception stating a bug in the code. Otherwise it puts the current ID
744 * there, and adds the ID to a linked list of IDs entered -- the list is
745 * used to check that exits are properly ordered.
746 *Next it is uses transactionID as index into an array of transaction
747 * structures.
748 *If the "VP_currently_executing" field is non-null, then put requesting VP
749 * into queue in the struct. (At some point a holder will request
750 * end-transaction, which will take this VP from the queue and resume it.)
751 *If NULL, then write requesting into the field and resume.
752 */
753 void
754 SSR__start_transaction( int32 transactionID, SlaveVP *animPr )
755 {
756 SSRSemReq reqData;
758 //
759 reqData.sendPr = animPr;
760 reqData.reqType = trans_start;
761 reqData.transID = transactionID;
763 VMS_WL__send_sem_request( &reqData, animPr );
764 }
766 /*This suspends to the master, then uses transactionID as index into an
767 * array of transaction structures.
768 *It looks at VP_currently_executing to be sure it's same as requesting VP.
769 * If different, throws an exception, stating there's a bug in the code.
770 *Next it looks at the queue in the structure.
771 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
772 *If something in, gets it, sets VP_currently_executing to that VP, then
773 * resumes both.
774 */
775 void
776 SSR__end_transaction( int32 transactionID, SlaveVP *animPr )
777 {
778 SSRSemReq reqData;
780 //
781 reqData.sendPr = animPr;
782 reqData.reqType = trans_end;
783 reqData.transID = transactionID;
785 VMS_WL__send_sem_request( &reqData, animPr );
786 }
