Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison VMS.c @ 28:8b9e4c333fe6
Sequential Version -- first compile succeeded
| author | Me |
|---|---|
| date | Mon, 26 Jul 2010 16:42:59 -0700 |
| parents | 668278fa7a63 |
| children | 0e008278fe3c |
comparison
equal
deleted
inserted
replaced
| 9:0cc3de1e9ce1 | 10:5b6503e02149 |
|---|---|
| 18 void | 18 void |
| 19 shutdownFn( void *dummy, VirtProcr *dummy2 ); | 19 shutdownFn( void *dummy, VirtProcr *dummy2 ); |
| 20 | 20 |
| 21 void | 21 void |
| 22 create_sched_slots( MasterEnv *masterEnv ); | 22 create_sched_slots( MasterEnv *masterEnv ); |
| 23 | |
| 24 void | |
| 25 create_masterEnv(); | |
| 26 | |
| 27 void | |
| 28 create_the_coreLoop_OS_threads(); | |
| 23 | 29 |
| 24 pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER; | 30 pthread_mutex_t suspendLock = PTHREAD_MUTEX_INITIALIZER; |
| 25 pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER; | 31 pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER; |
| 26 | 32 |
| 27 //=========================================================================== | 33 //=========================================================================== |
| 54 * and master environment, and returns the master environment to the semantic | 60 * and master environment, and returns the master environment to the semantic |
| 55 * layer. | 61 * layer. |
| 56 */ | 62 */ |
| 57 void | 63 void |
| 58 VMS__init() | 64 VMS__init() |
| 65 { | |
| 66 create_masterEnv(); | |
| 67 create_the_coreLoop_OS_threads(); | |
| 68 } | |
| 69 | |
| 70 /*To initialize the sequential version, just don't create the threads | |
| 71 */ | |
| 72 void | |
| 73 VMS__init_Seq() | |
| 74 { | |
| 75 create_masterEnv(); | |
| 76 } | |
| 77 | |
| 78 void | |
| 79 create_masterEnv() | |
| 59 { MasterEnv *masterEnv; | 80 { MasterEnv *masterEnv; |
| 60 VMSQueueStruc *workQ; | 81 VMSQueueStruc *workQ; |
| 61 | 82 |
| 62 //Make the central work-queue | 83 //Make the central work-queue |
| 63 _VMSWorkQ = makeVMSQ(); | 84 _VMSWorkQ = makeVMSQ(); |
| 71 | 92 |
| 72 create_sched_slots( masterEnv ); | 93 create_sched_slots( masterEnv ); |
| 73 | 94 |
| 74 masterEnv->stillRunning = FALSE; | 95 masterEnv->stillRunning = FALSE; |
| 75 masterEnv->numToPrecede = NUM_CORES; | 96 masterEnv->numToPrecede = NUM_CORES; |
| 76 | 97 |
| 77 //First core loop to start up gets this, which will schedule seed Pr | 98 //First core loop to start up gets this, which will schedule seed Pr |
| 78 //TODO: debug: check address of masterVirtPr | 99 //TODO: debug: check address of masterVirtPr |
| 79 writeVMSQ( masterEnv->masterVirtPr, workQ ); | 100 writeVMSQ( masterEnv->masterVirtPr, workQ ); |
| 80 | 101 |
| 81 numProcrsCreated = 1; | 102 numProcrsCreated = 1; //global counter for debugging |
| 82 | 103 } |
| 104 | |
| 105 void | |
| 106 create_sched_slots( MasterEnv *masterEnv ) | |
| 107 { SchedSlot **schedSlots, **filledSlots; | |
| 108 int i; | |
| 109 | |
| 110 schedSlots = malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) ); | |
| 111 filledSlots = malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) ); | |
| 112 masterEnv->schedSlots = schedSlots; | |
| 113 masterEnv->filledSlots = filledSlots; | |
| 114 | |
| 115 for( i = 0; i < NUM_SCHED_SLOTS; i++ ) | |
| 116 { | |
| 117 schedSlots[i] = malloc( sizeof(SchedSlot) ); | |
| 118 | |
| 119 //Set state to mean "handling requests done, slot needs filling" | |
| 120 schedSlots[i]->workIsDone = FALSE; | |
| 121 schedSlots[i]->needsProcrAssigned = TRUE; | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 | |
| 126 void | |
| 127 create_the_coreLoop_OS_threads() | |
| 128 { | |
| 83 //======================================================================== | 129 //======================================================================== |
| 84 // Create the Threads | 130 // Create the Threads |
| 85 int coreIdx, retCode; | 131 int coreIdx, retCode; |
| 86 | 132 |
| 87 //Need the threads to be created suspended, and wait for a signal | 133 //Need the threads to be created suspended, and wait for a signal |
| 88 // before proceeding -- gives time after creating to initialize other | 134 // before proceeding -- gives time after creating to initialize other |
| 89 // stuff before the coreLoops set off. | 135 // stuff before the coreLoops set off. |
| 90 _VMSMasterEnv->setupComplete = 0; | 136 _VMSMasterEnv->setupComplete = 0; |
| 91 | 137 |
| 93 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 139 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 94 { coreLoopThdParams[coreIdx] = malloc( sizeof(ThdParams) ); | 140 { coreLoopThdParams[coreIdx] = malloc( sizeof(ThdParams) ); |
| 95 coreLoopThdParams[coreIdx]->coreNum = coreIdx; | 141 coreLoopThdParams[coreIdx]->coreNum = coreIdx; |
| 96 | 142 |
| 97 retCode = | 143 retCode = |
| 98 pthread_create( &(coreLoopThdHandles[coreIdx]), | 144 pthread_create( &(coreLoopThdHandles[coreIdx]), |
| 99 thdAttrs, | 145 thdAttrs, |
| 100 &coreLoop, | 146 &coreLoop, |
| 101 (void *)(coreLoopThdParams[coreIdx]) ); | 147 (void *)(coreLoopThdParams[coreIdx]) ); |
| 102 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(0);} | 148 if(retCode){printf("ERROR creating thread: %d\n", retCode); exit(0);} |
| 103 } | 149 } |
| 104 } | 150 } |
| 105 | |
| 106 void | |
| 107 create_sched_slots( MasterEnv *masterEnv ) | |
| 108 { SchedSlot **schedSlots, **filledSlots; | |
| 109 int i; | |
| 110 | |
| 111 schedSlots = malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) ); | |
| 112 filledSlots = malloc( NUM_SCHED_SLOTS * sizeof(SchedSlot *) ); | |
| 113 masterEnv->schedSlots = schedSlots; | |
| 114 masterEnv->filledSlots = filledSlots; | |
| 115 | |
| 116 for( i = 0; i < NUM_SCHED_SLOTS; i++ ) | |
| 117 { | |
| 118 schedSlots[i] = malloc( sizeof(SchedSlot) ); | |
| 119 | |
| 120 //Set state to mean "handling requests done, slot needs filling" | |
| 121 schedSlots[i]->workIsDone = FALSE; | |
| 122 schedSlots[i]->needsProcrAssigned = TRUE; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 | 151 |
| 127 /*Semantic layer calls this when it want the system to start running.. | 152 /*Semantic layer calls this when it want the system to start running.. |
| 128 * | 153 * |
| 129 *This starts the core loops running then waits for them to exit. | 154 *This starts the core loops running then waits for them to exit. |
| 130 */ | 155 */ |
| 164 count = endCount - startCount; | 189 count = endCount - startCount; |
| 165 | 190 |
| 166 runTime = (double)count / (double)TSCOUNT_FREQ; | 191 runTime = (double)count / (double)TSCOUNT_FREQ; |
| 167 | 192 |
| 168 printf("\n Time startup to shutdown: %f\n", runTime); fflush( stdin ); | 193 printf("\n Time startup to shutdown: %f\n", runTime); fflush( stdin ); |
| 194 } | |
| 195 | |
| 196 /*Only difference between version with an OS thread pinned to each core and | |
| 197 * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq. | |
| 198 */ | |
| 199 void | |
| 200 VMS__start_the_work_then_wait_until_done_Seq() | |
| 201 { | |
| 202 //Instead of un-suspending threads, just call the one and only | |
| 203 // core loop (sequential version), in the main thread. | |
| 204 coreLoop_Seq( NULL ); | |
| 205 | |
| 169 } | 206 } |
| 170 | 207 |
| 171 | 208 |
| 172 | 209 |
| 173 /*Create stack, then create __cdecl structure on it and put initialData and | 210 /*Create stack, then create __cdecl structure on it and put initialData and |
