Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.c @ 147:98fc8f3761a2
Small changes to make SSR & SSR Sequential work
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 27 Sep 2011 14:37:59 +0200 |
| parents | e7cd1945c9b6 |
| children | 68449b64c3df |
line source
1 /*
2 * Copyright 2010 OpenSourceStewardshipFoundation
3 *
4 * Licensed under BSD
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <malloc.h>
11 #include <inttypes.h>
12 #include <sys/time.h>
13 #include <pthread.h>
15 #include "VMS.h"
16 #include "ProcrContext.h"
17 #include "scheduling.h"
18 #include "Queue_impl/BlockingQueue.h"
19 #include "Histogram/Histogram.h"
22 #define thdAttrs NULL
24 //===========================================================================
25 void
26 shutdownFn( void *dummy, VirtProcr *dummy2 );
28 SchedSlot **
29 create_sched_slots();
31 void
32 create_masterEnv();
34 void
35 create_the_coreLoop_OS_threads();
37 MallocProlog *
38 create_free_list();
40 void
41 endOSThreadFn( void *initData, VirtProcr *animatingPr );
43 pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER;
44 pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
46 //===========================================================================
48 /*Setup has two phases:
49 * 1) Semantic layer first calls init_VMS, which creates masterEnv, and puts
50 * the master virt procr into the work-queue, ready for first "call"
51 * 2) Semantic layer then does its own init, which creates the seed virt
52 * procr inside the semantic layer, ready to schedule it when
53 * asked by the first run of the masterLoop.
54 *
55 *This part is bit weird because VMS really wants to be "always there", and
56 * have applications attach and detach.. for now, this VMS is part of
57 * the app, so the VMS system starts up as part of running the app.
58 *
59 *The semantic layer is isolated from the VMS internals by making the
60 * semantic layer do setup to a state that it's ready with its
61 * initial virt procrs, ready to schedule them to slots when the masterLoop
62 * asks. Without this pattern, the semantic layer's setup would
63 * have to modify slots directly to assign the initial virt-procrs, and put
64 * them into the readyToAnimateQ itself, breaking the isolation completely.
65 *
66 *
67 *The semantic layer creates the initial virt procr(s), and adds its
68 * own environment to masterEnv, and fills in the pointers to
69 * the requestHandler and slaveScheduler plug-in functions
70 */
72 /*This allocates VMS data structures, populates the master VMSProc,
73 * and master environment, and returns the master environment to the semantic
74 * layer.
75 */
76 void
77 VMS__init()
78 {
79 create_masterEnv();
80 create_the_coreLoop_OS_threads();
81 }
83 #ifdef SEQUENTIAL
85 /*To initialize the sequential version, just don't create the threads
86 */
87 void
88 VMS__init_Seq()
89 {
90 create_masterEnv();
91 }
93 #endif
95 void
96 create_masterEnv()
97 { MasterEnv *masterEnv;
98 VMSQueueStruc **readyToAnimateQs;
99 int coreIdx;
100 VirtProcr **masterVPs;
101 SchedSlot ***allSchedSlots; //ptr to array of ptrs
104 //Make the master env, which holds everything else
105 _VMSMasterEnv = malloc( sizeof(MasterEnv) );
107 //Very first thing put into the master env is the free-list, seeded
108 // with a massive initial chunk of memory.
109 //After this, all other mallocs are VMS__malloc.
110 int i;
111 for(i=0; i<NUM_CORES; i++)
112 {
113 _VMSMasterEnv->freeLists[i] = VMS_ext__create_free_list();
114 _VMSMasterEnv->interMasterRequestsFor[i] = NULL;
115 _VMSMasterEnv->interMasterRequestsSentBy[i] = NULL;
116 }
117 _VMSMasterEnv->currentMasterProcrID = 0;
118 _VMSMasterEnv->amtOfOutstandingMem = NUM_CORES*MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE;
120 //============================= MEASUREMENT STUFF ========================
121 #ifdef MEAS__TIME_MALLOC
122 _VMSMasterEnv->mallocTimeHist = makeFixedBinHistExt( 100, 0, 100,
123 "malloc_time_hist");
124 _VMSMasterEnv->freeTimeHist = makeFixedBinHistExt( 80, 0, 100,
125 "free_time_hist");
126 #endif
127 #ifdef MEAS__TIME_PLUGIN
128 _VMSMasterEnv->reqHdlrLowTimeHist = makeFixedBinHistExt( 1000, 0, 100,
129 "plugin_low_time_hist");
130 _VMSMasterEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 1000, 0, 100,
131 "plugin_high_time_hist");
132 #endif
133 //========================================================================
135 //===================== Only VMS__malloc after this ====================
136 masterEnv = (MasterEnv*)_VMSMasterEnv;
138 //Make a readyToAnimateQ for each core loop
139 readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
140 masterVPs = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) );
142 //One array for each core, 3 in array, core's masterVP scheds all
143 allSchedSlots = VMS__malloc( NUM_CORES * sizeof(SchedSlot *) );
145 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr
146 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
147 {
148 readyToAnimateQs[ coreIdx ] = makeVMSQ();
150 //Q: should give masterVP core-specific info as its init data?
151 masterVPs[ coreIdx ] = VMS__create_procr( (VirtProcrFnPtr)&masterLoop, (void*)masterEnv );
152 masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
153 allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
154 _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0;
155 _VMSMasterEnv->workStealingGates[ coreIdx ] = NULL;
156 }
157 _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs;
158 _VMSMasterEnv->masterVPs = masterVPs;
159 _VMSMasterEnv->masterLock = UNLOCKED;
160 _VMSMasterEnv->allSchedSlots = allSchedSlots;
161 _VMSMasterEnv->workStealingLock = UNLOCKED;
164 //Aug 19, 2010: no longer need to place initial masterVP into queue
165 // because coreLoop now controls -- animates its masterVP when no work
168 //============================= MEASUREMENT STUFF ========================
169 #ifdef STATS__TURN_ON_PROBES
170 _VMSMasterEnv->dynIntervalProbesInfo =
171 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->intervalProbes), 200);
173 _VMSMasterEnv->probeNameHashTbl = makeHashTable( 1000, &VMS__free );
175 //put creation time directly into master env, for fast retrieval
176 struct timeval timeStamp;
177 gettimeofday( &(timeStamp), NULL);
178 _VMSMasterEnv->createPtInSecs =
179 timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0);
180 #endif
181 #ifdef MEAS__TIME_MASTER_LOCK
182 _VMSMasterEnv->masterLockLowTimeHist = makeFixedBinHist( 50, 0, 2,
183 "master lock low time hist");
184 _VMSMasterEnv->masterLockHighTimeHist = makeFixedBinHist( 50, 0, 100,
185 "master lock high time hist");
186 #endif
188 MakeTheMeasHists();
189 //========================================================================
191 }
193 SchedSlot **
194 create_sched_slots()
195 { SchedSlot **schedSlots;
196 int i;
198 schedSlots = VMS__malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) );
200 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
201 {
202 schedSlots[i] = VMS__malloc( sizeof(SchedSlot) );
204 //Set state to mean "handling requests done, slot needs filling"
205 schedSlots[i]->workIsDone = FALSE;
206 schedSlots[i]->needsProcrAssigned = TRUE;
207 }
208 return schedSlots;
209 }
212 void
213 freeSchedSlots( SchedSlot **schedSlots )
214 { int i;
215 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
216 {
217 VMS__free( schedSlots[i] );
218 }
219 VMS__free( schedSlots );
220 }
223 void
224 create_the_coreLoop_OS_threads()
225 {
226 //========================================================================
227 // Create the Threads
228 int coreIdx, retCode;
230 //Need the threads to be created suspended, and wait for a signal
231 // before proceeding -- gives time after creating to initialize other
232 // stuff before the coreLoops set off.
233 _VMSMasterEnv->setupComplete = 0;
235 //Make the threads that animate the core loops
236 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
237 { coreLoopThdParams[coreIdx] = VMS__malloc( sizeof(ThdParams) );
238 coreLoopThdParams[coreIdx]->coreNum = coreIdx;
240 retCode =
241 pthread_create( &(coreLoopThdHandles[coreIdx]),
242 thdAttrs,
243 &coreLoop,
244 (void *)(coreLoopThdParams[coreIdx]) );
245 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(1);}
246 }
247 }
249 /*Semantic layer calls this when it want the system to start running..
250 *
251 *This starts the core loops running then waits for them to exit.
252 */
253 void
254 VMS__start_the_work_then_wait_until_done()
255 { int coreIdx;
256 //Start the core loops running
258 //tell the core loop threads that setup is complete
259 //get lock, to lock out any threads still starting up -- they'll see
260 // that setupComplete is true before entering while loop, and so never
261 // wait on the condition
262 pthread_mutex_lock( &suspendLock );
263 _VMSMasterEnv->setupComplete = 1;
264 pthread_mutex_unlock( &suspendLock );
265 pthread_cond_broadcast( &suspend_cond );
268 //wait for all to complete
269 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
270 {
271 pthread_join( coreLoopThdHandles[coreIdx], NULL );
272 }
274 //NOTE: do not clean up VMS env here -- semantic layer has to have
275 // a chance to clean up its environment first, then do a call to free
276 // the Master env and rest of VMS locations
277 }
279 #ifdef SEQUENTIAL
280 /*Only difference between version with an OS thread pinned to each core and
281 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
282 */
283 void
284 VMS__start_the_work_then_wait_until_done_Seq()
285 {
286 //Instead of un-suspending threads, just call the one and only
287 // core loop (sequential version), in the main thread.
288 coreLoop_Seq( NULL );
289 flushRegisters();
291 }
292 #endif
294 inline VirtProcr *
295 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
296 { VirtProcr *newPr;
297 void *stackLocs;
299 newPr = VMS__malloc( sizeof(VirtProcr) );
300 stackLocs = VMS__malloc( VIRT_PROCR_STACK_SIZE );
301 if( stackLocs == 0 )
302 { perror("VMS__malloc stack"); exit(1); }
304 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
305 }
307 /* "ext" designates that it's for use outside the VMS system -- should only
308 * be called from main thread or other thread -- never from code animated by
309 * a VMS virtual processor.
310 */
311 inline VirtProcr *
312 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
313 { VirtProcr *newPr;
314 char *stackLocs;
316 newPr = malloc( sizeof(VirtProcr) );
317 stackLocs = malloc( VIRT_PROCR_STACK_SIZE );
318 if( stackLocs == 0 )
319 { perror("malloc stack"); exit(1); }
321 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
322 }
325 /*Anticipating multi-tasking
326 */
327 void *
328 VMS__give_sem_env_for( VirtProcr *animPr )
329 {
330 return _VMSMasterEnv->semanticEnv;
331 }
332 //===========================================================================
333 /*there is a label inside this function -- save the addr of this label in
334 * the callingPr struc, as the pick-up point from which to start the next
335 * work-unit for that procr. If turns out have to save registers, then
336 * save them in the procr struc too. Then do assembly jump to the CoreLoop's
337 * "done with work-unit" label. The procr struc is in the request in the
338 * slave that animated the just-ended work-unit, so all the state is saved
339 * there, and will get passed along, inside the request handler, to the
340 * next work-unit for that procr.
341 */
342 void
343 VMS__suspend_procr( VirtProcr *animatingPr )
344 {
346 //The request to master will cause this suspended virt procr to get
347 // scheduled again at some future point -- to resume, core loop jumps
348 // to the resume point (below), which causes restore of saved regs and
349 // "return" from this call.
350 //animatingPr->nextInstrPt = &&ResumePt;
352 //return ownership of the virt procr and sched slot to Master virt pr
353 animatingPr->schedSlot->workIsDone = TRUE;
355 //=========================== Measurement stuff ========================
356 #ifdef MEAS__TIME_STAMP_SUSP
357 //record time stamp: compare to time-stamp recorded below
358 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
359 #endif
360 //=======================================================================
362 switchToCoreLoop(animatingPr);
363 flushRegisters();
365 //=======================================================================
367 #ifdef MEAS__TIME_STAMP_SUSP
368 //NOTE: only take low part of count -- do sanity check when take diff
369 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
370 #endif
372 return;
373 }
377 /*For this implementation of VMS, it may not make much sense to have the
378 * system of requests for creating a new processor done this way.. but over
379 * the scope of single-master, multi-master, mult-tasking, OS-implementing,
380 * distributed-memory, and so on, this gives VMS implementation a chance to
381 * do stuff before suspend, in the AppVP, and in the Master before the plugin
382 * is called, as well as in the lang-lib before this is called, and in the
383 * plugin. So, this gives both VMS and language implementations a chance to
384 * intercept at various points and do order-dependent stuff.
385 *Having a standard VMSNewPrReqData struc allows the language to create and
386 * free the struc, while VMS knows how to get the newPr if it wants it, and
387 * it lets the lang have lang-specific data related to creation transported
388 * to the plugin.
389 */
390 void
391 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr )
392 { VMSReqst req;
394 req.reqType = createReq;
395 req.semReqData = semReqData;
396 req.nextReqst = reqstingPr->requests;
397 reqstingPr->requests = &req;
399 VMS__suspend_procr( reqstingPr );
400 }
403 /*
404 *This adds a request to dissipate, then suspends the processor so that the
405 * request handler will receive the request. The request handler is what
406 * does the work of freeing memory and removing the processor from the
407 * semantic environment's data structures.
408 *The request handler also is what figures out when to shutdown the VMS
409 * system -- which causes all the core loop threads to die, and returns from
410 * the call that started up VMS to perform the work.
411 *
412 *This form is a bit misleading to understand if one is trying to figure out
413 * how VMS works -- it looks like a normal function call, but inside it
414 * sends a request to the request handler and suspends the processor, which
415 * jumps out of the VMS__dissipate_procr function, and out of all nestings
416 * above it, transferring the work of dissipating to the request handler,
417 * which then does the actual work -- causing the processor that animated
418 * the call of this function to disappear and the "hanging" state of this
419 * function to just poof into thin air -- the virtual processor's trace
420 * never returns from this call, but instead the virtual processor's trace
421 * gets suspended in this call and all the virt processor's state disap-
422 * pears -- making that suspend the last thing in the virt procr's trace.
423 */
424 void
425 VMS__send_dissipate_req( VirtProcr *procrToDissipate )
426 { VMSReqst req;
428 req.reqType = dissipate;
429 req.nextReqst = procrToDissipate->requests;
430 procrToDissipate->requests = &req;
432 VMS__suspend_procr( procrToDissipate );
433 }
436 /* "ext" designates that it's for use outside the VMS system -- should only
437 * be called from main thread or other thread -- never from code animated by
438 * a VMS virtual processor.
439 *
440 *Use this version to dissipate VPs created outside the VMS system.
441 */
442 void
443 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate )
444 {
445 //NOTE: initialData was given to the processor, so should either have
446 // been alloc'd with VMS__malloc, or freed by the level above animPr.
447 //So, all that's left to free here is the stack and the VirtProcr struc
448 // itself
449 //Note, should not stack-allocate initial data -- no guarantee, in
450 // general that creating processor will outlive ones it creates.
451 free( procrToDissipate->startOfStack );
452 free( procrToDissipate );
453 }
457 /*This call's name indicates that request is malloc'd -- so req handler
458 * has to free any extra requests tacked on before a send, using this.
459 *
460 * This inserts the semantic-layer's request data into standard VMS carrier
461 * request data-struct that is mallocd. The sem request doesn't need to
462 * be malloc'd if this is called inside the same call chain before the
463 * send of the last request is called.
464 *
465 *The request handler has to call VMS__free_VMSReq for any of these
466 */
467 inline void
468 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData,
469 VirtProcr *callingPr )
470 { VMSReqst *req;
472 req = VMS__malloc( sizeof(VMSReqst) );
473 req->reqType = semantic;
474 req->semReqData = semReqData;
475 req->nextReqst = callingPr->requests;
476 callingPr->requests = req;
477 }
479 /*This inserts the semantic-layer's request data into standard VMS carrier
480 * request data-struct is allocated on stack of this call & ptr to it sent
481 * to plugin
482 *Then it does suspend, to cause request to be sent.
483 */
484 inline void
485 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr )
486 { VMSReqst req;
488 req.reqType = semantic;
489 req.semReqData = semReqData;
490 req.nextReqst = callingPr->requests;
491 callingPr->requests = &req;
493 VMS__suspend_procr( callingPr );
494 }
497 inline void
498 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr )
499 { VMSReqst req;
501 req.reqType = VMSSemantic;
502 req.semReqData = semReqData;
503 req.nextReqst = callingPr->requests; //gab any other preceeding
504 callingPr->requests = &req;
506 VMS__suspend_procr( callingPr );
507 }
509 void inline
510 VMS__send_inter_plugin_req( void *reqData, int32 targetMaster,
511 VirtProcr *requestingMaster )
512 { _VMSMasterEnv->interMasterRequestsFor[targetMaster] =
513 (InterMasterReqst *) reqData;
514 }
516 void inline
517 VMS__send_inter_VMSCore_req( InterVMSCoreReqst *reqData,
518 int32 targetMaster, VirtProcr *requestingMaster )
519 { _VMSMasterEnv->interMasterRequestsFor[targetMaster] =
520 (InterMasterReqst *) reqData;
521 }
523 /*
524 */
525 VMSReqst *
526 VMS__take_next_request_out_of( VirtProcr *procrWithReq )
527 { VMSReqst *req;
529 req = procrWithReq->requests;
530 if( req == NULL ) return NULL;
532 procrWithReq->requests = procrWithReq->requests->nextReqst;
533 return req;
534 }
537 inline void *
538 VMS__take_sem_reqst_from( VMSReqst *req )
539 {
540 return req->semReqData;
541 }
545 /* This is for OS requests and VMS infrastructure requests, such as to create
546 * a probe -- a probe is inside the heart of VMS-core, it's not part of any
547 * language -- but it's also a semantic thing that's triggered from and used
548 * in the application.. so it crosses abstractions.. so, need some special
549 * pattern here for handling such requests.
550 * Doing this just like it were a second language sharing VMS-core.
551 *
552 * This is called from the language's request handler when it sees a request
553 * of type VMSSemReq
554 *
555 * TODO: Later change this, to give probes their own separate plugin & have
556 * VMS-core steer the request to appropriate plugin
557 * Do the same for OS calls -- look later at it..
558 */
559 void inline
560 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
561 ResumePrFnPtr resumePrFnPtr )
562 { VMSSemReq *semReq;
563 IntervalProbe *newProbe;
565 semReq = req->semReqData;
567 switch(semReq->reqType){
568 case createProbe:
569 newProbe = VMS__malloc( sizeof(IntervalProbe) );
570 newProbe->nameStr = VMS__strDup( (char*)semReq->data );
571 newProbe->hist = NULL;
572 newProbe->schedChoiceWasRecorded = FALSE;
574 //This runs in masterVP, so no race-condition worries
575 newProbe->probeID =
576 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
577 requestingPr->dataRetFromReq = newProbe;
578 break;
579 case interMasterReqst:
580 VMS__sendInterMasterReqst(semReq->receiverID,
581 (InterMasterReqst*)semReq->data);
582 break;
583 default:
584 break;
585 }
587 resumePrFnPtr( requestingPr, semEnv );
588 }
592 /*This must be called by the request handler plugin -- it cannot be called
593 * from the semantic library "dissipate processor" function -- instead, the
594 * semantic layer has to generate a request, and the plug-in calls this
595 * function.
596 *The reason is that this frees the virtual processor's stack -- which is
597 * still in use inside semantic library calls!
598 *
599 *This frees or recycles all the state owned by and comprising the VMS
600 * portion of the animating virtual procr. The request handler must first
601 * free any semantic data created for the processor that didn't use the
602 * VMS_malloc mechanism. Then it calls this, which first asks the malloc
603 * system to disown any state that did use VMS_malloc, and then frees the
604 * statck and the processor-struct itself.
605 *If the dissipated processor is the sole (remaining) owner of VMS__malloc'd
606 * state, then that state gets freed (or sent to recycling) as a side-effect
607 * of dis-owning it.
608 */
609 void
610 VMS__dissipate_procr( VirtProcr *animatingPr )
611 {
612 //dis-own all locations owned by this processor, causing to be freed
613 // any locations that it is (was) sole owner of
614 //TODO: implement VMS__malloc system, including "give up ownership"
617 //NOTE: initialData was given to the processor, so should either have
618 // been alloc'd with VMS__malloc, or freed by the level above animPr.
619 //So, all that's left to free here is the stack and the VirtProcr struc
620 // itself
621 //Note, should not stack-allocate initial data -- no guarantee, in
622 // general that creating processor will outlive ones it creates.
624 VMS__free( animatingPr->startOfStack);
625 VMS__free( animatingPr);
626 }
629 //TODO: look at architecting cleanest separation between request handler
630 // and master loop, for dissipate, create, shutdown, and other non-semantic
631 // requests. Issue is chain: one removes requests from AppVP, one dispatches
632 // on type of request, and one handles each type.. but some types require
633 // action from both request handler and master loop -- maybe just give the
634 // request handler calls like: VMS__handle_X_request_type
637 /*This is called by the semantic layer's request handler when it decides its
638 * time to shut down the VMS system. Calling this causes the core loop OS
639 * threads to exit, which unblocks the entry-point function that started up
640 * VMS, and allows it to grab the result and return to the original single-
641 * threaded application.
642 *
643 *The _VMSMasterEnv is needed by this shut down function, so the create-seed-
644 * and-wait function has to free a bunch of stuff after it detects the
645 * threads have all died: the masterEnv, the thread-related locations,
646 * masterVP any AppVPs that might still be allocated and sitting in the
647 * semantic environment, or have been orphaned in the _VMSWorkQ.
648 *
649 *NOTE: the semantic plug-in is expected to use VMS__malloc to get all the
650 * locations it needs, and give ownership to masterVP. Then, they will be
651 * automatically freed.
652 *
653 *In here,create one core-loop shut-down processor for each core loop and put
654 * them all directly into the readyToAnimateQ.
655 *Note, this function can ONLY be called after the semantic environment no
656 * longer cares if AppVPs get animated after the point this is called. In
657 * other words, this can be used as an abort, or else it should only be
658 * called when all AppVPs have finished dissipate requests -- only at that
659 * point is it sure that all results have completed.
660 */
661 void
662 VMS__shutdown()
663 { int coreIdx;
664 //Send a shutdown Request to all MasterLoops.
665 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
666 { //Note, this is running in the master
667 InterVMSCoreReqst *shutdownReqst = VMS__malloc(sizeof(InterVMSCoreReqst));
668 shutdownReqst->secondReqType = shutdownVP;
669 VMS__sendInterMasterReqst(coreIdx, (InterMasterReqst*)shutdownReqst);
670 }
672 }
675 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for
676 * a special shutdown procr. Ended up with extra-complex shutdown sequence.
677 *This function has the sole purpose of setting the stack and framePtr
678 * to the coreLoop's stack and framePtr.. it does that then jumps to the
679 * core loop's shutdown point -- might be able to just call Pthread_exit
680 * from here, but am going back to the pthread's stack and setting everything
681 * up just as if it never jumped out, before calling pthread_exit.
682 *The end-point of core loop will free the stack and so forth of the
683 * processor that animates this function, (this fn is transfering the
684 * animator of the AppVP that is in turn animating this function over
685 * to core loop function -- note that this slices out a level of virtual
686 * processors).
687 */
688 /*
689 void
690 endOSThreadFn( void *initData, VirtProcr *animatingPr )
691 {
692 #ifdef SEQUENTIAL
693 asmTerminateCoreLoopSeq(animatingPr);
694 #else
695 asmTerminateCoreLoop(animatingPr);
696 #endif
697 }
698 */
701 /*This is called from the startup & shutdown
702 */
703 void
704 VMS__cleanup_at_end_of_shutdown()
705 {
706 // Set to zero so that all data structures are freed correctly
707 _VMSMasterEnv->currentMasterProcrID = 0;
709 //unused
710 //VMSQueueStruc **readyToAnimateQs;
711 //int coreIdx;
712 //VirtProcr **masterVPs;
713 //SchedSlot ***allSchedSlots; //ptr to array of ptrs
715 //Before getting rid of everything, print out any measurements made
716 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist );
717 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile);
718 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHist );
719 #ifdef MEAS__TIME_PLUGIN
720 printHist( _VMSMasterEnv->reqHdlrLowTimeHist );
721 saveHistToFile( _VMSMasterEnv->reqHdlrLowTimeHist );
722 printHist( _VMSMasterEnv->reqHdlrHighTimeHist );
723 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist );
724 freeHistExt( _VMSMasterEnv->reqHdlrLowTimeHist );
725 freeHistExt( _VMSMasterEnv->reqHdlrHighTimeHist );
726 #endif
727 #ifdef MEAS__TIME_MALLOC
728 printHist( _VMSMasterEnv->mallocTimeHist );
729 saveHistToFile( _VMSMasterEnv->mallocTimeHist );
730 printHist( _VMSMasterEnv->freeTimeHist );
731 saveHistToFile( _VMSMasterEnv->freeTimeHist );
732 freeHistExt( _VMSMasterEnv->mallocTimeHist );
733 freeHistExt( _VMSMasterEnv->freeTimeHist );
734 #endif
735 #ifdef MEAS__TIME_MASTER_LOCK
736 printHist( _VMSMasterEnv->masterLockLowTimeHist );
737 printHist( _VMSMasterEnv->masterLockHighTimeHist );
738 #endif
739 #ifdef MEAS__TIME_MASTER
740 printHist( _VMSMasterEnv->pluginTimeHist );
741 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
742 {
743 freeVMSQ( readyToAnimateQs[ coreIdx ] );
744 //master VPs were created external to VMS, so use external free
745 VMS__dissipate_procr( masterVPs[ coreIdx ] );
747 freeSchedSlots( allSchedSlots[ coreIdx ] );
748 }
749 #endif
750 #ifdef MEAS__TIME_STAMP_SUSP
751 printHist( _VMSMasterEnv->pluginTimeHist );
752 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
753 {
754 freeVMSQ( readyToAnimateQs[ coreIdx ] );
755 //master VPs were created external to VMS, so use external free
756 VMS__dissipate_procr( masterVPs[ coreIdx ] );
758 freeSchedSlots( allSchedSlots[ coreIdx ] );
759 }
760 #endif
762 //All the environment data has been allocated with VMS__malloc, so just
763 // free its internal big-chunk and all inside it disappear.
764 /*
765 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs;
766 masterVPs = _VMSMasterEnv->masterVPs;
767 allSchedSlots = _VMSMasterEnv->allSchedSlots;
769 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
770 {
771 freeVMSQ( readyToAnimateQs[ coreIdx ] );
772 //master VPs were created external to VMS, so use external free
773 VMS__dissipate_procr( masterVPs[ coreIdx ] );
775 freeSchedSlots( allSchedSlots[ coreIdx ] );
776 }
778 VMS__free( _VMSMasterEnv->readyToAnimateQs );
779 VMS__free( _VMSMasterEnv->masterVPs );
780 VMS__free( _VMSMasterEnv->allSchedSlots );
782 //============================= MEASUREMENT STUFF ========================
783 #ifdef STATS__TURN_ON_PROBES
784 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe);
785 #endif
786 //========================================================================
787 */
788 //These are the only two that use system free
789 int i;
790 for(i=0; i<NUM_CORES; i++)
791 VMS_ext__free_free_list( _VMSMasterEnv->freeLists[i]);
792 free( (void *)_VMSMasterEnv );
793 }
796 //================================
799 /*Later, improve this -- for now, just exits the application after printing
800 * the error message.
801 */
802 void
803 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData )
804 {
805 printf("%s",msgStr);
806 fflush(stdin);
807 exit(1);
808 }
