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