view VMS.c @ 170:92d97c6c09d6

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