Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VSs_impls > VSs__MC_shared_impl
view VSs.c @ 6:1780f6b00e3d
Not working -- checkpoint while making explicitly created VPs work, and DKU pattern
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Wed, 01 Aug 2012 00:18:53 -0700 |
| parents | 8188c5b4bfd7 |
| children | 3999b8429ddd |
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 "VSs.h"
15 #include "Measurement/VSs_Counter_Recording.h"
17 //==========================================================================
19 void
20 VSs__init();
22 void
23 VSs__init_Helper();
24 //==========================================================================
28 //===========================================================================
31 /*These are the library functions *called in the application*
32 *
33 *There's a pattern for the outside sequential code to interact with the
34 * VMS_HW code.
35 *The VMS_HW system is inside a boundary.. every VSs system is in its
36 * own directory that contains the functions for each of the processor types.
37 * One of the processor types is the "seed" processor that starts the
38 * cascade of creating all the processors that do the work.
39 *So, in the directory is a file called "EntryPoint.c" that contains the
40 * function, named appropriately to the work performed, that the outside
41 * sequential code calls. This function follows a pattern:
42 *1) it calls VSs__init()
43 *2) it creates the initial data for the seed processor, which is passed
44 * in to the function
45 *3) it creates the seed VSs processor, with the data to start it with.
46 *4) it calls startVSsThenWaitUntilWorkDone
47 *5) it gets the returnValue from the transfer struc and returns that
48 * from the function
49 *
50 *For now, a new VSs system has to be created via VSs__init every
51 * time an entry point function is called -- later, might add letting the
52 * VSs system be created once, and let all the entry points just reuse
53 * it -- want to be as simple as possible now, and see by using what makes
54 * sense for later..
55 */
59 //===========================================================================
61 /*This is the "border crossing" function -- the thing that crosses from the
62 * outside world, into the VMS_HW world. It initializes and starts up the
63 * VMS system, then creates one processor from the specified function and
64 * puts it into the readyQ. From that point, that one function is resp.
65 * for creating all the other processors, that then create others, and so
66 * forth.
67 *When all the processors, including the seed, have dissipated, then this
68 * function returns. The results will have been written by side-effect via
69 * pointers read from, or written into initData.
70 *
71 *NOTE: no Threads should exist in the outside program that might touch
72 * any of the data reachable from initData passed in to here
73 */
74 void
75 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fnPtr, void *initData )
76 { VSsSemEnv *semEnv;
77 SlaveVP *seedSlv;
78 VSsSemData *semData;
79 VSsTaskStub *explPrTaskStub;
81 VSs__init(); //normal multi-thd
83 semEnv = _VMSMasterEnv->semanticEnv;
85 //VSs starts with one processor, which is put into initial environ,
86 // and which then calls create() to create more, thereby expanding work
87 seedSlv = VSs__create_slave_helper( fnPtr, initData,
88 semEnv, semEnv->nextCoreToGetNewSlv++ );
90 //seed slave is an explicit processor, so make one of the special
91 // task stubs for explicit processors, and attach it to the slave
92 explPrTaskStub = create_expl_proc_task_stub( initData );
94 semData = (VSsSemData *)seedSlv->semanticData;
95 //seedVP already has a permanent task
96 semData->needsTaskAssigned = FALSE;
97 semData->taskStub = explPrTaskStub;
99 resume_slaveVP( seedSlv, semEnv ); //returns right away, just queues Slv
101 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
103 VSs__cleanup_after_shutdown();
104 }
107 int32
108 VSs__giveMinWorkUnitCycles( float32 percentOverhead )
109 {
110 return MIN_WORK_UNIT_CYCLES;
111 }
113 int32
114 VSs__giveIdealNumWorkUnits()
115 {
116 return NUM_ANIM_SLOTS * NUM_CORES;
117 }
119 int32
120 VSs__give_number_of_cores_to_schedule_onto()
121 {
122 return NUM_CORES;
123 }
125 /*For now, use TSC -- later, make these two macros with assembly that first
126 * saves jump point, and second jumps back several times to get reliable time
127 */
128 void
129 VSs__start_primitive()
130 { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))->
131 primitiveStartTime );
132 }
134 /*Just quick and dirty for now -- make reliable later
135 * will want this to jump back several times -- to be sure cache is warm
136 * because don't want comm time included in calc-time measurement -- and
137 * also to throw out any "weird" values due to OS interrupt or TSC rollover
138 */
139 int32
140 VSs__end_primitive_and_give_cycles()
141 { int32 endTime, startTime;
142 //TODO: fix by repeating time-measurement
143 saveLowTimeStampCountInto( endTime );
144 startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
145 return (endTime - startTime);
146 }
148 //===========================================================================
150 /*Initializes all the data-structures for a VSs system -- but doesn't
151 * start it running yet!
152 *
153 *This runs in the main thread -- before VMS starts up
154 *
155 *This sets up the semantic layer over the VMS system
156 *
157 *First, calls VMS_Setup, then creates own environment, making it ready
158 * for creating the seed processor and then starting the work.
159 */
160 void
161 VSs__init()
162 {
163 VMS_SS__init();
164 //masterEnv, a global var, now is partially set up by init_VMS
165 // after this, have VMS_int__malloc and VMS_int__free available
167 VSs__init_Helper();
168 }
171 void idle_fn(void* data, SlaveVP *animatingSlv){
172 while(1){
173 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
174 }
175 }
177 void
178 VSs__init_Helper()
179 { VSsSemEnv *semanticEnv;
180 int32 i, coreNum, slotNum;
182 //Hook up the semantic layer's plug-ins to the Master virt procr
183 _VMSMasterEnv->requestHandler = &VSs__Request_Handler;
184 _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot;
185 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
186 _VMSMasterEnv->counterHandler = &VSs__counter_handler;
187 #endif
189 //create the semantic layer's environment (all its data) and add to
190 // the master environment
191 semanticEnv = VMS_int__malloc( sizeof( VSsSemEnv ) );
192 _VMSMasterEnv->semanticEnv = semanticEnv;
194 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
195 VSs__init_counter_data_structs();
196 #endif
198 semanticEnv->shutdownInitiated = FALSE;
199 semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) );
200 //For each animation slot, there is an idle slave, and an initial
201 // slave assigned as the current-task-slave. Create them here.
202 SlaveVP *idleSlv, *currTaskSlv;
203 for( coreNum = 0; coreNum < NUM_CORES; coreNum++ )
204 { semanticEnv->coreIsDone[coreNum] = FALSE; //use during shutdown
206 for( slotNum = 0; slotNum < NUM_ANIM_SLOTS; ++slotNum )
207 { idleSlv = VMS_int__create_slaveVP(&idle_fn,NULL);
208 idleSlv->coreAnimatedBy = coreNum;
209 idleSlv->animSlotAssignedTo = slotNum;
210 semanticEnv->idleSlv[coreNum][slotNum] = idleSlv;
212 currTaskSlv = VMS_int__create_slaveVP( &idle_fn, NULL );
213 currTaskSlv->coreAnimatedBy = coreNum;
214 currTaskSlv->animSlotAssignedTo = slotNum;
215 semanticEnv->currTaskSlvs[coreNum][slotNum] = currTaskSlv;
216 }
217 }
219 //create the ready queues, hash tables used for matching and so forth
220 semanticEnv->slavesReadyToResumeQ = makeVMSQ();
221 semanticEnv->extraTaskSlvQ = makeVMSQ();
222 semanticEnv->taskReadyQ = makeVMSQ();
224 semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free );
225 semanticEnv->commHashTbl = makeHashTable32( 16, &VMS_int__free );
227 semanticEnv->nextCoreToGetNewSlv = 0;
230 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
231 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
232 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
233 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
234 {
235 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
236 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
237 semanticEnv->fnSingletons[i].hasFinished = FALSE;
238 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
239 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
240 }
242 semanticEnv->numAdditionalSlvs = 0; //must be last
244 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
245 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
246 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
247 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
248 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
249 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
251 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
252 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
253 #endif
254 }
257 /*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown
258 */
259 void
260 VSs__cleanup_after_shutdown()
261 { VSsSemEnv *semanticEnv;
263 semanticEnv = _VMSMasterEnv->semanticEnv;
265 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
266 //UCC
267 FILE* output;
268 int n;
269 char filename[255];
270 for(n=0;n<255;n++)
271 {
272 sprintf(filename, "./counters/UCC.%d",n);
273 output = fopen(filename,"r");
274 if(output)
275 {
276 fclose(output);
277 }else{
278 break;
279 }
280 }
281 if(n<255){
282 printf("Saving UCC to File: %s ...\n", filename);
283 output = fopen(filename,"w+");
284 if(output!=NULL){
285 set_dependency_file(output);
286 //fprintf(output,"digraph Dependencies {\n");
287 //set_dot_file(output);
288 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
289 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
290 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
291 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
292 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
293 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
294 //fprintf(output,"}\n");
295 fflush(output);
297 } else
298 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
299 } else {
300 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
301 }
302 //Loop Graph
303 for(n=0;n<255;n++)
304 {
305 sprintf(filename, "./counters/LoopGraph.%d",n);
306 output = fopen(filename,"r");
307 if(output)
308 {
309 fclose(output);
310 }else{
311 break;
312 }
313 }
314 if(n<255){
315 printf("Saving LoopGraph to File: %s ...\n", filename);
316 output = fopen(filename,"w+");
317 if(output!=NULL){
318 set_dependency_file(output);
319 //fprintf(output,"digraph Dependencies {\n");
320 //set_dot_file(output);
321 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
322 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
323 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
324 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
325 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
326 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_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);
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 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
398 SlaveVP *creatingSlv )
399 { VSsSemReq 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.callingSlv = creatingSlv;
410 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
412 return creatingSlv->dataRetFromReq;
413 }
415 SlaveVP *
416 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
417 SlaveVP *creatingSlv, int32 coreToAssignOnto )
418 { VSsSemReq 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 = create_slave_w_aff; //not used, May 2012
424 reqData.coreToAssignOnto = coreToAssignOnto;
425 reqData.fnPtr = fnPtr;
426 reqData.initData = initData;
427 reqData.callingSlv = creatingSlv;
429 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
431 return creatingSlv->dataRetFromReq;
432 }
435 void
436 VSs__dissipate_slave( SlaveVP *slaveToDissipate )
437 {
438 VMS_WL__send_dissipate_req( slaveToDissipate );
439 }
442 //===========================================================================
445 //======================= task submit and end ==============================
446 /*
447 */
448 void
449 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv)
450 { VSsSemReq reqData;
452 reqData.reqType = submit_task;
454 reqData.taskType = taskType;
455 reqData.args = args;
456 reqData.callingSlv = animSlv;
458 reqData.taskID = NULL;
460 VMS_WL__send_sem_request( &reqData, animSlv );
461 }
463 inline int32 *
464 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv )
465 { int32 *taskID;
467 taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) );
468 taskID[0] = numInts;
469 return taskID;
470 }
472 void
473 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
474 SlaveVP *animSlv)
475 { VSsSemReq reqData;
477 reqData.reqType = submit_task;
479 reqData.taskType = taskType;
480 reqData.args = args;
481 reqData.taskID = taskID;
482 reqData.callingSlv = animSlv;
484 VMS_WL__send_sem_request( &reqData, animSlv );
485 }
488 /*This call is the last to happen in every task. It causes the slave to
489 * suspend and get the next task out of the task-queue. Notice there is no
490 * assigner here.. only one slave, no slave ReadyQ, and so on..
491 *Can either make the assigner take the next task out of the taskQ, or can
492 * leave all as it is, and make task-end take the next task.
493 *Note: this fits the case in the new VMS for no-context tasks, so will use
494 * the built-in taskQ of new VMS, and should be local and much faster.
495 *
496 *The task-stub is saved in the animSlv, so the request handler will get it
497 * from there, along with the task-type which has arg types, and so on..
498 *
499 * NOTE: if want, don't need to send the animating SlaveVP around..
500 * instead, can make a single slave per core, and coreCtrlr looks up the
501 * slave from having the core number.
502 *
503 *But, to stay compatible with all the other VMS languages, leave it in..
504 */
505 void
506 VSs__end_task( SlaveVP *animSlv )
507 { VSsSemReq reqData;
509 reqData.reqType = end_task;
510 reqData.callingSlv = animSlv;
512 VMS_WL__send_sem_request( &reqData, animSlv );
513 }
516 void
517 VSs__taskwait(SlaveVP *animSlv)
518 {
519 VSsSemReq reqData;
521 reqData.reqType = taskwait;
522 reqData.callingSlv = animSlv;
524 VMS_WL__send_sem_request( &reqData, animSlv );
525 }
529 //========================== send and receive ============================
530 //
532 inline int32 *
533 VSs__give_self_taskID( SlaveVP *animSlv )
534 {
535 return ((VSsSemData*)animSlv->semanticData)->taskStub->taskID;
536 }
538 //================================ send ===================================
540 void
541 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
542 SlaveVP *senderSlv )
543 { VSsSemReq reqData;
545 reqData.reqType = send_type_to;
547 reqData.msg = msg;
548 reqData.msgType = type;
549 reqData.receiverID = receiverID;
550 reqData.senderSlv = senderSlv;
552 reqData.nextReqInHashEntry = NULL;
554 VMS_WL__send_sem_request( &reqData, senderSlv );
556 //When come back from suspend, no longer own data reachable from msg
557 }
559 void
560 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv )
561 { VSsSemReq reqData;
563 reqData.reqType = send_from_to;
565 reqData.msg = msg;
566 reqData.senderID = senderID;
567 reqData.receiverID = receiverID;
568 reqData.senderSlv = senderSlv;
570 reqData.nextReqInHashEntry = NULL;
572 VMS_WL__send_sem_request( &reqData, senderSlv );
573 }
576 //================================ receive ================================
578 /*The "type" version of send and receive creates a many-to-one relationship.
579 * The sender is anonymous, and many sends can stack up, waiting to be
580 * received. The same receiver can also have send from-to's
581 * waiting for it, and those will be kept separate from the "type"
582 * messages.
583 */
584 void *
585 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv )
586 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] );
587 VSsSemReq reqData;
589 reqData.reqType = receive_type_to;
591 reqData.msgType = type;
592 reqData.receiverID = receiverID;
593 reqData.receiverSlv = receiverSlv;
595 reqData.nextReqInHashEntry = NULL;
597 VMS_WL__send_sem_request( &reqData, receiverSlv );
599 return receiverSlv->dataRetFromReq;
600 }
604 /*Call this at the point a receiving task wants in-coming data.
605 * Use this from-to form when know senderID -- it makes a direct channel
606 * between sender and receiver.
607 */
608 void *
609 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv )
610 {
611 VSsSemReq reqData;
613 reqData.reqType = receive_from_to;
615 reqData.senderID = senderID;
616 reqData.receiverID = receiverID;
617 reqData.receiverSlv = receiverSlv;
619 reqData.nextReqInHashEntry = NULL;
620 DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]);
622 VMS_WL__send_sem_request( &reqData, receiverSlv );
624 return receiverSlv->dataRetFromReq;
625 }
630 //==========================================================================
631 //
632 /*A function singleton is a function whose body executes exactly once, on a
633 * single core, no matter how many times the fuction is called and no
634 * matter how many cores or the timing of cores calling it.
635 *
636 *A data singleton is a ticket attached to data. That ticket can be used
637 * to get the data through the function exactly once, no matter how many
638 * times the data is given to the function, and no matter the timing of
639 * trying to get the data through from different cores.
640 */
642 /*asm function declarations*/
643 void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr);
644 void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr);
646 /*Fn singleton uses ID as index into array of singleton structs held in the
647 * semantic environment.
648 */
649 void
650 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv )
651 {
652 VSsSemReq reqData;
654 //
655 reqData.reqType = singleton_fn_start;
656 reqData.singletonID = singletonID;
658 VMS_WL__send_sem_request( &reqData, animSlv );
659 if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton
660 {
661 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
662 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
663 }
664 }
666 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
667 * The start_data_singleton makes the structure and puts its addr into the
668 * location.
669 */
670 void
671 VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv )
672 {
673 VSsSemReq reqData;
675 if( *singletonAddr && (*singletonAddr)->hasFinished )
676 goto JmpToEndSingleton;
678 reqData.reqType = singleton_data_start;
679 reqData.singletonPtrAddr = singletonAddr;
681 VMS_WL__send_sem_request( &reqData, animSlv );
682 if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr
683 { //Assembly code changes the return addr on the stack to the one
684 // saved into the singleton by the end-singleton-fn
685 //The return addr is at 0x4(%%ebp)
686 JmpToEndSingleton:
687 asm_write_ret_from_singleton(*singletonAddr);
688 }
689 //now, simply return
690 //will exit either from the start singleton call or the end-singleton call
691 }
693 /*Uses ID as index into array of flags. If flag already set, resumes from
694 * end-label. Else, sets flag and resumes normally.
695 *
696 *Note, this call cannot be inlined because the instr addr at the label
697 * inside is shared by all invocations of a given singleton ID.
698 */
699 void
700 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv )
701 {
702 VSsSemReq reqData;
704 //don't need this addr until after at least one singleton has reached
705 // this function
706 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
707 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
709 reqData.reqType = singleton_fn_end;
710 reqData.singletonID = singletonID;
712 VMS_WL__send_sem_request( &reqData, animSlv );
714 EndSingletonInstrAddr:
715 return;
716 }
718 void
719 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv )
720 {
721 VSsSemReq reqData;
723 //don't need this addr until after singleton struct has reached
724 // this function for first time
725 //do assembly that saves the return addr of this fn call into the
726 // data singleton -- that data-singleton can only be given to exactly
727 // one instance in the code of this function. However, can use this
728 // function in different places for different data-singletons.
729 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
732 asm_save_ret_to_singleton(*singletonPtrAddr);
734 reqData.reqType = singleton_data_end;
735 reqData.singletonPtrAddr = singletonPtrAddr;
737 VMS_WL__send_sem_request( &reqData, animSlv );
738 }
740 /*This executes the function in the masterVP, so it executes in isolation
741 * from any other copies -- only one copy of the function can ever execute
742 * at a time.
743 *
744 *It suspends to the master, and the request handler takes the function
745 * pointer out of the request and calls it, then resumes the VP.
746 *Only very short functions should be called this way -- for longer-running
747 * isolation, use transaction-start and transaction-end, which run the code
748 * between as work-code.
749 */
750 void
751 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
752 void *data, SlaveVP *animSlv )
753 {
754 VSsSemReq reqData;
756 //
757 reqData.reqType = atomic;
758 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
759 reqData.dataForFn = data;
761 VMS_WL__send_sem_request( &reqData, animSlv );
762 }
765 /*This suspends to the master.
766 *First, it looks at the VP's data, to see the highest transactionID that VP
767 * already has entered. If the current ID is not larger, it throws an
768 * exception stating a bug in the code. Otherwise it puts the current ID
769 * there, and adds the ID to a linked list of IDs entered -- the list is
770 * used to check that exits are properly ordered.
771 *Next it is uses transactionID as index into an array of transaction
772 * structures.
773 *If the "VP_currently_executing" field is non-null, then put requesting VP
774 * into queue in the struct. (At some point a holder will request
775 * end-transaction, which will take this VP from the queue and resume it.)
776 *If NULL, then write requesting into the field and resume.
777 */
778 void
779 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv )
780 {
781 VSsSemReq reqData;
783 //
784 reqData.callingSlv = animSlv;
785 reqData.reqType = trans_start;
786 reqData.transID = transactionID;
788 VMS_WL__send_sem_request( &reqData, animSlv );
789 }
791 /*This suspends to the master, then uses transactionID as index into an
792 * array of transaction structures.
793 *It looks at VP_currently_executing to be sure it's same as requesting VP.
794 * If different, throws an exception, stating there's a bug in the code.
795 *Next it looks at the queue in the structure.
796 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
797 *If something in, gets it, sets VP_currently_executing to that VP, then
798 * resumes both.
799 */
800 void
801 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv )
802 {
803 VSsSemReq reqData;
805 //
806 reqData.callingSlv = animSlv;
807 reqData.reqType = trans_end;
808 reqData.transID = transactionID;
810 VMS_WL__send_sem_request( &reqData, animSlv );
811 }
