| rev |
line source |
|
Me@0
|
1 /*
|
|
Me@0
|
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
|
|
Me@0
|
3 * Licensed under GNU General Public License version 2
|
|
Me@0
|
4 *
|
|
Me@0
|
5 * Author: seanhalle@yahoo.com
|
|
Me@0
|
6 *
|
|
Me@0
|
7 */
|
|
Me@0
|
8
|
|
Me@0
|
9 #ifndef _VMS_H
|
|
Me@0
|
10 #define _VMS_H
|
|
Me@25
|
11 #define __USE_GNU
|
|
Me@0
|
12
|
|
Me@0
|
13 #include "VMS_primitive_data_types.h"
|
|
Me@0
|
14 #include "Queue_impl/BlockingQueue.h"
|
|
Me@38
|
15 #include "Histogram/Histogram.h"
|
|
Me@26
|
16 #include <pthread.h>
|
|
Me@0
|
17
|
|
Me@31
|
18 //When DEBUG is defined, VMS does sequential exe in the main thread
|
|
Me@31
|
19 // It still does co-routines and all the mechanisms are the same, it just
|
|
Me@31
|
20 // has only a single thread and animates VPs one at a time
|
|
Me@38
|
21 #define SEQUENTIAL
|
|
Me@38
|
22
|
|
Me@38
|
23 //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and
|
|
Me@38
|
24 // compiled-in that saves the low part of the time stamp count just before
|
|
Me@38
|
25 // suspending a processor and just after resuming that processor. It is
|
|
Me@38
|
26 // saved into a field added to VirtProcr. Have to sanity-check for
|
|
Me@38
|
27 // rollover of low portion into high portion.
|
|
Me@38
|
28 #define MEAS__TIME_STAMP_SUSP
|
|
Me@38
|
29 #define MEAS__TIME_MASTER
|
|
Me@38
|
30 #define MEAS__NUM_TIMES_TO_RUN 100000
|
|
Me@31
|
31
|
|
Me@23
|
32 //This value is the number of hardware threads in the shared memory
|
|
Me@23
|
33 // machine
|
|
Me@23
|
34 #define NUM_CORES 4
|
|
Me@23
|
35
|
|
Me@23
|
36 // make double-num-cores scheduling slots, plus extra for master
|
|
Me@29
|
37 //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1)
|
|
Me@29
|
38 #define NUM_SCHED_SLOTS 3
|
|
Me@23
|
39
|
|
Me@31
|
40 #define READYTOANIMATE_RETRIES 10000
|
|
Me@31
|
41
|
|
Me@31
|
42 // stack
|
|
Me@31
|
43 #define VIRT_PROCR_STACK_SIZE 0x10000
|
|
Me@30
|
44
|
|
Me@30
|
45 //256M of total memory for VMS application to VMS__malloc
|
|
Me@30
|
46 #define MASSIVE_MALLOC_SIZE 0x10000000
|
|
Me@30
|
47
|
|
Me@30
|
48 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
|
|
Me@0
|
49
|
|
Me@0
|
50 #define SUCCESS 0
|
|
Me@0
|
51
|
|
Me@30
|
52 #define writeVMSQ writeCASQ
|
|
Me@30
|
53 #define readVMSQ readCASQ
|
|
Me@30
|
54 #define makeVMSQ makeCASQ
|
|
Me@30
|
55 #define VMSQueueStruc CASQueueStruc
|
|
Me@26
|
56
|
|
Me@13
|
57 //#define thdAttrs NULL //For PThreads
|
|
Me@0
|
58
|
|
Me@16
|
59 typedef struct _SchedSlot SchedSlot;
|
|
Me@26
|
60 typedef struct _VMSReqst VMSReqst;
|
|
Me@5
|
61 typedef struct _VirtProcr VirtProcr;
|
|
Me@0
|
62
|
|
Me@31
|
63 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
|
|
Me@23
|
64 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
|
|
Me@23
|
65 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
|
|
Me@23
|
66 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
|
|
Me@16
|
67
|
|
Me@0
|
68 typedef struct
|
|
Me@0
|
69 {
|
|
Me@7
|
70 void *endThdPt;
|
|
Me@7
|
71 unsigned int coreNum;
|
|
Me@0
|
72 }
|
|
Me@0
|
73 ThdParams;
|
|
Me@0
|
74
|
|
Me@16
|
75
|
|
Me@5
|
76 struct _SchedSlot
|
|
Me@5
|
77 {
|
|
Me@5
|
78 int workIsDone;
|
|
Me@5
|
79 int needsProcrAssigned;
|
|
Me@5
|
80 VirtProcr *procrAssignedToSlot;
|
|
Me@5
|
81 };
|
|
Me@16
|
82 //SchedSlot
|
|
Me@16
|
83
|
|
Me@23
|
84 enum ReqstType
|
|
Me@23
|
85 {
|
|
Me@23
|
86 semantic = 1,
|
|
Me@23
|
87 dissipate,
|
|
Me@24
|
88 regCreated,
|
|
Me@23
|
89 IO
|
|
Me@23
|
90 };
|
|
Me@5
|
91
|
|
Me@24
|
92 struct _VMSReqst
|
|
Me@16
|
93 {
|
|
Me@23
|
94 // VirtProcr *virtProcrFrom;
|
|
Me@24
|
95 enum ReqstType reqType;//used for dissipate and in future for IO requests
|
|
Me@23
|
96 void *semReqData;
|
|
Me@16
|
97
|
|
Me@23
|
98 VMSReqst *nextReqst;
|
|
Me@16
|
99 };
|
|
Me@24
|
100 //VMSReqst
|
|
Me@5
|
101
|
|
Me@5
|
102 struct _VirtProcr
|
|
Me@13
|
103 { int procrID; //for debugging -- count up each time create
|
|
Me@16
|
104 int coreAnimatedBy;
|
|
Me@23
|
105 void *startOfStack;
|
|
Me@5
|
106 void *stackPtr;
|
|
Me@5
|
107 void *framePtr;
|
|
Me@5
|
108 void *nextInstrPt;
|
|
Me@16
|
109
|
|
Me@5
|
110 void *coreLoopStartPt; //allows proto-runtime to be linked later
|
|
Me@16
|
111 void *coreLoopFramePtr; //restore before jmp back to core loop
|
|
Me@16
|
112 void *coreLoopStackPtr; //restore before jmp back to core loop
|
|
Me@5
|
113
|
|
Me@5
|
114 void *initialData;
|
|
Me@5
|
115
|
|
Me@5
|
116 SchedSlot *schedSlot;
|
|
Me@23
|
117 VMSReqst *requests;
|
|
Me@5
|
118
|
|
Me@5
|
119 void *semanticData;
|
|
Me@38
|
120
|
|
Me@38
|
121 //============================= MEASUREMENT STUFF ========================
|
|
Me@38
|
122 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@38
|
123 unsigned int preSuspTSCLow;
|
|
Me@38
|
124 unsigned int postSuspTSCLow;
|
|
Me@38
|
125 #endif
|
|
Me@38
|
126 #ifdef MEAS__TIME_MASTER
|
|
Me@38
|
127 unsigned int startMasterTSCLow;
|
|
Me@38
|
128 unsigned int endMasterTSCLow;
|
|
Me@38
|
129 #endif
|
|
Me@38
|
130 //========================================================================
|
|
Me@5
|
131 };
|
|
Me@16
|
132 //VirtProcr
|
|
Me@5
|
133
|
|
Me@5
|
134
|
|
Me@16
|
135
|
|
Me@0
|
136 typedef struct
|
|
Me@0
|
137 {
|
|
Me@31
|
138 SlaveScheduler slaveScheduler;
|
|
Me@31
|
139 RequestHandler requestHandler;
|
|
Me@0
|
140
|
|
Me@31
|
141 SchedSlot ***allSchedSlots;
|
|
Me@31
|
142 SRSWQueueStruc **readyToAnimateQs;
|
|
Me@31
|
143 VirtProcr **masterVPs;
|
|
Me@25
|
144
|
|
Me@31
|
145 void *semanticEnv;
|
|
Me@31
|
146 void *OSEventStruc; //for future, when add I/O to BLIS
|
|
Me@16
|
147
|
|
Me@31
|
148 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
|
|
Me@31
|
149 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
|
|
Me@25
|
150
|
|
Me@31
|
151 int setupComplete;
|
|
Me@31
|
152 int masterLock;
|
|
Me@38
|
153
|
|
Me@38
|
154 //============================= MEASUREMENT STUFF ========================
|
|
Me@38
|
155 #ifdef MEAS__TIME_STAMP_SUSP
|
|
Me@38
|
156 Histogram *measSuspHist;
|
|
Me@38
|
157 #endif
|
|
Me@38
|
158 #ifdef MEAS__TIME_MASTER
|
|
Me@38
|
159 Histogram *measMasterHist;
|
|
Me@38
|
160 #endif
|
|
Me@38
|
161 //========================================================================
|
|
Me@0
|
162 }
|
|
Me@0
|
163 MasterEnv;
|
|
Me@0
|
164
|
|
Me@0
|
165
|
|
Me@16
|
166 //==========================================================
|
|
Me@0
|
167
|
|
Me@25
|
168 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@28
|
169 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@7
|
170 void masterLoop( void *initData, VirtProcr *masterPr );
|
|
Me@0
|
171
|
|
Me@0
|
172
|
|
Me@0
|
173 //===================== Global Vars ===================
|
|
Me@0
|
174
|
|
Me@5
|
175
|
|
Me@26
|
176 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
|
|
Me@26
|
177 ThdParams *coreLoopThdParams [ NUM_CORES ];
|
|
Me@26
|
178 pthread_mutex_t suspendLock;
|
|
Me@26
|
179 pthread_cond_t suspend_cond;
|
|
Me@0
|
180
|
|
Me@13
|
181 volatile MasterEnv *_VMSMasterEnv;
|
|
Me@5
|
182
|
|
Me@7
|
183 //==========================
|
|
Me@7
|
184 void
|
|
Me@7
|
185 VMS__init();
|
|
Me@7
|
186
|
|
Me@7
|
187 void
|
|
Me@28
|
188 VMS__init_Seq();
|
|
Me@28
|
189
|
|
Me@28
|
190 void
|
|
Me@24
|
191 VMS__start_the_work_then_wait_until_done();
|
|
Me@7
|
192
|
|
Me@28
|
193 void
|
|
Me@28
|
194 VMS__start_the_work_then_wait_until_done_Seq();
|
|
Me@28
|
195
|
|
Me@7
|
196 VirtProcr *
|
|
Me@7
|
197 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@7
|
198
|
|
Me@23
|
199 VirtProcr *
|
|
Me@23
|
200 VMS__create_the_shutdown_procr();
|
|
Me@23
|
201
|
|
Me@24
|
202 //==========================
|
|
Me@7
|
203 inline void
|
|
Me@24
|
204 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
|
|
Me@7
|
205
|
|
Me@7
|
206 void
|
|
Me@38
|
207 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister,
|
|
Me@24
|
208 VirtProcr *reqstingPr );
|
|
Me@24
|
209
|
|
Me@24
|
210 void
|
|
Me@24
|
211 VMS__free_request( VMSReqst *req );
|
|
Me@23
|
212
|
|
Me@23
|
213 void
|
|
Me@23
|
214 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
|
|
Me@23
|
215
|
|
Me@24
|
216 VMSReqst *
|
|
Me@24
|
217 VMS__take_top_request_from( VirtProcr *reqstingPr );
|
|
Me@24
|
218
|
|
Me@31
|
219 VMSReqst *
|
|
Me@31
|
220 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq );
|
|
Me@31
|
221
|
|
Me@24
|
222 inline void *
|
|
Me@24
|
223 VMS__take_sem_reqst_from( VMSReqst *req );
|
|
Me@24
|
224
|
|
Me@24
|
225 inline int
|
|
Me@24
|
226 VMS__isSemanticReqst( VMSReqst *req );
|
|
Me@24
|
227
|
|
Me@24
|
228 inline int
|
|
Me@24
|
229 VMS__isDissipateReqst( VMSReqst *req );
|
|
Me@24
|
230
|
|
Me@24
|
231 inline int
|
|
Me@24
|
232 VMS__isCreateReqst( VMSReqst *req );
|
|
Me@24
|
233
|
|
Me@24
|
234 //==========================
|
|
Me@24
|
235
|
|
Me@23
|
236 void
|
|
Me@23
|
237 VMS__suspend_procr( VirtProcr *callingPr );
|
|
Me@23
|
238
|
|
Me@23
|
239 void
|
|
Me@23
|
240 VMS__dissipate_procr( VirtProcr *prToDissipate );
|
|
Me@23
|
241
|
|
Me@23
|
242 void
|
|
Me@29
|
243 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
|
|
Me@29
|
244
|
|
Me@29
|
245 void
|
|
Me@29
|
246 VMS__cleanup_after_shutdown();
|
|
Me@7
|
247
|
|
Me@13
|
248 //============================= Statistics ==================================
|
|
Me@13
|
249
|
|
Me@13
|
250 typedef unsigned long long TSCount;
|
|
Me@13
|
251
|
|
Me@25
|
252 //Frequency of TS counts
|
|
Me@25
|
253 //TODO: change freq for each machine
|
|
Me@25
|
254 #define TSCOUNT_FREQ 3180000000
|
|
Me@25
|
255
|
|
Me@13
|
256 #define saveTimeStampCountInto(low, high) \
|
|
Me@13
|
257 asm volatile("RDTSC; \
|
|
Me@13
|
258 movl %%eax, %0; \
|
|
Me@13
|
259 movl %%edx, %1;" \
|
|
Me@13
|
260 /* outputs */ : "=m" (low), "=m" (high)\
|
|
Me@13
|
261 /* inputs */ : \
|
|
Me@13
|
262 /* clobber */ : "%eax", "%edx" \
|
|
Me@13
|
263 );
|
|
Me@13
|
264
|
|
Me@38
|
265 #define saveLowTimeStampCountInto(low) \
|
|
Me@38
|
266 asm volatile("RDTSC; \
|
|
Me@38
|
267 movl %%eax, %0;" \
|
|
Me@38
|
268 /* outputs */ : "=m" (low) \
|
|
Me@38
|
269 /* inputs */ : \
|
|
Me@38
|
270 /* clobber */ : "%eax", "%edx" \
|
|
Me@38
|
271 );
|
|
Me@38
|
272
|
|
Me@13
|
273 inline TSCount getTSCount();
|
|
Me@13
|
274
|
|
Me@23
|
275 //===================== Debug ==========================
|
|
Me@13
|
276 int numProcrsCreated;
|
|
Me@0
|
277
|
|
Me@23
|
278
|
|
Me@0
|
279 #endif /* _VMS_H */
|
|
Me@0
|
280
|