Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.c @ 120:d4c881c7f03a
Added fn to send inter-master requests, and cleaned up code
| author | Me@portablequad |
|---|---|
| date | Sat, 03 Sep 2011 20:41:51 -0700 |
| parents | efb55f1b5fb9 |
| children | dbfc8382d546 |
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, 100,
114 "malloc_time_hist");
115 _VMSMasterEnv->freeTimeHist = makeFixedBinHistExt( 80, 0, 100,
116 "free_time_hist");
117 #endif
118 #ifdef MEAS__TIME_PLUGIN
119 _VMSMasterEnv->reqHdlrLowTimeHist = makeFixedBinHistExt( 1000, 0, 100,
120 "plugin_low_time_hist");
121 _VMSMasterEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 1000, 0, 100,
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 }
500 void inline
501 VMS__send_inter_plugin_req( void *reqData, int32 targetMaster,
502 VirtProcr *requestingMaster )
503 { _VMSMasterEnv->interMasterRequestsFor[targetMaster] =
504 (InterMasterReqst *) reqData;
505 }
507 void inline
508 VMS__send_inter_VMSCore_req( InterVMSCoreReqst *reqData,
509 int32 targetMaster, VirtProcr *requestingMaster )
510 { _VMSMasterEnv->interMasterRequestsFor[targetMaster] =
511 (InterMasterReqst *) reqData;
512 }
514 /*
515 */
516 VMSReqst *
517 VMS__take_next_request_out_of( VirtProcr *procrWithReq )
518 { VMSReqst *req;
520 req = procrWithReq->requests;
521 if( req == NULL ) return NULL;
523 procrWithReq->requests = procrWithReq->requests->nextReqst;
524 return req;
525 }
528 inline void *
529 VMS__take_sem_reqst_from( VMSReqst *req )
530 {
531 return req->semReqData;
532 }
536 /* This is for OS requests and VMS infrastructure requests, such as to create
537 * a probe -- a probe is inside the heart of VMS-core, it's not part of any
538 * language -- but it's also a semantic thing that's triggered from and used
539 * in the application.. so it crosses abstractions.. so, need some special
540 * pattern here for handling such requests.
541 * Doing this just like it were a second language sharing VMS-core.
542 *
543 * This is called from the language's request handler when it sees a request
544 * of type VMSSemReq
545 *
546 * TODO: Later change this, to give probes their own separate plugin & have
547 * VMS-core steer the request to appropriate plugin
548 * Do the same for OS calls -- look later at it..
549 */
550 void inline
551 VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
552 ResumePrFnPtr resumePrFnPtr )
553 { VMSSemReq *semReq;
554 IntervalProbe *newProbe;
556 semReq = req->semReqData;
558 newProbe = VMS__malloc( sizeof(IntervalProbe) );
559 newProbe->nameStr = VMS__strDup( semReq->nameStr );
560 newProbe->hist = NULL;
561 newProbe->schedChoiceWasRecorded = FALSE;
563 //This runs in masterVP, so no race-condition worries
564 newProbe->probeID =
565 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
567 requestingPr->dataRetFromReq = newProbe;
569 (*resumePrFnPtr)( requestingPr, semEnv );
570 }
574 /*This must be called by the request handler plugin -- it cannot be called
575 * from the semantic library "dissipate processor" function -- instead, the
576 * semantic layer has to generate a request, and the plug-in calls this
577 * function.
578 *The reason is that this frees the virtual processor's stack -- which is
579 * still in use inside semantic library calls!
580 *
581 *This frees or recycles all the state owned by and comprising the VMS
582 * portion of the animating virtual procr. The request handler must first
583 * free any semantic data created for the processor that didn't use the
584 * VMS_malloc mechanism. Then it calls this, which first asks the malloc
585 * system to disown any state that did use VMS_malloc, and then frees the
586 * statck and the processor-struct itself.
587 *If the dissipated processor is the sole (remaining) owner of VMS__malloc'd
588 * state, then that state gets freed (or sent to recycling) as a side-effect
589 * of dis-owning it.
590 */
591 void
592 VMS__dissipate_procr( VirtProcr *animatingPr )
593 {
594 //dis-own all locations owned by this processor, causing to be freed
595 // any locations that it is (was) sole owner of
596 //TODO: implement VMS__malloc system, including "give up ownership"
599 //NOTE: initialData was given to the processor, so should either have
600 // been alloc'd with VMS__malloc, or freed by the level above animPr.
601 //So, all that's left to free here is the stack and the VirtProcr struc
602 // itself
603 //Note, should not stack-allocate initial data -- no guarantee, in
604 // general that creating processor will outlive ones it creates.
605 VMS__free( animatingPr->startOfStack );
606 VMS__free( animatingPr );
607 }
610 //TODO: look at architecting cleanest separation between request handler
611 // and master loop, for dissipate, create, shutdown, and other non-semantic
612 // requests. Issue is chain: one removes requests from AppVP, one dispatches
613 // on type of request, and one handles each type.. but some types require
614 // action from both request handler and master loop -- maybe just give the
615 // request handler calls like: VMS__handle_X_request_type
618 /*This is called by the semantic layer's request handler when it decides its
619 * time to shut down the VMS system. Calling this causes the core loop OS
620 * threads to exit, which unblocks the entry-point function that started up
621 * VMS, and allows it to grab the result and return to the original single-
622 * threaded application.
623 *
624 *The _VMSMasterEnv is needed by this shut down function, so the create-seed-
625 * and-wait function has to free a bunch of stuff after it detects the
626 * threads have all died: the masterEnv, the thread-related locations,
627 * masterVP any AppVPs that might still be allocated and sitting in the
628 * semantic environment, or have been orphaned in the _VMSWorkQ.
629 *
630 *NOTE: the semantic plug-in is expected to use VMS__malloc to get all the
631 * locations it needs, and give ownership to masterVP. Then, they will be
632 * automatically freed.
633 *
634 *In here,create one core-loop shut-down processor for each core loop and put
635 * them all directly into the readyToAnimateQ.
636 *Note, this function can ONLY be called after the semantic environment no
637 * longer cares if AppVPs get animated after the point this is called. In
638 * other words, this can be used as an abort, or else it should only be
639 * called when all AppVPs have finished dissipate requests -- only at that
640 * point is it sure that all results have completed.
641 */
642 void
643 VMS__shutdown()
644 { int coreIdx;
645 VirtProcr *shutDownPr;
647 //create the shutdown processors, one for each core loop -- put them
648 // directly into the Q -- each core will die when gets one
649 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
650 { //Note, this is running in the master
651 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
652 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
653 }
655 }
658 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for
659 * a special shutdown procr. Ended up with extra-complex shutdown sequence.
660 *This function has the sole purpose of setting the stack and framePtr
661 * to the coreLoop's stack and framePtr.. it does that then jumps to the
662 * core loop's shutdown point -- might be able to just call Pthread_exit
663 * from here, but am going back to the pthread's stack and setting everything
664 * up just as if it never jumped out, before calling pthread_exit.
665 *The end-point of core loop will free the stack and so forth of the
666 * processor that animates this function, (this fn is transfering the
667 * animator of the AppVP that is in turn animating this function over
668 * to core loop function -- note that this slices out a level of virtual
669 * processors).
670 */
671 void
672 endOSThreadFn( void *initData, VirtProcr *animatingPr )
673 {
674 #ifdef SEQUENTIAL
675 asmTerminateCoreLoopSeq(animatingPr);
676 #else
677 asmTerminateCoreLoop(animatingPr);
678 #endif
679 }
682 /*This is called from the startup & shutdown
683 */
684 void
685 VMS__cleanup_at_end_of_shutdown()
686 {
687 //unused
688 //VMSQueueStruc **readyToAnimateQs;
689 //int coreIdx;
690 //VirtProcr **masterVPs;
691 //SchedSlot ***allSchedSlots; //ptr to array of ptrs
693 //Before getting rid of everything, print out any measurements made
694 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&printHist );
695 forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, (DynArrayFnPtr)&saveHistToFile);
696 //forAllInDynArrayDo( _VMSMasterEnv->measHistsInfo, &freeHistExt );
697 #ifdef MEAS__TIME_PLUGIN
698 printHist( _VMSMasterEnv->reqHdlrLowTimeHist );
699 saveHistToFile( _VMSMasterEnv->reqHdlrLowTimeHist );
700 printHist( _VMSMasterEnv->reqHdlrHighTimeHist );
701 saveHistToFile( _VMSMasterEnv->reqHdlrHighTimeHist );
702 freeHistExt( _VMSMasterEnv->reqHdlrLowTimeHist );
703 freeHistExt( _VMSMasterEnv->reqHdlrHighTimeHist );
704 #endif
705 #ifdef MEAS__TIME_MALLOC
706 printHist( _VMSMasterEnv->mallocTimeHist );
707 saveHistToFile( _VMSMasterEnv->mallocTimeHist );
708 printHist( _VMSMasterEnv->freeTimeHist );
709 saveHistToFile( _VMSMasterEnv->freeTimeHist );
710 freeHistExt( _VMSMasterEnv->mallocTimeHist );
711 freeHistExt( _VMSMasterEnv->freeTimeHist );
712 #endif
713 #ifdef MEAS__TIME_MASTER_LOCK
714 printHist( _VMSMasterEnv->masterLockLowTimeHist );
715 printHist( _VMSMasterEnv->masterLockHighTimeHist );
716 #endif
717 #ifdef MEAS__TIME_MASTER
718 printHist( _VMSMasterEnv->pluginTimeHist );
719 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
720 {
721 freeVMSQ( readyToAnimateQs[ coreIdx ] );
722 //master VPs were created external to VMS, so use external free
723 VMS__dissipate_procr( masterVPs[ coreIdx ] );
725 freeSchedSlots( allSchedSlots[ coreIdx ] );
726 }
727 #endif
728 #ifdef MEAS__TIME_STAMP_SUSP
729 printHist( _VMSMasterEnv->pluginTimeHist );
730 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
731 {
732 freeVMSQ( readyToAnimateQs[ coreIdx ] );
733 //master VPs were created external to VMS, so use external free
734 VMS__dissipate_procr( masterVPs[ coreIdx ] );
736 freeSchedSlots( allSchedSlots[ coreIdx ] );
737 }
738 #endif
740 //All the environment data has been allocated with VMS__malloc, so just
741 // free its internal big-chunk and all inside it disappear.
742 /*
743 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs;
744 masterVPs = _VMSMasterEnv->masterVPs;
745 allSchedSlots = _VMSMasterEnv->allSchedSlots;
747 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
748 {
749 freeVMSQ( readyToAnimateQs[ coreIdx ] );
750 //master VPs were created external to VMS, so use external free
751 VMS__dissipate_procr( masterVPs[ coreIdx ] );
753 freeSchedSlots( allSchedSlots[ coreIdx ] );
754 }
756 VMS__free( _VMSMasterEnv->readyToAnimateQs );
757 VMS__free( _VMSMasterEnv->masterVPs );
758 VMS__free( _VMSMasterEnv->allSchedSlots );
760 //============================= MEASUREMENT STUFF ========================
761 #ifdef STATS__TURN_ON_PROBES
762 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe);
763 #endif
764 //========================================================================
765 */
766 //These are the only two that use system free
767 VMS_ext__free_free_list( _VMSMasterEnv->freeListHead );
768 free( (void *)_VMSMasterEnv );
769 }
772 //================================
775 /*Later, improve this -- for now, just exits the application after printing
776 * the error message.
777 */
778 void
779 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData )
780 {
781 printf("%s",msgStr);
782 fflush(stdin);
783 exit(1);
784 }
