| 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@26
|
15 #include <pthread.h>
|
|
Me@0
|
16
|
|
Me@23
|
17 //This value is the number of hardware threads in the shared memory
|
|
Me@23
|
18 // machine
|
|
Me@23
|
19 #define NUM_CORES 4
|
|
Me@23
|
20
|
|
Me@23
|
21 // make double-num-cores scheduling slots, plus extra for master
|
|
Me@29
|
22 //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1)
|
|
Me@29
|
23 #define NUM_SCHED_SLOTS 3
|
|
Me@23
|
24
|
|
Me@30
|
25 // 8K stack
|
|
Me@30
|
26 #define VIRT_PROCR_STACK_SIZE 0x20000
|
|
Me@30
|
27
|
|
Me@30
|
28 //256M of total memory for VMS application to VMS__malloc
|
|
Me@30
|
29 #define MASSIVE_MALLOC_SIZE 0x10000000
|
|
Me@30
|
30
|
|
Me@30
|
31 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
|
|
Me@0
|
32
|
|
Me@0
|
33 #define SUCCESS 0
|
|
Me@0
|
34
|
|
Me@30
|
35 #define writeVMSQ writeCASQ
|
|
Me@30
|
36 #define readVMSQ readCASQ
|
|
Me@30
|
37 #define makeVMSQ makeCASQ
|
|
Me@30
|
38 #define VMSQueueStruc CASQueueStruc
|
|
Me@26
|
39
|
|
Me@13
|
40 //#define thdAttrs NULL //For PThreads
|
|
Me@0
|
41
|
|
Me@16
|
42 typedef struct _SchedSlot SchedSlot;
|
|
Me@26
|
43 typedef struct _VMSReqst VMSReqst;
|
|
Me@5
|
44 typedef struct _VirtProcr VirtProcr;
|
|
Me@0
|
45
|
|
Me@23
|
46 typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv
|
|
Me@23
|
47 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
|
|
Me@23
|
48 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
|
|
Me@23
|
49 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
|
|
Me@16
|
50
|
|
Me@0
|
51 typedef struct
|
|
Me@0
|
52 {
|
|
Me@7
|
53 void *endThdPt;
|
|
Me@7
|
54 unsigned int coreNum;
|
|
Me@16
|
55 // void *framePtr;
|
|
Me@16
|
56 // void *stackPtr;
|
|
Me@0
|
57 }
|
|
Me@0
|
58 ThdParams;
|
|
Me@0
|
59
|
|
Me@16
|
60
|
|
Me@5
|
61 struct _SchedSlot
|
|
Me@5
|
62 {
|
|
Me@5
|
63 int workIsDone;
|
|
Me@5
|
64 int needsProcrAssigned;
|
|
Me@5
|
65 VirtProcr *procrAssignedToSlot;
|
|
Me@5
|
66 };
|
|
Me@16
|
67 //SchedSlot
|
|
Me@16
|
68
|
|
Me@23
|
69 enum ReqstType
|
|
Me@23
|
70 {
|
|
Me@23
|
71 semantic = 1,
|
|
Me@23
|
72 dissipate,
|
|
Me@24
|
73 regCreated,
|
|
Me@23
|
74 IO
|
|
Me@23
|
75 };
|
|
Me@5
|
76
|
|
Me@24
|
77 struct _VMSReqst
|
|
Me@16
|
78 {
|
|
Me@23
|
79 // VirtProcr *virtProcrFrom;
|
|
Me@24
|
80 enum ReqstType reqType;//used for dissipate and in future for IO requests
|
|
Me@23
|
81 void *semReqData;
|
|
Me@16
|
82
|
|
Me@23
|
83 VMSReqst *nextReqst;
|
|
Me@16
|
84 };
|
|
Me@24
|
85 //VMSReqst
|
|
Me@5
|
86
|
|
Me@5
|
87 struct _VirtProcr
|
|
Me@13
|
88 { int procrID; //for debugging -- count up each time create
|
|
Me@16
|
89 int coreAnimatedBy;
|
|
Me@23
|
90 void *startOfStack;
|
|
Me@5
|
91 void *stackPtr;
|
|
Me@5
|
92 void *framePtr;
|
|
Me@5
|
93 void *nextInstrPt;
|
|
Me@16
|
94
|
|
Me@5
|
95 void *coreLoopStartPt; //allows proto-runtime to be linked later
|
|
Me@16
|
96 void *coreLoopFramePtr; //restore before jmp back to core loop
|
|
Me@16
|
97 void *coreLoopStackPtr; //restore before jmp back to core loop
|
|
Me@5
|
98
|
|
Me@5
|
99 void *initialData;
|
|
Me@5
|
100
|
|
Me@5
|
101 SchedSlot *schedSlot;
|
|
Me@23
|
102 VMSReqst *requests;
|
|
Me@5
|
103
|
|
Me@5
|
104 void *semanticData;
|
|
Me@5
|
105 };
|
|
Me@16
|
106 //VirtProcr
|
|
Me@5
|
107
|
|
Me@5
|
108
|
|
Me@16
|
109
|
|
Me@0
|
110 typedef struct
|
|
Me@0
|
111 {
|
|
Me@30
|
112 SlaveScheduler slaveScheduler;
|
|
Me@30
|
113 RequestHandler requestHandler;
|
|
Me@0
|
114
|
|
Me@30
|
115 SchedSlot **schedSlots;
|
|
Me@30
|
116 SchedSlot **filledSlots;
|
|
Me@30
|
117 int numToPrecede;
|
|
Me@5
|
118
|
|
Me@30
|
119 volatile int stillRunning;
|
|
Me@0
|
120
|
|
Me@30
|
121 VirtProcr *masterVirtPr;
|
|
Me@25
|
122
|
|
Me@30
|
123 void *semanticEnv;
|
|
Me@30
|
124 void *OSEventStruc; //for future, when add I/O to BLIS
|
|
Me@16
|
125
|
|
Me@30
|
126 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
|
|
Me@25
|
127
|
|
Me@30
|
128 int setupComplete;
|
|
Me@30
|
129
|
|
Me@30
|
130 void *mallocChunk;
|
|
Me@0
|
131 }
|
|
Me@0
|
132 MasterEnv;
|
|
Me@0
|
133
|
|
Me@0
|
134
|
|
Me@16
|
135 //==========================================================
|
|
Me@0
|
136
|
|
Me@25
|
137 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@28
|
138 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@7
|
139 void masterLoop( void *initData, VirtProcr *masterPr );
|
|
Me@0
|
140
|
|
Me@0
|
141
|
|
Me@0
|
142 //===================== Global Vars ===================
|
|
Me@0
|
143
|
|
Me@5
|
144
|
|
Me@26
|
145 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
|
|
Me@26
|
146 ThdParams *coreLoopThdParams [ NUM_CORES ];
|
|
Me@26
|
147 pthread_mutex_t suspendLock;
|
|
Me@26
|
148 pthread_cond_t suspend_cond;
|
|
Me@0
|
149
|
|
Me@13
|
150 volatile MasterEnv *_VMSMasterEnv;
|
|
Me@5
|
151
|
|
Me@5
|
152 //workQ is global, static, and volatile so that core loop has its location
|
|
Me@5
|
153 // hard coded, and reloads every time through the loop -- that way don't
|
|
Me@25
|
154 // need to save any regs used by core loop
|
|
Me@26
|
155 volatile VMSQueueStruc *_VMSWorkQ;
|
|
Me@0
|
156
|
|
Me@7
|
157 //==========================
|
|
Me@7
|
158 void
|
|
Me@7
|
159 VMS__init();
|
|
Me@7
|
160
|
|
Me@7
|
161 void
|
|
Me@28
|
162 VMS__init_Seq();
|
|
Me@28
|
163
|
|
Me@28
|
164 void
|
|
Me@24
|
165 VMS__start_the_work_then_wait_until_done();
|
|
Me@7
|
166
|
|
Me@28
|
167 void
|
|
Me@28
|
168 VMS__start_the_work_then_wait_until_done_Seq();
|
|
Me@28
|
169
|
|
Me@7
|
170 VirtProcr *
|
|
Me@7
|
171 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@7
|
172
|
|
Me@23
|
173 VirtProcr *
|
|
Me@23
|
174 VMS__create_the_shutdown_procr();
|
|
Me@23
|
175
|
|
Me@24
|
176 //==========================
|
|
Me@7
|
177 inline void
|
|
Me@24
|
178 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
|
|
Me@7
|
179
|
|
Me@7
|
180 void
|
|
Me@24
|
181 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
|
|
Me@24
|
182 VirtProcr *reqstingPr );
|
|
Me@24
|
183
|
|
Me@24
|
184 void
|
|
Me@24
|
185 VMS__free_request( VMSReqst *req );
|
|
Me@23
|
186
|
|
Me@23
|
187 void
|
|
Me@23
|
188 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
|
|
Me@23
|
189
|
|
Me@24
|
190 VMSReqst *
|
|
Me@24
|
191 VMS__take_top_request_from( VirtProcr *reqstingPr );
|
|
Me@24
|
192
|
|
Me@24
|
193 inline void *
|
|
Me@24
|
194 VMS__take_sem_reqst_from( VMSReqst *req );
|
|
Me@24
|
195
|
|
Me@24
|
196 inline int
|
|
Me@24
|
197 VMS__isSemanticReqst( VMSReqst *req );
|
|
Me@24
|
198
|
|
Me@24
|
199 inline int
|
|
Me@24
|
200 VMS__isDissipateReqst( VMSReqst *req );
|
|
Me@24
|
201
|
|
Me@24
|
202 inline int
|
|
Me@24
|
203 VMS__isCreateReqst( VMSReqst *req );
|
|
Me@24
|
204
|
|
Me@24
|
205 //==========================
|
|
Me@24
|
206
|
|
Me@23
|
207 void
|
|
Me@23
|
208 VMS__suspend_procr( VirtProcr *callingPr );
|
|
Me@23
|
209
|
|
Me@23
|
210 void
|
|
Me@23
|
211 VMS__dissipate_procr( VirtProcr *prToDissipate );
|
|
Me@23
|
212
|
|
Me@23
|
213 void
|
|
Me@29
|
214 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
|
|
Me@29
|
215
|
|
Me@29
|
216 void
|
|
Me@29
|
217 VMS__cleanup_after_shutdown();
|
|
Me@7
|
218
|
|
Me@13
|
219 //============================= Statistics ==================================
|
|
Me@13
|
220
|
|
Me@13
|
221 typedef unsigned long long TSCount;
|
|
Me@13
|
222
|
|
Me@25
|
223 //Frequency of TS counts
|
|
Me@25
|
224 //TODO: change freq for each machine
|
|
Me@25
|
225 #define TSCOUNT_FREQ 3180000000
|
|
Me@25
|
226
|
|
Me@13
|
227 #define saveTimeStampCountInto(low, high) \
|
|
Me@13
|
228 asm volatile("RDTSC; \
|
|
Me@13
|
229 movl %%eax, %0; \
|
|
Me@13
|
230 movl %%edx, %1;" \
|
|
Me@13
|
231 /* outputs */ : "=m" (low), "=m" (high)\
|
|
Me@13
|
232 /* inputs */ : \
|
|
Me@13
|
233 /* clobber */ : "%eax", "%edx" \
|
|
Me@13
|
234 );
|
|
Me@13
|
235
|
|
Me@13
|
236 inline TSCount getTSCount();
|
|
Me@13
|
237
|
|
Me@23
|
238 //===================== Debug ==========================
|
|
Me@13
|
239 int numProcrsCreated;
|
|
Me@0
|
240
|
|
Me@23
|
241
|
|
Me@0
|
242 #endif /* _VMS_H */
|
|
Me@0
|
243
|