view VMS.c @ 201:0320b49ca013

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