comparison VMS.c @ 139:99798e4438a6

Merge of Malloc2 and inter master requests
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 19 Sep 2011 16:12:01 +0200
parents def70e32cf2c 99343ffe1918
children 2c8f3cf6c058
comparison
equal deleted inserted replaced
48:36c2d5074306 63:e2b9bc75f03c
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 "scheduling.h"
16 #include "Queue_impl/BlockingQueue.h" 17 #include "Queue_impl/BlockingQueue.h"
17 #include "Histogram/Histogram.h" 18 #include "Histogram/Histogram.h"
18 19
19 20
20 #define thdAttrs NULL 21 #define thdAttrs NULL
103 _VMSMasterEnv = malloc( sizeof(MasterEnv) ); 104 _VMSMasterEnv = malloc( sizeof(MasterEnv) );
104 105
105 //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
106 // with a massive initial chunk of memory. 107 // with a massive initial chunk of memory.
107 //After this, all other mallocs are VMS__malloc. 108 //After this, all other mallocs are VMS__malloc.
108 _VMSMasterEnv->freeLists = VMS_ext__create_free_list(); 109 int i;
109 110 for(i=0; i<NUM_CORES; i++)
111 {
112 _VMSMasterEnv->freeLists[i] = VMS_ext__create_free_list();
113 _VMSMasterEnv->interMasterRequestsFor[i] = NULL;
114 _VMSMasterEnv->interMasterRequestsSentBy[i] = NULL;
115 }
116 _VMSMasterEnv->currentMasterProcrID = 0;
110 117
111 //============================= MEASUREMENT STUFF ======================== 118 //============================= MEASUREMENT STUFF ========================
112 #ifdef MEAS__TIME_MALLOC 119 #ifdef MEAS__TIME_MALLOC
113 _VMSMasterEnv->mallocTimeHist = makeFixedBinHistExt( 100, 0, 100, 120 _VMSMasterEnv->mallocTimeHist = makeFixedBinHistExt( 100, 0, 100,
114 "malloc_time_hist"); 121 "malloc_time_hist");
495 callingPr->requests = &req; 502 callingPr->requests = &req;
496 503
497 VMS__suspend_procr( callingPr ); 504 VMS__suspend_procr( callingPr );
498 } 505 }
499 506
507 void inline
508 VMS__send_inter_plugin_req( void *reqData, int32 targetMaster,
509 VirtProcr *requestingMaster )
510 { _VMSMasterEnv->interMasterRequestsFor[targetMaster] =
511 (InterMasterReqst *) reqData;
512 }
513
514 void inline
515 VMS__send_inter_VMSCore_req( InterVMSCoreReqst *reqData,
516 int32 targetMaster, VirtProcr *requestingMaster )
517 { _VMSMasterEnv->interMasterRequestsFor[targetMaster] =
518 (InterMasterReqst *) reqData;
519 }
500 520
501 /* 521 /*
502 */ 522 */
503 VMSReqst * 523 VMSReqst *
504 VMS__take_next_request_out_of( VirtProcr *procrWithReq ) 524 VMS__take_next_request_out_of( VirtProcr *procrWithReq )
540 { VMSSemReq *semReq; 560 { VMSSemReq *semReq;
541 IntervalProbe *newProbe; 561 IntervalProbe *newProbe;
542 562
543 semReq = req->semReqData; 563 semReq = req->semReqData;
544 564
545 newProbe = VMS__malloc( sizeof(IntervalProbe) ); 565 switch(semReq->reqType){
546 newProbe->nameStr = VMS__strDup( semReq->nameStr ); 566 case createProbe:
547 newProbe->hist = NULL; 567 newProbe = VMS__malloc( sizeof(IntervalProbe) );
548 newProbe->schedChoiceWasRecorded = FALSE; 568 newProbe->nameStr = VMS__strDup( (char*)semReq->data );
549 569 newProbe->hist = NULL;
550 //This runs in masterVP, so no race-condition worries 570 newProbe->schedChoiceWasRecorded = FALSE;
551 newProbe->probeID = 571
552 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo ); 572 //This runs in masterVP, so no race-condition worries
553 573 newProbe->probeID =
554 requestingPr->dataRetFromReq = newProbe; 574 addToDynArray( newProbe, _VMSMasterEnv->dynIntervalProbesInfo );
555 575 requestingPr->dataRetFromReq = newProbe;
556 (*resumePrFnPtr)( requestingPr, semEnv ); 576 break;
577 case interMasterReqst:
578 sendInterMasterReqst(semReq->receiverID,
579 (InterMasterReqst*)semReq->data);
580 break;
581 default:
582 break;
583 }
584
585 resumePrFnPtr( requestingPr, semEnv );
557 } 586 }
558 587
559 588
560 589
561 /*This must be called by the request handler plugin -- it cannot be called 590 /*This must be called by the request handler plugin -- it cannot be called
587 // been alloc'd with VMS__malloc, or freed by the level above animPr. 616 // been alloc'd with VMS__malloc, or freed by the level above animPr.
588 //So, all that's left to free here is the stack and the VirtProcr struc 617 //So, all that's left to free here is the stack and the VirtProcr struc
589 // itself 618 // itself
590 //Note, should not stack-allocate initial data -- no guarantee, in 619 //Note, should not stack-allocate initial data -- no guarantee, in
591 // general that creating processor will outlive ones it creates. 620 // general that creating processor will outlive ones it creates.
592 VMS__free( animatingPr->startOfStack ); 621
593 VMS__free( animatingPr ); 622 VMS__free( animatingPr->startOfStack);
623 VMS__free( animatingPr);
594 } 624 }
595 625
596 626
597 //TODO: look at architecting cleanest separation between request handler 627 //TODO: look at architecting cleanest separation between request handler
598 // and master loop, for dissipate, create, shutdown, and other non-semantic 628 // and master loop, for dissipate, create, shutdown, and other non-semantic
627 * point is it sure that all results have completed. 657 * point is it sure that all results have completed.
628 */ 658 */
629 void 659 void
630 VMS__shutdown() 660 VMS__shutdown()
631 { int coreIdx; 661 { int coreIdx;
632 VirtProcr *shutDownPr; 662 //Send a shutdown Request to all MasterLoops.
633
634 //create the shutdown processors, one for each core loop -- put them
635 // directly into the Q -- each core will die when gets one
636 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 663 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
637 { //Note, this is running in the master 664 { //Note, this is running in the master
638 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL ); 665 InterVMSCoreReqst *shutdownReqst = VMS__malloc(sizeof(InterVMSCoreReqst));
639 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] ); 666 shutdownReqst->secondReqType = shutdownVP;
667 sendInterMasterReqst(coreIdx, (InterMasterReqst*)shutdownReqst);
640 } 668 }
641 669
642 } 670 }
643 671
644 672
653 * processor that animates this function, (this fn is transfering the 681 * processor that animates this function, (this fn is transfering the
654 * animator of the AppVP that is in turn animating this function over 682 * animator of the AppVP that is in turn animating this function over
655 * to core loop function -- note that this slices out a level of virtual 683 * to core loop function -- note that this slices out a level of virtual
656 * processors). 684 * processors).
657 */ 685 */
686 /*
658 void 687 void
659 endOSThreadFn( void *initData, VirtProcr *animatingPr ) 688 endOSThreadFn( void *initData, VirtProcr *animatingPr )
660 { 689 {
661 #ifdef SEQUENTIAL 690 #ifdef SEQUENTIAL
662 asmTerminateCoreLoopSeq(animatingPr); 691 asmTerminateCoreLoopSeq(animatingPr);
663 #else 692 #else
664 asmTerminateCoreLoop(animatingPr); 693 asmTerminateCoreLoop(animatingPr);
665 #endif 694 #endif
666 } 695 }
696 */
667 697
668 698
669 /*This is called from the startup & shutdown 699 /*This is called from the startup & shutdown
670 */ 700 */
671 void 701 void
672 VMS__cleanup_at_end_of_shutdown() 702 VMS__cleanup_at_end_of_shutdown()
673 { 703 {
704 // Set to zero so that all data structures are freed correctly
705 _VMSMasterEnv->currentMasterProcrID = 0;
706
674 //unused 707 //unused
675 //VMSQueueStruc **readyToAnimateQs; 708 //VMSQueueStruc **readyToAnimateQs;
676 //int coreIdx; 709 //int coreIdx;
677 //VirtProcr **masterVPs; 710 //VirtProcr **masterVPs;
678 //SchedSlot ***allSchedSlots; //ptr to array of ptrs 711 //SchedSlot ***allSchedSlots; //ptr to array of ptrs
749 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe); 782 freeDynArrayDeep( _VMSMasterEnv->dynIntervalProbesInfo, &VMS__free_probe);
750 #endif 783 #endif
751 //======================================================================== 784 //========================================================================
752 */ 785 */
753 //These are the only two that use system free 786 //These are the only two that use system free
754 VMS_ext__free_free_list( _VMSMasterEnv->freeLists ); 787 int i;
788 for(i=0; i<NUM_CORES; i++)
789 VMS_ext__free_free_list( _VMSMasterEnv->freeLists[i]);
755 free( (void *)_VMSMasterEnv ); 790 free( (void *)_VMSMasterEnv );
756 } 791 }
757 792
758 793
759 //================================ 794 //================================