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