Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison VMS.h @ 50:8f7141a9272e
Added VMS__malloc and probes, and major re-factoring to separate mallocs
| author | Me |
|---|---|
| date | Sat, 30 Oct 2010 20:54:36 -0700 |
| parents | 5388f1c2da6f |
| children | f59cfa31a579 |
comparison
equal
deleted
inserted
replaced
| 16:e6c9287eeb6c | 19:f965ee07e901 |
|---|---|
| 11 #define __USE_GNU | 11 #define __USE_GNU |
| 12 | 12 |
| 13 #include "VMS_primitive_data_types.h" | 13 #include "VMS_primitive_data_types.h" |
| 14 #include "Queue_impl/BlockingQueue.h" | 14 #include "Queue_impl/BlockingQueue.h" |
| 15 #include "Histogram/Histogram.h" | 15 #include "Histogram/Histogram.h" |
| 16 #include "DynArray/DynArray.h" | |
| 17 #include "Hash_impl/PrivateHash.h" | |
| 18 #include "vmalloc.h" | |
| 19 | |
| 16 #include <pthread.h> | 20 #include <pthread.h> |
| 17 | 21 #include <sys/time.h> |
| 22 | |
| 23 | |
| 24 //=============================== Debug =================================== | |
| 18 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread | 25 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread |
| 19 // It still does co-routines and all the mechanisms are the same, it just | 26 // It still does co-routines and all the mechanisms are the same, it just |
| 20 // has only a single thread and animates VPs one at a time | 27 // has only a single thread and animates VPs one at a time |
| 21 //#define SEQUENTIAL | 28 //#define SEQUENTIAL |
| 22 | 29 |
| 23 #define PRINT_DEBUG(msg) //printf(msg); fflush(stdin); | 30 #define PRINT_DEBUG(msg)// printf(msg); fflush(stdin); |
| 24 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin); | 31 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin); |
| 25 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin); | 32 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin); |
| 33 | |
| 34 #define PRINT_ERROR(msg) printf(msg); fflush(stdin); | |
| 35 #define PRINT1_ERROR(msg, param) printf(msg, param); fflush(stdin); | |
| 36 #define PRINT2_ERROR(msg, p1, p2) printf(msg, p1, p2); fflush(stdin); | |
| 37 | |
| 38 | |
| 39 //=========================== STATS ======================= | |
| 26 | 40 |
| 27 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and | 41 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and |
| 28 // compiled-in that saves the low part of the time stamp count just before | 42 // compiled-in that saves the low part of the time stamp count just before |
| 29 // suspending a processor and just after resuming that processor. It is | 43 // suspending a processor and just after resuming that processor. It is |
| 30 // saved into a field added to VirtProcr. Have to sanity-check for | 44 // saved into a field added to VirtProcr. Have to sanity-check for |
| 33 #define MEAS__TIME_MASTER | 47 #define MEAS__TIME_MASTER |
| 34 #define MEAS__NUM_TIMES_TO_RUN 100000 | 48 #define MEAS__NUM_TIMES_TO_RUN 100000 |
| 35 | 49 |
| 36 #define NUM_TSC_ROUND_TRIPS 10 | 50 #define NUM_TSC_ROUND_TRIPS 10 |
| 37 | 51 |
| 52 | |
| 53 //========================= Hardware related Constants ===================== | |
| 38 //This value is the number of hardware threads in the shared memory | 54 //This value is the number of hardware threads in the shared memory |
| 39 // machine | 55 // machine |
| 40 #define NUM_CORES 4 | 56 #define NUM_CORES 4 |
| 41 | 57 |
| 42 // balance amortizing master fixed overhead vs imbalance potential | 58 // balance amortizing master fixed overhead vs imbalance potential |
| 45 #define MIN_WORK_UNIT_CYCLES 20000 | 61 #define MIN_WORK_UNIT_CYCLES 20000 |
| 46 | 62 |
| 47 #define READYTOANIMATE_RETRIES 10000 | 63 #define READYTOANIMATE_RETRIES 10000 |
| 48 | 64 |
| 49 // stack | 65 // stack |
| 50 #define VIRT_PROCR_STACK_SIZE 0x10000 | 66 #define VIRT_PROCR_STACK_SIZE 0x4000 |
| 51 | 67 |
| 52 //256M of total memory for VMS__malloc | 68 // memory for VMS__malloc -- 256M |
| 53 #define MASSIVE_MALLOC_SIZE 0x10000000 | 69 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 |
| 54 | 70 |
| 55 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); | 71 |
| 72 //============================== | |
| 56 | 73 |
| 57 #define SUCCESS 0 | 74 #define SUCCESS 0 |
| 58 | 75 |
| 59 #define writeVMSQ writeCASQ | 76 #define writeVMSQ writeSRSWQ |
| 60 #define readVMSQ readCASQ | 77 #define readVMSQ readSRSWQ |
| 61 #define makeVMSQ makeCASQ | 78 #define makeVMSQ makeSRSWQ |
| 62 #define VMSQueueStruc CASQueueStruc | 79 #define VMSQueueStruc SRSWQueueStruc |
| 63 | 80 |
| 64 //#define thdAttrs NULL //For PThreads | 81 |
| 65 | 82 |
| 66 typedef struct _SchedSlot SchedSlot; | 83 //=========================================================================== |
| 67 typedef struct _VMSReqst VMSReqst; | 84 typedef unsigned long long TSCount; |
| 68 typedef struct _VirtProcr VirtProcr; | 85 |
| 86 typedef struct _SchedSlot SchedSlot; | |
| 87 typedef struct _VMSReqst VMSReqst; | |
| 88 typedef struct _VirtProcr VirtProcr; | |
| 89 typedef struct _IntervalProbe IntervalProbe; | |
| 69 | 90 |
| 70 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx | 91 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx |
| 71 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv | 92 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv |
| 72 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr | 93 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr |
| 73 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr | 94 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr |
| 95 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * ); | |
| 96 | |
| 97 | |
| 98 //============= Requests =========== | |
| 99 // | |
| 100 | |
| 101 enum VMSReqstType //avoid starting enums at 0, for debug reasons | |
| 102 { | |
| 103 semantic = 1, | |
| 104 createReq, | |
| 105 dissipate, | |
| 106 VMSSemantic //goes with VMSSemReqst below | |
| 107 }; | |
| 108 | |
| 109 struct _VMSReqst | |
| 110 { | |
| 111 enum VMSReqstType reqType;//used for dissipate and in future for IO requests | |
| 112 void *semReqData; | |
| 113 | |
| 114 VMSReqst *nextReqst; | |
| 115 }; | |
| 116 //VMSReqst | |
| 117 | |
| 118 enum VMSSemReqstType //These are equivalent to semantic requests, but for | |
| 119 { // VMS's services available directly to app, like OS | |
| 120 createProbe = 1, // and probe services -- like a VMS-wide built-in lang | |
| 121 openFile, | |
| 122 otherIO | |
| 123 }; | |
| 74 | 124 |
| 75 typedef struct | 125 typedef struct |
| 76 { | 126 { enum VMSSemReqstType reqType; |
| 77 void *endThdPt; | 127 VirtProcr *requestingPr; |
| 78 unsigned int coreNum; | 128 char *nameStr; //for create probe |
| 79 } | 129 } |
| 80 ThdParams; | 130 VMSSemReq; |
| 81 | 131 |
| 132 | |
| 133 //==================== Core data structures =================== | |
| 82 | 134 |
| 83 struct _SchedSlot | 135 struct _SchedSlot |
| 84 { | 136 { |
| 85 int workIsDone; | 137 int workIsDone; |
| 86 int needsProcrAssigned; | 138 int needsProcrAssigned; |
| 87 VirtProcr *procrAssignedToSlot; | 139 VirtProcr *procrAssignedToSlot; |
| 88 }; | 140 }; |
| 89 //SchedSlot | 141 //SchedSlot |
| 90 | |
| 91 enum ReqstType | |
| 92 { | |
| 93 semantic = 1, | |
| 94 dissipate, | |
| 95 regCreated, | |
| 96 IO | |
| 97 }; | |
| 98 | |
| 99 struct _VMSReqst | |
| 100 { | |
| 101 // VirtProcr *virtProcrFrom; | |
| 102 enum ReqstType reqType;//used for dissipate and in future for IO requests | |
| 103 void *semReqData; | |
| 104 | |
| 105 VMSReqst *nextReqst; | |
| 106 }; | |
| 107 //VMSReqst | |
| 108 | 142 |
| 109 struct _VirtProcr | 143 struct _VirtProcr |
| 110 { int procrID; //for debugging -- count up each time create | 144 { int procrID; //for debugging -- count up each time create |
| 111 int coreAnimatedBy; | 145 int coreAnimatedBy; |
| 112 void *startOfStack; | 146 void *startOfStack; |
| 121 void *initialData; | 155 void *initialData; |
| 122 | 156 |
| 123 SchedSlot *schedSlot; | 157 SchedSlot *schedSlot; |
| 124 VMSReqst *requests; | 158 VMSReqst *requests; |
| 125 | 159 |
| 126 void *semanticData; | 160 void *semanticData; //this lives here for the life of VP |
| 127 | 161 void *dataReturnedFromReq;//values returned from plugin to VP go here |
| 128 //============================= MEASUREMENT STUFF ======================== | 162 |
| 163 //=========== MEASUREMENT STUFF ========== | |
| 129 #ifdef MEAS__TIME_STAMP_SUSP | 164 #ifdef MEAS__TIME_STAMP_SUSP |
| 130 unsigned int preSuspTSCLow; | 165 unsigned int preSuspTSCLow; |
| 131 unsigned int postSuspTSCLow; | 166 unsigned int postSuspTSCLow; |
| 132 #endif | 167 #endif |
| 133 #ifdef MEAS__TIME_MASTER | 168 #ifdef MEAS__TIME_MASTER |
| 134 unsigned int startMasterTSCLow; | 169 unsigned int startMasterTSCLow; |
| 135 unsigned int endMasterTSCLow; | 170 unsigned int endMasterTSCLow; |
| 136 #endif | 171 #endif |
| 137 //======================================================================== | 172 |
| 173 float64 createPtInSecs; //have space but don't use on some configs | |
| 138 }; | 174 }; |
| 139 //VirtProcr | 175 //VirtProcr |
| 140 | |
| 141 | 176 |
| 142 | 177 |
| 143 typedef struct | 178 typedef struct |
| 144 { | 179 { |
| 145 SlaveScheduler slaveScheduler; | 180 SlaveScheduler slaveScheduler; |
| 149 SRSWQueueStruc **readyToAnimateQs; | 184 SRSWQueueStruc **readyToAnimateQs; |
| 150 VirtProcr **masterVPs; | 185 VirtProcr **masterVPs; |
| 151 | 186 |
| 152 void *semanticEnv; | 187 void *semanticEnv; |
| 153 void *OSEventStruc; //for future, when add I/O to BLIS | 188 void *OSEventStruc; //for future, when add I/O to BLIS |
| 189 MallocProlog *freeListHead; | |
| 190 int32 amtOfOutstandingMem; //total currently allocated | |
| 154 | 191 |
| 155 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop | 192 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop |
| 156 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop | 193 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop |
| 157 | 194 |
| 158 int setupComplete; | 195 int32 setupComplete; |
| 159 int masterLock; | 196 int32 masterLock; |
| 160 | 197 |
| 198 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP | |
| 199 int32 numProcrsCreated; //gives ordering to processor creation | |
| 200 | |
| 201 //=========== MEASUREMENT STUFF ============= | |
| 202 IntervalProbe **intervalProbes; | |
| 203 DynArrayInfo *dynIntervalProbesInfo; | |
| 204 HashTable *probeNameHashTbl; | |
| 205 int32 masterCreateProbeID; | |
| 206 float64 createPtInSecs; | |
| 161 } | 207 } |
| 162 MasterEnv; | 208 MasterEnv; |
| 163 | 209 |
| 164 | 210 |
| 165 //========================================================== | 211 |
| 212 | |
| 213 //======================= OS Thread related =============================== | |
| 166 | 214 |
| 167 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype | 215 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype |
| 168 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype | 216 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype |
| 169 void masterLoop( void *initData, VirtProcr *masterPr ); | 217 void masterLoop( void *initData, VirtProcr *masterPr ); |
| 170 | 218 |
| 171 | 219 |
| 172 //===================== Global Vars =================== | 220 typedef struct |
| 173 | 221 { |
| 222 void *endThdPt; | |
| 223 unsigned int coreNum; | |
| 224 } | |
| 225 ThdParams; | |
| 174 | 226 |
| 175 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state | 227 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state |
| 176 ThdParams *coreLoopThdParams [ NUM_CORES ]; | 228 ThdParams *coreLoopThdParams [ NUM_CORES ]; |
| 177 pthread_mutex_t suspendLock; | 229 pthread_mutex_t suspendLock; |
| 178 pthread_cond_t suspend_cond; | 230 pthread_cond_t suspend_cond; |
| 179 | 231 |
| 232 | |
| 233 | |
| 234 //===================== Global Vars =================== | |
| 235 | |
| 180 volatile MasterEnv *_VMSMasterEnv; | 236 volatile MasterEnv *_VMSMasterEnv; |
| 181 | 237 |
| 182 //========================== | 238 |
| 239 | |
| 240 | |
| 241 //=========================== Function Prototypes ========================= | |
| 242 | |
| 243 //============== Setup and shutdown ============= | |
| 183 void | 244 void |
| 184 VMS__init(); | 245 VMS__init(); |
| 185 | 246 |
| 186 void | 247 void |
| 187 VMS__init_Seq(); | 248 VMS__init_Seq(); |
| 193 VMS__start_the_work_then_wait_until_done_Seq(); | 254 VMS__start_the_work_then_wait_until_done_Seq(); |
| 194 | 255 |
| 195 VirtProcr * | 256 VirtProcr * |
| 196 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); | 257 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); |
| 197 | 258 |
| 259 //Use this to create processor inside entry point & other places outside | |
| 260 // the VMS system boundary (IE, not run in slave nor Master) | |
| 261 VirtProcr * | |
| 262 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); | |
| 263 | |
| 198 VirtProcr * | 264 VirtProcr * |
| 199 VMS__create_the_shutdown_procr(); | 265 VMS__create_the_shutdown_procr(); |
| 200 | 266 |
| 201 //========================== | 267 void |
| 268 VMS__cleanup_after_shutdown(); | |
| 269 | |
| 270 | |
| 271 //============== Request Related =============== | |
| 272 | |
| 273 void | |
| 274 VMS__suspend_procr( VirtProcr *callingPr ); | |
| 275 | |
| 202 inline void | 276 inline void |
| 203 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); | 277 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); |
| 204 | 278 |
| 205 void | 279 void |
| 206 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister, | 280 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr ); |
| 207 VirtProcr *reqstingPr ); | |
| 208 | 281 |
| 209 void | 282 void |
| 210 VMS__free_request( VMSReqst *req ); | 283 VMS__free_request( VMSReqst *req ); |
| 211 | 284 |
| 212 void | 285 void |
| 214 | 287 |
| 215 VMSReqst * | 288 VMSReqst * |
| 216 VMS__take_top_request_from( VirtProcr *reqstingPr ); | 289 VMS__take_top_request_from( VirtProcr *reqstingPr ); |
| 217 | 290 |
| 218 VMSReqst * | 291 VMSReqst * |
| 219 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq ); | 292 VMS__take_next_request_out_of( VirtProcr *procrWithReq ); |
| 220 | 293 |
| 221 inline void * | 294 inline void * |
| 222 VMS__take_sem_reqst_from( VMSReqst *req ); | 295 VMS__take_sem_reqst_from( VMSReqst *req ); |
| 223 | 296 |
| 224 inline int | 297 inline int |
| 230 inline int | 303 inline int |
| 231 VMS__isCreateReqst( VMSReqst *req ); | 304 VMS__isCreateReqst( VMSReqst *req ); |
| 232 | 305 |
| 233 //========================== | 306 //========================== |
| 234 | 307 |
| 235 void | 308 void inline |
| 236 VMS__suspend_procr( VirtProcr *callingPr ); | |
| 237 | |
| 238 void | |
| 239 VMS__dissipate_procr( VirtProcr *prToDissipate ); | 309 VMS__dissipate_procr( VirtProcr *prToDissipate ); |
| 240 | 310 |
| 241 void | 311 void |
| 242 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate ); | 312 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate ); |
| 243 | 313 |
| 244 void | 314 |
| 245 VMS__cleanup_after_shutdown(); | 315 |
| 246 | 316 //===================== RDTSC wrapper ================== |
| 247 //============================= Statistics ================================== | |
| 248 | |
| 249 typedef unsigned long long TSCount; | |
| 250 | |
| 251 //Frequency of TS counts | |
| 252 //TODO: change freq for each machine | |
| 253 #define TSCOUNT_FREQ 3180000000 | |
| 254 | 317 |
| 255 #define saveTimeStampCountInto(low, high) \ | 318 #define saveTimeStampCountInto(low, high) \ |
| 256 asm volatile("RDTSC; \ | 319 asm volatile("RDTSC; \ |
| 257 movl %%eax, %0; \ | 320 movl %%eax, %0; \ |
| 258 movl %%edx, %1;" \ | 321 movl %%edx, %1;" \ |
| 267 /* outputs */ : "=m" (low) \ | 330 /* outputs */ : "=m" (low) \ |
| 268 /* inputs */ : \ | 331 /* inputs */ : \ |
| 269 /* clobber */ : "%eax", "%edx" \ | 332 /* clobber */ : "%eax", "%edx" \ |
| 270 ); | 333 ); |
| 271 | 334 |
| 272 inline TSCount getTSCount(); | 335 //======================== STATS ====================== |
| 273 | 336 |
| 274 //===================== Debug ========================== | 337 #include "probes.h" |
| 275 int numProcrsCreated; | |
| 276 | |
| 277 | 338 |
| 278 #endif /* _VMS_H */ | 339 #endif /* _VMS_H */ |
| 279 | 340 |
