Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
diff MasterLoop.c @ 26:668278fa7a63
Sequential -- just starting to add sequential version
| author | Me |
|---|---|
| date | Mon, 26 Jul 2010 15:25:53 -0700 |
| parents | a0af8d4fca35 |
| children | 5a2068cbc28b |
line diff
1.1 --- a/MasterLoop.c Sat Jul 24 08:58:47 2010 -0700 1.2 +++ b/MasterLoop.c Mon Jul 26 15:25:53 2010 -0700 1.3 @@ -6,7 +6,6 @@ 1.4 1.5 1.6 1.7 -#include <windows.h> 1.8 #include <stdio.h> 1.9 #include <malloc.h> 1.10 #include <stddef.h> 1.11 @@ -48,11 +47,11 @@ 1.12 */ 1.13 void masterLoop( void *initData, VirtProcr *masterPr ) 1.14 { 1.15 - int slotIdx, numFilled, numInFirstChunk, filledSlotIdx; 1.16 + int slotIdx, numFilled, filledSlotIdx, masterHasBeenQueued; 1.17 VirtProcr *schedVirtPr; 1.18 SchedSlot *currSlot, **schedSlots, **filledSlots; 1.19 MasterEnv *masterEnv; 1.20 - CASQueueStruc *workQ; 1.21 + VMSQueueStruc *workQ; 1.22 void *jmpPt, *stackPtrAddr, *framePtrAddr, *stillRunningAddr; 1.23 void *coreLoopFramePtr, *coreLoopStackPtr, *semanticEnv; 1.24 1.25 @@ -65,7 +64,26 @@ 1.26 // of setup code.. 1.27 masterPr->nextInstrPt = &&masterLoopStartPt; 1.28 1.29 - 1.30 + //The second time MasterVP comes out of queue, the first animation of 1.31 + // it hasn't written the stackPtr and framePtr yet -- but the second 1.32 + // animation has already had its stackPtr and framePtr set to the old 1.33 + // value by the coreLoop. Fix this by writing the correct stack and 1.34 + // frame pointers here, at which point they're correct in the first 1.35 + // animation of MasterVP. 1.36 + //TODO: remove writing stackPtr and framePtr at the bottom, for eff 1.37 + stackPtrAddr = &(masterPr->stackPtr); 1.38 + framePtrAddr = &(masterPr->framePtr); 1.39 + 1.40 + asm volatile("movl %0, %%eax; \ 1.41 + movl %%esp, (%%eax); \ 1.42 + movl %1, %%eax; \ 1.43 + movl %%ebp, (%%eax); " 1.44 + /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \ 1.45 + /* inputs */ : \ 1.46 + /* clobber */ : "memory", "%eax", "%ebx" \ 1.47 + ); 1.48 + 1.49 + 1.50 masterLoopStartPt: 1.51 1.52 //if another reference to same Master VirtProcr still going, busy-wait 1.53 @@ -88,10 +106,11 @@ 1.54 semanticEnv = masterEnv->semanticEnv; 1.55 1.56 //prepare for scheduling 1.57 - masterEnv->numFilled = 0; 1.58 + numFilled = 0; 1.59 + masterHasBeenQueued = FALSE; 1.60 1.61 //Poll each slot's Done flag -- slot 0 reserved for master, start at 1 1.62 - for( slotIdx = 1; slotIdx < NUM_SCHED_SLOTS; slotIdx++) 1.63 + for( slotIdx = 0; slotIdx < NUM_SCHED_SLOTS; slotIdx++) 1.64 { 1.65 currSlot = schedSlots[ slotIdx ]; 1.66 1.67 @@ -110,50 +129,63 @@ 1.68 1.69 if( schedVirtPr != NULL ) 1.70 { currSlot->procrAssignedToSlot = schedVirtPr; 1.71 - schedVirtPr->schedSlot = currSlot; 1.72 + schedVirtPr->schedSlot = currSlot; 1.73 + currSlot->needsProcrAssigned = FALSE; 1.74 1.75 - filledSlots[ masterEnv->numFilled ] = currSlot; 1.76 - masterEnv->numFilled += 1; 1.77 + filledSlots[ numFilled ] = currSlot; 1.78 + numFilled += 1; 1.79 1.80 - currSlot->needsProcrAssigned = FALSE; 1.81 + writeVMSQ( schedVirtPr, workQ ); 1.82 + if( numFilled == masterEnv->numToPrecede ) 1.83 + { 1.84 + writeVMSQ( masterEnv->masterVirtPr, workQ ); 1.85 + masterHasBeenQueued = TRUE; 1.86 + } 1.87 + 1.88 } 1.89 } 1.90 } 1.91 1.92 + if( !masterHasBeenQueued ) 1.93 + { 1.94 + writeVMSQ( masterEnv->masterVirtPr, workQ ); 1.95 + } 1.96 + 1.97 + //Adjust the number to precede, for next round -- assume rate of 1.98 + // finishing work is stable -- which is a bad assumption! But, just 1.99 + // want something working for the moment, look at dynamic behavior 1.100 + // later 1.101 +//TODO: look at dynamic behavior -- time-average numToPrecede or something 1.102 + if( numFilled < NUM_CORES - 1 ) 1.103 + { 1.104 + masterEnv->numToPrecede = 0; 1.105 + } 1.106 + else 1.107 + { masterEnv->numToPrecede = numFilled - NUM_CORES + 1; 1.108 + } 1.109 +/* 1.110 //put some scheduled slaves in, then Master continuation, then rest 1.111 //Adjust position of master such that it maintains close to a fixed 1.112 // ratio --> make NUM_CORES - 1 slots or fewer come after the master 1.113 - numFilled = masterEnv->numFilled; 1.114 - 1.115 - int numPrecede = numFilled; 1.116 - int numFollow = NUM_CORES - 1; 1.117 - 1.118 - if( numFilled < numFollow ) 1.119 - { numFollow = numFilled; 1.120 - numPrecede = 0; 1.121 - } 1.122 - else 1.123 - { numPrecede -= numFollow; 1.124 - } 1.125 - 1.126 + 1.127 for( filledSlotIdx = 0; filledSlotIdx < numPrecede; filledSlotIdx++) 1.128 { 1.129 - writeCASQ( filledSlots[ filledSlotIdx ]->procrAssignedToSlot, workQ ); 1.130 + writeVMSQ( filledSlots[ filledSlotIdx ]->procrAssignedToSlot, workQ ); 1.131 } 1.132 1.133 //enqueue continuation of this loop 1.134 // note that After this enqueue, continuation might sneak through 1.135 - writeCASQ( masterEnv->masterVirtPr, workQ ); 1.136 + writeVMSQ( masterEnv->masterVirtPr, workQ ); 1.137 1.138 for( filledSlotIdx = numPrecede; 1.139 filledSlotIdx < numFilled; 1.140 filledSlotIdx++) 1.141 { 1.142 - writeCASQ( filledSlots[ filledSlotIdx ]->procrAssignedToSlot, workQ ); 1.143 + writeVMSQ( filledSlots[ filledSlotIdx ]->procrAssignedToSlot, workQ ); 1.144 } 1.145 1.146 masterEnv->numFilled = 0; 1.147 - 1.148 +*/ 1.149 1.150 //Save stack ptr and frame -- don't need to, take out later, but safe 1.151 // Also, wait to set stillRunning to FALSE until just before jump, to
