| 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@42
|
14 #include "Queue_impl/BlockingQueue.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@54
|
25 //These defines turn types of bug messages on and off
|
|
Me@54
|
26 #define dbgProbes FALSE
|
|
Me@54
|
27 #define dbgAppFlow FALSE
|
|
Me@54
|
28
|
|
Me@45
|
29 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
|
|
Me@42
|
30 // It still does co-routines and all the mechanisms are the same, it just
|
|
Me@42
|
31 // has only a single thread and animates VPs one at a time
|
|
Me@45
|
32 //#define SEQUENTIAL
|
|
Me@42
|
33
|
|
Me@52
|
34 //turns on the probe-instrumentation in the application -- when not
|
|
Me@52
|
35 // defined, the calls to the probe functions turn into comments
|
|
Me@52
|
36 #define STATS__ENABLE_PROBES
|
|
Me@52
|
37
|
|
Me@52
|
38
|
|
Me@54
|
39 #define DEBUG(msg)// printf(msg); fflush(stdin);
|
|
Me@54
|
40 #define DEBUG_MSG( bool, msg) //if( bool){ printf(msg); fflush(stdin);}
|
|
Me@45
|
41 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin);
|
|
Me@45
|
42 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin);
|
|
Me@45
|
43
|
|
Me@50
|
44 #define PRINT_ERROR(msg) printf(msg); fflush(stdin);
|
|
Me@50
|
45 #define PRINT1_ERROR(msg, param) printf(msg, param); fflush(stdin);
|
|
Me@50
|
46 #define PRINT2_ERROR(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
|
|
Me@50
|
47
|
|
Me@50
|
48 //=========================== STATS =======================
|
|
Me@50
|
49
|
|
Me@45
|
50 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
|
|
Me@42
|
51 // compiled-in that saves the low part of the time stamp count just before
|
|
Me@42
|
52 // suspending a processor and just after resuming that processor. It is
|
|
Me@42
|
53 // saved into a field added to VirtProcr. Have to sanity-check for
|
|
Me@42
|
54 // rollover of low portion into high portion.
|
|
Me@42
|
55 #define MEAS__TIME_STAMP_SUSP
|
|
Me@42
|
56 #define MEAS__TIME_MASTER
|
|
Me@42
|
57 #define MEAS__NUM_TIMES_TO_RUN 100000
|
|
Me@42
|
58
|
|
Me@45
|
59 #define NUM_TSC_ROUND_TRIPS 10
|
|
Me@45
|
60
|
|
Me@50
|
61
|
|
Me@50
|
62 //========================= Hardware related Constants =====================
|
|
Me@42
|
63 //This value is the number of hardware threads in the shared memory
|
|
Me@42
|
64 // machine
|
|
Me@42
|
65 #define NUM_CORES 4
|
|
Me@42
|
66
|
|
Me@45
|
67 // balance amortizing master fixed overhead vs imbalance potential
|
|
Me@42
|
68 #define NUM_SCHED_SLOTS 3
|
|
Me@42
|
69
|
|
Me@45
|
70 #define MIN_WORK_UNIT_CYCLES 20000
|
|
Me@45
|
71
|
|
Me@53
|
72 #define MASTERLOCK_RETRIES 10000
|
|
Me@42
|
73
|
|
Me@54
|
74 // stack size in virtual processors created
|
|
Me@54
|
75 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
|
|
Me@42
|
76
|
|
Me@54
|
77 // memory for VMS__malloc
|
|
Me@54
|
78 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
|
|
Me@42
|
79
|
|
Me@50
|
80
|
|
Me@50
|
81 //==============================
|
|
Me@42
|
82
|
|
Me@42
|
83 #define SUCCESS 0
|
|
Me@42
|
84
|
|
Me@50
|
85 #define writeVMSQ writeSRSWQ
|
|
Me@50
|
86 #define readVMSQ readSRSWQ
|
|
Me@50
|
87 #define makeVMSQ makeSRSWQ
|
|
Me@50
|
88 #define VMSQueueStruc SRSWQueueStruc
|
|
Me@42
|
89
|
|
Me@42
|
90
|
|
Me@50
|
91
|
|
Me@50
|
92 //===========================================================================
|
|
Me@50
|
93 typedef unsigned long long TSCount;
|
|
Me@50
|
94
|
|
Me@50
|
95 typedef struct _SchedSlot SchedSlot;
|
|
Me@50
|
96 typedef struct _VMSReqst VMSReqst;
|
|
Me@50
|
97 typedef struct _VirtProcr VirtProcr;
|
|
Me@50
|
98 typedef struct _IntervalProbe IntervalProbe;
|
|
Me@42
|
99
|
|
Me@42
|
100 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
|
|
Me@42
|
101 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
|
|
Me@42
|
102 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
|
|
Me@42
|
103 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
|
|
Me@50
|
104 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
|
|
Me@50
|
105
|
|
Me@50
|
106
|
|
Me@50
|
107 //============= Requests ===========
|
|
Me@50
|
108 //
|
|
Me@50
|
109
|
|
Me@50
|
110 enum VMSReqstType //avoid starting enums at 0, for debug reasons
|
|
Me@50
|
111 {
|
|
Me@50
|
112 semantic = 1,
|
|
Me@50
|
113 createReq,
|
|
Me@50
|
114 dissipate,
|
|
Me@50
|
115 VMSSemantic //goes with VMSSemReqst below
|
|
Me@50
|
116 };
|
|
Me@50
|
117
|
|
Me@50
|
118 struct _VMSReqst
|
|
Me@50
|
119 {
|
|
Me@50
|
120 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
|
|
Me@50
|
121 void *semReqData;
|
|
Me@50
|
122
|
|
Me@50
|
123 VMSReqst *nextReqst;
|
|
Me@50
|
124 };
|
|
Me@50
|
125 //VMSReqst
|
|
Me@50
|
126
|
|
Me@50
|
127 enum VMSSemReqstType //These are equivalent to semantic requests, but for
|
|
Me@50
|
128 { // VMS's services available directly to app, like OS
|
|
Me@50
|
129 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
|
|
Me@50
|
130 openFile,
|
|
Me@50
|
131 otherIO
|
|
Me@50
|
132 };
|
|
Me@42
|
133
|
|
Me@42
|
134 typedef struct
|
|
Me@50
|
135 { enum VMSSemReqstType reqType;
|
|
Me@50
|
136 VirtProcr *requestingPr;
|
|
Me@50
|
137 char *nameStr; //for create probe
|
|
Me@42
|
138 }
|
|
Me@50
|
139 VMSSemReq;
|
|
Me@42
|
140
|
|
Me@42
|
141
|
|
Me@50
|
142 //==================== Core data structures ===================
|
|
Me@50
|
143
|
|
Me@42
|
144 struct _SchedSlot
|
|
Me@42
|
145 {
|
|
Me@42
|
146 int workIsDone;
|
|
Me@42
|
147 int needsProcrAssigned;
|
|
Me@42
|
148 VirtProcr *procrAssignedToSlot;
|
|
Me@42
|
149 };
|
|
Me@42
|
150 //SchedSlot
|
|
Me@42
|
151
|
|
Me@42
|
152 struct _VirtProcr
|
|
Me@42
|
153 { int procrID; //for debugging -- count up each time create
|
|
Me@42
|
154 int coreAnimatedBy;
|
|
Me@42
|
155 void *startOfStack;
|
|
Me@42
|
156 void *stackPtr;
|
|
Me@42
|
157 void *framePtr;
|
|
Me@42
|
158 void *nextInstrPt;
|
|
Me@42
|
159
|
|
Me@42
|
160 void *coreLoopStartPt; //allows proto-runtime to be linked later
|
|
Me@42
|
161 void *coreLoopFramePtr; //restore before jmp back to core loop
|
|
Me@42
|
162 void *coreLoopStackPtr; //restore before jmp back to core loop
|
|
Me@42
|
163
|
|
Me@42
|
164 void *initialData;
|
|
Me@42
|
165
|
|
Me@42
|
166 SchedSlot *schedSlot;
|
|
Me@42
|
167 VMSReqst *requests;
|
|
Me@42
|
168
|
|
Me@50
|
169 void *semanticData; //this lives here for the life of VP
|
|
Me@53
|
170 void *dataRetFromReq;//values returned from plugin to VP go here
|
|
Me@42
|
171
|
|
Me@50
|
172 //=========== MEASUREMENT STUFF ==========
|
|
Me@42
|
173 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@42
|
174 unsigned int preSuspTSCLow;
|
|
Me@42
|
175 unsigned int postSuspTSCLow;
|
|
Me@42
|
176 #endif
|
|
Me@42
|
177 #ifdef MEAS__TIME_MASTER
|
|
Me@42
|
178 unsigned int startMasterTSCLow;
|
|
Me@42
|
179 unsigned int endMasterTSCLow;
|
|
Me@42
|
180 #endif
|
|
Me@50
|
181
|
|
Me@50
|
182 float64 createPtInSecs; //have space but don't use on some configs
|
|
Me@42
|
183 };
|
|
Me@42
|
184 //VirtProcr
|
|
Me@42
|
185
|
|
Me@42
|
186
|
|
Me@42
|
187 typedef struct
|
|
Me@42
|
188 {
|
|
Me@42
|
189 SlaveScheduler slaveScheduler;
|
|
Me@42
|
190 RequestHandler requestHandler;
|
|
Me@42
|
191
|
|
Me@42
|
192 SchedSlot ***allSchedSlots;
|
|
Me@42
|
193 SRSWQueueStruc **readyToAnimateQs;
|
|
Me@42
|
194 VirtProcr **masterVPs;
|
|
Me@42
|
195
|
|
Me@42
|
196 void *semanticEnv;
|
|
Me@42
|
197 void *OSEventStruc; //for future, when add I/O to BLIS
|
|
Me@50
|
198 MallocProlog *freeListHead;
|
|
Me@50
|
199 int32 amtOfOutstandingMem; //total currently allocated
|
|
Me@42
|
200
|
|
Me@42
|
201 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
|
|
Me@42
|
202 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
|
|
Me@42
|
203
|
|
Me@50
|
204 int32 setupComplete;
|
|
Me@50
|
205 int32 masterLock;
|
|
Me@42
|
206
|
|
Me@50
|
207 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
|
|
Me@50
|
208 int32 numProcrsCreated; //gives ordering to processor creation
|
|
Me@50
|
209
|
|
Me@50
|
210 //=========== MEASUREMENT STUFF =============
|
|
Me@50
|
211 IntervalProbe **intervalProbes;
|
|
Me@53
|
212 PrivDynArrayInfo *dynIntervalProbesInfo;
|
|
Me@50
|
213 HashTable *probeNameHashTbl;
|
|
Me@50
|
214 int32 masterCreateProbeID;
|
|
Me@50
|
215 float64 createPtInSecs;
|
|
Me@42
|
216 }
|
|
Me@42
|
217 MasterEnv;
|
|
Me@42
|
218
|
|
Me@54
|
219 //=============================
|
|
Me@54
|
220 typedef struct
|
|
Me@54
|
221 {
|
|
Me@42
|
222
|
|
Me@54
|
223 }
|
|
Me@54
|
224 VMSExcp;
|
|
Me@50
|
225
|
|
Me@50
|
226
|
|
Me@50
|
227 //======================= OS Thread related ===============================
|
|
Me@42
|
228
|
|
Me@42
|
229 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@42
|
230 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@42
|
231 void masterLoop( void *initData, VirtProcr *masterPr );
|
|
Me@42
|
232
|
|
Me@42
|
233
|
|
Me@50
|
234 typedef struct
|
|
Me@50
|
235 {
|
|
Me@50
|
236 void *endThdPt;
|
|
Me@50
|
237 unsigned int coreNum;
|
|
Me@50
|
238 }
|
|
Me@50
|
239 ThdParams;
|
|
Me@42
|
240
|
|
Me@42
|
241 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
|
|
Me@42
|
242 ThdParams *coreLoopThdParams [ NUM_CORES ];
|
|
Me@42
|
243 pthread_mutex_t suspendLock;
|
|
Me@42
|
244 pthread_cond_t suspend_cond;
|
|
Me@42
|
245
|
|
Me@50
|
246
|
|
Me@50
|
247
|
|
Me@50
|
248 //===================== Global Vars ===================
|
|
Me@50
|
249
|
|
Me@42
|
250 volatile MasterEnv *_VMSMasterEnv;
|
|
Me@42
|
251
|
|
Me@50
|
252
|
|
Me@50
|
253
|
|
Me@50
|
254
|
|
Me@50
|
255 //=========================== Function Prototypes =========================
|
|
Me@50
|
256
|
|
Me@53
|
257
|
|
Me@53
|
258 //========== Setup and shutdown ==========
|
|
Me@42
|
259 void
|
|
Me@42
|
260 VMS__init();
|
|
Me@42
|
261
|
|
Me@42
|
262 void
|
|
Me@42
|
263 VMS__init_Seq();
|
|
Me@42
|
264
|
|
Me@42
|
265 void
|
|
Me@42
|
266 VMS__start_the_work_then_wait_until_done();
|
|
Me@42
|
267
|
|
Me@42
|
268 void
|
|
Me@42
|
269 VMS__start_the_work_then_wait_until_done_Seq();
|
|
Me@42
|
270
|
|
Me@42
|
271 VirtProcr *
|
|
Me@42
|
272 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@42
|
273
|
|
Me@53
|
274 void
|
|
Me@53
|
275 VMS__dissipate_procr( VirtProcr *procrToDissipate );
|
|
Me@53
|
276
|
|
Me@50
|
277 //Use this to create processor inside entry point & other places outside
|
|
Me@50
|
278 // the VMS system boundary (IE, not run in slave nor Master)
|
|
Me@50
|
279 VirtProcr *
|
|
Me@50
|
280 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@50
|
281
|
|
Me@53
|
282 void
|
|
Me@53
|
283 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
|
|
Me@42
|
284
|
|
Me@50
|
285 void
|
|
Me@54
|
286 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
|
|
Me@54
|
287
|
|
Me@54
|
288 void
|
|
Me@53
|
289 VMS__shutdown();
|
|
Me@53
|
290
|
|
Me@53
|
291 void
|
|
Me@53
|
292 VMS__cleanup_at_end_of_shutdown();
|
|
Me@50
|
293
|
|
Me@50
|
294
|
|
Me@50
|
295 //============== Request Related ===============
|
|
Me@50
|
296
|
|
Me@50
|
297 void
|
|
Me@50
|
298 VMS__suspend_procr( VirtProcr *callingPr );
|
|
Me@50
|
299
|
|
Me@42
|
300 inline void
|
|
Me@53
|
301 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
|
|
Me@53
|
302
|
|
Me@53
|
303 inline void
|
|
Me@53
|
304 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
|
|
Me@42
|
305
|
|
Me@42
|
306 void
|
|
Me@50
|
307 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
|
|
Me@42
|
308
|
|
Me@53
|
309 void inline
|
|
Me@53
|
310 VMS__send_dissipate_req( VirtProcr *prToDissipate );
|
|
Me@53
|
311
|
|
Me@52
|
312 inline void
|
|
Me@52
|
313 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
|
|
Me@52
|
314
|
|
Me@42
|
315 VMSReqst *
|
|
Me@50
|
316 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
|
|
Me@42
|
317
|
|
Me@42
|
318 inline void *
|
|
Me@42
|
319 VMS__take_sem_reqst_from( VMSReqst *req );
|
|
Me@42
|
320
|
|
Me@42
|
321
|
|
Me@42
|
322
|
|
Me@53
|
323 //======================== STATS ======================
|
|
Me@42
|
324
|
|
Me@53
|
325 //===== RDTSC wrapper =====
|
|
Me@42
|
326
|
|
Me@42
|
327 #define saveTimeStampCountInto(low, high) \
|
|
Me@42
|
328 asm volatile("RDTSC; \
|
|
Me@42
|
329 movl %%eax, %0; \
|
|
Me@42
|
330 movl %%edx, %1;" \
|
|
Me@42
|
331 /* outputs */ : "=m" (low), "=m" (high)\
|
|
Me@42
|
332 /* inputs */ : \
|
|
Me@42
|
333 /* clobber */ : "%eax", "%edx" \
|
|
Me@42
|
334 );
|
|
Me@42
|
335
|
|
Me@42
|
336 #define saveLowTimeStampCountInto(low) \
|
|
Me@42
|
337 asm volatile("RDTSC; \
|
|
Me@42
|
338 movl %%eax, %0;" \
|
|
Me@42
|
339 /* outputs */ : "=m" (low) \
|
|
Me@42
|
340 /* inputs */ : \
|
|
Me@42
|
341 /* clobber */ : "%eax", "%edx" \
|
|
Me@42
|
342 );
|
|
Me@53
|
343 //=====
|
|
Me@42
|
344
|
|
Me@50
|
345 #include "probes.h"
|
|
Me@42
|
346
|
|
Me@42
|
347 #endif /* _VMS_H */
|
|
Me@42
|
348
|