Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VSs_impls > VSs__MC_shared_impl
view VSs.c @ 5:8188c5b4bfd7
implemented taskwait
author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
---|---|
date | Fri, 13 Jul 2012 17:35:49 +0200 |
parents | 13af59ed7ea5 |
children | 1780f6b00e3d |
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;
79 VSs__init(); //normal multi-thd
81 semEnv = _VMSMasterEnv->semanticEnv;
83 //VSs starts with one processor, which is put into initial environ,
84 // and which then calls create() to create more, thereby expanding work
85 seedSlv = VSs__create_slave_helper( fnPtr, initData,
86 semEnv, semEnv->nextCoreToGetNewSlv++ );
88 //seedVP doesn't do tasks
89 ((VSsSemData *)seedSlv->semanticData)->needsTaskAssigned = FALSE;
91 resume_slaveVP( seedSlv, semEnv );
93 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
95 VSs__cleanup_after_shutdown();
96 }
99 int32
100 VSs__giveMinWorkUnitCycles( float32 percentOverhead )
101 {
102 return MIN_WORK_UNIT_CYCLES;
103 }
105 int32
106 VSs__giveIdealNumWorkUnits()
107 {
108 return NUM_ANIM_SLOTS * NUM_CORES;
109 }
111 int32
112 VSs__give_number_of_cores_to_schedule_onto()
113 {
114 return NUM_CORES;
115 }
117 /*For now, use TSC -- later, make these two macros with assembly that first
118 * saves jump point, and second jumps back several times to get reliable time
119 */
120 void
121 VSs__start_primitive()
122 { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))->
123 primitiveStartTime );
124 }
126 /*Just quick and dirty for now -- make reliable later
127 * will want this to jump back several times -- to be sure cache is warm
128 * because don't want comm time included in calc-time measurement -- and
129 * also to throw out any "weird" values due to OS interrupt or TSC rollover
130 */
131 int32
132 VSs__end_primitive_and_give_cycles()
133 { int32 endTime, startTime;
134 //TODO: fix by repeating time-measurement
135 saveLowTimeStampCountInto( endTime );
136 startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
137 return (endTime - startTime);
138 }
140 //===========================================================================
142 /*Initializes all the data-structures for a VSs system -- but doesn't
143 * start it running yet!
144 *
145 *This runs in the main thread -- before VMS starts up
146 *
147 *This sets up the semantic layer over the VMS system
148 *
149 *First, calls VMS_Setup, then creates own environment, making it ready
150 * for creating the seed processor and then starting the work.
151 */
152 void
153 VSs__init()
154 {
155 VMS_SS__init();
156 //masterEnv, a global var, now is partially set up by init_VMS
157 // after this, have VMS_int__malloc and VMS_int__free available
159 VSs__init_Helper();
160 }
163 void idle_fn(void* data, SlaveVP *animatingSlv){
164 while(1){
165 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
166 }
167 }
169 void
170 VSs__init_Helper()
171 { VSsSemEnv *semanticEnv;
172 PrivQueueStruc **readyVPQs;
173 int coreIdx, i, j;
175 //Hook up the semantic layer's plug-ins to the Master virt procr
176 _VMSMasterEnv->requestHandler = &VSs__Request_Handler;
177 _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot;
178 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
179 _VMSMasterEnv->counterHandler = &VSs__counter_handler;
180 #endif
182 //create the semantic layer's environment (all its data) and add to
183 // the master environment
184 semanticEnv = VMS_int__malloc( sizeof( VSsSemEnv ) );
185 _VMSMasterEnv->semanticEnv = semanticEnv;
187 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
188 VSs__init_counter_data_structs();
189 #endif
191 semanticEnv->shutdownInitiated = FALSE;
192 semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) );
193 for( i = 0; i < NUM_CORES; ++i )
194 { semanticEnv->coreIsDone[i] = FALSE;
195 for( j = 0; j < NUM_ANIM_SLOTS; ++j )
196 {
197 semanticEnv->idleSlv[i][j] = VMS_int__create_slaveVP(&idle_fn,NULL);
198 semanticEnv->idleSlv[i][j]->coreAnimatedBy = i;
199 }
200 }
202 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
203 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
204 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
205 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
206 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
207 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
209 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
210 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
211 #endif
213 //create the ready queue, hash tables used for matching and so forth
214 readyVPQs = VMS_int__malloc( NUM_CORES * sizeof(PrivQueueStruc *) );
216 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
217 {
218 readyVPQs[ coreIdx ] = makeVMSQ();
219 }
221 semanticEnv->readyVPQs = readyVPQs;
223 semanticEnv->taskReadyQ = makeVMSQ();
225 semanticEnv->nextCoreToGetNewSlv = 0;
226 semanticEnv->numSlaveVP = 0;
228 semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free );
229 semanticEnv->commHashTbl = makeHashTable32( 16, &VMS_int__free );
231 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
232 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
233 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
234 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
235 {
236 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
237 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
238 semanticEnv->fnSingletons[i].hasFinished = FALSE;
239 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
240 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
241 }
242 }
245 /*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown
246 */
247 void
248 VSs__cleanup_after_shutdown()
249 { VSsSemEnv *semanticEnv;
251 semanticEnv = _VMSMasterEnv->semanticEnv;
253 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
254 //UCC
255 FILE* output;
256 int n;
257 char filename[255];
258 for(n=0;n<255;n++)
259 {
260 sprintf(filename, "./counters/UCC.%d",n);
261 output = fopen(filename,"r");
262 if(output)
263 {
264 fclose(output);
265 }else{
266 break;
267 }
268 }
269 if(n<255){
270 printf("Saving UCC to File: %s ...\n", filename);
271 output = fopen(filename,"w+");
272 if(output!=NULL){
273 set_dependency_file(output);
274 //fprintf(output,"digraph Dependencies {\n");
275 //set_dot_file(output);
276 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
277 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
278 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
279 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
280 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
281 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
282 //fprintf(output,"}\n");
283 fflush(output);
285 } else
286 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
287 } else {
288 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
289 }
290 //Loop Graph
291 for(n=0;n<255;n++)
292 {
293 sprintf(filename, "./counters/LoopGraph.%d",n);
294 output = fopen(filename,"r");
295 if(output)
296 {
297 fclose(output);
298 }else{
299 break;
300 }
301 }
302 if(n<255){
303 printf("Saving LoopGraph to File: %s ...\n", filename);
304 output = fopen(filename,"w+");
305 if(output!=NULL){
306 set_dependency_file(output);
307 //fprintf(output,"digraph Dependencies {\n");
308 //set_dot_file(output);
309 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
310 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
311 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
312 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
313 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
314 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
315 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
316 //fprintf(output,"}\n");
317 fflush(output);
319 } else
320 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
321 } else {
322 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
323 }
326 freeListOfArrays(semanticEnv->unitList);
327 freeListOfArrays(semanticEnv->commDependenciesList);
328 freeListOfArrays(semanticEnv->ctlDependenciesList);
329 freeListOfArrays(semanticEnv->dynDependenciesList);
331 #endif
332 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
333 for(n=0;n<255;n++)
334 {
335 sprintf(filename, "./counters/Counters.%d.csv",n);
336 output = fopen(filename,"r");
337 if(output)
338 {
339 fclose(output);
340 }else{
341 break;
342 }
343 }
344 if(n<255){
345 printf("Saving Counter measurements to File: %s ...\n", filename);
346 output = fopen(filename,"w+");
347 if(output!=NULL){
348 set_counter_file(output);
349 int i;
350 for(i=0;i<NUM_CORES;i++){
351 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
352 fflush(output);
353 }
355 } else
356 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
357 } else {
358 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
359 }
361 #endif
362 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
363 * nothing to do here
366 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
367 {
368 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
369 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
370 }
371 VMS_int__free( semanticEnv->readyVPQs );
373 freeHashTable( semanticEnv->commHashTbl );
374 VMS_int__free( _VMSMasterEnv->semanticEnv );
375 */
376 VMS_SS__cleanup_at_end_of_shutdown();
377 }
380 //===========================================================================
382 /*
383 */
384 SlaveVP *
385 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
386 SlaveVP *creatingSlv )
387 { VSsSemReq reqData;
389 //the semantic request data is on the stack and disappears when this
390 // call returns -- it's guaranteed to remain in the VP's stack for as
391 // long as the VP is suspended.
392 reqData.reqType = 0; //know type because in a VMS create req
393 reqData.coreToAssignOnto = -1; //means round-robin assign
394 reqData.fnPtr = fnPtr;
395 reqData.initData = initData;
396 reqData.callingSlv = creatingSlv;
398 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
400 return creatingSlv->dataRetFromReq;
401 }
403 SlaveVP *
404 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
405 SlaveVP *creatingSlv, int32 coreToAssignOnto )
406 { VSsSemReq reqData;
408 //the semantic request data is on the stack and disappears when this
409 // call returns -- it's guaranteed to remain in the VP's stack for as
410 // long as the VP is suspended.
411 reqData.reqType = create_slave_w_aff; //not used, May 2012
412 reqData.coreToAssignOnto = coreToAssignOnto;
413 reqData.fnPtr = fnPtr;
414 reqData.initData = initData;
415 reqData.callingSlv = creatingSlv;
417 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
419 return creatingSlv->dataRetFromReq;
420 }
423 void
424 VSs__dissipate_slave( SlaveVP *slaveToDissipate )
425 {
426 VMS_WL__send_dissipate_req( slaveToDissipate );
427 }
430 //===========================================================================
433 //======================= task submit and end ==============================
434 /*
435 */
436 void
437 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv)
438 { VSsSemReq reqData;
440 reqData.reqType = submit_task;
442 reqData.taskType = taskType;
443 reqData.args = args;
444 reqData.callingSlv = animSlv;
446 reqData.taskID = NULL;
448 VMS_WL__send_sem_request( &reqData, animSlv );
449 }
451 inline int32 *
452 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv )
453 { int32 *taskID;
455 taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) );
456 taskID[0] = numInts;
457 return taskID;
458 }
460 void
461 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
462 SlaveVP *animSlv)
463 { VSsSemReq reqData;
465 reqData.reqType = submit_task;
467 reqData.taskType = taskType;
468 reqData.args = args;
469 reqData.taskID = taskID;
470 reqData.callingSlv = animSlv;
472 VMS_WL__send_sem_request( &reqData, animSlv );
473 }
476 /*This call is the last to happen in every task. It causes the slave to
477 * suspend and get the next task out of the task-queue. Notice there is no
478 * assigner here.. only one slave, no slave ReadyQ, and so on..
479 *Can either make the assigner take the next task out of the taskQ, or can
480 * leave all as it is, and make task-end take the next task.
481 *Note: this fits the case in the new VMS for no-context tasks, so will use
482 * the built-in taskQ of new VMS, and should be local and much faster.
483 *
484 *The task-stub is saved in the animSlv, so the request handler will get it
485 * from there, along with the task-type which has arg types, and so on..
486 *
487 * NOTE: if want, don't need to send the animating SlaveVP around..
488 * instead, can make a single slave per core, and coreCtrlr looks up the
489 * slave from having the core number.
490 *
491 *But, to stay compatible with all the other VMS languages, leave it in..
492 */
493 void
494 VSs__end_task( SlaveVP *animSlv )
495 { VSsSemReq reqData;
497 reqData.reqType = end_task;
498 reqData.callingSlv = animSlv;
500 VMS_WL__send_sem_request( &reqData, animSlv );
501 }
504 void
505 VSs__taskwait(SlaveVP *animSlv)
506 {
507 VSsSemReq reqData;
509 reqData.reqType = taskwait;
510 reqData.callingSlv = animSlv;
512 VMS_WL__send_sem_request( &reqData, animSlv );
513 }
517 //========================== send and receive ============================
518 //
520 inline int32 *
521 VSs__give_self_taskID( SlaveVP *animSlv )
522 {
523 return ((VSsSemData*)animSlv->semanticData)->taskStub->taskID;
524 }
526 //================================ send ===================================
528 void
529 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
530 SlaveVP *senderSlv )
531 { VSsSemReq reqData;
533 reqData.reqType = send_type_to;
535 reqData.msg = msg;
536 reqData.msgType = type;
537 reqData.receiverID = receiverID;
538 reqData.senderSlv = senderSlv;
540 reqData.nextReqInHashEntry = NULL;
542 VMS_WL__send_sem_request( &reqData, senderSlv );
544 //When come back from suspend, no longer own data reachable from msg
545 }
547 void
548 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv )
549 { VSsSemReq reqData;
551 reqData.reqType = send_from_to;
553 reqData.msg = msg;
554 reqData.senderID = senderID;
555 reqData.receiverID = receiverID;
556 reqData.senderSlv = senderSlv;
558 reqData.nextReqInHashEntry = NULL;
560 VMS_WL__send_sem_request( &reqData, senderSlv );
561 }
564 //================================ receive ================================
566 /*The "type" version of send and receive creates a many-to-one relationship.
567 * The sender is anonymous, and many sends can stack up, waiting to be
568 * received. The same receiver can also have send from-to's
569 * waiting for it, and those will be kept separate from the "type"
570 * messages.
571 */
572 void *
573 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv )
574 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] );
575 VSsSemReq reqData;
577 reqData.reqType = receive_type_to;
579 reqData.msgType = type;
580 reqData.receiverID = receiverID;
581 reqData.receiverSlv = receiverSlv;
583 reqData.nextReqInHashEntry = NULL;
585 VMS_WL__send_sem_request( &reqData, receiverSlv );
587 return receiverSlv->dataRetFromReq;
588 }
592 /*Call this at the point a receiving task wants in-coming data.
593 * Use this from-to form when know senderID -- it makes a direct channel
594 * between sender and receiver.
595 */
596 void *
597 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv )
598 {
599 VSsSemReq reqData;
601 reqData.reqType = receive_from_to;
603 reqData.senderID = senderID;
604 reqData.receiverID = receiverID;
605 reqData.receiverSlv = receiverSlv;
607 reqData.nextReqInHashEntry = NULL;
608 DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]);
610 VMS_WL__send_sem_request( &reqData, receiverSlv );
612 return receiverSlv->dataRetFromReq;
613 }
618 //==========================================================================
619 //
620 /*A function singleton is a function whose body executes exactly once, on a
621 * single core, no matter how many times the fuction is called and no
622 * matter how many cores or the timing of cores calling it.
623 *
624 *A data singleton is a ticket attached to data. That ticket can be used
625 * to get the data through the function exactly once, no matter how many
626 * times the data is given to the function, and no matter the timing of
627 * trying to get the data through from different cores.
628 */
630 /*asm function declarations*/
631 void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr);
632 void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr);
634 /*Fn singleton uses ID as index into array of singleton structs held in the
635 * semantic environment.
636 */
637 void
638 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv )
639 {
640 VSsSemReq reqData;
642 //
643 reqData.reqType = singleton_fn_start;
644 reqData.singletonID = singletonID;
646 VMS_WL__send_sem_request( &reqData, animSlv );
647 if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton
648 {
649 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
650 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
651 }
652 }
654 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
655 * The start_data_singleton makes the structure and puts its addr into the
656 * location.
657 */
658 void
659 VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv )
660 {
661 VSsSemReq reqData;
663 if( *singletonAddr && (*singletonAddr)->hasFinished )
664 goto JmpToEndSingleton;
666 reqData.reqType = singleton_data_start;
667 reqData.singletonPtrAddr = singletonAddr;
669 VMS_WL__send_sem_request( &reqData, animSlv );
670 if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr
671 { //Assembly code changes the return addr on the stack to the one
672 // saved into the singleton by the end-singleton-fn
673 //The return addr is at 0x4(%%ebp)
674 JmpToEndSingleton:
675 asm_write_ret_from_singleton(*singletonAddr);
676 }
677 //now, simply return
678 //will exit either from the start singleton call or the end-singleton call
679 }
681 /*Uses ID as index into array of flags. If flag already set, resumes from
682 * end-label. Else, sets flag and resumes normally.
683 *
684 *Note, this call cannot be inlined because the instr addr at the label
685 * inside is shared by all invocations of a given singleton ID.
686 */
687 void
688 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv )
689 {
690 VSsSemReq reqData;
692 //don't need this addr until after at least one singleton has reached
693 // this function
694 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
695 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
697 reqData.reqType = singleton_fn_end;
698 reqData.singletonID = singletonID;
700 VMS_WL__send_sem_request( &reqData, animSlv );
702 EndSingletonInstrAddr:
703 return;
704 }
706 void
707 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv )
708 {
709 VSsSemReq reqData;
711 //don't need this addr until after singleton struct has reached
712 // this function for first time
713 //do assembly that saves the return addr of this fn call into the
714 // data singleton -- that data-singleton can only be given to exactly
715 // one instance in the code of this function. However, can use this
716 // function in different places for different data-singletons.
717 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
720 asm_save_ret_to_singleton(*singletonPtrAddr);
722 reqData.reqType = singleton_data_end;
723 reqData.singletonPtrAddr = singletonPtrAddr;
725 VMS_WL__send_sem_request( &reqData, animSlv );
726 }
728 /*This executes the function in the masterVP, so it executes in isolation
729 * from any other copies -- only one copy of the function can ever execute
730 * at a time.
731 *
732 *It suspends to the master, and the request handler takes the function
733 * pointer out of the request and calls it, then resumes the VP.
734 *Only very short functions should be called this way -- for longer-running
735 * isolation, use transaction-start and transaction-end, which run the code
736 * between as work-code.
737 */
738 void
739 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
740 void *data, SlaveVP *animSlv )
741 {
742 VSsSemReq reqData;
744 //
745 reqData.reqType = atomic;
746 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
747 reqData.dataForFn = data;
749 VMS_WL__send_sem_request( &reqData, animSlv );
750 }
753 /*This suspends to the master.
754 *First, it looks at the VP's data, to see the highest transactionID that VP
755 * already has entered. If the current ID is not larger, it throws an
756 * exception stating a bug in the code. Otherwise it puts the current ID
757 * there, and adds the ID to a linked list of IDs entered -- the list is
758 * used to check that exits are properly ordered.
759 *Next it is uses transactionID as index into an array of transaction
760 * structures.
761 *If the "VP_currently_executing" field is non-null, then put requesting VP
762 * into queue in the struct. (At some point a holder will request
763 * end-transaction, which will take this VP from the queue and resume it.)
764 *If NULL, then write requesting into the field and resume.
765 */
766 void
767 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv )
768 {
769 VSsSemReq reqData;
771 //
772 reqData.callingSlv = animSlv;
773 reqData.reqType = trans_start;
774 reqData.transID = transactionID;
776 VMS_WL__send_sem_request( &reqData, animSlv );
777 }
779 /*This suspends to the master, then uses transactionID as index into an
780 * array of transaction structures.
781 *It looks at VP_currently_executing to be sure it's same as requesting VP.
782 * If different, throws an exception, stating there's a bug in the code.
783 *Next it looks at the queue in the structure.
784 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
785 *If something in, gets it, sets VP_currently_executing to that VP, then
786 * resumes both.
787 */
788 void
789 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv )
790 {
791 VSsSemReq reqData;
793 //
794 reqData.callingSlv = animSlv;
795 reqData.reqType = trans_end;
796 reqData.transID = transactionID;
798 VMS_WL__send_sem_request( &reqData, animSlv );
799 }