view VMS.h @ 48:054006c26b92

Added instrumentation to measure master time, master lock time and create time
author Me
date Tue, 26 Oct 2010 18:18:30 -0700
parents 72373405c816
children 984f7d78bfdf
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 <pthread.h>
18 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
19 // It still does co-routines and all the mechanisms are the same, it just
20 // has only a single thread and animates VPs one at a time
21 //#define SEQUENTIAL
23 #define PRINT_DEBUG(msg) //printf(msg); fflush(stdin);
24 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin);
25 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin);
27 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
28 // compiled-in that saves the low part of the time stamp count just before
29 // suspending a processor and just after resuming that processor. It is
30 // saved into a field added to VirtProcr. Have to sanity-check for
31 // rollover of low portion into high portion.
32 #define MEAS__TIME_STAMP_SUSP
33 #define MEAS__TIME_MASTER
34 #define MEAS__NUM_TIMES_TO_RUN 100000
36 #define NUM_TSC_ROUND_TRIPS 10
38 //This value is the number of hardware threads in the shared memory
39 // machine
40 #define NUM_CORES 4
42 // balance amortizing master fixed overhead vs imbalance potential
43 #define NUM_SCHED_SLOTS 3
45 #define MIN_WORK_UNIT_CYCLES 20000
47 #define READYTOANIMATE_RETRIES 10000
49 // stack
50 #define VIRT_PROCR_STACK_SIZE 0x10000
52 //256M of total memory for VMS__malloc
53 #define MASSIVE_MALLOC_SIZE 0x10000000
55 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
57 #define SUCCESS 0
59 #define writeVMSQ writeSRSWQ
60 #define readVMSQ readSRSWQ
61 #define makeVMSQ makeSRSWQ
62 #define VMSQueueStruc SRSWQueueStruc
64 //#define thdAttrs NULL //For PThreads
66 typedef struct _SchedSlot SchedSlot;
67 typedef struct _VMSReqst VMSReqst;
68 typedef struct _VirtProcr VirtProcr;
70 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
71 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
72 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
73 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
75 typedef struct
76 {
77 void *endThdPt;
78 unsigned int coreNum;
79 }
80 ThdParams;
83 struct _SchedSlot
84 {
85 int workIsDone;
86 int needsProcrAssigned;
87 VirtProcr *procrAssignedToSlot;
88 };
89 //SchedSlot
91 enum ReqstType
92 {
93 semantic = 1,
94 dissipate,
95 regCreated,
96 IO
97 };
99 struct _VMSReqst
100 {
101 // VirtProcr *virtProcrFrom;
102 enum ReqstType reqType;//used for dissipate and in future for IO requests
103 void *semReqData;
105 VMSReqst *nextReqst;
106 };
107 //VMSReqst
109 struct _VirtProcr
110 { int procrID; //for debugging -- count up each time create
111 int coreAnimatedBy;
112 void *startOfStack;
113 void *stackPtr;
114 void *framePtr;
115 void *nextInstrPt;
117 void *coreLoopStartPt; //allows proto-runtime to be linked later
118 void *coreLoopFramePtr; //restore before jmp back to core loop
119 void *coreLoopStackPtr; //restore before jmp back to core loop
121 void *initialData;
123 SchedSlot *schedSlot;
124 VMSReqst *requests;
126 void *semanticData;
128 //============================= MEASUREMENT STUFF ========================
129 #ifdef MEAS__TIME_STAMP_SUSP
130 unsigned int preSuspTSCLow;
131 unsigned int postSuspTSCLow;
132 #endif
133 #ifdef MEAS__TIME_MASTER
134 unsigned int startMasterTSCLow;
135 unsigned int endMasterTSCLow;
136 #endif
137 //========================================================================
138 };
139 //VirtProcr
142 typedef struct
143 {
144 Histogram *createHist;
145 Histogram *masterLockHist;
146 Histogram *masterTimeHist;
147 }
148 VMSStats;
150 typedef struct
151 {
152 SlaveScheduler slaveScheduler;
153 RequestHandler requestHandler;
155 SchedSlot ***allSchedSlots;
156 VMSQueueStruc **readyToAnimateQs;
157 VirtProcr **masterVPs;
159 void *semanticEnv;
160 void *OSEventStruc; //for future, when add I/O to BLIS
162 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
163 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
165 int setupComplete;
166 int masterLock;
168 VMSStats *stats;
169 }
170 MasterEnv;
173 //==========================================================
175 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
176 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
177 void masterLoop( void *initData, VirtProcr *masterPr );
180 //===================== Global Vars ===================
183 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
184 ThdParams *coreLoopThdParams [ NUM_CORES ];
185 pthread_mutex_t suspendLock;
186 pthread_cond_t suspend_cond;
188 volatile MasterEnv *_VMSMasterEnv;
191 //==========================
192 void
193 VMS__init();
195 void
196 VMS__init_Seq();
198 void
199 VMS__start_the_work_then_wait_until_done();
201 void
202 VMS__start_the_work_then_wait_until_done_Seq();
204 VirtProcr *
205 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
207 VirtProcr *
208 VMS__create_the_shutdown_procr();
210 //==========================
211 inline void
212 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
214 void
215 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister,
216 VirtProcr *reqstingPr );
218 void
219 VMS__free_request( VMSReqst *req );
221 void
222 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
224 VMSReqst *
225 VMS__take_top_request_from( VirtProcr *reqstingPr );
227 VMSReqst *
228 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq );
230 inline void *
231 VMS__take_sem_reqst_from( VMSReqst *req );
233 inline int
234 VMS__isSemanticReqst( VMSReqst *req );
236 inline int
237 VMS__isDissipateReqst( VMSReqst *req );
239 inline int
240 VMS__isCreateReqst( VMSReqst *req );
242 //==========================
244 void
245 VMS__suspend_procr( VirtProcr *callingPr );
247 void
248 VMS__dissipate_procr( VirtProcr *prToDissipate );
250 void
251 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
253 void
254 VMS__cleanup_after_shutdown();
256 //==========================
257 void
258 measureTSCOffsetsAsCore0();
260 void
261 measureTSCOffsetsAsRemoteCore( int coreIdx );
263 //============================= Statistics ==================================
265 typedef unsigned long long TSCount;
267 //Frequency of TS counts
268 //TODO: change freq for each machine
269 #define TSCOUNT_FREQ 3180000000
271 #define saveTimeStampCountInto(low, high) \
272 asm volatile("RDTSC; \
273 movl %%eax, %0; \
274 movl %%edx, %1;" \
275 /* outputs */ : "=m" (low), "=m" (high)\
276 /* inputs */ : \
277 /* clobber */ : "%eax", "%edx" \
278 );
280 #define saveLowTimeStampCountInto(low) \
281 asm volatile("RDTSC; \
282 movl %%eax, %0;" \
283 /* outputs */ : "=m" (low) \
284 /* inputs */ : \
285 /* clobber */ : "%eax", "%edx" \
286 );
288 inline TSCount getTSC();
290 inline TSCount getTSC();
292 //===================== Debug ==========================
293 int numProcrsCreated;
296 int *pongNums;
297 TSCount *pongTimes;
298 TSCount *pingTimes;
300 #endif /* _VMS_H */