view VMS.h @ 66:bf08108405cc

Added recycle pool -- will merge later -- need to get PLDI results for now
author Me
date Mon, 15 Nov 2010 12:11:24 -0800
parents 13b22ffb8a2f
children
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 dbgAppFlow TRUE /* Top level flow of application code -- general*/
41 #define dbgProbes FALSE /* for issues inside probes themselves*/
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__TIME_PLUGIN
67 //#define MEAS__TIME_MALLOC
68 //#define MEAS__TIME_MASTER_LOCK
69 #define MEAS__NUM_TIMES_TO_RUN 100000
71 //For code that calculates normalization-offset between TSC counts of
72 // different cores.
73 #define NUM_TSC_ROUND_TRIPS 10
76 //========================= Hardware related Constants =====================
77 //This value is the number of hardware threads in the shared memory
78 // machine
79 #define NUM_CORES 4
81 // tradeoff amortizing master fixed overhead vs imbalance potential
82 // when work-stealing, can make bigger, at risk of losing cache affinity
83 #define NUM_SCHED_SLOTS 5
85 #define MIN_WORK_UNIT_CYCLES 20000
87 #define MASTERLOCK_RETRIES 10000
89 // stack size in virtual processors created
90 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
92 // memory for VMS__malloc
93 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
96 //==============================
98 #define SUCCESS 0
100 #define writeVMSQ writePrivQ
101 #define readVMSQ readPrivQ
102 #define makeVMSQ makeVMSPrivQ
103 #define numInVMSQ numInPrivQ
104 #define VMSQueueStruc PrivQueueStruc
108 //===========================================================================
109 typedef unsigned long long TSCount;
111 typedef struct _SchedSlot SchedSlot;
112 typedef struct _VMSReqst VMSReqst;
113 typedef struct _VirtProcr VirtProcr;
114 typedef struct _IntervalProbe IntervalProbe;
115 typedef struct _GateStruc GateStruc;
118 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
119 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
120 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
121 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
122 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
125 //============= Requests ===========
126 //
128 enum VMSReqstType //avoid starting enums at 0, for debug reasons
129 {
130 semantic = 1,
131 createReq,
132 dissipate,
133 VMSSemantic //goes with VMSSemReqst below
134 };
136 struct _VMSReqst
137 {
138 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
139 void *semReqData;
141 VMSReqst *nextReqst;
142 };
143 //VMSReqst
145 enum VMSSemReqstType //These are equivalent to semantic requests, but for
146 { // VMS's services available directly to app, like OS
147 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
148 openFile,
149 otherIO
150 };
152 typedef struct
153 { enum VMSSemReqstType reqType;
154 VirtProcr *requestingPr;
155 char *nameStr; //for create probe
156 }
157 VMSSemReq;
160 //==================== Core data structures ===================
162 struct _SchedSlot
163 {
164 int workIsDone;
165 int needsProcrAssigned;
166 VirtProcr *procrAssignedToSlot;
167 };
168 //SchedSlot
170 /*WARNING: re-arranging this data structure could cause VP switching
171 * assembly code to fail -- hard-codes offsets of fields
172 */
173 struct _VirtProcr
174 { int procrID; //for debugging -- count up each time create
175 int coreAnimatedBy;
176 void *startOfStack;
177 void *stackPtr;
178 void *framePtr;
179 void *nextInstrPt;
181 void *coreLoopStartPt; //allows proto-runtime to be linked later
182 void *coreLoopFramePtr; //restore before jmp back to core loop
183 void *coreLoopStackPtr; //restore before jmp back to core loop
185 void *initialData;
187 SchedSlot *schedSlot;
188 VMSReqst *requests;
190 void *semanticData; //this lives here for the life of VP
191 void *dataRetFromReq;//values returned from plugin to VP go here
193 //=========== MEASUREMENT STUFF ==========
194 #ifdef MEAS__TIME_STAMP_SUSP
195 unsigned int preSuspTSCLow;
196 unsigned int postSuspTSCLow;
197 #endif
198 #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
199 unsigned int startMasterTSCLow;
200 unsigned int endMasterTSCLow;
201 #endif
202 //========================================
204 float64 createPtInSecs; //have space but don't use on some configs
205 };
206 //VirtProcr
209 /*WARNING: re-arranging this data structure could cause VP-switching
210 * assembly code to fail -- hard-codes offsets of fields
211 * (because -O3 messes with things otherwise)
212 */
213 typedef struct
214 {
215 SlaveScheduler slaveScheduler;
216 RequestHandler requestHandler;
218 SchedSlot ***allSchedSlots;
219 VMSQueueStruc **readyToAnimateQs;
220 VirtProcr **masterVPs;
222 void *semanticEnv;
223 void *OSEventStruc; //for future, when add I/O to BLIS
224 MallocProlog *freeListHead;
225 int32 amtOfOutstandingMem; //total currently allocated
227 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
228 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
230 int32 setupComplete;
231 int32 masterLock;
233 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
234 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
235 int32 workStealingLock;
237 int32 numProcrsCreated; //gives ordering to processor creation
239 //=========== MEASUREMENT STUFF =============
240 IntervalProbe **intervalProbes;
241 PrivDynArrayInfo *dynIntervalProbesInfo;
242 HashTable *probeNameHashTbl;
243 int32 masterCreateProbeID;
244 float64 createPtInSecs;
245 #ifdef MEAS__TIME_PLUGIN
246 Histogram *pluginLowTimeHist;
247 Histogram *pluginHighTimeHist;
248 #endif
249 #ifdef MEAS__TIME_MALLOC
250 Histogram *mallocTimeHist;
251 Histogram *freeTimeHist;
252 #endif
253 #ifdef MEAS__TIME_MASTER_LOCK
254 Histogram *masterLockLowTimeHist;
255 Histogram *masterLockHighTimeHist;
256 #endif
257 }
258 MasterEnv;
260 //========================= Extra Stuff Data Strucs =======================
261 typedef struct
262 {
264 }
265 VMSExcp;
267 struct _GateStruc
268 {
269 int32 gateClosed;
270 int32 preGateProgress;
271 int32 waitProgress;
272 int32 exitProgress;
273 };
274 //GateStruc
276 //======================= OS Thread related ===============================
278 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
279 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
280 void masterLoop( void *initData, VirtProcr *masterPr );
283 typedef struct
284 {
285 void *endThdPt;
286 unsigned int coreNum;
287 }
288 ThdParams;
290 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
291 ThdParams *coreLoopThdParams [ NUM_CORES ];
292 pthread_mutex_t suspendLock;
293 pthread_cond_t suspend_cond;
297 //===================== Global Vars ===================
299 volatile MasterEnv *_VMSMasterEnv;
304 //=========================== Function Prototypes =========================
307 //========== Setup and shutdown ==========
308 void
309 VMS__init();
311 void
312 VMS__init_Seq();
314 void
315 VMS__start_the_work_then_wait_until_done();
317 void
318 VMS__start_the_work_then_wait_until_done_Seq();
320 VirtProcr *
321 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
323 void
324 VMS__dissipate_procr( VirtProcr *procrToDissipate );
326 //Use this to create processor inside entry point & other places outside
327 // the VMS system boundary (IE, not run in slave nor Master)
328 VirtProcr *
329 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
331 void
332 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
334 void
335 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
337 void
338 VMS__shutdown();
340 void
341 VMS__cleanup_at_end_of_shutdown();
343 void *
344 VMS__give_sem_env_for( VirtProcr *animPr );
347 //============== Request Related ===============
349 void
350 VMS__suspend_procr( VirtProcr *callingPr );
352 inline void
353 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
355 inline void
356 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
358 void
359 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
361 void inline
362 VMS__send_dissipate_req( VirtProcr *prToDissipate );
364 inline void
365 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
367 VMSReqst *
368 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
370 inline void *
371 VMS__take_sem_reqst_from( VMSReqst *req );
373 //======================== STATS ======================
375 //===== RDTSC wrapper =====
377 #define saveTimeStampCountInto(low, high) \
378 asm volatile("RDTSC; \
379 movl %%eax, %0; \
380 movl %%edx, %1;" \
381 /* outputs */ : "=m" (low), "=m" (high)\
382 /* inputs */ : \
383 /* clobber */ : "%eax", "%edx" \
384 );
386 #define saveLowTimeStampCountInto(low) \
387 asm volatile("RDTSC; \
388 movl %%eax, %0;" \
389 /* outputs */ : "=m" (low) \
390 /* inputs */ : \
391 /* clobber */ : "%eax", "%edx" \
392 );
393 //=====
395 #include "SwitchAnimators.h"
396 #include "probes.h"
397 #include "vutilities.h"
399 #endif /* _VMS_H */