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