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