view VMS.h @ 38:17d20e5cf924

measures coreloop and masterVP times
author Me
date Tue, 07 Sep 2010 18:40:57 -0700
parents e69579a0e797
children cf3e9238aeb0
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 DEBUG 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 //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and
24 // compiled-in that saves the low part of the time stamp count just before
25 // suspending a processor and just after resuming that processor. It is
26 // saved into a field added to VirtProcr. Have to sanity-check for
27 // rollover of low portion into high portion.
28 #define MEAS__TIME_STAMP_SUSP
29 #define MEAS__TIME_MASTER
30 #define MEAS__NUM_TIMES_TO_RUN 100000
32 //This value is the number of hardware threads in the shared memory
33 // machine
34 #define NUM_CORES 4
36 // make double-num-cores scheduling slots, plus extra for master
37 //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1)
38 #define NUM_SCHED_SLOTS 3
40 #define READYTOANIMATE_RETRIES 10000
42 // stack
43 #define VIRT_PROCR_STACK_SIZE 0x10000
45 //256M of total memory for VMS application to VMS__malloc
46 #define MASSIVE_MALLOC_SIZE 0x10000000
48 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
50 #define SUCCESS 0
52 #define writeVMSQ writeCASQ
53 #define readVMSQ readCASQ
54 #define makeVMSQ makeCASQ
55 #define VMSQueueStruc CASQueueStruc
57 //#define thdAttrs NULL //For PThreads
59 typedef struct _SchedSlot SchedSlot;
60 typedef struct _VMSReqst VMSReqst;
61 typedef struct _VirtProcr VirtProcr;
63 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
64 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
65 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
66 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
68 typedef struct
69 {
70 void *endThdPt;
71 unsigned int coreNum;
72 }
73 ThdParams;
76 struct _SchedSlot
77 {
78 int workIsDone;
79 int needsProcrAssigned;
80 VirtProcr *procrAssignedToSlot;
81 };
82 //SchedSlot
84 enum ReqstType
85 {
86 semantic = 1,
87 dissipate,
88 regCreated,
89 IO
90 };
92 struct _VMSReqst
93 {
94 // VirtProcr *virtProcrFrom;
95 enum ReqstType reqType;//used for dissipate and in future for IO requests
96 void *semReqData;
98 VMSReqst *nextReqst;
99 };
100 //VMSReqst
102 struct _VirtProcr
103 { int procrID; //for debugging -- count up each time create
104 int coreAnimatedBy;
105 void *startOfStack;
106 void *stackPtr;
107 void *framePtr;
108 void *nextInstrPt;
110 void *coreLoopStartPt; //allows proto-runtime to be linked later
111 void *coreLoopFramePtr; //restore before jmp back to core loop
112 void *coreLoopStackPtr; //restore before jmp back to core loop
114 void *initialData;
116 SchedSlot *schedSlot;
117 VMSReqst *requests;
119 void *semanticData;
121 //============================= MEASUREMENT STUFF ========================
122 #ifdef MEAS__TIME_STAMP_SUSP
123 unsigned int preSuspTSCLow;
124 unsigned int postSuspTSCLow;
125 #endif
126 #ifdef MEAS__TIME_MASTER
127 unsigned int startMasterTSCLow;
128 unsigned int endMasterTSCLow;
129 #endif
130 //========================================================================
131 };
132 //VirtProcr
136 typedef struct
137 {
138 SlaveScheduler slaveScheduler;
139 RequestHandler requestHandler;
141 SchedSlot ***allSchedSlots;
142 SRSWQueueStruc **readyToAnimateQs;
143 VirtProcr **masterVPs;
145 void *semanticEnv;
146 void *OSEventStruc; //for future, when add I/O to BLIS
148 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
149 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
151 int setupComplete;
152 int masterLock;
154 //============================= MEASUREMENT STUFF ========================
155 #ifdef MEAS__TIME_STAMP_SUSP
156 Histogram *measSuspHist;
157 #endif
158 #ifdef MEAS__TIME_MASTER
159 Histogram *measMasterHist;
160 #endif
161 //========================================================================
162 }
163 MasterEnv;
166 //==========================================================
168 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
169 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
170 void masterLoop( void *initData, VirtProcr *masterPr );
173 //===================== Global Vars ===================
176 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
177 ThdParams *coreLoopThdParams [ NUM_CORES ];
178 pthread_mutex_t suspendLock;
179 pthread_cond_t suspend_cond;
181 volatile MasterEnv *_VMSMasterEnv;
183 //==========================
184 void
185 VMS__init();
187 void
188 VMS__init_Seq();
190 void
191 VMS__start_the_work_then_wait_until_done();
193 void
194 VMS__start_the_work_then_wait_until_done_Seq();
196 VirtProcr *
197 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
199 VirtProcr *
200 VMS__create_the_shutdown_procr();
202 //==========================
203 inline void
204 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
206 void
207 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister,
208 VirtProcr *reqstingPr );
210 void
211 VMS__free_request( VMSReqst *req );
213 void
214 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
216 VMSReqst *
217 VMS__take_top_request_from( VirtProcr *reqstingPr );
219 VMSReqst *
220 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq );
222 inline void *
223 VMS__take_sem_reqst_from( VMSReqst *req );
225 inline int
226 VMS__isSemanticReqst( VMSReqst *req );
228 inline int
229 VMS__isDissipateReqst( VMSReqst *req );
231 inline int
232 VMS__isCreateReqst( VMSReqst *req );
234 //==========================
236 void
237 VMS__suspend_procr( VirtProcr *callingPr );
239 void
240 VMS__dissipate_procr( VirtProcr *prToDissipate );
242 void
243 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
245 void
246 VMS__cleanup_after_shutdown();
248 //============================= Statistics ==================================
250 typedef unsigned long long TSCount;
252 //Frequency of TS counts
253 //TODO: change freq for each machine
254 #define TSCOUNT_FREQ 3180000000
256 #define saveTimeStampCountInto(low, high) \
257 asm volatile("RDTSC; \
258 movl %%eax, %0; \
259 movl %%edx, %1;" \
260 /* outputs */ : "=m" (low), "=m" (high)\
261 /* inputs */ : \
262 /* clobber */ : "%eax", "%edx" \
263 );
265 #define saveLowTimeStampCountInto(low) \
266 asm volatile("RDTSC; \
267 movl %%eax, %0;" \
268 /* outputs */ : "=m" (low) \
269 /* inputs */ : \
270 /* clobber */ : "%eax", "%edx" \
271 );
273 inline TSCount getTSCount();
275 //===================== Debug ==========================
276 int numProcrsCreated;
279 #endif /* _VMS_H */