comparison VMS.h @ 61:984f7d78bfdf

Merge See what happens -- merged test stuff into Nov 8 VMS version
author SeanHalle
date Thu, 11 Nov 2010 06:19:51 -0800
parents 054006c26b92 7b799a46cc87
children
comparison
equal deleted inserted replaced
18:a566fdfce723 29:a867b3dc3eb5
5 * Author: seanhalle@yahoo.com 5 * Author: seanhalle@yahoo.com
6 * 6 *
7 */ 7 */
8 8
9 #ifndef _VMS_H 9 #ifndef _VMS_H
10 #define _VMS_H 10 #define _VMS_H
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/PrivateQueue.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 ===================================
25 //
18 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread 26 //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 27 // 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 28 // has only a single thread and animates VPs one at a time
21 //#define SEQUENTIAL 29 //#define SEQUENTIAL
22 30
23 #define PRINT_DEBUG(msg) //printf(msg); fflush(stdin); 31 //#define USE_WORK_STEALING
24 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin); 32
25 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin); 33 //turns on the probe-instrumentation in the application -- when not
34 // defined, the calls to the probe functions turn into comments
35 #define STATS__ENABLE_PROBES
36 //#define TURN_ON_DEBUG_PROBES
37
38 //These defines turn types of bug messages on and off
39 // be sure debug messages are un-commented (next block of defines)
40 #define dbgProbes FALSE /* for issues inside probes themselves*/
41 #define dbgAppFlow FALSE /* Top level flow of application code -- general*/
42 #define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
43 #define dbgRqstHdlr FALSE /* in request handler code*/
44
45 //Comment or un- the substitute half to turn on/off types of debug message
46 #define DEBUG( bool, msg) \
47 // if( bool){ printf(msg); fflush(stdin);}
48 #define DEBUG1( bool, msg, param) \
49 // if(bool){printf(msg, param); fflush(stdin);}
50 #define DEBUG2( bool, msg, p1, p2) \
51 // if(bool) {printf(msg, p1, p2); fflush(stdin);}
52
53 #define ERROR(msg) printf(msg); fflush(stdin);
54 #define ERROR1(msg, param) printf(msg, param); fflush(stdin);
55 #define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
56
57 //=========================== STATS =======================
26 58
27 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and 59 //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 60 // 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 61 // suspending a processor and just after resuming that processor. It is
30 // saved into a field added to VirtProcr. Have to sanity-check for 62 // saved into a field added to VirtProcr. Have to sanity-check for
31 // rollover of low portion into high portion. 63 // rollover of low portion into high portion.
32 #define MEAS__TIME_STAMP_SUSP 64 #define MEAS__TIME_STAMP_SUSP
33 #define MEAS__TIME_MASTER 65 #define MEAS__TIME_MASTER
34 #define MEAS__NUM_TIMES_TO_RUN 100000 66 #define MEAS__NUM_TIMES_TO_RUN 100000
35 67
68 //For code that calculates normalization-offset between TSC counts of
69 // different cores.
36 #define NUM_TSC_ROUND_TRIPS 10 70 #define NUM_TSC_ROUND_TRIPS 10
37 71
72
73 //========================= Hardware related Constants =====================
38 //This value is the number of hardware threads in the shared memory 74 //This value is the number of hardware threads in the shared memory
39 // machine 75 // machine
40 #define NUM_CORES 4 76 #define NUM_CORES 4
41 77
42 // balance amortizing master fixed overhead vs imbalance potential 78 // tradeoff amortizing master fixed overhead vs imbalance potential
43 #define NUM_SCHED_SLOTS 3 79 // when work-stealing, can make bigger, at risk of losing cache affinity
80 #define NUM_SCHED_SLOTS 5
44 81
45 #define MIN_WORK_UNIT_CYCLES 20000 82 #define MIN_WORK_UNIT_CYCLES 20000
46 83
47 #define READYTOANIMATE_RETRIES 10000 84 #define MASTERLOCK_RETRIES 10000
48 85
49 // stack 86 // stack size in virtual processors created
50 #define VIRT_PROCR_STACK_SIZE 0x10000 87 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
51 88
52 //256M of total memory for VMS__malloc 89 // memory for VMS__malloc
53 #define MASSIVE_MALLOC_SIZE 0x10000000 90 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
54 91
55 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem); 92
93 //==============================
56 94
57 #define SUCCESS 0 95 #define SUCCESS 0
58 96
59 #define writeVMSQ writeSRSWQ 97 #define writeVMSQ writePrivQ
60 #define readVMSQ readSRSWQ 98 #define readVMSQ readPrivQ
61 #define makeVMSQ makeSRSWQ 99 #define makeVMSQ makePrivQ
62 #define VMSQueueStruc SRSWQueueStruc 100 #define numInVMSQ numInPrivQ
63 101 #define VMSQueueStruc PrivQueueStruc
64 //#define thdAttrs NULL //For PThreads 102
65 103
66 typedef struct _SchedSlot SchedSlot; 104
67 typedef struct _VMSReqst VMSReqst; 105 //===========================================================================
68 typedef struct _VirtProcr VirtProcr; 106 typedef unsigned long long TSCount;
107
108 typedef struct _SchedSlot SchedSlot;
109 typedef struct _VMSReqst VMSReqst;
110 typedef struct _VirtProcr VirtProcr;
111 typedef struct _IntervalProbe IntervalProbe;
112 typedef struct _GateStruc GateStruc;
113
69 114
70 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx 115 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
71 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv 116 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
72 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr 117 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
73 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr 118 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
74 119 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
75 typedef struct 120
76 { 121
77 void *endThdPt; 122 //============= Requests ===========
78 unsigned int coreNum; 123 //
79 } 124
80 ThdParams; 125 enum VMSReqstType //avoid starting enums at 0, for debug reasons
81 126 {
127 semantic = 1,
128 createReq,
129 dissipate,
130 VMSSemantic //goes with VMSSemReqst below
131 };
132
133 struct _VMSReqst
134 {
135 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
136 void *semReqData;
137
138 VMSReqst *nextReqst;
139 };
140 //VMSReqst
141
142 enum VMSSemReqstType //These are equivalent to semantic requests, but for
143 { // VMS's services available directly to app, like OS
144 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
145 openFile,
146 otherIO
147 };
148
149 typedef struct
150 { enum VMSSemReqstType reqType;
151 VirtProcr *requestingPr;
152 char *nameStr; //for create probe
153 }
154 VMSSemReq;
155
156
157 //==================== Core data structures ===================
82 158
83 struct _SchedSlot 159 struct _SchedSlot
84 { 160 {
85 int workIsDone; 161 int workIsDone;
86 int needsProcrAssigned; 162 int needsProcrAssigned;
87 VirtProcr *procrAssignedToSlot; 163 VirtProcr *procrAssignedToSlot;
88 }; 164 };
89 //SchedSlot 165 //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 166
109 struct _VirtProcr 167 struct _VirtProcr
110 { int procrID; //for debugging -- count up each time create 168 { int procrID; //for debugging -- count up each time create
111 int coreAnimatedBy; 169 int coreAnimatedBy;
112 void *startOfStack; 170 void *startOfStack;
121 void *initialData; 179 void *initialData;
122 180
123 SchedSlot *schedSlot; 181 SchedSlot *schedSlot;
124 VMSReqst *requests; 182 VMSReqst *requests;
125 183
126 void *semanticData; 184 void *semanticData; //this lives here for the life of VP
127 185 void *dataRetFromReq;//values returned from plugin to VP go here
128 //============================= MEASUREMENT STUFF ======================== 186
187 //=========== MEASUREMENT STUFF ==========
129 #ifdef MEAS__TIME_STAMP_SUSP 188 #ifdef MEAS__TIME_STAMP_SUSP
130 unsigned int preSuspTSCLow; 189 unsigned int preSuspTSCLow;
131 unsigned int postSuspTSCLow; 190 unsigned int postSuspTSCLow;
132 #endif 191 #endif
133 #ifdef MEAS__TIME_MASTER 192 #ifdef MEAS__TIME_MASTER
134 unsigned int startMasterTSCLow; 193 unsigned int startMasterTSCLow;
135 unsigned int endMasterTSCLow; 194 unsigned int endMasterTSCLow;
136 #endif 195 #endif
137 //======================================================================== 196
197 float64 createPtInSecs; //have space but don't use on some configs
138 }; 198 };
139 //VirtProcr 199 //VirtProcr
140 200
141 201
142 typedef struct 202 typedef struct
156 VMSQueueStruc **readyToAnimateQs; 216 VMSQueueStruc **readyToAnimateQs;
157 VirtProcr **masterVPs; 217 VirtProcr **masterVPs;
158 218
159 void *semanticEnv; 219 void *semanticEnv;
160 void *OSEventStruc; //for future, when add I/O to BLIS 220 void *OSEventStruc; //for future, when add I/O to BLIS
221 MallocProlog *freeListHead;
222 int32 amtOfOutstandingMem; //total currently allocated
161 223
162 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop 224 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
163 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop 225 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
164 226
165 int setupComplete; 227 int32 setupComplete;
166 int masterLock; 228 int32 masterLock;
167 229
168 VMSStats *stats; 230 VMSStats *stats;
231 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
232 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
233 int32 workStealingLock;
234
235 int32 numProcrsCreated; //gives ordering to processor creation
236
237 //=========== MEASUREMENT STUFF =============
238 IntervalProbe **intervalProbes;
239 PrivDynArrayInfo *dynIntervalProbesInfo;
240 HashTable *probeNameHashTbl;
241 int32 masterCreateProbeID;
242 float64 createPtInSecs;
169 } 243 }
170 MasterEnv; 244 MasterEnv;
171 245
172 246 //========================= Extra Stuff Data Strucs =======================
173 //========================================================== 247 typedef struct
248 {
249
250 }
251 VMSExcp;
252
253 struct _GateStruc
254 {
255 int32 gateClosed;
256 int32 preGateProgress;
257 int32 waitProgress;
258 int32 exitProgress;
259 };
260 //GateStruc
261
262 //======================= OS Thread related ===============================
174 263
175 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype 264 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
176 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype 265 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
177 void masterLoop( void *initData, VirtProcr *masterPr ); 266 void masterLoop( void *initData, VirtProcr *masterPr );
178 267
179 268
180 //===================== Global Vars =================== 269 typedef struct
181 270 {
271 void *endThdPt;
272 unsigned int coreNum;
273 }
274 ThdParams;
182 275
183 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state 276 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
184 ThdParams *coreLoopThdParams [ NUM_CORES ]; 277 ThdParams *coreLoopThdParams [ NUM_CORES ];
185 pthread_mutex_t suspendLock; 278 pthread_mutex_t suspendLock;
186 pthread_cond_t suspend_cond; 279 pthread_cond_t suspend_cond;
187 280
281
282
283 //===================== Global Vars ===================
284
188 volatile MasterEnv *_VMSMasterEnv; 285 volatile MasterEnv *_VMSMasterEnv;
189 286
190 287
191 //========================== 288
289
290 //=========================== Function Prototypes =========================
291
292
293 //========== Setup and shutdown ==========
192 void 294 void
193 VMS__init(); 295 VMS__init();
194 296
195 void 297 void
196 VMS__init_Seq(); 298 VMS__init_Seq();
202 VMS__start_the_work_then_wait_until_done_Seq(); 304 VMS__start_the_work_then_wait_until_done_Seq();
203 305
204 VirtProcr * 306 VirtProcr *
205 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData ); 307 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
206 308
309 void
310 VMS__dissipate_procr( VirtProcr *procrToDissipate );
311
312 //Use this to create processor inside entry point & other places outside
313 // the VMS system boundary (IE, not run in slave nor Master)
207 VirtProcr * 314 VirtProcr *
208 VMS__create_the_shutdown_procr(); 315 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
209 316
210 //========================== 317 void
318 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
319
320 void
321 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
322
323 void
324 VMS__shutdown();
325
326 void
327 VMS__cleanup_at_end_of_shutdown();
328
329
330 //============== Request Related ===============
331
332 void
333 VMS__suspend_procr( VirtProcr *callingPr );
334
211 inline void 335 inline void
212 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr ); 336 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
213 337
214 void 338 inline void
215 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister, 339 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
216 VirtProcr *reqstingPr ); 340
217 341 void
218 void 342 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
219 VMS__free_request( VMSReqst *req ); 343
220 344 void inline
221 void 345 VMS__send_dissipate_req( VirtProcr *prToDissipate );
222 VMS__remove_and_free_top_request( VirtProcr *reqstingPr ); 346
347 inline void
348 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
223 349
224 VMSReqst * 350 VMSReqst *
225 VMS__take_top_request_from( VirtProcr *reqstingPr ); 351 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
226
227 VMSReqst *
228 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq );
229 352
230 inline void * 353 inline void *
231 VMS__take_sem_reqst_from( VMSReqst *req ); 354 VMS__take_sem_reqst_from( VMSReqst *req );
232
233 inline int
234 VMS__isSemanticReqst( VMSReqst *req );
235
236 inline int
237 VMS__isDissipateReqst( VMSReqst *req );
238
239 inline int
240 VMS__isCreateReqst( VMSReqst *req );
241
242 //==========================
243
244 void
245 VMS__suspend_procr( VirtProcr *callingPr );
246
247 void
248 VMS__dissipate_procr( VirtProcr *prToDissipate );
249
250 void
251 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
252
253 void
254 VMS__cleanup_after_shutdown();
255
256 //==========================
257 void
258 measureTSCOffsetsAsCore0();
259
260 void
261 measureTSCOffsetsAsRemoteCore( int coreIdx );
262
263 //============================= Statistics ==================================
264
265 typedef unsigned long long TSCount;
266 355
267 //Frequency of TS counts 356 //Frequency of TS counts
268 //TODO: change freq for each machine 357 //TODO: change freq for each machine
269 #define TSCOUNT_FREQ 3180000000 358 #define TSCOUNT_FREQ 3180000000
359 //======================== STATS ======================
360
361 //===== RDTSC wrapper =====
270 362
271 #define saveTimeStampCountInto(low, high) \ 363 #define saveTimeStampCountInto(low, high) \
272 asm volatile("RDTSC; \ 364 asm volatile("RDTSC; \
273 movl %%eax, %0; \ 365 movl %%eax, %0; \
274 movl %%edx, %1;" \ 366 movl %%edx, %1;" \
282 movl %%eax, %0;" \ 374 movl %%eax, %0;" \
283 /* outputs */ : "=m" (low) \ 375 /* outputs */ : "=m" (low) \
284 /* inputs */ : \ 376 /* inputs */ : \
285 /* clobber */ : "%eax", "%edx" \ 377 /* clobber */ : "%eax", "%edx" \
286 ); 378 );
287 379 //=====
288 inline TSCount getTSC(); 380
289 381 #include "SwitchAnimators.h"
290 inline TSCount getTSC(); 382 #include "probes.h"
383
384
291 385
292 //===================== Debug ========================== 386 //===================== Debug ==========================
293 int numProcrsCreated; 387 int numProcrsCreated;
294 388
295 389
296 int *pongNums; 390 int *pongNums;
297 TSCount *pongTimes; 391 TSCount *pongTimes;
298 TSCount *pingTimes; 392 TSCount *pingTimes;
299 393
300 #endif /* _VMS_H */ 394 #endif /* _VMS_H */
301