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