comparison 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
comparison
equal deleted inserted replaced
85:d2370869bf6e 94:44222cde49c9
11 #include <inttypes.h> 11 #include <inttypes.h>
12 #include <sys/time.h> 12 #include <sys/time.h>
13 13
14 #include "VMS.h" 14 #include "VMS.h"
15 #include "ProcrContext.h" 15 #include "ProcrContext.h"
16 #include "Queue_impl/BlockingQueue.h" 16 #include "C_Libraries/Queue_impl/BlockingQueue.h"
17 #include "Histogram/Histogram.h" 17 #include "C_Libraries/Histogram/Histogram.h"
18 18
19 19
20 #define thdAttrs NULL 20 #define thdAttrs NULL
21 21
22 //=========================================================================== 22 //===========================================================================
103 posix_memalign((void*)&_VMSMasterEnv, CACHELINE_SIZE, sizeof(MasterEnv) ); 103 posix_memalign((void*)&_VMSMasterEnv, CACHELINE_SIZE, sizeof(MasterEnv) );
104 memset( _VMSMasterEnv, 0, sizeof(MasterEnv) ); 104 memset( _VMSMasterEnv, 0, sizeof(MasterEnv) );
105 105
106 //Very first thing put into the master env is the free-list, seeded 106 //Very first thing put into the master env is the free-list, seeded
107 // with a massive initial chunk of memory. 107 // with a massive initial chunk of memory.
108 //After this, all other mallocs are VMS__malloc. 108 //After this, all other mallocs are VMS_int__malloc.
109 _VMSMasterEnv->freeLists = VMS_ext__create_free_list(); 109 _VMSMasterEnv->freeLists = VMS_ext__create_free_list();
110 110
111 111
112 //============================= MEASUREMENT STUFF ======================== 112 //============================= MEASUREMENT STUFF ========================
113 #ifdef MEAS__TIME_MALLOC 113 #ifdef MEAS__TIME_MALLOC
122 _VMSMasterEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 100, 0, 200, 122 _VMSMasterEnv->reqHdlrHighTimeHist = makeFixedBinHistExt( 100, 0, 200,
123 "plugin_high_time_hist"); 123 "plugin_high_time_hist");
124 #endif 124 #endif
125 //======================================================================== 125 //========================================================================
126 126
127 //===================== Only VMS__malloc after this ==================== 127 //===================== Only VMS_int__malloc after this ====================
128 masterEnv = (MasterEnv*)_VMSMasterEnv; 128 masterEnv = (MasterEnv*)_VMSMasterEnv;
129 129
130 //Make a readyToAnimateQ for each core loop 130 //Make a readyToAnimateQ for each core loop
131 readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(VMSQueueStruc *) ); 131 readyToAnimateQs = VMS_int__malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
132 masterVPs = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) ); 132 masterVPs = VMS_int__malloc( NUM_CORES * sizeof(VirtProcr *) );
133 133
134 //One array for each core, 3 in array, core's masterVP scheds all 134 //One array for each core, 3 in array, core's masterVP scheds all
135 allSchedSlots = VMS__malloc( NUM_CORES * sizeof(SchedSlot *) ); 135 allSchedSlots = VMS_int__malloc( NUM_CORES * sizeof(SchedSlot *) );
136 136
137 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr 137 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr
138 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) 138 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
139 { 139 {
140 readyToAnimateQs[ coreIdx ] = makeVMSQ(); 140 readyToAnimateQs[ coreIdx ] = makeVMSQ();
160 //============================= MEASUREMENT STUFF ======================== 160 //============================= MEASUREMENT STUFF ========================
161 #ifdef STATS__TURN_ON_PROBES 161 #ifdef STATS__TURN_ON_PROBES
162 _VMSMasterEnv->dynIntervalProbesInfo = 162 _VMSMasterEnv->dynIntervalProbesInfo =
163 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->intervalProbes), 200); 163 makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->intervalProbes), 200);
164 164
165 _VMSMasterEnv->probeNameHashTbl = makeHashTable( 1000, &VMS__free ); 165 _VMSMasterEnv->probeNameHashTbl = makeHashTable( 1000, &VMS_int__free );
166 166
167 //put creation time directly into master env, for fast retrieval 167 //put creation time directly into master env, for fast retrieval
168 struct timeval timeStamp; 168 struct timeval timeStamp;
169 gettimeofday( &(timeStamp), NULL); 169 gettimeofday( &(timeStamp), NULL);
170 _VMSMasterEnv->createPtInSecs = 170 _VMSMasterEnv->createPtInSecs =
185 SchedSlot ** 185 SchedSlot **
186 create_sched_slots() 186 create_sched_slots()
187 { SchedSlot **schedSlots; 187 { SchedSlot **schedSlots;
188 int i; 188 int i;
189 189
190 //schedSlots = VMS__malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) ); 190 //schedSlots = VMS_int__malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) );
191 posix_memalign(&schedSlots, CACHELINE_SIZE, NUM_SCHED_SLOTS * sizeof(SchedSlot *)); 191 posix_memalign(&schedSlots, CACHELINE_SIZE, NUM_SCHED_SLOTS * sizeof(SchedSlot *));
192 192
193 for( i = 0; i < NUM_SCHED_SLOTS; i++ ) 193 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
194 { 194 {
195 //schedSlots[i] = VMS__malloc( sizeof(SchedSlot) ); 195 //schedSlots[i] = VMS_int__malloc( sizeof(SchedSlot) );
196 posix_memalign(&schedSlots[i], CACHELINE_SIZE, CACHELINE_SIZE ); 196 posix_memalign(&schedSlots[i], CACHELINE_SIZE, CACHELINE_SIZE );
197 197
198 //Set state to mean "handling requests done, slot needs filling" 198 //Set state to mean "handling requests done, slot needs filling"
199 schedSlots[i]->workIsDone = FALSE; 199 schedSlots[i]->workIsDone = FALSE;
200 schedSlots[i]->needsProcrAssigned = TRUE; 200 schedSlots[i]->needsProcrAssigned = TRUE;
206 void 206 void
207 freeSchedSlots( SchedSlot **schedSlots ) 207 freeSchedSlots( SchedSlot **schedSlots )
208 { int i; 208 { int i;
209 for( i = 0; i < NUM_SCHED_SLOTS; i++ ) 209 for( i = 0; i < NUM_SCHED_SLOTS; i++ )
210 { 210 {
211 VMS__free( schedSlots[i] ); 211 VMS_int__free( schedSlots[i] );
212 } 212 }
213 VMS__free( schedSlots ); 213 VMS_int__free( schedSlots );
214 } 214 }
215 215
216 216
217 void 217 void
218 create_the_coreLoop_OS_threads() 218 create_the_coreLoop_OS_threads()
226 // stuff before the coreLoops set off. 226 // stuff before the coreLoops set off.
227 _VMSMasterEnv->setupComplete = 0; 227 _VMSMasterEnv->setupComplete = 0;
228 228
229 //Make the threads that animate the core loops 229 //Make the threads that animate the core loops
230 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 230 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
231 { coreLoopThdParams[coreIdx] = VMS__malloc( sizeof(ThdParams) ); 231 { coreLoopThdParams[coreIdx] = VMS_int__malloc( sizeof(ThdParams) );
232 coreLoopThdParams[coreIdx]->coreNum = coreIdx; 232 coreLoopThdParams[coreIdx]->coreNum = coreIdx;
233 233
234 retCode = 234 retCode =
235 pthread_create( &(coreLoopThdHandles[coreIdx]), 235 pthread_create( &(coreLoopThdHandles[coreIdx]),
236 thdAttrs, 236 thdAttrs,
291 void *stackLocs; 291 void *stackLocs;
292 292
293 posix_memalign((void*)&newPr, CACHELINE_SIZE, sizeof(VirtProcr) ); //align to cacheline 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 294 posix_memalign(&stackLocs, CACHELINE_SIZE, VIRT_PROCR_STACK_SIZE ); //align to cacheline
295 if( stackLocs == 0 ) 295 if( stackLocs == 0 )
296 { perror("VMS__malloc stack"); exit(1); } 296 { perror("VMS_int__malloc stack"); exit(1); }
297 297
298 return create_procr_helper( newPr, fnPtr, initialData, stackLocs ); 298 return create_procr_helper( newPr, fnPtr, initialData, stackLocs );
299 } 299 }
300 300
301 /* "ext" designates that it's for use outside the VMS system -- should only 301 /* "ext" designates that it's for use outside the VMS system -- should only
435 */ 435 */
436 void 436 void
437 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate ) 437 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate )
438 { 438 {
439 //NOTE: initialData was given to the processor, so should either have 439 //NOTE: initialData was given to the processor, so should either have
440 // been alloc'd with VMS__malloc, or freed by the level above animPr. 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 441 //So, all that's left to free here is the stack and the VirtProcr struc
442 // itself 442 // itself
443 //Note, should not stack-allocate initial data -- no guarantee, in 443 //Note, should not stack-allocate initial data -- no guarantee, in
444 // general that creating processor will outlive ones it creates. 444 // general that creating processor will outlive ones it creates.
445 free( procrToDissipate->startOfStack ); 445 free( procrToDissipate->startOfStack );
454 * This inserts the semantic-layer's request data into standard VMS carrier 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 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 456 * be malloc'd if this is called inside the same call chain before the
457 * send of the last request is called. 457 * send of the last request is called.
458 * 458 *
459 *The request handler has to call VMS__free_VMSReq for any of these 459 *The request handler has to call VMS_int__free_VMSReq for any of these
460 */ 460 */
461 inline void 461 inline void
462 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, 462 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData,
463 VirtProcr *callingPr ) 463 VirtProcr *callingPr )
464 { VMSReqst *req; 464 { VMSReqst *req;
465 465
466 req = VMS__malloc( sizeof(VMSReqst) ); 466 req = VMS_int__malloc( sizeof(VMSReqst) );
467 req->reqType = semantic; 467 req->reqType = semantic;
468 req->semReqData = semReqData; 468 req->semReqData = semReqData;
469 req->nextReqst = callingPr->requests; 469 req->nextReqst = callingPr->requests;
470 callingPr->requests = req; 470 callingPr->requests = req;
471 } 471 }
543 { VMSSemReq *semReq; 543 { VMSSemReq *semReq;
544 IntervalProbe *newProbe; 544 IntervalProbe *newProbe;
545 545
546 semReq = req->semReqData; 546 semReq = req->semReqData;
547 547
548 newProbe = VMS__malloc( sizeof(IntervalProbe) ); 548 newProbe = VMS_int__malloc( sizeof(IntervalProbe) );
549 newProbe->nameStr = VMS__strDup( semReq->nameStr ); 549 newProbe->nameStr = VMS_int__strDup( semReq->nameStr );
550 newProbe->hist = NULL; 550 newProbe->hist = NULL;
551 newProbe->schedChoiceWasRecorded = FALSE; 551 newProbe->schedChoiceWasRecorded = FALSE;
552 552
553 //This runs in masterVP, so no race-condition worries 553 //This runs in masterVP, so no race-condition worries
554 newProbe->probeID = 554 newProbe->probeID =
572 * portion of the animating virtual procr. The request handler must first 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 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 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 575 * system to disown any state that did use VMS_malloc, and then frees the
576 * statck and the processor-struct itself. 576 * statck and the processor-struct itself.
577 *If the dissipated processor is the sole (remaining) owner of VMS__malloc'd 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 578 * state, then that state gets freed (or sent to recycling) as a side-effect
579 * of dis-owning it. 579 * of dis-owning it.
580 */ 580 */
581 void 581 void
582 VMS__dissipate_procr( VirtProcr *animatingPr ) 582 VMS__dissipate_procr( VirtProcr *animatingPr )
583 { 583 {
584 //dis-own all locations owned by this processor, causing to be freed 584 //dis-own all locations owned by this processor, causing to be freed
585 // any locations that it is (was) sole owner of 585 // any locations that it is (was) sole owner of
586 //TODO: implement VMS__malloc system, including "give up ownership" 586 //TODO: implement VMS_int__malloc system, including "give up ownership"
587 587
588 588
589 //NOTE: initialData was given to the processor, so should either have 589 //NOTE: initialData was given to the processor, so should either have
590 // been alloc'd with VMS__malloc, or freed by the level above animPr. 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 591 //So, all that's left to free here is the stack and the VirtProcr struc
592 // itself 592 // itself
593 //Note, should not stack-allocate initial data -- no guarantee, in 593 //Note, should not stack-allocate initial data -- no guarantee, in
594 // general that creating processor will outlive ones it creates. 594 // general that creating processor will outlive ones it creates.
595 free( animatingPr->startOfStack ); 595 free( animatingPr->startOfStack );
615 * and-wait function has to free a bunch of stuff after it detects the 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, 616 * threads have all died: the masterEnv, the thread-related locations,
617 * masterVP any AppVPs that might still be allocated and sitting in the 617 * masterVP any AppVPs that might still be allocated and sitting in the
618 * semantic environment, or have been orphaned in the _VMSWorkQ. 618 * semantic environment, or have been orphaned in the _VMSWorkQ.
619 * 619 *
620 *NOTE: the semantic plug-in is expected to use VMS__malloc to get all the 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 621 * locations it needs, and give ownership to masterVP. Then, they will be
622 * automatically freed. 622 * automatically freed.
623 * 623 *
624 *In here,create one core-loop shut-down processor for each core loop and put 624 *In here,create one core-loop shut-down processor for each core loop and put
625 * them all directly into the readyToAnimateQ. 625 * them all directly into the readyToAnimateQ.
727 727
728 freeSchedSlots( allSchedSlots[ coreIdx ] ); 728 freeSchedSlots( allSchedSlots[ coreIdx ] );
729 } 729 }
730 #endif 730 #endif
731 731
732 //All the environment data has been allocated with VMS__malloc, so just 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. 733 // free its internal big-chunk and all inside it disappear.
734 /* 734 /*
735 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs; 735 readyToAnimateQs = _VMSMasterEnv->readyToAnimateQs;
736 masterVPs = _VMSMasterEnv->masterVPs; 736 masterVPs = _VMSMasterEnv->masterVPs;
737 allSchedSlots = _VMSMasterEnv->allSchedSlots; 737 allSchedSlots = _VMSMasterEnv->allSchedSlots;
743 VMS__dissipate_procr( masterVPs[ coreIdx ] ); 743 VMS__dissipate_procr( masterVPs[ coreIdx ] );
744 744
745 freeSchedSlots( allSchedSlots[ coreIdx ] ); 745 freeSchedSlots( allSchedSlots[ coreIdx ] );
746 } 746 }
747 747
748 VMS__free( _VMSMasterEnv->readyToAnimateQs ); 748 VMS_int__free( _VMSMasterEnv->readyToAnimateQs );
749 VMS__free( _VMSMasterEnv->masterVPs ); 749 VMS_int__free( _VMSMasterEnv->masterVPs );
750 VMS__free( _VMSMasterEnv->allSchedSlots ); 750 VMS_int__free( _VMSMasterEnv->allSchedSlots );
751 751
752 //============================= MEASUREMENT STUFF ======================== 752 //============================= MEASUREMENT STUFF ========================
753 #ifdef STATS__TURN_ON_PROBES 753 #ifdef STATS__TURN_ON_PROBES
754 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe); 754 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS_int__free_probe);
755 #endif 755 #endif
756 //======================================================================== 756 //========================================================================
757 */ 757 */
758 //These are the only two that use system free 758 //These are the only two that use system free
759 VMS_ext__free_free_list( _VMSMasterEnv->freeLists ); 759 VMS_ext__free_free_list( _VMSMasterEnv->freeLists );