Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.c @ 180:3b67317d2e3f
cloned the sub-repositories (DynArray, Hash_impl, etc) now committing the clones
| author | Me@portablequad |
|---|---|
| date | Wed, 04 Jan 2012 16:29:11 -0800 |
| parents | b86c54dfb19f |
| children | d7c0c0a8187a 7523ee70d66c 6db9e4898978 |
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) );
105 //Very first thing put into the master env is the free-list, seeded
106 // with a massive initial chunk of memory.
107 //After this, all other mallocs are VMS__malloc.
108 _VMSMasterEnv->freeListHead = VMS_ext__create_free_list();
111 //============================= MEASUREMENT STUFF ========================
112 #ifdef MEAS__TIME_MALLOC
113 _VMSMasterEnv->mallocTimeHist = makeFixedBinHistExt( 100, 0, 30,
114 "malloc_time_hist");
115 _VMSMasterEnv->freeTimeHist = makeFixedBinHistExt( 100, 0, 30,
116 "free_time_hist");
117 #endif
118 #ifdef MEAS__TIME_PLUGIN
119 _VMSMasterEnv->reqHdlrLowTimeHist = makeFixedBinHistExt( 100, 0, 200,
120 "plugin_low_time_hist");
121 _VMSMasterEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 100, 0, 200,
122 "plugin_high_time_hist");
123 #endif
124 //========================================================================
126 //===================== Only VMS__malloc after this ====================
127 masterEnv = (MasterEnv*)_VMSMasterEnv;
129 //Make a readyToAnimateQ for each core loop
130 readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
131 masterVPs = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) );
133 //One array for each core, 3 in array, core's masterVP scheds all
134 allSchedSlots = VMS__malloc( NUM_CORES * sizeof(SchedSlot *) );
136 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr
137 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
138 {
139 readyToAnimateQs[ coreIdx ] = makeVMSQ();
141 //Q: should give masterVP core-specific info as its init data?
142 masterVPs[ coreIdx ] = VMS__create_procr( (VirtProcrFnPtr)&masterLoop, (void*)masterEnv );
143 masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
144 allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
145 _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0;
146 _VMSMasterEnv->workStealingGates[ coreIdx ] = NULL;
147 }
148 _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs;
149 _VMSMasterEnv->masterVPs = masterVPs;
150 _VMSMasterEnv->masterLock = UNLOCKED;
151 _VMSMasterEnv->allSchedSlots = allSchedSlots;
152 _VMSMasterEnv->workStealingLock = UNLOCKED;
155 //Aug 19, 2010: no longer need to place initial masterVP into queue
156 // because coreLoop now controls -- animates its masterVP when no work
159 //============================= MEASUREMENT STUFF ========================
160 #ifdef STATS__TURN_ON_PROBES
161 _VMSMasterEnv->dynIntervalProbesInfo =
162 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->intervalProbes), 200);
164 _VMSMasterEnv->probeNameHashTbl = makeHashTable( 1000, &VMS__free );
166 //put creation time directly into master env, for fast retrieval
167 struct timeval timeStamp;
168 gettimeofday( &(timeStamp), NULL);
169 _VMSMasterEnv->createPtInSecs =
170 timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0);
171 #endif
172 #ifdef MEAS__TIME_MASTER_LOCK
173 _VMSMasterEnv->masterLockLowTimeHist = makeFixedBinHist( 50, 0, 2,
174 "master lock low time hist");
175 _VMSMasterEnv->masterLockHighTimeHist = makeFixedBinHist( 50, 0, 100,
176 "master lock high time hist");
177 #endif
179 MakeTheMeasHists();
180 //========================================================================
182 }
184 SchedSlot **
185 create_sched_slots()
186 { SchedSlot **schedSlots;
187 int i;
189 schedSlots = VMS__malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) );
191 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
192 {
193 schedSlots[i] = VMS__malloc( sizeof(SchedSlot) );
195 //Set state to mean "handling requests done, slot needs filling"
196 schedSlots[i]->workIsDone = FALSE;
197 schedSlots[i]->needsProcrAssigned = TRUE;
198 }
199 return schedSlots;
200 }
203 void
204 freeSchedSlots( SchedSlot **schedSlots )
205 { int i;
206 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
207 {
208 VMS__free( schedSlots[i] );
209 }
210 VMS__free( schedSlots );
211 }
214 void
215 create_the_coreLoop_OS_threads()
216 {
217 //========================================================================
218 // Create the Threads
219 int coreIdx, retCode;
221 //Need the threads to be created suspended, and wait for a signal
222 // before proceeding -- gives time after creating to initialize other
223 // stuff before the coreLoops set off.
224 _VMSMasterEnv->setupComplete = 0;
226 //Make the threads that animate the core loops
227 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
228 { coreLoopThdParams[coreIdx] = VMS__malloc( sizeof(ThdParams) );
229 coreLoopThdParams[coreIdx]->coreNum = coreIdx;
231 retCode =
232 pthread_create( &(coreLoopThdHandles[coreIdx]),
233 thdAttrs,
234 &coreLoop,
235 (void *)(coreLoopThdParams[coreIdx]) );
236 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(1);}
237 }
238 }
240 /*Semantic layer calls this when it want the system to start running..
241 *
242 *This starts the core loops running then waits for them to exit.
243 */
244 void
245 VMS__start_the_work_then_wait_until_done()
246 { int coreIdx;
247 //Start the core loops running
249 //tell the core loop threads that setup is complete
250 //get lock, to lock out any threads still starting up -- they'll see
251 // that setupComplete is true before entering while loop, and so never
252 // wait on the condition
253 pthread_mutex_lock( &suspendLock );
254 _VMSMasterEnv->setupComplete = 1;
255 pthread_mutex_unlock( &suspendLock );
256 pthread_cond_broadcast( &suspend_cond );
259 //wait for all to complete
260 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
261 {
262 pthread_join( coreLoopThdHandles[coreIdx], NULL );
263 }
265 //NOTE: do not clean up VMS env here -- semantic layer has to have
266 // a chance to clean up its environment first, then do a call to free
267 // the Master env and rest of VMS locations
268 }
270 #ifdef SEQUENTIAL
271 /*Only difference between version with an OS thread pinned to each core and
272 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
273 */
274 void
275 VMS__start_the_work_then_wait_until_done_Seq()
276 {
277 //Instead of un-suspending threads, just call the one and only
278 // core loop (sequential version), in the main thread.
279 coreLoop_Seq( NULL );
280 flushRegisters();
282 }
283 #endif
285 inline VirtProcr *
286 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
287 { VirtProcr *newPr;
288 void *stackLocs;
290 newPr = VMS__malloc( sizeof(VirtProcr) );
291 stackLocs = VMS__malloc( VIRT_PROCR_STACK_SIZE );
292 if( stackLocs == 0 )
293 { perror("VMS__malloc stack"); exit(1); }
295 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
296 }
298 /* "ext" designates that it's for use outside the VMS system -- should only
299 * be called from main thread or other thread -- never from code animated by
300 * a VMS virtual processor.
301 */
302 inline VirtProcr *
303 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
304 { VirtProcr *newPr;
305 char *stackLocs;
307 newPr = malloc( sizeof(VirtProcr) );
308 stackLocs = malloc( VIRT_PROCR_STACK_SIZE );
309 if( stackLocs == 0 )
310 { perror("malloc stack"); exit(1); }
312 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
313 }
316 /*Anticipating multi-tasking
317 */
318 void *
319 VMS__give_sem_env_for( VirtProcr *animPr )
320 {
321 return _VMSMasterEnv->semanticEnv;
322 }
323 //===========================================================================
324 /*there is a label inside this function -- save the addr of this label in
325 * the callingPr struc, as the pick-up point from which to start the next
326 * work-unit for that procr. If turns out have to save registers, then
327 * save them in the procr struc too. Then do assembly jump to the CoreLoop's
328 * "done with work-unit" label. The procr struc is in the request in the
329 * slave that animated the just-ended work-unit, so all the state is saved
330 * there, and will get passed along, inside the request handler, to the
331 * next work-unit for that procr.
332 */
333 void
334 VMS__suspend_procr( VirtProcr *animatingPr )
335 {
337 //The request to master will cause this suspended virt procr to get
338 // scheduled again at some future point -- to resume, core loop jumps
339 // to the resume point (below), which causes restore of saved regs and
340 // "return" from this call.
341 //animatingPr->nextInstrPt = &&ResumePt;
343 //return ownership of the virt procr and sched slot to Master virt pr
344 animatingPr->schedSlot->workIsDone = TRUE;
346 //=========================== Measurement stuff ========================
347 #ifdef MEAS__TIME_STAMP_SUSP
348 //record time stamp: compare to time-stamp recorded below
349 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
350 #endif
351 //=======================================================================
353 switchToCoreLoop(animatingPr);
354 flushRegisters();
356 //=======================================================================
358 #ifdef MEAS__TIME_STAMP_SUSP
359 //NOTE: only take low part of count -- do sanity check when take diff
360 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
361 #endif
363 return;
364 }
368 /*For this implementation of VMS, it may not make much sense to have the
369 * system of requests for creating a new processor done this way.. but over
370 * the scope of single-master, multi-master, mult-tasking, OS-implementing,
371 * distributed-memory, and so on, this gives VMS implementation a chance to
372 * do stuff before suspend, in the AppVP, and in the Master before the plugin
373 * is called, as well as in the lang-lib before this is called, and in the
374 * plugin. So, this gives both VMS and language implementations a chance to
375 * intercept at various points and do order-dependent stuff.
376 *Having a standard VMSNewPrReqData struc allows the language to create and
377 * free the struc, while VMS knows how to get the newPr if it wants it, and
378 * it lets the lang have lang-specific data related to creation transported
379 * to the plugin.
380 */
381 void
382 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr )
383 { VMSReqst req;
385 req.reqType = createReq;
386 req.semReqData = semReqData;
387 req.nextReqst = reqstingPr->requests;
388 reqstingPr->requests = &req;
390 VMS__suspend_procr( reqstingPr );
391 }
394 /*
395 *This adds a request to dissipate, then suspends the processor so that the
396 * request handler will receive the request. The request handler is what
397 * does the work of freeing memory and removing the processor from the
398 * semantic environment's data structures.
399 *The request handler also is what figures out when to shutdown the VMS
400 * system -- which causes all the core loop threads to die, and returns from
401 * the call that started up VMS to perform the work.
402 *
403 *This form is a bit misleading to understand if one is trying to figure out
404 * how VMS works -- it looks like a normal function call, but inside it
405 * sends a request to the request handler and suspends the processor, which
406 * jumps out of the VMS__dissipate_procr function, and out of all nestings
407 * above it, transferring the work of dissipating to the request handler,
408 * which then does the actual work -- causing the processor that animated
409 * the call of this function to disappear and the "hanging" state of this
410 * function to just poof into thin air -- the virtual processor's trace
411 * never returns from this call, but instead the virtual processor's trace
412 * gets suspended in this call and all the virt processor's state disap-
413 * pears -- making that suspend the last thing in the virt procr's trace.
414 */
415 void
416 VMS__send_dissipate_req( VirtProcr *procrToDissipate )
417 { VMSReqst req;
419 req.reqType = dissipate;
420 req.nextReqst = procrToDissipate->requests;
421 procrToDissipate->requests = &req;
423 VMS__suspend_procr( procrToDissipate );
424 }
427 /* "ext" designates that it's for use outside the VMS system -- should only
428 * be called from main thread or other thread -- never from code animated by
429 * a VMS virtual processor.
430 *
431 *Use this version to dissipate VPs created outside the VMS system.
432 */
433 void
434 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate )
435 {
436 //NOTE: initialData was given to the processor, so should either have
437 // been alloc'd with VMS__malloc, or freed by the level above animPr.
438 //So, all that's left to free here is the stack and the VirtProcr struc
439 // itself
440 //Note, should not stack-allocate initial data -- no guarantee, in
441 // general that creating processor will outlive ones it creates.
442 free( procrToDissipate->startOfStack );
443 free( procrToDissipate );
444 }
448 /*This call's name indicates that request is malloc'd -- so req handler
449 * has to free any extra requests tacked on before a send, using this.
450 *
451 * This inserts the semantic-layer's request data into standard VMS carrier
452 * request data-struct that is mallocd. The sem request doesn't need to
453 * be malloc'd if this is called inside the same call chain before the
454 * send of the last request is called.
455 *
456 *The request handler has to call VMS__free_VMSReq for any of these
457 */
458 inline void
459 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData,
460 VirtProcr *callingPr )
461 { VMSReqst *req;
463 req = VMS__malloc( sizeof(VMSReqst) );
464 req->reqType = semantic;
465 req->semReqData = semReqData;
466 req->nextReqst = callingPr->requests;
467 callingPr->requests = req;
468 }
470 /*This inserts the semantic-layer's request data into standard VMS carrier
471 * request data-struct is allocated on stack of this call & ptr to it sent
472 * to plugin
473 *Then it does suspend, to cause request to be sent.
474 */
475 inline void
476 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr )
477 { VMSReqst req;
479 req.reqType = semantic;
480 req.semReqData = semReqData;
481 req.nextReqst = callingPr->requests;
482 callingPr->requests = &req;
484 VMS__suspend_procr( callingPr );
485 }
488 inline void
489 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr )
490 { VMSReqst req;
492 req.reqType = VMSSemantic;
493 req.semReqData = semReqData;
494 req.nextReqst = callingPr->requests; //gab any other preceeding
495 callingPr->requests = &req;
497 VMS__suspend_procr( callingPr );
498 }
501 /*
502 */
503 VMSReqst *
504 VMS__take_next_request_out_of( VirtProcr *procrWithReq )
505 { VMSReqst *req;
507 req = procrWithReq->requests;
508 if( req == NULL ) return NULL;
510 procrWithReq->requests = procrWithReq->requests->nextReqst;
511 return req;
512 }
515 inline void *
516 VMS__take_sem_reqst_from( VMSReqst *req )
517 {
518 return req->semReqData;
519 }
523 /* This is for OS requests and VMS infrastructure requests, such as to create
524 * a probe -- a probe is inside the heart of VMS-core, it's not part of any
525 * language -- but it's also a semantic thing that's triggered from and used
526 * in the application.. so it crosses abstractions.. so, need some special
527 * pattern here for handling such requests.
528 * Doing this just like it were a second language sharing VMS-core.
529 *
530 * This is called from the language's request handler when it sees a request
531 * of type VMSSemReq
532 *
533 * TODO: Later change this, to give probes their own separate plugin & have
534 * VMS-core steer the request to appropriate plugin
535 * Do the same for OS calls -- look later at it..
536 */
537 void inline
538 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
539 ResumePrFnPtr resumePrFnPtr )
540 { VMSSemReq *semReq;
541 IntervalProbe *newProbe;
543 semReq = req->semReqData;
545 newProbe = VMS__malloc( sizeof(IntervalProbe) );
546 newProbe->nameStr = VMS__strDup( semReq->nameStr );
547 newProbe->hist = NULL;
548 newProbe->schedChoiceWasRecorded = FALSE;
550 //This runs in masterVP, so no race-condition worries
551 newProbe->probeID =
552 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
554 requestingPr->dataRetFromReq = newProbe;
556 (*resumePrFnPtr)( requestingPr, semEnv );
557 }
561 /*This must be called by the request handler plugin -- it cannot be called
562 * from the semantic library "dissipate processor" function -- instead, the
563 * semantic layer has to generate a request, and the plug-in calls this
564 * function.
565 *The reason is that this frees the virtual processor's stack -- which is
566 * still in use inside semantic library calls!
567 *
568 *This frees or recycles all the state owned by and comprising the VMS
569 * portion of the animating virtual procr. The request handler must first
570 * free any semantic data created for the processor that didn't use the
571 * VMS_malloc mechanism. Then it calls this, which first asks the malloc
572 * system to disown any state that did use VMS_malloc, and then frees the
573 * statck and the processor-struct itself.
574 *If the dissipated processor is the sole (remaining) owner of VMS__malloc'd
575 * state, then that state gets freed (or sent to recycling) as a side-effect
576 * of dis-owning it.
577 */
578 void
579 VMS__dissipate_procr( VirtProcr *animatingPr )
580 {
581 //dis-own all locations owned by this processor, causing to be freed
582 // any locations that it is (was) sole owner of
583 //TODO: implement VMS__malloc system, including "give up ownership"
586 //NOTE: initialData was given to the processor, so should either have
587 // been alloc'd with VMS__malloc, or freed by the level above animPr.
588 //So, all that's left to free here is the stack and the VirtProcr struc
589 // itself
590 //Note, should not stack-allocate initial data -- no guarantee, in
591 // general that creating processor will outlive ones it creates.
592 VMS__free( animatingPr->startOfStack );
593 VMS__free( animatingPr );
594 }
597 //TODO: look at architecting cleanest separation between request handler
598 // and master loop, for dissipate, create, shutdown, and other non-semantic
599 // requests. Issue is chain: one removes requests from AppVP, one dispatches
600 // on type of request, and one handles each type.. but some types require
601 // action from both request handler and master loop -- maybe just give the
602 // request handler calls like: VMS__handle_X_request_type
605 /*This is called by the semantic layer's request handler when it decides its
606 * time to shut down the VMS system. Calling this causes the core loop OS
607 * threads to exit, which unblocks the entry-point function that started up
608 * VMS, and allows it to grab the result and return to the original single-
609 * threaded application.
610 *
611 *The _VMSMasterEnv is needed by this shut down function, so the create-seed-
612 * and-wait function has to free a bunch of stuff after it detects the
613 * threads have all died: the masterEnv, the thread-related locations,
614 * masterVP any AppVPs that might still be allocated and sitting in the
615 * semantic environment, or have been orphaned in the _VMSWorkQ.
616 *
617 *NOTE: the semantic plug-in is expected to use VMS__malloc to get all the
618 * locations it needs, and give ownership to masterVP. Then, they will be
619 * automatically freed.
620 *
621 *In here,create one core-loop shut-down processor for each core loop and put
622 * them all directly into the readyToAnimateQ.
623 *Note, this function can ONLY be called after the semantic environment no
624 * longer cares if AppVPs get animated after the point this is called. In
625 * other words, this can be used as an abort, or else it should only be
626 * called when all AppVPs have finished dissipate requests -- only at that
627 * point is it sure that all results have completed.
628 */
629 void
630 VMS__shutdown()
631 { int coreIdx;
632 VirtProcr *shutDownPr;
634 //create the shutdown processors, one for each core loop -- put them
635 // directly into the Q -- each core will die when gets one
636 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
637 { //Note, this is running in the master
638 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
639 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
640 }
642 }
645 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for
646 * a special shutdown procr. Ended up with extra-complex shutdown sequence.
647 *This function has the sole purpose of setting the stack and framePtr
648 * to the coreLoop's stack and framePtr.. it does that then jumps to the
649 * core loop's shutdown point -- might be able to just call Pthread_exit
650 * from here, but am going back to the pthread's stack and setting everything
651 * up just as if it never jumped out, before calling pthread_exit.
652 *The end-point of core loop will free the stack and so forth of the
653 * processor that animates this function, (this fn is transfering the
654 * animator of the AppVP that is in turn animating this function over
655 * to core loop function -- note that this slices out a level of virtual
656 * processors).
657 */
658 void
659 endOSThreadFn( void *initData, VirtProcr *animatingPr )
660 {
661 #ifdef SEQUENTIAL
662 asmTerminateCoreLoopSeq(animatingPr);
663 #else
664 asmTerminateCoreLoop(animatingPr);
665 #endif
666 }
669 /*This is called from the startup & shutdown
670 */
671 void
672 VMS__cleanup_at_end_of_shutdown()
673 {
674 //unused
675 //VMSQueueStruc **readyToAnimateQs;
676 //int coreIdx;
677 //VirtProcr **masterVPs;
678 //SchedSlot ***allSchedSlots; //ptr to array of ptrs
680 //Before getting rid of everything, print out any measurements made
681 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist );
682 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile);
683 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHist );
684 #ifdef MEAS__TIME_PLUGIN
685 printHist( _VMSMasterEnv->reqHdlrLowTimeHist );
686 saveHistToFile( _VMSMasterEnv->reqHdlrLowTimeHist );
687 printHist( _VMSMasterEnv->reqHdlrHighTimeHist );
688 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist );
689 freeHistExt( _VMSMasterEnv->reqHdlrLowTimeHist );
690 freeHistExt( _VMSMasterEnv->reqHdlrHighTimeHist );
691 #endif
692 #ifdef MEAS__TIME_MALLOC
693 printHist( _VMSMasterEnv->mallocTimeHist );
694 saveHistToFile( _VMSMasterEnv->mallocTimeHist );
695 printHist( _VMSMasterEnv->freeTimeHist );
696 saveHistToFile( _VMSMasterEnv->freeTimeHist );
697 freeHistExt( _VMSMasterEnv->mallocTimeHist );
698 freeHistExt( _VMSMasterEnv->freeTimeHist );
699 #endif
700 #ifdef MEAS__TIME_MASTER_LOCK
701 printHist( _VMSMasterEnv->masterLockLowTimeHist );
702 printHist( _VMSMasterEnv->masterLockHighTimeHist );
703 #endif
704 #ifdef MEAS__TIME_MASTER
705 printHist( _VMSMasterEnv->pluginTimeHist );
706 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
707 {
708 freeVMSQ( readyToAnimateQs[ coreIdx ] );
709 //master VPs were created external to VMS, so use external free
710 VMS__dissipate_procr( masterVPs[ coreIdx ] );
712 freeSchedSlots( allSchedSlots[ coreIdx ] );
713 }
714 #endif
715 #ifdef MEAS__TIME_STAMP_SUSP
716 printHist( _VMSMasterEnv->pluginTimeHist );
717 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
718 {
719 freeVMSQ( readyToAnimateQs[ coreIdx ] );
720 //master VPs were created external to VMS, so use external free
721 VMS__dissipate_procr( masterVPs[ coreIdx ] );
723 freeSchedSlots( allSchedSlots[ coreIdx ] );
724 }
725 #endif
727 //All the environment data has been allocated with VMS__malloc, so just
728 // free its internal big-chunk and all inside it disappear.
729 /*
730 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs;
731 masterVPs = _VMSMasterEnv->masterVPs;
732 allSchedSlots = _VMSMasterEnv->allSchedSlots;
734 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
735 {
736 freeVMSQ( readyToAnimateQs[ coreIdx ] );
737 //master VPs were created external to VMS, so use external free
738 VMS__dissipate_procr( masterVPs[ coreIdx ] );
740 freeSchedSlots( allSchedSlots[ coreIdx ] );
741 }
743 VMS__free( _VMSMasterEnv->readyToAnimateQs );
744 VMS__free( _VMSMasterEnv->masterVPs );
745 VMS__free( _VMSMasterEnv->allSchedSlots );
747 //============================= MEASUREMENT STUFF ========================
748 #ifdef STATS__TURN_ON_PROBES
749 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe);
750 #endif
751 //========================================================================
752 */
753 //These are the only two that use system free
754 VMS_ext__free_free_list( _VMSMasterEnv->freeListHead );
755 free( (void *)_VMSMasterEnv );
756 }
759 //================================
762 /*Later, improve this -- for now, just exits the application after printing
763 * the error message.
764 */
765 void
766 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData )
767 {
768 printf("%s",msgStr);
769 fflush(stdin);
770 exit(1);
771 }
