Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 55:3bac84e4e56e
Works with correct matrix mult Nov 4 -- switch animators macros, many updates
Changed all queues back to VMSQ variants #defines
correct, protected, work-stealing, with compiler switch in and out
| author | Me |
|---|---|
| date | Thu, 04 Nov 2010 18:13:18 -0700 |
| parents | f8508572f3de |
| children | 26d53313a8f2 |
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
37 //These defines turn types of bug messages on and off
38 // be sure debug messages are un-commented (next block of defines)
39 #define dbgProbes FALSE /* for issues inside probes themselves*/
40 #define dbgAppFlow TRUE /* Top level flow of application code -- general*/
41 #define dbgB2BMaster FALSE/* in coreloop, back to back master VPs*/
42 #define dbgRqstHdlr FALSE /* in request handler code*/
44 //Comment or un- the substitute half to turn on/off types of debug message
45 #define DEBUG( bool, msg) \
46 if( bool){ printf(msg); fflush(stdin);}
47 #define DEBUG1( bool, msg, param) \
48 if(bool){printf(msg, param); fflush(stdin);}
49 #define DEBUG2( bool, msg, p1, p2) \
50 //if(bool) {printf(msg, p1, p2); fflush(stdin);}
52 #define ERROR(msg) printf(msg); fflush(stdin);
53 #define ERROR1(msg, param) printf(msg, param); fflush(stdin);
54 #define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
56 //=========================== STATS =======================
58 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
59 // compiled-in that saves the low part of the time stamp count just before
60 // suspending a processor and just after resuming that processor. It is
61 // saved into a field added to VirtProcr. Have to sanity-check for
62 // rollover of low portion into high portion.
63 #define MEAS__TIME_STAMP_SUSP
64 #define MEAS__TIME_MASTER
65 #define MEAS__NUM_TIMES_TO_RUN 100000
67 //For code that calculates normalization-offset between TSC counts of
68 // different cores.
69 #define NUM_TSC_ROUND_TRIPS 10
72 //========================= Hardware related Constants =====================
73 //This value is the number of hardware threads in the shared memory
74 // machine
75 #define NUM_CORES 4
77 // tradeoff amortizing master fixed overhead vs imbalance potential
78 // when work-stealing, can make bigger, at risk of losing cache affinity
79 #define NUM_SCHED_SLOTS 5
81 #define MIN_WORK_UNIT_CYCLES 20000
83 #define MASTERLOCK_RETRIES 10000
85 // stack size in virtual processors created
86 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
88 // memory for VMS__malloc
89 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
92 //==============================
94 #define SUCCESS 0
96 #define writeVMSQ writePrivQ
97 #define readVMSQ readPrivQ
98 #define makeVMSQ makePrivQ
99 #define numInVMSQ numInPrivQ
100 #define VMSQueueStruc PrivQueueStruc
104 //===========================================================================
105 typedef unsigned long long TSCount;
107 typedef struct _SchedSlot SchedSlot;
108 typedef struct _VMSReqst VMSReqst;
109 typedef struct _VirtProcr VirtProcr;
110 typedef struct _IntervalProbe IntervalProbe;
111 typedef struct _GateStruc GateStruc;
114 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
115 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
116 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
117 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
118 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
121 //============= Requests ===========
122 //
124 enum VMSReqstType //avoid starting enums at 0, for debug reasons
125 {
126 semantic = 1,
127 createReq,
128 dissipate,
129 VMSSemantic //goes with VMSSemReqst below
130 };
132 struct _VMSReqst
133 {
134 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
135 void *semReqData;
137 VMSReqst *nextReqst;
138 };
139 //VMSReqst
141 enum VMSSemReqstType //These are equivalent to semantic requests, but for
142 { // VMS's services available directly to app, like OS
143 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
144 openFile,
145 otherIO
146 };
148 typedef struct
149 { enum VMSSemReqstType reqType;
150 VirtProcr *requestingPr;
151 char *nameStr; //for create probe
152 }
153 VMSSemReq;
156 //==================== Core data structures ===================
158 struct _SchedSlot
159 {
160 int workIsDone;
161 int needsProcrAssigned;
162 VirtProcr *procrAssignedToSlot;
163 };
164 //SchedSlot
166 struct _VirtProcr
167 { int procrID; //for debugging -- count up each time create
168 int coreAnimatedBy;
169 void *startOfStack;
170 void *stackPtr;
171 void *framePtr;
172 void *nextInstrPt;
174 void *coreLoopStartPt; //allows proto-runtime to be linked later
175 void *coreLoopFramePtr; //restore before jmp back to core loop
176 void *coreLoopStackPtr; //restore before jmp back to core loop
178 void *initialData;
180 SchedSlot *schedSlot;
181 VMSReqst *requests;
183 void *semanticData; //this lives here for the life of VP
184 void *dataRetFromReq;//values returned from plugin to VP go here
186 //=========== MEASUREMENT STUFF ==========
187 #ifdef MEAS__TIME_STAMP_SUSP
188 unsigned int preSuspTSCLow;
189 unsigned int postSuspTSCLow;
190 #endif
191 #ifdef MEAS__TIME_MASTER
192 unsigned int startMasterTSCLow;
193 unsigned int endMasterTSCLow;
194 #endif
196 float64 createPtInSecs; //have space but don't use on some configs
197 };
198 //VirtProcr
201 typedef struct
202 {
203 SlaveScheduler slaveScheduler;
204 RequestHandler requestHandler;
206 SchedSlot ***allSchedSlots;
207 VMSQueueStruc **readyToAnimateQs;
208 VirtProcr **masterVPs;
210 void *semanticEnv;
211 void *OSEventStruc; //for future, when add I/O to BLIS
212 MallocProlog *freeListHead;
213 int32 amtOfOutstandingMem; //total currently allocated
215 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
216 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
218 int32 setupComplete;
219 int32 masterLock;
221 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
222 GateStruc **workStealingGates[ NUM_CORES ]; //concurrent work-steal
223 int32 workStealingLock;
225 int32 numProcrsCreated; //gives ordering to processor creation
227 //=========== MEASUREMENT STUFF =============
228 IntervalProbe **intervalProbes;
229 PrivDynArrayInfo *dynIntervalProbesInfo;
230 HashTable *probeNameHashTbl;
231 int32 masterCreateProbeID;
232 float64 createPtInSecs;
233 }
234 MasterEnv;
236 //========================= Extra Stuff Data Strucs =======================
237 typedef struct
238 {
240 }
241 VMSExcp;
243 struct _GateStruc
244 {
245 int32 gateClosed;
246 int32 preGateProgress;
247 int32 waitProgress;
248 int32 exitProgress;
249 };
250 //GateStruc
252 //======================= OS Thread related ===============================
254 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
255 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
256 void masterLoop( void *initData, VirtProcr *masterPr );
259 typedef struct
260 {
261 void *endThdPt;
262 unsigned int coreNum;
263 }
264 ThdParams;
266 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
267 ThdParams *coreLoopThdParams [ NUM_CORES ];
268 pthread_mutex_t suspendLock;
269 pthread_cond_t suspend_cond;
273 //===================== Global Vars ===================
275 volatile MasterEnv *_VMSMasterEnv;
280 //=========================== Function Prototypes =========================
283 //========== Setup and shutdown ==========
284 void
285 VMS__init();
287 void
288 VMS__init_Seq();
290 void
291 VMS__start_the_work_then_wait_until_done();
293 void
294 VMS__start_the_work_then_wait_until_done_Seq();
296 VirtProcr *
297 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
299 void
300 VMS__dissipate_procr( VirtProcr *procrToDissipate );
302 //Use this to create processor inside entry point & other places outside
303 // the VMS system boundary (IE, not run in slave nor Master)
304 VirtProcr *
305 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
307 void
308 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
310 void
311 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
313 void
314 VMS__shutdown();
316 void
317 VMS__cleanup_at_end_of_shutdown();
320 //============== Request Related ===============
322 void
323 VMS__suspend_procr( VirtProcr *callingPr );
325 inline void
326 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
328 inline void
329 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
331 void
332 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
334 void inline
335 VMS__send_dissipate_req( VirtProcr *prToDissipate );
337 inline void
338 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
340 VMSReqst *
341 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
343 inline void *
344 VMS__take_sem_reqst_from( VMSReqst *req );
348 //======================== STATS ======================
350 //===== RDTSC wrapper =====
352 #define saveTimeStampCountInto(low, high) \
353 asm volatile("RDTSC; \
354 movl %%eax, %0; \
355 movl %%edx, %1;" \
356 /* outputs */ : "=m" (low), "=m" (high)\
357 /* inputs */ : \
358 /* clobber */ : "%eax", "%edx" \
359 );
361 #define saveLowTimeStampCountInto(low) \
362 asm volatile("RDTSC; \
363 movl %%eax, %0;" \
364 /* outputs */ : "=m" (low) \
365 /* inputs */ : \
366 /* clobber */ : "%eax", "%edx" \
367 );
368 //=====
370 #include "SwitchAnimators.h"
371 #include "probes.h"
373 #endif /* _VMS_H */
