view VMS.h @ 53:42dd44df1bb0

Init changed to only use VMS__malloc & uses VMS__malloc versions of utilities
author Me
date Mon, 01 Nov 2010 21:21:32 -0700
parents f59cfa31a579
children f8508572f3de
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 MASTERLOCK_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 *dataRetFromReq;//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 PrivDynArrayInfo *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 =========================
249 //========== Setup and shutdown ==========
250 void
251 VMS__init();
253 void
254 VMS__init_Seq();
256 void
257 VMS__start_the_work_then_wait_until_done();
259 void
260 VMS__start_the_work_then_wait_until_done_Seq();
262 VirtProcr *
263 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
265 void
266 VMS__dissipate_procr( VirtProcr *procrToDissipate );
268 //Use this to create processor inside entry point & other places outside
269 // the VMS system boundary (IE, not run in slave nor Master)
270 VirtProcr *
271 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
273 void
274 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
276 void
277 VMS__shutdown();
279 void
280 VMS__cleanup_at_end_of_shutdown();
283 //============== Request Related ===============
285 void
286 VMS__suspend_procr( VirtProcr *callingPr );
288 inline void
289 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
291 inline void
292 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
294 void
295 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
297 void inline
298 VMS__send_dissipate_req( VirtProcr *prToDissipate );
300 inline void
301 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
303 VMSReqst *
304 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
306 inline void *
307 VMS__take_sem_reqst_from( VMSReqst *req );
311 //======================== STATS ======================
313 //===== RDTSC wrapper =====
315 #define saveTimeStampCountInto(low, high) \
316 asm volatile("RDTSC; \
317 movl %%eax, %0; \
318 movl %%edx, %1;" \
319 /* outputs */ : "=m" (low), "=m" (high)\
320 /* inputs */ : \
321 /* clobber */ : "%eax", "%edx" \
322 );
324 #define saveLowTimeStampCountInto(low) \
325 asm volatile("RDTSC; \
326 movl %%eax, %0;" \
327 /* outputs */ : "=m" (low) \
328 /* inputs */ : \
329 /* clobber */ : "%eax", "%edx" \
330 );
331 //=====
333 #include "probes.h"
335 #endif /* _VMS_H */