view VMS.h @ 60:7b799a46cc87

Added compiler switch to turn on and off debug-only probes, deleted time-junk
author Me
date Mon, 08 Nov 2010 03:57:46 -0800
parents 407f8ede98b4
children 984f7d78bfdf dd3e60aeae26
line source
1 /*
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
9 #ifndef _VMS_H
10 #define _VMS_H
11 #define __USE_GNU
13 #include "VMS_primitive_data_types.h"
14 #include "Queue_impl/PrivateQueue.h"
15 #include "Histogram/Histogram.h"
16 #include "DynArray/DynArray.h"
17 #include "Hash_impl/PrivateHash.h"
18 #include "vmalloc.h"
20 #include <pthread.h>
21 #include <sys/time.h>
24 //=============================== Debug ===================================
25 //
26 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
27 // It still does co-routines and all the mechanisms are the same, it just
28 // has only a single thread and animates VPs one at a time
29 //#define SEQUENTIAL
31 //#define USE_WORK_STEALING
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
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*/
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);}
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);
57 //=========================== STATS =======================
59 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
60 // compiled-in that saves the low part of the time stamp count just before
61 // suspending a processor and just after resuming that processor. It is
62 // saved into a field added to VirtProcr. Have to sanity-check for
63 // rollover of low portion into high portion.
64 #define MEAS__TIME_STAMP_SUSP
65 #define MEAS__TIME_MASTER
66 #define MEAS__NUM_TIMES_TO_RUN 100000
68 //For code that calculates normalization-offset between TSC counts of
69 // different cores.
70 #define NUM_TSC_ROUND_TRIPS 10
73 //========================= Hardware related Constants =====================
74 //This value is the number of hardware threads in the shared memory
75 // machine
76 #define NUM_CORES 4
78 // tradeoff amortizing master fixed overhead vs imbalance potential
79 // when work-stealing, can make bigger, at risk of losing cache affinity
80 #define NUM_SCHED_SLOTS 5
82 #define MIN_WORK_UNIT_CYCLES 20000
84 #define MASTERLOCK_RETRIES 10000
86 // stack size in virtual processors created
87 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
89 // memory for VMS__malloc
90 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
93 //==============================
95 #define SUCCESS 0
97 #define writeVMSQ writePrivQ
98 #define readVMSQ readPrivQ
99 #define makeVMSQ makePrivQ
100 #define numInVMSQ numInPrivQ
101 #define VMSQueueStruc PrivQueueStruc
105 //===========================================================================
106 typedef unsigned long long TSCount;
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;
115 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
116 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
117 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
118 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
119 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
122 //============= Requests ===========
123 //
125 enum VMSReqstType //avoid starting enums at 0, for debug reasons
126 {
127 semantic = 1,
128 createReq,
129 dissipate,
130 VMSSemantic //goes with VMSSemReqst below
131 };
133 struct _VMSReqst
134 {
135 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
136 void *semReqData;
138 VMSReqst *nextReqst;
139 };
140 //VMSReqst
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 };
149 typedef struct
150 { enum VMSSemReqstType reqType;
151 VirtProcr *requestingPr;
152 char *nameStr; //for create probe
153 }
154 VMSSemReq;
157 //==================== Core data structures ===================
159 struct _SchedSlot
160 {
161 int workIsDone;
162 int needsProcrAssigned;
163 VirtProcr *procrAssignedToSlot;
164 };
165 //SchedSlot
167 struct _VirtProcr
168 { int procrID; //for debugging -- count up each time create
169 int coreAnimatedBy;
170 void *startOfStack;
171 void *stackPtr;
172 void *framePtr;
173 void *nextInstrPt;
175 void *coreLoopStartPt; //allows proto-runtime to be linked later
176 void *coreLoopFramePtr; //restore before jmp back to core loop
177 void *coreLoopStackPtr; //restore before jmp back to core loop
179 void *initialData;
181 SchedSlot *schedSlot;
182 VMSReqst *requests;
184 void *semanticData; //this lives here for the life of VP
185 void *dataRetFromReq;//values returned from plugin to VP go here
187 //=========== MEASUREMENT STUFF ==========
188 #ifdef MEAS__TIME_STAMP_SUSP
189 unsigned int preSuspTSCLow;
190 unsigned int postSuspTSCLow;
191 #endif
192 #ifdef MEAS__TIME_MASTER
193 unsigned int startMasterTSCLow;
194 unsigned int endMasterTSCLow;
195 #endif
197 float64 createPtInSecs; //have space but don't use on some configs
198 };
199 //VirtProcr
202 typedef struct
203 {
204 SlaveScheduler slaveScheduler;
205 RequestHandler requestHandler;
207 SchedSlot ***allSchedSlots;
208 VMSQueueStruc **readyToAnimateQs;
209 VirtProcr **masterVPs;
211 void *semanticEnv;
212 void *OSEventStruc; //for future, when add I/O to BLIS
213 MallocProlog *freeListHead;
214 int32 amtOfOutstandingMem; //total currently allocated
216 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
217 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
219 int32 setupComplete;
220 int32 masterLock;
222 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
223 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
224 int32 workStealingLock;
226 int32 numProcrsCreated; //gives ordering to processor creation
228 //=========== MEASUREMENT STUFF =============
229 IntervalProbe **intervalProbes;
230 PrivDynArrayInfo *dynIntervalProbesInfo;
231 HashTable *probeNameHashTbl;
232 int32 masterCreateProbeID;
233 float64 createPtInSecs;
234 }
235 MasterEnv;
237 //========================= Extra Stuff Data Strucs =======================
238 typedef struct
239 {
241 }
242 VMSExcp;
244 struct _GateStruc
245 {
246 int32 gateClosed;
247 int32 preGateProgress;
248 int32 waitProgress;
249 int32 exitProgress;
250 };
251 //GateStruc
253 //======================= OS Thread related ===============================
255 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
256 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
257 void masterLoop( void *initData, VirtProcr *masterPr );
260 typedef struct
261 {
262 void *endThdPt;
263 unsigned int coreNum;
264 }
265 ThdParams;
267 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
268 ThdParams *coreLoopThdParams [ NUM_CORES ];
269 pthread_mutex_t suspendLock;
270 pthread_cond_t suspend_cond;
274 //===================== Global Vars ===================
276 volatile MasterEnv *_VMSMasterEnv;
281 //=========================== Function Prototypes =========================
284 //========== Setup and shutdown ==========
285 void
286 VMS__init();
288 void
289 VMS__init_Seq();
291 void
292 VMS__start_the_work_then_wait_until_done();
294 void
295 VMS__start_the_work_then_wait_until_done_Seq();
297 VirtProcr *
298 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
300 void
301 VMS__dissipate_procr( VirtProcr *procrToDissipate );
303 //Use this to create processor inside entry point & other places outside
304 // the VMS system boundary (IE, not run in slave nor Master)
305 VirtProcr *
306 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
308 void
309 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
311 void
312 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
314 void
315 VMS__shutdown();
317 void
318 VMS__cleanup_at_end_of_shutdown();
321 //============== Request Related ===============
323 void
324 VMS__suspend_procr( VirtProcr *callingPr );
326 inline void
327 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
329 inline void
330 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
332 void
333 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
335 void inline
336 VMS__send_dissipate_req( VirtProcr *prToDissipate );
338 inline void
339 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
341 VMSReqst *
342 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
344 inline void *
345 VMS__take_sem_reqst_from( VMSReqst *req );
347 //======================== STATS ======================
349 //===== RDTSC wrapper =====
351 #define saveTimeStampCountInto(low, high) \
352 asm volatile("RDTSC; \
353 movl %%eax, %0; \
354 movl %%edx, %1;" \
355 /* outputs */ : "=m" (low), "=m" (high)\
356 /* inputs */ : \
357 /* clobber */ : "%eax", "%edx" \
358 );
360 #define saveLowTimeStampCountInto(low) \
361 asm volatile("RDTSC; \
362 movl %%eax, %0;" \
363 /* outputs */ : "=m" (low) \
364 /* inputs */ : \
365 /* clobber */ : "%eax", "%edx" \
366 );
367 //=====
369 #include "SwitchAnimators.h"
370 #include "probes.h"
372 #endif /* _VMS_H */