Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
diff VMS.h @ 42:6c9f314daf24
testing
| author | Me |
|---|---|
| date | Sat, 11 Sep 2010 04:47:17 -0700 |
| parents | cf3e9238aeb0 |
| children | 5388f1c2da6f |
line diff
1.1 --- a/VMS.h Sat Sep 11 04:40:12 2010 -0700 1.2 +++ b/VMS.h Sat Sep 11 04:47:17 2010 -0700 1.3 @@ -1,272 +1,272 @@ 1.4 -/* 1.5 - * Copyright 2009 OpenSourceStewardshipFoundation.org 1.6 - * Licensed under GNU General Public License version 2 1.7 - * 1.8 - * Author: seanhalle@yahoo.com 1.9 - * 1.10 - */ 1.11 - 1.12 -#ifndef _VMS_H 1.13 -#define _VMS_H 1.14 -#define __USE_GNU 1.15 - 1.16 -#include "VMS_primitive_data_types.h" 1.17 -#include "Queue_impl/BlockingQueue.h" 1.18 -#include "Histogram/Histogram.h" 1.19 -#include <pthread.h> 1.20 - 1.21 - //When DEBUG is defined, VMS does sequential exe in the main thread 1.22 - // It still does co-routines and all the mechanisms are the same, it just 1.23 - // has only a single thread and animates VPs one at a time 1.24 -#define SEQUENTIAL 1.25 - 1.26 - //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and 1.27 - // compiled-in that saves the low part of the time stamp count just before 1.28 - // suspending a processor and just after resuming that processor. It is 1.29 - // saved into a field added to VirtProcr. Have to sanity-check for 1.30 - // rollover of low portion into high portion. 1.31 -#define MEAS__TIME_STAMP_SUSP 1.32 -#define MEAS__TIME_MASTER 1.33 -#define MEAS__NUM_TIMES_TO_RUN 100000 1.34 - 1.35 - //This value is the number of hardware threads in the shared memory 1.36 - // machine 1.37 -#define NUM_CORES 4 1.38 - 1.39 - // make double-num-cores scheduling slots, plus extra for master 1.40 -//#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1) 1.41 -#define NUM_SCHED_SLOTS 3 1.42 - 1.43 -#define READYTOANIMATE_RETRIES 10000 1.44 - 1.45 - // stack 1.46 -#define VIRT_PROCR_STACK_SIZE 0x10000 1.47 - 1.48 - //256M of total memory for VMS__malloc 1.49 -#define MASSIVE_MALLOC_SIZE 0x10000000 1.50 - 1.51 -#define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); 1.52 - 1.53 -#define SUCCESS 0 1.54 - 1.55 -#define writeVMSQ writeCASQ 1.56 -#define readVMSQ readCASQ 1.57 -#define makeVMSQ makeCASQ 1.58 -#define VMSQueueStruc CASQueueStruc 1.59 - 1.60 -//#define thdAttrs NULL //For PThreads 1.61 - 1.62 -typedef struct _SchedSlot SchedSlot; 1.63 -typedef struct _VMSReqst VMSReqst; 1.64 -typedef struct _VirtProcr VirtProcr; 1.65 - 1.66 -typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx 1.67 -typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv 1.68 -typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr 1.69 -typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr 1.70 - 1.71 -typedef struct 1.72 - { 1.73 - void *endThdPt; 1.74 - unsigned int coreNum; 1.75 - } 1.76 -ThdParams; 1.77 - 1.78 - 1.79 -struct _SchedSlot 1.80 - { 1.81 - int workIsDone; 1.82 - int needsProcrAssigned; 1.83 - VirtProcr *procrAssignedToSlot; 1.84 - }; 1.85 -//SchedSlot 1.86 - 1.87 -enum ReqstType 1.88 - { 1.89 - semantic = 1, 1.90 - dissipate, 1.91 - regCreated, 1.92 - IO 1.93 - }; 1.94 - 1.95 -struct _VMSReqst 1.96 - { 1.97 -// VirtProcr *virtProcrFrom; 1.98 - enum ReqstType reqType;//used for dissipate and in future for IO requests 1.99 - void *semReqData; 1.100 - 1.101 - VMSReqst *nextReqst; 1.102 - }; 1.103 -//VMSReqst 1.104 - 1.105 -struct _VirtProcr 1.106 - { int procrID; //for debugging -- count up each time create 1.107 - int coreAnimatedBy; 1.108 - void *startOfStack; 1.109 - void *stackPtr; 1.110 - void *framePtr; 1.111 - void *nextInstrPt; 1.112 - 1.113 - void *coreLoopStartPt; //allows proto-runtime to be linked later 1.114 - void *coreLoopFramePtr; //restore before jmp back to core loop 1.115 - void *coreLoopStackPtr; //restore before jmp back to core loop 1.116 - 1.117 - void *initialData; 1.118 - 1.119 - SchedSlot *schedSlot; 1.120 - VMSReqst *requests; 1.121 - 1.122 - void *semanticData; 1.123 - 1.124 - //============================= MEASUREMENT STUFF ======================== 1.125 - #ifdef MEAS__TIME_STAMP_SUSP 1.126 - unsigned int preSuspTSCLow; 1.127 - unsigned int postSuspTSCLow; 1.128 - #endif 1.129 - #ifdef MEAS__TIME_MASTER 1.130 - unsigned int startMasterTSCLow; 1.131 - unsigned int endMasterTSCLow; 1.132 - #endif 1.133 - //======================================================================== 1.134 - }; 1.135 -//VirtProcr 1.136 - 1.137 - 1.138 - 1.139 -typedef struct 1.140 - { 1.141 - SlaveScheduler slaveScheduler; 1.142 - RequestHandler requestHandler; 1.143 - 1.144 - SchedSlot ***allSchedSlots; 1.145 - SRSWQueueStruc **readyToAnimateQs; 1.146 - VirtProcr **masterVPs; 1.147 - 1.148 - void *semanticEnv; 1.149 - void *OSEventStruc; //for future, when add I/O to BLIS 1.150 - 1.151 - void *coreLoopStartPt;//addr to jump to to re-enter coreLoop 1.152 - void *coreLoopEndPt; //addr to jump to to shut down a coreLoop 1.153 - 1.154 - int setupComplete; 1.155 - int masterLock; 1.156 - 1.157 - } 1.158 -MasterEnv; 1.159 - 1.160 - 1.161 -//========================================================== 1.162 - 1.163 -void * coreLoop( void *paramsIn ); //standard PThreads fn prototype 1.164 -void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype 1.165 -void masterLoop( void *initData, VirtProcr *masterPr ); 1.166 - 1.167 - 1.168 -//===================== Global Vars =================== 1.169 - 1.170 - 1.171 -pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state 1.172 -ThdParams *coreLoopThdParams [ NUM_CORES ]; 1.173 -pthread_mutex_t suspendLock; 1.174 -pthread_cond_t suspend_cond; 1.175 - 1.176 -volatile MasterEnv *_VMSMasterEnv; 1.177 - 1.178 -//========================== 1.179 -void 1.180 -VMS__init(); 1.181 - 1.182 -void 1.183 -VMS__init_Seq(); 1.184 - 1.185 -void 1.186 -VMS__start_the_work_then_wait_until_done(); 1.187 - 1.188 -void 1.189 -VMS__start_the_work_then_wait_until_done_Seq(); 1.190 - 1.191 -VirtProcr * 1.192 -VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); 1.193 - 1.194 -VirtProcr * 1.195 -VMS__create_the_shutdown_procr(); 1.196 - 1.197 -//========================== 1.198 -inline void 1.199 -VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); 1.200 - 1.201 -void 1.202 -VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister, 1.203 - VirtProcr *reqstingPr ); 1.204 - 1.205 -void 1.206 -VMS__free_request( VMSReqst *req ); 1.207 - 1.208 -void 1.209 -VMS__remove_and_free_top_request( VirtProcr *reqstingPr ); 1.210 - 1.211 -VMSReqst * 1.212 -VMS__take_top_request_from( VirtProcr *reqstingPr ); 1.213 - 1.214 -VMSReqst * 1.215 -VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq ); 1.216 - 1.217 -inline void * 1.218 -VMS__take_sem_reqst_from( VMSReqst *req ); 1.219 - 1.220 -inline int 1.221 -VMS__isSemanticReqst( VMSReqst *req ); 1.222 - 1.223 -inline int 1.224 -VMS__isDissipateReqst( VMSReqst *req ); 1.225 - 1.226 -inline int 1.227 -VMS__isCreateReqst( VMSReqst *req ); 1.228 - 1.229 -//========================== 1.230 - 1.231 -void 1.232 -VMS__suspend_procr( VirtProcr *callingPr ); 1.233 - 1.234 -void 1.235 -VMS__dissipate_procr( VirtProcr *prToDissipate ); 1.236 - 1.237 -void 1.238 -VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate ); 1.239 - 1.240 -void 1.241 -VMS__cleanup_after_shutdown(); 1.242 - 1.243 -//============================= Statistics ================================== 1.244 - 1.245 -typedef unsigned long long TSCount; 1.246 - 1.247 - //Frequency of TS counts 1.248 - //TODO: change freq for each machine 1.249 -#define TSCOUNT_FREQ 3180000000 1.250 - 1.251 -#define saveTimeStampCountInto(low, high) \ 1.252 - asm volatile("RDTSC; \ 1.253 - movl %%eax, %0; \ 1.254 - movl %%edx, %1;" \ 1.255 - /* outputs */ : "=m" (low), "=m" (high)\ 1.256 - /* inputs */ : \ 1.257 - /* clobber */ : "%eax", "%edx" \ 1.258 - ); 1.259 - 1.260 -#define saveLowTimeStampCountInto(low) \ 1.261 - asm volatile("RDTSC; \ 1.262 - movl %%eax, %0;" \ 1.263 - /* outputs */ : "=m" (low) \ 1.264 - /* inputs */ : \ 1.265 - /* clobber */ : "%eax", "%edx" \ 1.266 - ); 1.267 - 1.268 -inline TSCount getTSCount(); 1.269 - 1.270 -//===================== Debug ========================== 1.271 -int numProcrsCreated; 1.272 - 1.273 - 1.274 -#endif /* _VMS_H */ 1.275 - 1.276 +/* 1.277 + * Copyright 2009 OpenSourceStewardshipFoundation.org 1.278 + * Licensed under GNU General Public License version 2 1.279 + * 1.280 + * Author: seanhalle@yahoo.com 1.281 + * 1.282 + */ 1.283 + 1.284 +#ifndef _VMS_H 1.285 +#define _VMS_H 1.286 +#define __USE_GNU 1.287 + 1.288 +#include "VMS_primitive_data_types.h" 1.289 +#include "Queue_impl/BlockingQueue.h" 1.290 +#include "Histogram/Histogram.h" 1.291 +#include <pthread.h> 1.292 + 1.293 + //When DEBUG is defined, VMS does sequential exe in the main thread 1.294 + // It still does co-routines and all the mechanisms are the same, it just 1.295 + // has only a single thread and animates VPs one at a time 1.296 +#define SEQUENTIAL 1.297 + 1.298 + //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and 1.299 + // compiled-in that saves the low part of the time stamp count just before 1.300 + // suspending a processor and just after resuming that processor. It is 1.301 + // saved into a field added to VirtProcr. Have to sanity-check for 1.302 + // rollover of low portion into high portion. 1.303 +#define MEAS__TIME_STAMP_SUSP 1.304 +#define MEAS__TIME_MASTER 1.305 +#define MEAS__NUM_TIMES_TO_RUN 100000 1.306 + 1.307 + //This value is the number of hardware threads in the shared memory 1.308 + // machine 1.309 +#define NUM_CORES 4 1.310 + 1.311 + // make double-num-cores scheduling slots, plus extra for master 1.312 +//#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1) 1.313 +#define NUM_SCHED_SLOTS 3 1.314 + 1.315 +#define READYTOANIMATE_RETRIES 10000 1.316 + 1.317 + // stack 1.318 +#define VIRT_PROCR_STACK_SIZE 0x10000 1.319 + 1.320 + //256M of total memory for VMS__malloc 1.321 +#define MASSIVE_MALLOC_SIZE 0x10000000 1.322 + 1.323 +#define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); 1.324 + 1.325 +#define SUCCESS 0 1.326 + 1.327 +#define writeVMSQ writeCASQ 1.328 +#define readVMSQ readCASQ 1.329 +#define makeVMSQ makeCASQ 1.330 +#define VMSQueueStruc CASQueueStruc 1.331 + 1.332 +//#define thdAttrs NULL //For PThreads 1.333 + 1.334 +typedef struct _SchedSlot SchedSlot; 1.335 +typedef struct _VMSReqst VMSReqst; 1.336 +typedef struct _VirtProcr VirtProcr; 1.337 + 1.338 +typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx 1.339 +typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv 1.340 +typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr 1.341 +typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr 1.342 + 1.343 +typedef struct 1.344 + { 1.345 + void *endThdPt; 1.346 + unsigned int coreNum; 1.347 + } 1.348 +ThdParams; 1.349 + 1.350 + 1.351 +struct _SchedSlot 1.352 + { 1.353 + int workIsDone; 1.354 + int needsProcrAssigned; 1.355 + VirtProcr *procrAssignedToSlot; 1.356 + }; 1.357 +//SchedSlot 1.358 + 1.359 +enum ReqstType 1.360 + { 1.361 + semantic = 1, 1.362 + dissipate, 1.363 + regCreated, 1.364 + IO 1.365 + }; 1.366 + 1.367 +struct _VMSReqst 1.368 + { 1.369 +// VirtProcr *virtProcrFrom; 1.370 + enum ReqstType reqType;//used for dissipate and in future for IO requests 1.371 + void *semReqData; 1.372 + 1.373 + VMSReqst *nextReqst; 1.374 + }; 1.375 +//VMSReqst 1.376 + 1.377 +struct _VirtProcr 1.378 + { int procrID; //for debugging -- count up each time create 1.379 + int coreAnimatedBy; 1.380 + void *startOfStack; 1.381 + void *stackPtr; 1.382 + void *framePtr; 1.383 + void *nextInstrPt; 1.384 + 1.385 + void *coreLoopStartPt; //allows proto-runtime to be linked later 1.386 + void *coreLoopFramePtr; //restore before jmp back to core loop 1.387 + void *coreLoopStackPtr; //restore before jmp back to core loop 1.388 + 1.389 + void *initialData; 1.390 + 1.391 + SchedSlot *schedSlot; 1.392 + VMSReqst *requests; 1.393 + 1.394 + void *semanticData; 1.395 + 1.396 + //============================= MEASUREMENT STUFF ======================== 1.397 + #ifdef MEAS__TIME_STAMP_SUSP 1.398 + unsigned int preSuspTSCLow; 1.399 + unsigned int postSuspTSCLow; 1.400 + #endif 1.401 + #ifdef MEAS__TIME_MASTER 1.402 + unsigned int startMasterTSCLow; 1.403 + unsigned int endMasterTSCLow; 1.404 + #endif 1.405 + //======================================================================== 1.406 + }; 1.407 +//VirtProcr 1.408 + 1.409 + 1.410 + 1.411 +typedef struct 1.412 + { 1.413 + SlaveScheduler slaveScheduler; 1.414 + RequestHandler requestHandler; 1.415 + 1.416 + SchedSlot ***allSchedSlots; 1.417 + SRSWQueueStruc **readyToAnimateQs; 1.418 + VirtProcr **masterVPs; 1.419 + 1.420 + void *semanticEnv; 1.421 + void *OSEventStruc; //for future, when add I/O to BLIS 1.422 + 1.423 + void *coreLoopStartPt;//addr to jump to to re-enter coreLoop 1.424 + void *coreLoopEndPt; //addr to jump to to shut down a coreLoop 1.425 + 1.426 + int setupComplete; 1.427 + int masterLock; 1.428 + 1.429 + } 1.430 +MasterEnv; 1.431 + 1.432 + 1.433 +//========================================================== 1.434 + 1.435 +void * coreLoop( void *paramsIn ); //standard PThreads fn prototype 1.436 +void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype 1.437 +void masterLoop( void *initData, VirtProcr *masterPr ); 1.438 + 1.439 + 1.440 +//===================== Global Vars =================== 1.441 + 1.442 + 1.443 +pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state 1.444 +ThdParams *coreLoopThdParams [ NUM_CORES ]; 1.445 +pthread_mutex_t suspendLock; 1.446 +pthread_cond_t suspend_cond; 1.447 + 1.448 +volatile MasterEnv *_VMSMasterEnv; 1.449 + 1.450 +//========================== 1.451 +void 1.452 +VMS__init(); 1.453 + 1.454 +void 1.455 +VMS__init_Seq(); 1.456 + 1.457 +void 1.458 +VMS__start_the_work_then_wait_until_done(); 1.459 + 1.460 +void 1.461 +VMS__start_the_work_then_wait_until_done_Seq(); 1.462 + 1.463 +VirtProcr * 1.464 +VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); 1.465 + 1.466 +VirtProcr * 1.467 +VMS__create_the_shutdown_procr(); 1.468 + 1.469 +//========================== 1.470 +inline void 1.471 +VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); 1.472 + 1.473 +void 1.474 +VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister, 1.475 + VirtProcr *reqstingPr ); 1.476 + 1.477 +void 1.478 +VMS__free_request( VMSReqst *req ); 1.479 + 1.480 +void 1.481 +VMS__remove_and_free_top_request( VirtProcr *reqstingPr ); 1.482 + 1.483 +VMSReqst * 1.484 +VMS__take_top_request_from( VirtProcr *reqstingPr ); 1.485 + 1.486 +VMSReqst * 1.487 +VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq ); 1.488 + 1.489 +inline void * 1.490 +VMS__take_sem_reqst_from( VMSReqst *req ); 1.491 + 1.492 +inline int 1.493 +VMS__isSemanticReqst( VMSReqst *req ); 1.494 + 1.495 +inline int 1.496 +VMS__isDissipateReqst( VMSReqst *req ); 1.497 + 1.498 +inline int 1.499 +VMS__isCreateReqst( VMSReqst *req ); 1.500 + 1.501 +//========================== 1.502 + 1.503 +void 1.504 +VMS__suspend_procr( VirtProcr *callingPr ); 1.505 + 1.506 +void 1.507 +VMS__dissipate_procr( VirtProcr *prToDissipate ); 1.508 + 1.509 +void 1.510 +VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate ); 1.511 + 1.512 +void 1.513 +VMS__cleanup_after_shutdown(); 1.514 + 1.515 +//============================= Statistics ================================== 1.516 + 1.517 +typedef unsigned long long TSCount; 1.518 + 1.519 + //Frequency of TS counts 1.520 + //TODO: change freq for each machine 1.521 +#define TSCOUNT_FREQ 3180000000 1.522 + 1.523 +#define saveTimeStampCountInto(low, high) \ 1.524 + asm volatile("RDTSC; \ 1.525 + movl %%eax, %0; \ 1.526 + movl %%edx, %1;" \ 1.527 + /* outputs */ : "=m" (low), "=m" (high)\ 1.528 + /* inputs */ : \ 1.529 + /* clobber */ : "%eax", "%edx" \ 1.530 + ); 1.531 + 1.532 +#define saveLowTimeStampCountInto(low) \ 1.533 + asm volatile("RDTSC; \ 1.534 + movl %%eax, %0;" \ 1.535 + /* outputs */ : "=m" (low) \ 1.536 + /* inputs */ : \ 1.537 + /* clobber */ : "%eax", "%edx" \ 1.538 + ); 1.539 + 1.540 +inline TSCount getTSCount(); 1.541 + 1.542 +//===================== Debug ========================== 1.543 +int numProcrsCreated; 1.544 + 1.545 + 1.546 +#endif /* _VMS_H */ 1.547 +
