comparison VMS.c @ 55:3bac84e4e56e

Works with correct matrix mult Nov 4 -- switch animators macros, many updates Changed all queues back to VMSQ variants #defines correct, protected, work-stealing, with compiler switch in and out
author Me
date Thu, 04 Nov 2010 18:13:18 -0700
parents f8508572f3de
children 26d53313a8f2
comparison
equal deleted inserted replaced
24:3bf3a370dba5 25:ae39c2a83901
85 } 85 }
86 86
87 void 87 void
88 create_masterEnv() 88 create_masterEnv()
89 { MasterEnv *masterEnv; 89 { MasterEnv *masterEnv;
90 SRSWQueueStruc **readyToAnimateQs; 90 VMSQueueStruc **readyToAnimateQs;
91 int coreIdx; 91 int coreIdx;
92 VirtProcr **masterVPs; 92 VirtProcr **masterVPs;
93 SchedSlot ***allSchedSlots; //ptr to array of ptrs 93 SchedSlot ***allSchedSlots; //ptr to array of ptrs
94 94
95 95
103 103
104 //===================== Only VMS__malloc after this ==================== 104 //===================== Only VMS__malloc after this ====================
105 masterEnv = _VMSMasterEnv; 105 masterEnv = _VMSMasterEnv;
106 106
107 //Make a readyToAnimateQ for each core loop 107 //Make a readyToAnimateQ for each core loop
108 readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(SRSWQueueStruc *) ); 108 readyToAnimateQs = VMS__malloc( NUM_CORES * sizeof(VMSQueueStruc *) );
109 masterVPs = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) ); 109 masterVPs = VMS__malloc( NUM_CORES * sizeof(VirtProcr *) );
110 110
111 //One array for each core, 3 in array, core's masterVP scheds all 111 //One array for each core, 3 in array, core's masterVP scheds all
112 allSchedSlots = VMS__malloc( NUM_CORES * sizeof(SchedSlot *) ); 112 allSchedSlots = VMS__malloc( NUM_CORES * sizeof(SchedSlot *) );
113 113
114 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr 114 _VMSMasterEnv->numProcrsCreated = 0; //used by create procr
115 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) 115 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
116 { 116 {
117 readyToAnimateQs[ coreIdx ] = makeSRSWQ(); 117 readyToAnimateQs[ coreIdx ] = makeVMSQ();
118 118
119 //Q: should give masterVP core-specific info as its init data? 119 //Q: should give masterVP core-specific info as its init data?
120 masterVPs[ coreIdx ] = VMS__create_procr( &masterLoop, masterEnv ); 120 masterVPs[ coreIdx ] = VMS__create_procr( &masterLoop, masterEnv );
121 masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx; 121 masterVPs[ coreIdx ]->coreAnimatedBy = coreIdx;
122 allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core 122 allSchedSlots[ coreIdx ] = create_sched_slots(); //makes for one core
123 _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0; 123 _VMSMasterEnv->numMasterInARow[ coreIdx ] = 0;
124 _VMSMasterEnv->workStealingGates[ coreIdx ] = NULL;
124 } 125 }
125 _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs; 126 _VMSMasterEnv->readyToAnimateQs = readyToAnimateQs;
126 _VMSMasterEnv->masterVPs = masterVPs; 127 _VMSMasterEnv->masterVPs = masterVPs;
127 _VMSMasterEnv->masterLock = UNLOCKED; 128 _VMSMasterEnv->masterLock = UNLOCKED;
128 _VMSMasterEnv->allSchedSlots = allSchedSlots; 129 _VMSMasterEnv->allSchedSlots = allSchedSlots;
130 _VMSMasterEnv->workStealingLock = UNLOCKED;
129 131
130 132
131 //Aug 19, 2010: no longer need to place initial masterVP into queue 133 //Aug 19, 2010: no longer need to place initial masterVP into queue
132 // because coreLoop now controls -- animates its masterVP when no work 134 // because coreLoop now controls -- animates its masterVP when no work
133 135
336 * there, and will get passed along, inside the request handler, to the 338 * there, and will get passed along, inside the request handler, to the
337 * next work-unit for that procr. 339 * next work-unit for that procr.
338 */ 340 */
339 void 341 void
340 VMS__suspend_procr( VirtProcr *animatingPr ) 342 VMS__suspend_procr( VirtProcr *animatingPr )
341 { void *jmpPt, *stackPtrAddr, *framePtrAddr, *coreLoopStackPtr; 343 {
342 void *coreLoopFramePtr;
343 344
344 //The request to master will cause this suspended virt procr to get 345 //The request to master will cause this suspended virt procr to get
345 // scheduled again at some future point -- to resume, core loop jumps 346 // scheduled again at some future point -- to resume, core loop jumps
346 // to the resume point (below), which causes restore of saved regs and 347 // to the resume point (below), which causes restore of saved regs and
347 // "return" from this call. 348 // "return" from this call.
348 animatingPr->nextInstrPt = &&ResumePt; 349 animatingPr->nextInstrPt = &&ResumePt;
349 350
350 //return ownership of the virt procr and sched slot to Master virt pr 351 //return ownership of the virt procr and sched slot to Master virt pr
351 animatingPr->schedSlot->workIsDone = TRUE; 352 animatingPr->schedSlot->workIsDone = TRUE;
352
353 stackPtrAddr = &(animatingPr->stackPtr);
354 framePtrAddr = &(animatingPr->framePtr);
355
356 jmpPt = _VMSMasterEnv->coreLoopStartPt;
357 coreLoopFramePtr = animatingPr->coreLoopFramePtr;//need this only
358 coreLoopStackPtr = animatingPr->coreLoopStackPtr;//safety
359
360 //Save the virt procr's stack and frame ptrs,
361 asm volatile("movl %0, %%eax; \
362 movl %%esp, (%%eax); \
363 movl %1, %%eax; \
364 movl %%ebp, (%%eax) "\
365 /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \
366 /* inputs */ : \
367 /* clobber */ : "%eax" \
368 );
369 353
370 //=========================== Measurement stuff ======================== 354 //=========================== Measurement stuff ========================
371 #ifdef MEAS__TIME_STAMP_SUSP 355 #ifdef MEAS__TIME_STAMP_SUSP
372 //record time stamp: compare to time-stamp recorded below 356 //record time stamp: compare to time-stamp recorded below
373 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow ); 357 saveLowTimeStampCountInto( animatingPr->preSuspTSCLow );
374 #endif 358 #endif
375 //======================================================================= 359 //=======================================================================
376 360
377 //restore coreloop's frame ptr, then jump back to "start" of core loop 361
378 //Note, GCC compiles to assembly that saves esp and ebp in the stack 362 SwitchToCoreLoop( animatingPr )
379 // frame -- so have to explicitly do assembly that saves to memory 363
380 asm volatile("movl %0, %%eax; \ 364 //=======================================================================
381 movl %1, %%esp; \
382 movl %2, %%ebp; \
383 jmp %%eax " \
384 /* outputs */ : \
385 /* inputs */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
386 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \
387 ); //list everything as clobbered to force GCC to save all
388 // live vars that are in regs on stack before this
389 // assembly, so that stack pointer is correct, before jmp
390
391 ResumePt: 365 ResumePt:
392 #ifdef MEAS__TIME_STAMP_SUSP 366 #ifdef MEAS__TIME_STAMP_SUSP
393 //NOTE: only take low part of count -- do sanity check when take diff 367 //NOTE: only take low part of count -- do sanity check when take diff
394 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow ); 368 saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
395 #endif 369 #endif
671 //create the shutdown processors, one for each core loop -- put them 645 //create the shutdown processors, one for each core loop -- put them
672 // directly into the Q -- each core will die when gets one 646 // directly into the Q -- each core will die when gets one
673 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) 647 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ )
674 { //Note, this is running in the master 648 { //Note, this is running in the master
675 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL ); 649 shutDownPr = VMS__create_procr( &endOSThreadFn, NULL );
676 writeSRSWQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] ); 650 writeVMSQ( shutDownPr, _VMSMasterEnv->readyToAnimateQs[coreIdx] );
677 } 651 }
678 652
679 } 653 }
680 654
681 655
715 /*This is called from the startup & shutdown 689 /*This is called from the startup & shutdown
716 */ 690 */
717 void 691 void
718 VMS__cleanup_at_end_of_shutdown() 692 VMS__cleanup_at_end_of_shutdown()
719 { 693 {
720 SRSWQueueStruc **readyToAnimateQs; 694 VMSQueueStruc **readyToAnimateQs;
721 int coreIdx; 695 int coreIdx;
722 VirtProcr **masterVPs; 696 VirtProcr **masterVPs;
723 SchedSlot ***allSchedSlots; //ptr to array of ptrs 697 SchedSlot ***allSchedSlots; //ptr to array of ptrs
724 698
725 //All the environment data has been allocated with VMS__malloc, so just 699 //All the environment data has been allocated with VMS__malloc, so just
729 masterVPs = _VMSMasterEnv->masterVPs; 703 masterVPs = _VMSMasterEnv->masterVPs;
730 allSchedSlots = _VMSMasterEnv->allSchedSlots; 704 allSchedSlots = _VMSMasterEnv->allSchedSlots;
731 705
732 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) 706 for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ )
733 { 707 {
734 freeSRSWQ( readyToAnimateQs[ coreIdx ] ); 708 freeVMSQ( readyToAnimateQs[ coreIdx ] );
735 //master VPs were created external to VMS, so use external free 709 //master VPs were created external to VMS, so use external free
736 VMS__dissipate_procr( masterVPs[ coreIdx ] ); 710 VMS__dissipate_procr( masterVPs[ coreIdx ] );
737 711
738 freeSchedSlots( allSchedSlots[ coreIdx ] ); 712 freeSchedSlots( allSchedSlots[ coreIdx ] );
739 } 713 }