view VSs.c @ 9:832bc715fbf2

Some bug fixes.. not compiling yet
author Sean Halle <seanhalle@yahoo.com>
date Mon, 06 Aug 2012 01:14:41 -0700
parents eb3d77ca9f59
children b13fbd445e0a ed268fc7376a
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->parentTasksStub = parentTaskStub;
101 semData = (VSsSemData *)seedSlv->semanticData;
102 //seedVP is a thread, so has a permanent task
103 semData->needsTaskAssigned = FALSE;
104 semData->taskStub = threadTaskStub;
106 resume_slaveVP( seedSlv, semEnv ); //returns right away, just queues Slv
108 VMS_SS__start_the_work_then_wait_until_done(); //normal multi-thd
110 VSs__cleanup_after_shutdown();
111 }
114 int32
115 VSs__giveMinWorkUnitCycles( float32 percentOverhead )
116 {
117 return MIN_WORK_UNIT_CYCLES;
118 }
120 int32
121 VSs__giveIdealNumWorkUnits()
122 {
123 return NUM_ANIM_SLOTS * NUM_CORES;
124 }
126 int32
127 VSs__give_number_of_cores_to_schedule_onto()
128 {
129 return NUM_CORES;
130 }
132 /*For now, use TSC -- later, make these two macros with assembly that first
133 * saves jump point, and second jumps back several times to get reliable time
134 */
135 void
136 VSs__start_primitive()
137 { saveLowTimeStampCountInto( ((VSsSemEnv *)(_VMSMasterEnv->semanticEnv))->
138 primitiveStartTime );
139 }
141 /*Just quick and dirty for now -- make reliable later
142 * will want this to jump back several times -- to be sure cache is warm
143 * because don't want comm time included in calc-time measurement -- and
144 * also to throw out any "weird" values due to OS interrupt or TSC rollover
145 */
146 int32
147 VSs__end_primitive_and_give_cycles()
148 { int32 endTime, startTime;
149 //TODO: fix by repeating time-measurement
150 saveLowTimeStampCountInto( endTime );
151 startTime =((VSsSemEnv*)(_VMSMasterEnv->semanticEnv))->primitiveStartTime;
152 return (endTime - startTime);
153 }
155 //===========================================================================
157 /*Initializes all the data-structures for a VSs system -- but doesn't
158 * start it running yet!
159 *
160 *This runs in the main thread -- before VMS starts up
161 *
162 *This sets up the semantic layer over the VMS system
163 *
164 *First, calls VMS_Setup, then creates own environment, making it ready
165 * for creating the seed processor and then starting the work.
166 */
167 void
168 VSs__init()
169 {
170 VMS_SS__init();
171 //masterEnv, a global var, now is partially set up by init_VMS
172 // after this, have VMS_int__malloc and VMS_int__free available
174 VSs__init_Helper();
175 }
178 void idle_fn(void* data, SlaveVP *animatingSlv){
179 while(1){
180 VMS_int__suspend_slaveVP_and_send_req(animatingSlv);
181 }
182 }
184 void
185 VSs__init_Helper()
186 { VSsSemEnv *semanticEnv;
187 int32 i, coreNum, slotNum;
189 //Hook up the semantic layer's plug-ins to the Master virt procr
190 _VMSMasterEnv->requestHandler = &VSs__Request_Handler;
191 _VMSMasterEnv->slaveAssigner = &VSs__assign_slaveVP_to_slot;
192 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
193 _VMSMasterEnv->counterHandler = &VSs__counter_handler;
194 #endif
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 VSs__init_counter_data_structs();
203 #endif
205 semanticEnv->shutdownInitiated = FALSE;
206 semanticEnv->coreIsDone = VMS_int__malloc( NUM_CORES * sizeof( bool32 ) );
207 //For each animation slot, there is an idle slave, and an initial
208 // slave assigned as the current-task-slave. Create them here.
209 SlaveVP *idleSlv, *currTaskSlv;
210 for( coreNum = 0; coreNum < NUM_CORES; coreNum++ )
211 { semanticEnv->coreIsDone[coreNum] = FALSE; //use during shutdown
213 for( slotNum = 0; slotNum < NUM_ANIM_SLOTS; ++slotNum )
214 { idleSlv = VMS_int__create_slaveVP(&idle_fn,NULL);
215 idleSlv->coreAnimatedBy = coreNum;
216 idleSlv->animSlotAssignedTo =
217 _VMSMasterEnv->allAnimSlots[coreNum][slotNum];
218 semanticEnv->idleSlv[coreNum][slotNum] = idleSlv;
220 currTaskSlv = VMS_int__create_slaveVP( &idle_fn, NULL );
221 currTaskSlv->coreAnimatedBy = coreNum;
222 currTaskSlv->animSlotAssignedTo =
223 _VMSMasterEnv->allAnimSlots[coreNum][slotNum];
224 semanticEnv->currTaskSlvs[coreNum][slotNum] = currTaskSlv;
225 }
226 }
228 //create the ready queues, hash tables used for matching and so forth
229 semanticEnv->slavesReadyToResumeQ = makeVMSQ();
230 semanticEnv->freeExtraTaskSlvQ = makeVMSQ();
231 semanticEnv->taskReadyQ = makeVMSQ();
233 semanticEnv->argPtrHashTbl = makeHashTable32( 16, &VMS_int__free );
234 semanticEnv->commHashTbl = makeHashTable32( 16, &VMS_int__free );
236 semanticEnv->nextCoreToGetNewSlv = 0;
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 }
251 semanticEnv->numLiveExtraTaskSlvs = 0; //must be last
252 semanticEnv->numLiveThreadSlvs = 1; //must be last, count the seed
254 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
255 semanticEnv->unitList = makeListOfArrays(sizeof(Unit),128);
256 semanticEnv->ctlDependenciesList = makeListOfArrays(sizeof(Dependency),128);
257 semanticEnv->commDependenciesList = makeListOfArrays(sizeof(Dependency),128);
258 semanticEnv->dynDependenciesList = makeListOfArrays(sizeof(Dependency),128);
259 semanticEnv->ntonGroupsInfo = makePrivDynArrayOfSize((void***)&(semanticEnv->ntonGroups),8);
261 semanticEnv->hwArcs = makeListOfArrays(sizeof(Dependency),128);
262 memset(semanticEnv->last_in_slot,0,sizeof(NUM_CORES * NUM_ANIM_SLOTS * sizeof(Unit)));
263 #endif
264 }
267 /*Frees any memory allocated by VSs__init() then calls VMS_int__shutdown
268 */
269 void
270 VSs__cleanup_after_shutdown()
271 { VSsSemEnv *semanticEnv;
273 semanticEnv = _VMSMasterEnv->semanticEnv;
275 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
276 //UCC
277 FILE* output;
278 int n;
279 char filename[255];
280 for(n=0;n<255;n++)
281 {
282 sprintf(filename, "./counters/UCC.%d",n);
283 output = fopen(filename,"r");
284 if(output)
285 {
286 fclose(output);
287 }else{
288 break;
289 }
290 }
291 if(n<255){
292 printf("Saving UCC to File: %s ...\n", filename);
293 output = fopen(filename,"w+");
294 if(output!=NULL){
295 set_dependency_file(output);
296 //fprintf(output,"digraph Dependencies {\n");
297 //set_dot_file(output);
298 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
299 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
300 forAllInListOfArraysDo(semanticEnv->unitList, &print_unit_to_file);
301 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
302 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
303 forAllInDynArrayDo(semanticEnv->ntonGroupsInfo,&print_nton_to_file);
304 //fprintf(output,"}\n");
305 fflush(output);
307 } else
308 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
309 } else {
310 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
311 }
312 //Loop Graph
313 for(n=0;n<255;n++)
314 {
315 sprintf(filename, "./counters/LoopGraph.%d",n);
316 output = fopen(filename,"r");
317 if(output)
318 {
319 fclose(output);
320 }else{
321 break;
322 }
323 }
324 if(n<255){
325 printf("Saving LoopGraph to File: %s ...\n", filename);
326 output = fopen(filename,"w+");
327 if(output!=NULL){
328 set_dependency_file(output);
329 //fprintf(output,"digraph Dependencies {\n");
330 //set_dot_file(output);
331 //FIXME: first line still depends on counters being enabled, replace w/ unit struct!
332 //forAllInDynArrayDo(_VMSMasterEnv->counter_history_array_info, &print_dot_node_info );
333 forAllInListOfArraysDo( semanticEnv->unitList, &print_unit_to_file );
334 forAllInListOfArraysDo( semanticEnv->commDependenciesList, &print_comm_dependency_to_file );
335 forAllInListOfArraysDo( semanticEnv->ctlDependenciesList, &print_ctl_dependency_to_file );
336 forAllInListOfArraysDo( semanticEnv->dynDependenciesList, &print_dyn_dependency_to_file );
337 forAllInListOfArraysDo( semanticEnv->hwArcs, &print_hw_dependency_to_file );
338 //fprintf(output,"}\n");
339 fflush(output);
341 } else
342 printf("Opening LoopGraph file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
343 } else {
344 printf("Could not open LoopGraph file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
345 }
348 freeListOfArrays(semanticEnv->unitList);
349 freeListOfArrays(semanticEnv->commDependenciesList);
350 freeListOfArrays(semanticEnv->ctlDependenciesList);
351 freeListOfArrays(semanticEnv->dynDependenciesList);
353 #endif
354 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
355 for(n=0;n<255;n++)
356 {
357 sprintf(filename, "./counters/Counters.%d.csv",n);
358 output = fopen(filename,"r");
359 if(output)
360 {
361 fclose(output);
362 }else{
363 break;
364 }
365 }
366 if(n<255){
367 printf("Saving Counter measurements to File: %s ...\n", filename);
368 output = fopen(filename,"w+");
369 if(output!=NULL){
370 set_counter_file(output);
371 int i;
372 for(i=0;i<NUM_CORES;i++){
373 forAllInListOfArraysDo( semanticEnv->counterList[i], &print_counter_events_to_file );
374 fflush(output);
375 }
377 } else
378 printf("Opening UCC file failed. Please check that folder \"counters\" exists in run directory and has write permission.\n");
379 } else {
380 printf("Could not open UCC file, please clean \"counters\" folder. (Must contain less than 255 files.)\n");
381 }
383 #endif
384 /* It's all allocated inside VMS's big chunk -- that's about to be freed, so
385 * nothing to do here
388 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
389 {
390 VMS_int__free( semanticEnv->readyVPQs[coreIdx]->startOfData );
391 VMS_int__free( semanticEnv->readyVPQs[coreIdx] );
392 }
393 VMS_int__free( semanticEnv->readyVPQs );
395 freeHashTable( semanticEnv->commHashTbl );
396 VMS_int__free( _VMSMasterEnv->semanticEnv );
397 */
398 VMS_SS__cleanup_at_end_of_shutdown();
399 }
402 //===========================================================================
404 SlaveVP *
405 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
406 SlaveVP *creatingThd )
407 { VSsSemReq reqData;
409 //the semantic request data is on the stack and disappears when this
410 // call returns -- it's guaranteed to remain in the VP's stack for as
411 // long as the VP is suspended.
412 reqData.reqType = 0; //know type because in a VMS create req
413 reqData.fnPtr = fnPtr;
414 reqData.initData = initData;
415 reqData.callingSlv = creatingThd;
417 VMS_WL__send_create_slaveVP_req( &reqData, creatingThd );
419 return creatingThd->dataRetFromReq;
420 }
422 /*This is always the last thing done in the code animated by a thread.
423 * Normally, this would be the last line of the thread's top level function.
424 * But, if the thread exits from any point, it has to do so by calling
425 * this.
426 *
427 *This must update the count of active sub-tasks (sub-threads) of parents,
428 * and the semantic data and task stub must stay.
429 */
430 void
431 VSs__end_thread( SlaveVP *thdToEnd )
432 { VSsSemData *semData;
434 //check whether all sub-tasks have ended.. if not, don't free the
435 // semantic data nor task stub of this thread.
436 semData = (VSsSemData *)thdToEnd->semanticData;
437 if( semData->taskStub->numLiveChildTasks != 0 )
438 {
439 fix_me();
440 }
442 //Update the count of live sub-tasks in parent. If parent was a
443 // thread and has already ended, then if this was the last sub-task,
444 // free the semantic data and task stub of the parent.
446 VMS_WL__send_dissipate_req( thdToEnd );
447 }
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 }