Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VSs_impls > VSs__MC_shared_impl
view VSs.c @ 16:1ffd5df22df9
add CG instrumentation; still missing WaR hazard constraints
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 28 Aug 2012 15:33:16 +0200 |
| parents | 459055db7fc0 |
| children | f83fff8bd4b2 |
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 *threadTaskStub, *parentTaskStub;
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 a thread slave, so make a thread's task stub for it
91 // and then make another to stand for the seed's parent task. Make
92 // the parent be already ended, and have one child (the seed). This
93 // will make the dissipate handler do the right thing when the seed
94 // is dissipated.
95 threadTaskStub = create_thread_task_stub( initData );
96 parentTaskStub = create_thread_task_stub( NULL );
97 parentTaskStub->isEnded = TRUE;
98 parentTaskStub->numLiveChildThreads = 1; //so dissipate works for seed
99 threadTaskStub->parentTaskStub = parentTaskStub;
100 threadTaskStub->slaveAssignedTo = seedSlv;
102 semData = (VSsSemData *)seedSlv->semanticData;
103 //seedVP is a thread, so has a permanent task
104 semData->needsTaskAssigned = FALSE;
105 semData->taskStub = threadTaskStub;
106 semData->slaveType = ThreadSlv;
108 resume_slaveVP( seedSlv, semEnv ); //returns right away, just queues Slv
110 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
112 VSs__cleanup_after_shutdown();
113 }
116 int32
117 VSs__giveMinWorkUnitCycles( float32 percentOverhead )
118 {
119 return MIN_WORK_UNIT_CYCLES;
120 }
122 int32
123 VSs__giveIdealNumWorkUnits()
124 {
125 return NUM_ANIM_SLOTS * NUM_CORES;
126 }
128 int32
129 VSs__give_number_of_cores_to_schedule_onto()
130 {
131 return NUM_CORES;
132 }
134 /*For now, use TSC -- later, make these two macros with assembly that first
135 * saves jump point, and second jumps back several times to get reliable time
136 */
137 void
138 VSs__start_primitive()
139 { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))->
140 primitiveStartTime );
141 }
143 /*Just quick and dirty for now -- make reliable later
144 * will want this to jump back several times -- to be sure cache is warm
145 * because don't want comm time included in calc-time measurement -- and
146 * also to throw out any "weird" values due to OS interrupt or TSC rollover
147 */
148 int32
149 VSs__end_primitive_and_give_cycles()
150 { int32 endTime, startTime;
151 //TODO: fix by repeating time-measurement
152 saveLowTimeStampCountInto( endTime );
153 startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
154 return (endTime - startTime);
155 }
157 //===========================================================================
159 /*Initializes all the data-structures for a VSs system -- but doesn't
160 * start it running yet!
161 *
162 *This runs in the main thread -- before VMS starts up
163 *
164 *This sets up the semantic layer over the VMS system
165 *
166 *First, calls VMS_Setup, then creates own environment, making it ready
167 * for creating the seed processor and then starting the work.
168 */
169 void
170 VSs__init()
171 {
172 VMS_SS__init();
173 //masterEnv, a global var, now is partially set up by init_VMS
174 // after this, have VMS_int__malloc and VMS_int__free available
176 VSs__init_Helper();
177 }
180 void idle_fn(void* data, SlaveVP *animatingSlv){
181 while(1){
182 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
183 }
184 }
186 void
187 VSs__init_Helper()
188 { VSsSemEnv *semanticEnv;
189 int32 i, coreNum, slotNum;
190 VSsSemData *semData;
192 //Hook up the semantic layer's plug-ins to the Master virt procr
193 _VMSMasterEnv->requestHandler = &VSs__Request_Handler;
194 _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot;
196 //create the semantic layer's environment (all its data) and add to
197 // the master environment
198 semanticEnv = VMS_int__malloc( sizeof( VSsSemEnv ) );
199 _VMSMasterEnv->semanticEnv = semanticEnv;
201 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
202 _VMSMasterEnv->counterHandler = &VSs__counter_handler;
203 VSs__init_counter_data_structs();
204 #endif
206 semanticEnv->shutdownInitiated = FALSE;
207 semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) );
208 //For each animation slot, there is an idle slave, and an initial
209 // slave assigned as the current-task-slave. Create them here.
210 SlaveVP *idleSlv, *slotTaskSlv;
211 for( coreNum = 0; coreNum < NUM_CORES; coreNum++ )
212 { semanticEnv->coreIsDone[coreNum] = FALSE; //use during shutdown
214 for( slotNum = 0; slotNum < NUM_ANIM_SLOTS; ++slotNum )
215 { idleSlv = VSs__create_slave_helper( &idle_fn, NULL, semanticEnv, 0);
216 idleSlv->coreAnimatedBy = coreNum;
217 idleSlv->animSlotAssignedTo =
218 _VMSMasterEnv->allAnimSlots[coreNum][slotNum];
219 semanticEnv->idleSlv[coreNum][slotNum] = idleSlv;
221 slotTaskSlv = VSs__create_slave_helper( &idle_fn, NULL, semanticEnv, 0);
222 slotTaskSlv->coreAnimatedBy = coreNum;
223 slotTaskSlv->animSlotAssignedTo =
224 _VMSMasterEnv->allAnimSlots[coreNum][slotNum];
226 semData = slotTaskSlv->semanticData;
227 semData->needsTaskAssigned = TRUE;
228 semData->slaveType = SlotTaskSlv;
229 semanticEnv->slotTaskSlvs[coreNum][slotNum] = slotTaskSlv;
230 }
231 }
233 //create the ready queues, hash tables used for matching and so forth
234 semanticEnv->slavesReadyToResumeQ = makeVMSQ();
235 semanticEnv->freeExtraTaskSlvQ = makeVMSQ();
236 semanticEnv->taskReadyQ = makeVMSQ();
238 semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free );
239 semanticEnv->commHashTbl = makeHashTable32( 16, &VMS_int__free );
241 semanticEnv->nextCoreToGetNewSlv = 0;
244 //TODO: bug -- turn these arrays into dyn arrays to eliminate limit
245 //semanticEnv->singletonHasBeenExecutedFlags = makeDynArrayInfo( );
246 //semanticEnv->transactionStrucs = makeDynArrayInfo( );
247 for( i = 0; i < NUM_STRUCS_IN_SEM_ENV; i++ )
248 {
249 semanticEnv->fnSingletons[i].endInstrAddr = NULL;
250 semanticEnv->fnSingletons[i].hasBeenStarted = FALSE;
251 semanticEnv->fnSingletons[i].hasFinished = FALSE;
252 semanticEnv->fnSingletons[i].waitQ = makeVMSQ();
253 semanticEnv->transactionStrucs[i].waitingVPQ = makeVMSQ();
254 }
256 semanticEnv->numLiveExtraTaskSlvs = 0; //must be last
257 semanticEnv->numLiveThreadSlvs = 1; //must be last, counts the seed
259 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
260 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
261 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
262 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
263 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
264 semanticEnv->dataDependenciesList = makeListOfArrays(sizeof(Dependency),128);
265 semanticEnv->singletonDependenciesList = makeListOfArrays(sizeof(Dependency),128);
266 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
268 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
269 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
270 #endif
271 }
274 /*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown
275 */
276 void
277 VSs__cleanup_after_shutdown()
278 { VSsSemEnv *semanticEnv;
280 semanticEnv = _VMSMasterEnv->semanticEnv;
282 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
283 //UCC
284 FILE* output;
285 int n;
286 char filename[255];
287 for(n=0;n<255;n++)
288 {
289 sprintf(filename, "./counters/UCC.%d",n);
290 output = fopen(filename,"r");
291 if(output)
292 {
293 fclose(output);
294 }else{
295 break;
296 }
297 }
298 if(n<255){
299 printf("Saving UCC to File: %s ...\n", filename);
300 output = fopen(filename,"w+");
301 if(output!=NULL){
302 set_dependency_file(output);
303 //fprintf(output,"digraph Dependencies {\n");
304 //set_dot_file(output);
305 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
306 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
307 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
308 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
309 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
310 forAllInListOfArraysDo( semanticEnv->dataDependenciesList, &print_data_dependency_to_file );
311 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
312 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
313 //fprintf(output,"}\n");
314 fflush(output);
316 } else
317 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
318 } else {
319 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
320 }
321 //Loop Graph
322 for(n=0;n<255;n++)
323 {
324 sprintf(filename, "./counters/LoopGraph.%d",n);
325 output = fopen(filename,"r");
326 if(output)
327 {
328 fclose(output);
329 }else{
330 break;
331 }
332 }
333 if(n<255){
334 printf("Saving LoopGraph to File: %s ...\n", filename);
335 output = fopen(filename,"w+");
336 if(output!=NULL){
337 set_dependency_file(output);
338 //fprintf(output,"digraph Dependencies {\n");
339 //set_dot_file(output);
340 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
341 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
342 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
343 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
344 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
345 forAllInListOfArraysDo( semanticEnv->dataDependenciesList, &print_data_dependency_to_file );
346 forAllInListOfArraysDo( semanticEnv->singletonDependenciesList, &print_singleton_dependency_to_file );
347 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
348 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
349 //fprintf(output,"}\n");
350 fflush(output);
352 } else
353 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
354 } else {
355 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
356 }
359 freeListOfArrays(semanticEnv->unitList);
360 freeListOfArrays(semanticEnv->commDependenciesList);
361 freeListOfArrays(semanticEnv->ctlDependenciesList);
362 freeListOfArrays(semanticEnv->dynDependenciesList);
363 freeListOfArrays(semanticEnv->dataDependenciesList);
365 #endif
366 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
367 for(n=0;n<255;n++)
368 {
369 sprintf(filename, "./counters/Counters.%d.csv",n);
370 output = fopen(filename,"r");
371 if(output)
372 {
373 fclose(output);
374 }else{
375 break;
376 }
377 }
378 if(n<255){
379 printf("Saving Counter measurements to File: %s ...\n", filename);
380 output = fopen(filename,"w+");
381 if(output!=NULL){
382 set_counter_file(output);
383 int i;
384 for(i=0;i<NUM_CORES;i++){
385 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
386 fflush(output);
387 }
389 } else
390 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
391 } else {
392 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
393 }
395 #endif
396 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
397 * nothing to do here
400 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
401 {
402 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
403 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
404 }
405 VMS_int__free( semanticEnv->readyVPQs );
407 freeHashTable( semanticEnv->commHashTbl );
408 VMS_int__free( _VMSMasterEnv->semanticEnv );
409 */
410 VMS_SS__cleanup_at_end_of_shutdown();
411 }
414 //===========================================================================
416 SlaveVP *
417 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
418 SlaveVP *creatingThd )
419 { VSsSemReq reqData;
421 //the semantic request data is on the stack and disappears when this
422 // call returns -- it's guaranteed to remain in the VP's stack for as
423 // long as the VP is suspended.
424 reqData.reqType = 0; //know type because in a VMS create req
425 reqData.fnPtr = fnPtr;
426 reqData.initData = initData;
427 reqData.callingSlv = creatingThd;
429 VMS_WL__send_create_slaveVP_req( &reqData, creatingThd );
431 return creatingThd->dataRetFromReq;
432 }
434 /*This is always the last thing done in the code animated by a thread VP.
435 * Normally, this would be the last line of the thread's top level function.
436 * But, if the thread exits from any point, it has to do so by calling
437 * this.
438 *
439 *It simply sends a dissipate request, which handles all the state cleanup.
440 */
441 void
442 VSs__end_thread( SlaveVP *thdToEnd )
443 { VSsSemData *semData;
445 VMS_WL__send_dissipate_req( thdToEnd );
446 }
450 //===========================================================================
453 //======================= task submit and end ==============================
454 /*
455 */
456 void
457 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv)
458 { VSsSemReq reqData;
460 reqData.reqType = submit_task;
462 reqData.taskType = taskType;
463 reqData.args = args;
464 reqData.callingSlv = animSlv;
466 reqData.taskID = NULL;
468 VMS_WL__send_sem_request( &reqData, animSlv );
469 }
471 inline int32 *
472 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv )
473 { int32 *taskID;
475 taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) );
476 taskID[0] = numInts;
477 return taskID;
478 }
480 void
481 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
482 SlaveVP *animSlv)
483 { VSsSemReq reqData;
485 reqData.reqType = submit_task;
487 reqData.taskType = taskType;
488 reqData.args = args;
489 reqData.taskID = taskID;
490 reqData.callingSlv = animSlv;
492 VMS_WL__send_sem_request( &reqData, animSlv );
493 }
496 /*This call is the last to happen in every task. It causes the slave to
497 * suspend and get the next task out of the task-queue. Notice there is no
498 * assigner here.. only one slave, no slave ReadyQ, and so on..
499 *Can either make the assigner take the next task out of the taskQ, or can
500 * leave all as it is, and make task-end take the next task.
501 *Note: this fits the case in the new VMS for no-context tasks, so will use
502 * the built-in taskQ of new VMS, and should be local and much faster.
503 *
504 *The task-stub is saved in the animSlv, so the request handler will get it
505 * from there, along with the task-type which has arg types, and so on..
506 *
507 * NOTE: if want, don't need to send the animating SlaveVP around..
508 * instead, can make a single slave per core, and coreCtrlr looks up the
509 * slave from having the core number.
510 *
511 *But, to stay compatible with all the other VMS languages, leave it in..
512 */
513 void
514 VSs__end_task( SlaveVP *animSlv )
515 { VSsSemReq reqData;
517 reqData.reqType = end_task;
518 reqData.callingSlv = animSlv;
520 VMS_WL__send_sem_request( &reqData, animSlv );
521 }
524 void
525 VSs__taskwait(SlaveVP *animSlv)
526 {
527 VSsSemReq reqData;
529 reqData.reqType = taskwait;
530 reqData.callingSlv = animSlv;
532 VMS_WL__send_sem_request( &reqData, animSlv );
533 }
537 //========================== send and receive ============================
538 //
540 inline int32 *
541 VSs__give_self_taskID( SlaveVP *animSlv )
542 {
543 return ((VSsSemData*)animSlv->semanticData)->taskStub->taskID;
544 }
546 //================================ send ===================================
548 void
549 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
550 SlaveVP *senderSlv )
551 { VSsSemReq reqData;
553 reqData.reqType = send_type_to;
555 reqData.msg = msg;
556 reqData.msgType = type;
557 reqData.receiverID = receiverID;
558 reqData.senderSlv = senderSlv;
560 reqData.nextReqInHashEntry = NULL;
562 VMS_WL__send_sem_request( &reqData, senderSlv );
564 //When come back from suspend, no longer own data reachable from msg
565 }
567 void
568 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv )
569 { VSsSemReq reqData;
571 reqData.reqType = send_from_to;
573 reqData.msg = msg;
574 reqData.senderID = senderID;
575 reqData.receiverID = receiverID;
576 reqData.senderSlv = senderSlv;
578 reqData.nextReqInHashEntry = NULL;
580 VMS_WL__send_sem_request( &reqData, senderSlv );
581 }
584 //================================ receive ================================
586 /*The "type" version of send and receive creates a many-to-one relationship.
587 * The sender is anonymous, and many sends can stack up, waiting to be
588 * received. The same receiver can also have send from-to's
589 * waiting for it, and those will be kept separate from the "type"
590 * messages.
591 */
592 void *
593 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv )
594 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] );
595 VSsSemReq reqData;
597 reqData.reqType = receive_type_to;
599 reqData.msgType = type;
600 reqData.receiverID = receiverID;
601 reqData.receiverSlv = receiverSlv;
603 reqData.nextReqInHashEntry = NULL;
605 VMS_WL__send_sem_request( &reqData, receiverSlv );
607 return receiverSlv->dataRetFromReq;
608 }
612 /*Call this at the point a receiving task wants in-coming data.
613 * Use this from-to form when know senderID -- it makes a direct channel
614 * between sender and receiver.
615 */
616 void *
617 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv )
618 {
619 VSsSemReq reqData;
621 reqData.reqType = receive_from_to;
623 reqData.senderID = senderID;
624 reqData.receiverID = receiverID;
625 reqData.receiverSlv = receiverSlv;
627 reqData.nextReqInHashEntry = NULL;
628 DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]);
630 VMS_WL__send_sem_request( &reqData, receiverSlv );
632 return receiverSlv->dataRetFromReq;
633 }
638 //==========================================================================
639 //
640 /*A function singleton is a function whose body executes exactly once, on a
641 * single core, no matter how many times the fuction is called and no
642 * matter how many cores or the timing of cores calling it.
643 *
644 *A data singleton is a ticket attached to data. That ticket can be used
645 * to get the data through the function exactly once, no matter how many
646 * times the data is given to the function, and no matter the timing of
647 * trying to get the data through from different cores.
648 */
650 /*asm function declarations*/
651 void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr);
652 void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr);
654 /*Fn singleton uses ID as index into array of singleton structs held in the
655 * semantic environment.
656 */
657 void
658 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv )
659 {
660 VSsSemReq reqData;
662 //
663 reqData.reqType = singleton_fn_start;
664 reqData.singletonID = singletonID;
666 VMS_WL__send_sem_request( &reqData, animSlv );
667 if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton
668 {
669 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
670 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
671 }
672 }
674 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
675 * The start_data_singleton makes the structure and puts its addr into the
676 * location.
677 */
678 void
679 VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv )
680 {
681 VSsSemReq reqData;
683 if( *singletonAddr && (*singletonAddr)->hasFinished )
684 goto JmpToEndSingleton;
686 reqData.reqType = singleton_data_start;
687 reqData.singletonPtrAddr = singletonAddr;
689 VMS_WL__send_sem_request( &reqData, animSlv );
690 if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr
691 { //Assembly code changes the return addr on the stack to the one
692 // saved into the singleton by the end-singleton-fn
693 //The return addr is at 0x4(%%ebp)
694 JmpToEndSingleton:
695 asm_write_ret_from_singleton(*singletonAddr);
696 }
697 //now, simply return
698 //will exit either from the start singleton call or the end-singleton call
699 }
701 /*Uses ID as index into array of flags. If flag already set, resumes from
702 * end-label. Else, sets flag and resumes normally.
703 *
704 *Note, this call cannot be inlined because the instr addr at the label
705 * inside is shared by all invocations of a given singleton ID.
706 */
707 void
708 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv )
709 {
710 VSsSemReq reqData;
712 //don't need this addr until after at least one singleton has reached
713 // this function
714 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv );
715 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
717 reqData.reqType = singleton_fn_end;
718 reqData.singletonID = singletonID;
720 VMS_WL__send_sem_request( &reqData, animSlv );
722 EndSingletonInstrAddr:
723 return;
724 }
726 void
727 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv )
728 {
729 VSsSemReq reqData;
731 //don't need this addr until after singleton struct has reached
732 // this function for first time
733 //do assembly that saves the return addr of this fn call into the
734 // data singleton -- that data-singleton can only be given to exactly
735 // one instance in the code of this function. However, can use this
736 // function in different places for different data-singletons.
737 // (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr;
740 asm_save_ret_to_singleton(*singletonPtrAddr);
742 reqData.reqType = singleton_data_end;
743 reqData.singletonPtrAddr = singletonPtrAddr;
745 VMS_WL__send_sem_request( &reqData, animSlv );
746 }
748 /*This executes the function in the masterVP, so it executes in isolation
749 * from any other copies -- only one copy of the function can ever execute
750 * at a time.
751 *
752 *It suspends to the master, and the request handler takes the function
753 * pointer out of the request and calls it, then resumes the VP.
754 *Only very short functions should be called this way -- for longer-running
755 * isolation, use transaction-start and transaction-end, which run the code
756 * between as work-code.
757 */
758 void
759 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
760 void *data, SlaveVP *animSlv )
761 {
762 VSsSemReq reqData;
764 //
765 reqData.reqType = atomic;
766 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
767 reqData.dataForFn = data;
769 VMS_WL__send_sem_request( &reqData, animSlv );
770 }
773 /*This suspends to the master.
774 *First, it looks at the VP's data, to see the highest transactionID that VP
775 * already has entered. If the current ID is not larger, it throws an
776 * exception stating a bug in the code. Otherwise it puts the current ID
777 * there, and adds the ID to a linked list of IDs entered -- the list is
778 * used to check that exits are properly ordered.
779 *Next it is uses transactionID as index into an array of transaction
780 * structures.
781 *If the "VP_currently_executing" field is non-null, then put requesting VP
782 * into queue in the struct. (At some point a holder will request
783 * end-transaction, which will take this VP from the queue and resume it.)
784 *If NULL, then write requesting into the field and resume.
785 */
786 void
787 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv )
788 {
789 VSsSemReq reqData;
791 //
792 reqData.callingSlv = animSlv;
793 reqData.reqType = trans_start;
794 reqData.transID = transactionID;
796 VMS_WL__send_sem_request( &reqData, animSlv );
797 }
799 /*This suspends to the master, then uses transactionID as index into an
800 * array of transaction structures.
801 *It looks at VP_currently_executing to be sure it's same as requesting VP.
802 * If different, throws an exception, stating there's a bug in the code.
803 *Next it looks at the queue in the structure.
804 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
805 *If something in, gets it, sets VP_currently_executing to that VP, then
806 * resumes both.
807 */
808 void
809 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv )
810 {
811 VSsSemReq reqData;
813 //
814 reqData.callingSlv = animSlv;
815 reqData.reqType = trans_end;
816 reqData.transID = transactionID;
818 VMS_WL__send_sem_request( &reqData, animSlv );
819 }
821 //======================== Internal ==================================
822 /*
823 */
824 SlaveVP *
825 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
826 SlaveVP *creatingSlv )
827 { VSsSemReq reqData;
829 //the semantic request data is on the stack and disappears when this
830 // call returns -- it's guaranteed to remain in the VP's stack for as
831 // long as the VP is suspended.
832 reqData.reqType = 0; //know type because in a VMS create req
833 reqData.coreToAssignOnto = -1; //means round-robin assign
834 reqData.fnPtr = fnPtr;
835 reqData.initData = initData;
836 reqData.callingSlv = creatingSlv;
838 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
840 return creatingSlv->dataRetFromReq;
841 }
843 SlaveVP *
844 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
845 SlaveVP *creatingSlv, int32 coreToAssignOnto )
846 { VSsSemReq reqData;
848 //the semantic request data is on the stack and disappears when this
849 // call returns -- it's guaranteed to remain in the VP's stack for as
850 // long as the VP is suspended.
851 reqData.reqType = create_slave_w_aff; //not used, May 2012
852 reqData.coreToAssignOnto = coreToAssignOnto;
853 reqData.fnPtr = fnPtr;
854 reqData.initData = initData;
855 reqData.callingSlv = creatingSlv;
857 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
859 return creatingSlv->dataRetFromReq;
860 }
