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