view VMS.h @ 57:85b731b290f8

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