Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view VMS.h @ 50:8f7141a9272e
Added VMS__malloc and probes, and major re-factoring to separate mallocs
| author | Me |
|---|---|
| date | Sat, 30 Oct 2010 20:54:36 -0700 |
| parents | 5388f1c2da6f |
| children | f59cfa31a579 |
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 #define PRINT_DEBUG(msg)// printf(msg); fflush(stdin);
31 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin);
32 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin);
34 #define PRINT_ERROR(msg) printf(msg); fflush(stdin);
35 #define PRINT1_ERROR(msg, param) printf(msg, param); fflush(stdin);
36 #define PRINT2_ERROR(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
39 //=========================== STATS =======================
41 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
42 // compiled-in that saves the low part of the time stamp count just before
43 // suspending a processor and just after resuming that processor. It is
44 // saved into a field added to VirtProcr. Have to sanity-check for
45 // rollover of low portion into high portion.
46 #define MEAS__TIME_STAMP_SUSP
47 #define MEAS__TIME_MASTER
48 #define MEAS__NUM_TIMES_TO_RUN 100000
50 #define NUM_TSC_ROUND_TRIPS 10
53 //========================= Hardware related Constants =====================
54 //This value is the number of hardware threads in the shared memory
55 // machine
56 #define NUM_CORES 4
58 // balance amortizing master fixed overhead vs imbalance potential
59 #define NUM_SCHED_SLOTS 3
61 #define MIN_WORK_UNIT_CYCLES 20000
63 #define READYTOANIMATE_RETRIES 10000
65 // stack
66 #define VIRT_PROCR_STACK_SIZE 0x4000
68 // memory for VMS__malloc -- 256M
69 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000
72 //==============================
74 #define SUCCESS 0
76 #define writeVMSQ writeSRSWQ
77 #define readVMSQ readSRSWQ
78 #define makeVMSQ makeSRSWQ
79 #define VMSQueueStruc SRSWQueueStruc
83 //===========================================================================
84 typedef unsigned long long TSCount;
86 typedef struct _SchedSlot SchedSlot;
87 typedef struct _VMSReqst VMSReqst;
88 typedef struct _VirtProcr VirtProcr;
89 typedef struct _IntervalProbe IntervalProbe;
91 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
92 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
93 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
94 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
95 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
98 //============= Requests ===========
99 //
101 enum VMSReqstType //avoid starting enums at 0, for debug reasons
102 {
103 semantic = 1,
104 createReq,
105 dissipate,
106 VMSSemantic //goes with VMSSemReqst below
107 };
109 struct _VMSReqst
110 {
111 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
112 void *semReqData;
114 VMSReqst *nextReqst;
115 };
116 //VMSReqst
118 enum VMSSemReqstType //These are equivalent to semantic requests, but for
119 { // VMS's services available directly to app, like OS
120 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
121 openFile,
122 otherIO
123 };
125 typedef struct
126 { enum VMSSemReqstType reqType;
127 VirtProcr *requestingPr;
128 char *nameStr; //for create probe
129 }
130 VMSSemReq;
133 //==================== Core data structures ===================
135 struct _SchedSlot
136 {
137 int workIsDone;
138 int needsProcrAssigned;
139 VirtProcr *procrAssignedToSlot;
140 };
141 //SchedSlot
143 struct _VirtProcr
144 { int procrID; //for debugging -- count up each time create
145 int coreAnimatedBy;
146 void *startOfStack;
147 void *stackPtr;
148 void *framePtr;
149 void *nextInstrPt;
151 void *coreLoopStartPt; //allows proto-runtime to be linked later
152 void *coreLoopFramePtr; //restore before jmp back to core loop
153 void *coreLoopStackPtr; //restore before jmp back to core loop
155 void *initialData;
157 SchedSlot *schedSlot;
158 VMSReqst *requests;
160 void *semanticData; //this lives here for the life of VP
161 void *dataReturnedFromReq;//values returned from plugin to VP go here
163 //=========== MEASUREMENT STUFF ==========
164 #ifdef MEAS__TIME_STAMP_SUSP
165 unsigned int preSuspTSCLow;
166 unsigned int postSuspTSCLow;
167 #endif
168 #ifdef MEAS__TIME_MASTER
169 unsigned int startMasterTSCLow;
170 unsigned int endMasterTSCLow;
171 #endif
173 float64 createPtInSecs; //have space but don't use on some configs
174 };
175 //VirtProcr
178 typedef struct
179 {
180 SlaveScheduler slaveScheduler;
181 RequestHandler requestHandler;
183 SchedSlot ***allSchedSlots;
184 SRSWQueueStruc **readyToAnimateQs;
185 VirtProcr **masterVPs;
187 void *semanticEnv;
188 void *OSEventStruc; //for future, when add I/O to BLIS
189 MallocProlog *freeListHead;
190 int32 amtOfOutstandingMem; //total currently allocated
192 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
193 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
195 int32 setupComplete;
196 int32 masterLock;
198 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
199 int32 numProcrsCreated; //gives ordering to processor creation
201 //=========== MEASUREMENT STUFF =============
202 IntervalProbe **intervalProbes;
203 DynArrayInfo *dynIntervalProbesInfo;
204 HashTable *probeNameHashTbl;
205 int32 masterCreateProbeID;
206 float64 createPtInSecs;
207 }
208 MasterEnv;
213 //======================= OS Thread related ===============================
215 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
216 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
217 void masterLoop( void *initData, VirtProcr *masterPr );
220 typedef struct
221 {
222 void *endThdPt;
223 unsigned int coreNum;
224 }
225 ThdParams;
227 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
228 ThdParams *coreLoopThdParams [ NUM_CORES ];
229 pthread_mutex_t suspendLock;
230 pthread_cond_t suspend_cond;
234 //===================== Global Vars ===================
236 volatile MasterEnv *_VMSMasterEnv;
241 //=========================== Function Prototypes =========================
243 //============== Setup and shutdown =============
244 void
245 VMS__init();
247 void
248 VMS__init_Seq();
250 void
251 VMS__start_the_work_then_wait_until_done();
253 void
254 VMS__start_the_work_then_wait_until_done_Seq();
256 VirtProcr *
257 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
259 //Use this to create processor inside entry point & other places outside
260 // the VMS system boundary (IE, not run in slave nor Master)
261 VirtProcr *
262 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
264 VirtProcr *
265 VMS__create_the_shutdown_procr();
267 void
268 VMS__cleanup_after_shutdown();
271 //============== Request Related ===============
273 void
274 VMS__suspend_procr( VirtProcr *callingPr );
276 inline void
277 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
279 void
280 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
282 void
283 VMS__free_request( VMSReqst *req );
285 void
286 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
288 VMSReqst *
289 VMS__take_top_request_from( VirtProcr *reqstingPr );
291 VMSReqst *
292 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
294 inline void *
295 VMS__take_sem_reqst_from( VMSReqst *req );
297 inline int
298 VMS__isSemanticReqst( VMSReqst *req );
300 inline int
301 VMS__isDissipateReqst( VMSReqst *req );
303 inline int
304 VMS__isCreateReqst( VMSReqst *req );
306 //==========================
308 void inline
309 VMS__dissipate_procr( VirtProcr *prToDissipate );
311 void
312 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
316 //===================== RDTSC wrapper ==================
318 #define saveTimeStampCountInto(low, high) \
319 asm volatile("RDTSC; \
320 movl %%eax, %0; \
321 movl %%edx, %1;" \
322 /* outputs */ : "=m" (low), "=m" (high)\
323 /* inputs */ : \
324 /* clobber */ : "%eax", "%edx" \
325 );
327 #define saveLowTimeStampCountInto(low) \
328 asm volatile("RDTSC; \
329 movl %%eax, %0;" \
330 /* outputs */ : "=m" (low) \
331 /* inputs */ : \
332 /* clobber */ : "%eax", "%edx" \
333 );
335 //======================== STATS ======================
337 #include "probes.h"
339 #endif /* _VMS_H */
