Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison VMS.c @ 12:d801fe740275
Middle of testing core loop
| author | Me |
|---|---|
| date | Sat, 19 Jun 2010 19:26:38 -0700 |
| parents | 9a1b7de19e39 |
| children | 65c8fb2821ee |
comparison
equal
deleted
inserted
replaced
| 2:e330519cdcd3 | 3:8f2dd6dd4ccf |
|---|---|
| 45 * layer. | 45 * layer. |
| 46 */ | 46 */ |
| 47 void | 47 void |
| 48 VMS__init() | 48 VMS__init() |
| 49 { MasterEnv *masterEnv; | 49 { MasterEnv *masterEnv; |
| 50 QueueStruc *workQ; | 50 CASQueueStruc *workQ; |
| 51 | 51 |
| 52 //Make the central work-queue | 52 //Make the central work-queue |
| 53 _VMSWorkQ = makeQ(); | 53 _VMSWorkQ = makeCASQ(); |
| 54 workQ = _VMSWorkQ; | 54 workQ = _VMSWorkQ; |
| 55 | 55 |
| 56 _VMSMasterEnv = malloc( sizeof(MasterEnv) ); | 56 _VMSMasterEnv = malloc( sizeof(MasterEnv) ); |
| 57 masterEnv = _VMSMasterEnv; | 57 masterEnv = _VMSMasterEnv; |
| 58 | 58 |
| 66 masterEnv->schedSlots[0]->workIsDone = FALSE; //says don't touch | 66 masterEnv->schedSlots[0]->workIsDone = FALSE; //says don't touch |
| 67 masterEnv->schedSlots[0]->procrAssignedToSlot = masterEnv->masterVirtPr; | 67 masterEnv->schedSlots[0]->procrAssignedToSlot = masterEnv->masterVirtPr; |
| 68 | 68 |
| 69 //First core loop to start up gets this, which will schedule seed Pr | 69 //First core loop to start up gets this, which will schedule seed Pr |
| 70 //TODO: debug: check address of masterVirtPr | 70 //TODO: debug: check address of masterVirtPr |
| 71 writeQ( masterEnv->masterVirtPr, workQ ); | 71 //TODO: commented out for debugging -- put it back in!! |
| 72 // writeCASQ( masterEnv->masterVirtPr, workQ ); | |
| 73 | |
| 74 numProcrsCreated = 1; | |
| 72 } | 75 } |
| 73 | 76 |
| 74 | 77 |
| 75 void | 78 void |
| 76 create_sched_slots( MasterEnv *masterEnv ) | 79 create_sched_slots( MasterEnv *masterEnv ) |
| 96 /*Semantic layer calls this when it want the system to start running.. | 99 /*Semantic layer calls this when it want the system to start running.. |
| 97 * | 100 * |
| 98 *This creates the core loops, pins them to physical cores, gives them the | 101 *This creates the core loops, pins them to physical cores, gives them the |
| 99 * pointer to the workQ, and starts them running. | 102 * pointer to the workQ, and starts them running. |
| 100 */ | 103 */ |
| 101 void | 104 void |
| 102 VMS__start() | 105 VMS__start() |
| 103 { int retCode, coreIdx; | 106 { int coreIdx; |
| 104 | 107 |
| 105 //Create the win threads that animate the core loops | 108 //Create the win threads that animate the core loops |
| 106 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 109 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 107 { | 110 { |
| 108 thdParams[coreIdx] = (ThdParams *)malloc( sizeof(ThdParams) ); | 111 coreLoopThdParams[coreIdx] = (ThdParams *)malloc( sizeof(ThdParams) ); |
| 109 thdParams[coreIdx]->coreNum = coreIdx; | 112 coreLoopThdParams[coreIdx]->coreNum = coreIdx; |
| 110 | 113 |
| 111 coreLoopThds[coreIdx] = | 114 coreLoopThdHandles[coreIdx] = |
| 112 CreateThread ( NULL, // Security attributes | 115 CreateThread ( NULL, // Security attributes |
| 113 0, // Stack size | 116 0, // Stack size |
| 114 coreLoop, | 117 coreLoop, |
| 115 thdParams[coreIdx], | 118 coreLoopThdParams[coreIdx], |
| 116 CREATE_SUSPENDED, | 119 CREATE_SUSPENDED, |
| 117 &(thdIds[coreIdx]) | 120 &(coreLoopThdIds[coreIdx]) |
| 118 ); | 121 ); |
| 119 ResumeThread( coreLoopThds[coreIdx] ); //starts thread | 122 ResumeThread( coreLoopThdHandles[coreIdx] ); //starts thread |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 | 125 |
| 123 | 126 |
| 124 | 127 |
| 136 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ) | 139 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ) |
| 137 { VirtProcr *newPr; | 140 { VirtProcr *newPr; |
| 138 char *stackLocs, *stackPtr; | 141 char *stackLocs, *stackPtr; |
| 139 | 142 |
| 140 newPr = malloc( sizeof(VirtProcr) ); | 143 newPr = malloc( sizeof(VirtProcr) ); |
| 144 newPr->procrID = numProcrsCreated++; | |
| 141 newPr->nextInstrPt = fnPtr; | 145 newPr->nextInstrPt = fnPtr; |
| 142 newPr->initialData = initialData; | 146 newPr->initialData = initialData; |
| 143 | 147 |
| 144 //alloc stack locations, make stackPtr be the highest addr minus room | 148 //alloc stack locations, make stackPtr be the highest addr minus room |
| 145 // for 2 params. Put initData at stackPtr, animatingPr just above | 149 // for 2 params. Put initData at stackPtr, animatingPr just above |
| 146 stackLocs = malloc( 0x100000 ); //1 meg stack -- default Win thread's size | 150 stackLocs = malloc( 0x100000 ); //1 meg stack -- default Win thread's size |
| 147 stackPtr = ( (char *)stackLocs + 0x100000 - 0x8 ); | 151 stackPtr = ( (char *)stackLocs + 0x100000 - 0x8 ); |
| 148 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp | 152 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp |
| 149 *(stackPtr + 4) = newPr; //rightmost param | 153 *( (int *)stackPtr + 1) = (int) newPr; //rightmost param -- 32bit pointer |
| 150 *stackPtr = initialData; //next param to left | 154 *( (int *)stackPtr ) = (int) initialData; //next param to left |
| 151 newPr->stackPtr = stackPtr; //core loop will switch to this, then | 155 newPr->stackPtr = stackPtr; //core loop will switch to this, then |
| 152 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr | 156 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr |
| 153 | 157 |
| 154 return newPr; | 158 return newPr; |
| 155 } | 159 } |
| 196 movl %%ebp, %1; \ | 200 movl %%ebp, %1; \ |
| 197 jmp %2 " | 201 jmp %2 " |
| 198 /* outputs */ : "=g" (stackPtr), "=g" (framePtr) | 202 /* outputs */ : "=g" (stackPtr), "=g" (framePtr) |
| 199 /* inputs */ : "g" (jmpPt) | 203 /* inputs */ : "g" (jmpPt) |
| 200 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" | 204 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" |
| 201 ); | 205 ); //list everything as clobbered to force GCC to save all |
| 206 // live vars that are in regs on stack before this | |
| 207 // assembly, so that stack pointer is correct, before jmp | |
| 202 | 208 |
| 203 ResumePt: | 209 ResumePt: |
| 204 return; | 210 return; |
| 205 } | 211 } |
| 206 | 212 |
| 228 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 234 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 229 { | 235 { |
| 230 | 236 |
| 231 } | 237 } |
| 232 } | 238 } |
| 239 | |
| 240 | |
| 241 | |
| 242 inline TSCount getTSCount() | |
| 243 { unsigned int low, high; | |
| 244 TSCount out; | |
| 245 | |
| 246 saveTimeStampCountInto( low, high ); | |
| 247 out = high; | |
| 248 out = (out << 32) + low; | |
| 249 return out; | |
| 250 } | |
| 251 |
