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