view VMS.c @ 47:72373405c816

Adding TSC normalization -- still in progress, not working
author Me
date Sat, 16 Oct 2010 04:11:15 -0700
parents cf3e9238aeb0
children 054006c26b92
line source
1 /*
2 * Copyright 2010 OpenSourceStewardshipFoundation
3 *
4 * Licensed under BSD
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <malloc.h>
11 #include "VMS.h"
12 #include "Queue_impl/BlockingQueue.h"
13 #include "Histogram/Histogram.h"
16 #define thdAttrs NULL
18 //===========================================================================
19 void
20 shutdownFn( void *dummy, VirtProcr *dummy2 );
22 SchedSlot **
23 create_sched_slots();
25 void
26 create_masterEnv();
28 void
29 create_the_coreLoop_OS_threads();
31 pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER;
32 pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
34 //===========================================================================
36 /*Setup has two phases:
37 * 1) Semantic layer first calls init_VMS, which creates masterEnv, and puts
38 * the master virt procr into the work-queue, ready for first "call"
39 * 2) Semantic layer then does its own init, which creates the seed virt
40 * procr inside the semantic layer, ready to schedule it when
41 * asked by the first run of the masterLoop.
42 *
43 *This part is bit weird because VMS really wants to be "always there", and
44 * have applications attach and detach.. for now, this VMS is part of
45 * the app, so the VMS system starts up as part of running the app.
46 *
47 *The semantic layer is isolated from the VMS internals by making the
48 * semantic layer do setup to a state that it's ready with its
49 * initial virt procrs, ready to schedule them to slots when the masterLoop
50 * asks. Without this pattern, the semantic layer's setup would
51 * have to modify slots directly to assign the initial virt-procrs, and put
52 * them into the readyToAnimateQ itself, breaking the isolation completely.
53 *
54 *
55 *The semantic layer creates the initial virt procr(s), and adds its
56 * own environment to masterEnv, and fills in the pointers to
57 * the requestHandler and slaveScheduler plug-in functions
58 */
60 /*This allocates VMS data structures, populates the master VMSProc,
61 * and master environment, and returns the master environment to the semantic
62 * layer.
63 */
64 void
65 VMS__init()
66 {
67 create_masterEnv();
68 create_the_coreLoop_OS_threads();
69 }
71 /*To initialize the sequential version, just don't create the threads
72 */
73 void
74 VMS__init_Seq()
75 {
76 create_masterEnv();
77 }
79 void
80 create_masterEnv()
81 { MasterEnv *masterEnv;
82 VMSQueueStruc **readyToAnimateQs;
83 int coreIdx;
84 VirtProcr **masterVPs;
85 SchedSlot ***allSchedSlots; //ptr to array of ptrs
87 //Make the master env, which holds everything else
88 _VMSMasterEnv = malloc( sizeof(MasterEnv) );
89 masterEnv = _VMSMasterEnv;
90 //Need to set start pt here 'cause used by seed procr, which is created
91 // before the first core loop starts up. -- not sure how yet..
92 // masterEnv->coreLoopStartPt = ;
93 // masterEnv->coreLoopEndPt = ;
95 //Make a readyToAnimateQ for each core loop
96 readyToAnimateQs = malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
97 masterVPs = malloc( NUM_CORES * sizeof(VirtProcr *) );
99 //One array for each core, 3 in array, core's masterVP scheds all
100 allSchedSlots = malloc( NUM_CORES * sizeof(SchedSlot *) );
102 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
103 {
104 readyToAnimateQs[ coreIdx ] = makeSRSWQ();
106 //Q: should give masterVP core-specific into as its init data?
107 masterVPs[ coreIdx ] = VMS__create_procr( &masterLoop, masterEnv );
108 masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
109 allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
110 }
111 _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs;
112 _VMSMasterEnv->masterVPs = masterVPs;
113 _VMSMasterEnv->allSchedSlots = allSchedSlots;
117 //Aug 19, 2010: no longer need to place initial masterVP into queue
118 // because coreLoop now controls -- animates its masterVP when no work
121 //==================== malloc substitute ========================
122 //
123 //Testing whether malloc is using thread-local storage and therefore
124 // causing unreliable behavior.
125 //Just allocate a massive chunk of memory and roll own malloc/free and
126 // make app use VMS__malloc_to, which will suspend and perform malloc
127 // in the master, taking from this massive chunk.
129 // initFreeList();
131 }
133 /*
134 void
135 initMasterMalloc()
136 {
137 _VMSMasterEnv->mallocChunk = malloc( MASSIVE_MALLOC_SIZE );
139 //The free-list element is the first several locations of an
140 // allocated chunk -- the address given to the application is pre-
141 // pended with both the ownership structure and the free-list struc.
142 //So, write the values of these into the first locations of
143 // mallocChunk -- which marks it as free & puts in its size.
144 listElem = (FreeListElem *)_VMSMasterEnv->mallocChunk;
145 listElem->size = MASSIVE_MALLOC_SIZE - NUM_PREPEND_BYTES
146 listElem->next = NULL;
147 }
149 void
150 dissipateMasterMalloc()
151 {
152 //Just foo code -- to get going -- doing as if free list were link-list
153 currElem = _VMSMasterEnv->freeList;
154 while( currElem != NULL )
155 {
156 nextElem = currElem->next;
157 masterFree( currElem );
158 currElem = nextElem;
159 }
160 free( _VMSMasterEnv->freeList );
161 }
162 */
164 SchedSlot **
165 create_sched_slots()
166 { SchedSlot **schedSlots;
167 int i;
169 schedSlots = malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) );
171 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
172 {
173 schedSlots[i] = malloc( sizeof(SchedSlot) );
175 //Set state to mean "handling requests done, slot needs filling"
176 schedSlots[i]->workIsDone = FALSE;
177 schedSlots[i]->needsProcrAssigned = TRUE;
178 }
179 return schedSlots;
180 }
183 void
184 freeSchedSlots( SchedSlot **schedSlots )
185 { int i;
186 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
187 {
188 free( schedSlots[i] );
189 }
190 free( schedSlots );
191 }
194 void
195 create_the_coreLoop_OS_threads()
196 {
197 //========================================================================
198 // Create the Threads
199 int coreIdx, retCode, i;
201 //create the arrays used to measure TSC offsets between cores
202 pongNums = malloc( NUM_CORES * sizeof( int ) );
203 pingTimes = malloc( NUM_CORES * NUM_TSC_ROUND_TRIPS * sizeof( TSCount ) );
204 pongTimes = malloc( NUM_CORES * NUM_TSC_ROUND_TRIPS * sizeof( TSCount ) );
206 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
207 {
208 pongNums[ coreIdx ] = 0;
209 for( i = 0; i < NUM_TSC_ROUND_TRIPS; i++ )
210 {
211 pingTimes[ coreIdx * NUM_TSC_ROUND_TRIPS + i ] = (TSCount) 0;
212 pingTimes[ coreIdx * NUM_TSC_ROUND_TRIPS + i ] = (TSCount) 0;
213 }
214 }
216 //Need the threads to be created suspended, and wait for a signal
217 // before proceeding -- gives time after creating to initialize other
218 // stuff before the coreLoops set off.
219 _VMSMasterEnv->setupComplete = 0;
221 //Make the threads that animate the core loops
222 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
223 { coreLoopThdParams[coreIdx] = malloc( sizeof(ThdParams) );
224 coreLoopThdParams[coreIdx]->coreNum = coreIdx;
226 retCode =
227 pthread_create( &(coreLoopThdHandles[coreIdx]),
228 thdAttrs,
229 &coreLoop,
230 (void *)(coreLoopThdParams[coreIdx]) );
231 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(0);}
232 }
233 }
235 /*Semantic layer calls this when it want the system to start running..
236 *
237 *This starts the core loops running then waits for them to exit.
238 */
239 void
240 VMS__start_the_work_then_wait_until_done()
241 { int coreIdx;
242 //Start the core loops running
243 //===========================================================================
244 TSCount startCount, endCount;
245 unsigned long long count = 0, freq = 0;
246 double runTime;
248 startCount = getTSC();
250 //tell the core loop threads that setup is complete
251 //get lock, to lock out any threads still starting up -- they'll see
252 // that setupComplete is true before entering while loop, and so never
253 // wait on the condition
254 pthread_mutex_lock( &suspendLock );
255 _VMSMasterEnv->setupComplete = 1;
256 pthread_mutex_unlock( &suspendLock );
257 pthread_cond_broadcast( &suspend_cond );
260 //wait for all to complete
261 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
262 {
263 pthread_join( coreLoopThdHandles[coreIdx], NULL );
264 }
266 //NOTE: do not clean up VMS env here -- semantic layer has to have
267 // a chance to clean up its environment first, then do a call to free
268 // the Master env and rest of VMS locations
271 endCount = getTSC();
272 count = endCount - startCount;
274 runTime = (double)count / (double)TSCOUNT_FREQ;
276 printf("\n Time startup to shutdown: %f\n", runTime); fflush( stdin );
277 }
279 /*Only difference between version with an OS thread pinned to each core and
280 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
281 */
282 void
283 VMS__start_the_work_then_wait_until_done_Seq()
284 {
285 //Instead of un-suspending threads, just call the one and only
286 // core loop (sequential version), in the main thread.
287 coreLoop_Seq( NULL );
289 }
293 /*Create stack, then create __cdecl structure on it and put initialData and
294 * pointer to the new structure instance into the parameter positions on
295 * the stack
296 *Then put function pointer into nextInstrPt -- the stack is setup in std
297 * call structure, so jumping to function ptr is same as a GCC generated
298 * function call
299 *No need to save registers on old stack frame, because there's no old
300 * animator state to return to --
301 *
302 */
303 VirtProcr *
304 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData )
305 { VirtProcr *newPr;
306 char *stackLocs, *stackPtr;
308 newPr = malloc( sizeof(VirtProcr) );
309 newPr->procrID = numProcrsCreated++;
310 newPr->nextInstrPt = fnPtr;
311 newPr->initialData = initialData;
312 newPr->requests = NULL;
313 newPr->schedSlot = NULL;
314 // newPr->coreLoopStartPt = _VMSMasterEnv->coreLoopStartPt;
316 //fnPtr takes two params -- void *initData & void *animProcr
317 //alloc stack locations, make stackPtr be the highest addr minus room
318 // for 2 params + return addr. Return addr (NULL) is in loc pointed to
319 // by stackPtr, initData at stackPtr + 4 bytes, animatingPr just above
320 stackLocs = malloc( VIRT_PROCR_STACK_SIZE );
321 if(stackLocs == 0) {perror("error: malloc stack"); exit(1);}
322 newPr->startOfStack = stackLocs;
323 stackPtr = ( (char *)stackLocs + VIRT_PROCR_STACK_SIZE - 0x10 );
324 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp
325 *( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer
326 *( (int *)stackPtr + 1 ) = (int) initialData; //next param to left
327 newPr->stackPtr = stackPtr; //core loop will switch to this, then
328 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr
330 return newPr;
331 }
334 /*there is a label inside this function -- save the addr of this label in
335 * the callingPr struc, as the pick-up point from which to start the next
336 * work-unit for that procr. If turns out have to save registers, then
337 * save them in the procr struc too. Then do assembly jump to the CoreLoop's
338 * "done with work-unit" label. The procr struc is in the request in the
339 * slave that animated the just-ended work-unit, so all the state is saved
340 * there, and will get passed along, inside the request handler, to the
341 * next work-unit for that procr.
342 */
343 void
344 VMS__suspend_procr( VirtProcr *animatingPr )
345 { void *jmpPt, *stackPtrAddr, *framePtrAddr, *coreLoopStackPtr;
346 void *coreLoopFramePtr;
348 //The request to master will cause this suspended virt procr to get
349 // scheduled again at some future point -- to resume, core loop jumps
350 // to the resume point (below), which causes restore of saved regs and
351 // "return" from this call.
352 animatingPr->nextInstrPt = &&ResumePt;
354 //return ownership of the virt procr and sched slot to Master virt pr
355 animatingPr->schedSlot->workIsDone = TRUE;
356 // coreIdx = callingPr->coreAnimatedBy;
358 stackPtrAddr = &(animatingPr->stackPtr);
359 framePtrAddr = &(animatingPr->framePtr);
361 jmpPt = _VMSMasterEnv->coreLoopStartPt;
362 coreLoopFramePtr = animatingPr->coreLoopFramePtr;//need this only
363 coreLoopStackPtr = animatingPr->coreLoopStackPtr;//safety
365 //Save the virt procr's stack and frame ptrs,
366 asm volatile("movl %0, %%eax; \
367 movl %%esp, (%%eax); \
368 movl %1, %%eax; \
369 movl %%ebp, (%%eax) "\
370 /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \
371 /* inputs */ : \
372 /* clobber */ : "%eax" \
373 );
375 //=========================== Measurement stuff ========================
376 #ifdef MEAS__TIME_STAMP_SUSP
377 //record time stamp: compare to time-stamp recorded below
378 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
379 #endif
380 //=======================================================================
382 //restore coreloop's frame ptr, then jump back to "start" of core loop
383 //Note, GCC compiles to assembly that saves esp and ebp in the stack
384 // frame -- so have to explicitly do assembly that saves to memory
385 asm volatile("movl %0, %%eax; \
386 movl %1, %%esp; \
387 movl %2, %%ebp; \
388 jmp %%eax " \
389 /* outputs */ : \
390 /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
391 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \
392 ); //list everything as clobbered to force GCC to save all
393 // live vars that are in regs on stack before this
394 // assembly, so that stack pointer is correct, before jmp
396 ResumePt:
397 #ifdef MEAS__TIME_STAMP_SUSP
398 //NOTE: only take low part of count -- do sanity check when take diff
399 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
400 #endif
402 return;
403 }
408 /*
409 *This adds a request to dissipate, then suspends the processor so that the
410 * request handler will receive the request. The request handler is what
411 * does the work of freeing memory and removing the processor from the
412 * semantic environment's data structures.
413 *The request handler also is what figures out when to shutdown the VMS
414 * system -- which causes all the core loop threads to die, and returns from
415 * the call that started up VMS to perform the work.
416 *
417 *This form is a bit misleading to understand if one is trying to figure out
418 * how VMS works -- it looks like a normal function call, but inside it
419 * sends a request to the request handler and suspends the processor, which
420 * jumps out of the VMS__dissipate_procr function, and out of all nestings
421 * above it, transferring the work of dissipating to the request handler,
422 * which then does the actual work -- causing the processor that animated
423 * the call of this function to disappear and the "hanging" state of this
424 * function to just poof into thin air -- the virtual processor's trace
425 * never returns from this call, but instead the virtual processor's trace
426 * gets suspended in this call and all the virt processor's state disap-
427 * pears -- making that suspend the last thing in the virt procr's trace.
428 */
429 void
430 VMS__dissipate_procr( VirtProcr *procrToDissipate )
431 { VMSReqst *req;
433 req = malloc( sizeof(VMSReqst) );
434 // req->virtProcrFrom = callingPr;
435 req->reqType = dissipate;
436 req->nextReqst = procrToDissipate->requests;
437 procrToDissipate->requests = req;
439 VMS__suspend_procr( procrToDissipate );
440 }
443 /*This inserts the semantic-layer's request data into standard VMS carrier
444 */
445 inline void
446 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr )
447 { VMSReqst *req;
449 req = malloc( sizeof(VMSReqst) );
450 // req->virtProcrFrom = callingPr;
451 req->reqType = semantic;
452 req->semReqData = semReqData;
453 req->nextReqst = callingPr->requests;
454 callingPr->requests = req;
455 }
458 /*Use this to get first request before starting request handler's loop
459 */
460 VMSReqst *
461 VMS__take_top_request_from( VirtProcr *procrWithReq )
462 { VMSReqst *req;
464 req = procrWithReq->requests;
465 if( req == NULL ) return req;
467 procrWithReq->requests = procrWithReq->requests->nextReqst;
468 return req;
469 }
471 /*A subtle bug due to freeing then accessing "next" after freed caused this
472 * form of call to be put in -- so call this at end of request handler loop
473 * that iterates through the requests.
474 */
475 VMSReqst *
476 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq )
477 { VMSReqst *req;
479 req = procrWithReq->requests;
480 if( req == NULL ) return NULL;
482 procrWithReq->requests = procrWithReq->requests->nextReqst;
483 VMS__free_request( req );
484 return procrWithReq->requests;
485 }
488 //TODO: add a semantic-layer supplied "freer" for the semantic-data portion
489 // of a request -- IE call with both a virt procr and a fn-ptr to request
490 // freer (also maybe put sem request freer as a field in virt procr?)
491 //MeasVMS relies right now on this only freeing VMS layer of request -- the
492 // semantic portion of request is alloc'd and freed by request handler
493 void
494 VMS__free_request( VMSReqst *req )
495 {
496 free( req );
497 }
501 inline int
502 VMS__isSemanticReqst( VMSReqst *req )
503 {
504 return ( req->reqType == semantic );
505 }
508 inline void *
509 VMS__take_sem_reqst_from( VMSReqst *req )
510 {
511 return req->semReqData;
512 }
514 inline int
515 VMS__isDissipateReqst( VMSReqst *req )
516 {
517 return ( req->reqType == dissipate );
518 }
520 inline int
521 VMS__isCreateReqst( VMSReqst *req )
522 {
523 return ( req->reqType == regCreated );
524 }
526 void
527 VMS__send_req_to_register_new_procr(VirtProcr *newPr, VirtProcr *reqstingPr)
528 { VMSReqst *req;
530 req = malloc( sizeof(VMSReqst) );
531 req->reqType = regCreated;
532 req->semReqData = newPr;
533 req->nextReqst = reqstingPr->requests;
534 reqstingPr->requests = req;
536 VMS__suspend_procr( reqstingPr );
537 }
541 /*This must be called by the request handler plugin -- it cannot be called
542 * from the semantic library "dissipate processor" function -- instead, the
543 * semantic layer has to generate a request for the plug-in to call this
544 * function.
545 *The reason is that this frees the virtual processor's stack -- which is
546 * still in use inside semantic library calls!
547 *
548 *This frees or recycles all the state owned by and comprising the VMS
549 * portion of the animating virtual procr. The request handler must first
550 * free any semantic data created for the processor that didn't use the
551 * VMS_malloc mechanism. Then it calls this, which first asks the malloc
552 * system to disown any state that did use VMS_malloc, and then frees the
553 * statck and the processor-struct itself.
554 *If the dissipated processor is the sole (remaining) owner of VMS__malloc'd
555 * state, then that state gets freed (or sent to recycling) as a side-effect
556 * of dis-owning it.
557 */
558 void
559 VMS__handle_dissipate_reqst( VirtProcr *animatingPr )
560 {
561 //dis-own all locations owned by this processor, causing to be freed
562 // any locations that it is (was) sole owner of
563 //TODO: implement VMS__malloc system, including "give up ownership"
565 //The dissipate request might still be attached, so remove and free it
566 VMS__free_top_and_give_next_request_from( animatingPr );
568 //NOTE: initialData was given to the processor, so should either have
569 // been alloc'd with VMS__malloc, or freed by the level above animPr.
570 //So, all that's left to free here is the stack and the VirtProcr struc
571 // itself
572 free( animatingPr->startOfStack );
573 free( animatingPr );
574 }
577 //TODO: re-architect so that have clean separation between request handler
578 // and master loop, for dissipate, create, shutdown, and other non-semantic
579 // requests. Issue is chain: one removes requests from AppVP, one dispatches
580 // on type of request, and one handles each type.. but some types require
581 // action from both request handler and master loop -- maybe just give the
582 // request handler calls like: VMS__handle_X_request_type
584 void
585 endOSThreadFn( void *initData, VirtProcr *animatingPr );
587 /*This is called by the semantic layer's request handler when it decides its
588 * time to shut down the VMS system. Calling this causes the core loop OS
589 * threads to exit, which unblocks the entry-point function that started up
590 * VMS, and allows it to grab the result and return to the original single-
591 * threaded application.
592 *
593 *The _VMSMasterEnv is needed by this shut down function, so the create-seed-
594 * and-wait function has to free a bunch of stuff after it detects the
595 * threads have all died: the masterEnv, the thread-related locations,
596 * masterVP any AppVPs that might still be allocated and sitting in the
597 * semantic environment, or have been orphaned in the _VMSWorkQ.
598 *
599 *NOTE: the semantic plug-in is expected to use VMS__malloc_to to get all the
600 * locations it needs, and give ownership to masterVP. Then, they will be
601 * automatically freed when the masterVP is dissipated. (This happens after
602 * the core loop threads have all exited)
603 *
604 *In here,create one core-loop shut-down processor for each core loop and put
605 * them all directly into the readyToAnimateQ.
606 *Note, this function can ONLY be called after the semantic environment no
607 * longer cares if AppVPs get animated after the point this is called. In
608 * other words, this can be used as an abort, or else it should only be
609 * called when all AppVPs have finished dissipate requests -- only at that
610 * point is it sure that all results have completed.
611 */
612 void
613 VMS__handle_shutdown_reqst( void *dummy, VirtProcr *animatingPr )
614 { int coreIdx;
615 VirtProcr *shutDownPr;
617 //create the shutdown processors, one for each core loop -- put them
618 // directly into the Q -- each core will die when gets one
619 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
620 {
621 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
622 writeSRSWQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
623 }
625 }
628 /*Am trying to be cute, avoiding IF statement in coreLoop that checks for
629 * a special shutdown procr. Ended up with extra-complex shutdown sequence.
630 *This function has the sole purpose of setting the stack and framePtr
631 * to the coreLoop's stack and framePtr.. it does that then jumps to the
632 * core loop's shutdown point -- might be able to just call Pthread_exit
633 * from here, but am going back to the pthread's stack and setting everything
634 * up just as if it never jumped out, before calling pthread_exit.
635 *The end-point of core loop will free the stack and so forth of the
636 * processor that animates this function, (this fn is transfering the
637 * animator of the AppVP that is in turn animating this function over
638 * to core loop function -- note that this slices out a level of virtual
639 * processors).
640 */
641 void
642 endOSThreadFn( void *initData, VirtProcr *animatingPr )
643 { void *jmpPt, *coreLoopStackPtr, *coreLoopFramePtr;
645 jmpPt = _VMSMasterEnv->coreLoopEndPt;
646 coreLoopStackPtr = animatingPr->coreLoopStackPtr;
647 coreLoopFramePtr = animatingPr->coreLoopFramePtr;
650 asm volatile("movl %0, %%eax; \
651 movl %1, %%esp; \
652 movl %2, %%ebp; \
653 jmp %%eax " \
654 /* outputs */ : \
655 /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
656 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \
657 );
658 }
661 /*This is called after the threads have shut down and control has returned
662 * to the semantic layer, in the entry point function in the main thread.
663 * It has to free anything allocated during VMS_init, and any other alloc'd
664 * locations that might be left over.
665 */
666 void
667 VMS__cleanup_after_shutdown()
668 {
669 VMSQueueStruc **readyToAnimateQs;
670 int coreIdx;
671 VirtProcr **masterVPs;
672 SchedSlot ***allSchedSlots; //ptr to array of ptrs
674 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs;
675 masterVPs = _VMSMasterEnv->masterVPs;
676 allSchedSlots = _VMSMasterEnv->allSchedSlots;
678 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
679 {
680 freeSRSWQ( readyToAnimateQs[ coreIdx ] );
682 VMS__handle_dissipate_reqst( masterVPs[ coreIdx ] );
684 freeSchedSlots( allSchedSlots[ coreIdx ] );
685 }
687 free( _VMSMasterEnv->readyToAnimateQs );
688 free( _VMSMasterEnv->masterVPs );
689 free( _VMSMasterEnv->allSchedSlots );
691 free( _VMSMasterEnv );
692 }
695 //===========================================================================
697 inline TSCount getTSC()
698 { unsigned int low, high;
699 TSCount out;
701 saveTimeStampCountInto( low, high );
702 out = high;
703 out = (out << 32) + low;
704 return out;
705 }