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