| 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@0
|
11
|
|
Me@0
|
12 #include "VMS_primitive_data_types.h"
|
|
Me@0
|
13 #include "Queue_impl/BlockingQueue.h"
|
|
Me@7
|
14 #include <windows.h>
|
|
Me@13
|
15 #include <winbase.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@0
|
111 void *semanticEnv;
|
|
Me@5
|
112 void *OSEventStruc; //for future, when add I/O to BLIS
|
|
Me@16
|
113
|
|
Me@16
|
114 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
|
|
Me@0
|
115 }
|
|
Me@0
|
116 MasterEnv;
|
|
Me@0
|
117
|
|
Me@0
|
118
|
|
Me@16
|
119 //==========================================================
|
|
Me@0
|
120
|
|
Me@7
|
121 DWORD WINAPI coreLoop( LPVOID paramsIn );
|
|
Me@7
|
122 //void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
|
|
Me@7
|
123 void masterLoop( void *initData, VirtProcr *masterPr );
|
|
Me@0
|
124
|
|
Me@0
|
125
|
|
Me@0
|
126 //===================== Global Vars ===================
|
|
Me@0
|
127
|
|
Me@5
|
128
|
|
Me@13
|
129 HANDLE coreLoopThdHandles[ NUM_CORES ]; //windows handle to thread
|
|
Me@13
|
130 ThdParams *coreLoopThdParams[ NUM_CORES ];
|
|
Me@13
|
131 DWORD coreLoopThdIds[ NUM_CORES ];
|
|
Me@0
|
132
|
|
Me@13
|
133 //TODO: Debug: figure out if need to be volatile or not
|
|
Me@13
|
134 volatile MasterEnv *_VMSMasterEnv;
|
|
Me@5
|
135
|
|
Me@5
|
136 //workQ is global, static, and volatile so that core loop has its location
|
|
Me@5
|
137 // hard coded, and reloads every time through the loop -- that way don't
|
|
Me@5
|
138 // need to save any regs used by core loop (will see if this really works)
|
|
Me@13
|
139 volatile CASQueueStruc *_VMSWorkQ;
|
|
Me@0
|
140
|
|
Me@7
|
141 //==========================
|
|
Me@7
|
142 void
|
|
Me@7
|
143 VMS__init();
|
|
Me@7
|
144
|
|
Me@7
|
145 void
|
|
Me@24
|
146 VMS__start_the_work_then_wait_until_done();
|
|
Me@7
|
147
|
|
Me@7
|
148 VirtProcr *
|
|
Me@7
|
149 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
|
|
Me@7
|
150
|
|
Me@23
|
151 VirtProcr *
|
|
Me@23
|
152 VMS__create_the_shutdown_procr();
|
|
Me@23
|
153
|
|
Me@24
|
154 //==========================
|
|
Me@7
|
155 inline void
|
|
Me@24
|
156 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
|
|
Me@7
|
157
|
|
Me@7
|
158 void
|
|
Me@24
|
159 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
|
|
Me@24
|
160 VirtProcr *reqstingPr );
|
|
Me@24
|
161
|
|
Me@24
|
162 void
|
|
Me@24
|
163 VMS__free_request( VMSReqst *req );
|
|
Me@23
|
164
|
|
Me@23
|
165 void
|
|
Me@23
|
166 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
|
|
Me@23
|
167
|
|
Me@24
|
168 VMSReqst *
|
|
Me@24
|
169 VMS__take_top_request_from( VirtProcr *reqstingPr );
|
|
Me@24
|
170
|
|
Me@24
|
171 inline void *
|
|
Me@24
|
172 VMS__take_sem_reqst_from( VMSReqst *req );
|
|
Me@24
|
173
|
|
Me@24
|
174 inline int
|
|
Me@24
|
175 VMS__isSemanticReqst( VMSReqst *req );
|
|
Me@24
|
176
|
|
Me@24
|
177 inline int
|
|
Me@24
|
178 VMS__isDissipateReqst( VMSReqst *req );
|
|
Me@24
|
179
|
|
Me@24
|
180 inline int
|
|
Me@24
|
181 VMS__isCreateReqst( VMSReqst *req );
|
|
Me@24
|
182
|
|
Me@24
|
183 //==========================
|
|
Me@24
|
184
|
|
Me@23
|
185 void
|
|
Me@23
|
186 VMS__suspend_procr( VirtProcr *callingPr );
|
|
Me@23
|
187
|
|
Me@23
|
188 void
|
|
Me@23
|
189 VMS__dissipate_procr( VirtProcr *prToDissipate );
|
|
Me@23
|
190
|
|
Me@23
|
191 void
|
|
Me@23
|
192 VMS__shutdown();
|
|
Me@7
|
193
|
|
Me@13
|
194 //============================= Statistics ==================================
|
|
Me@13
|
195
|
|
Me@13
|
196 typedef unsigned long long TSCount;
|
|
Me@13
|
197
|
|
Me@13
|
198 #define saveTimeStampCountInto(low, high) \
|
|
Me@13
|
199 asm volatile("RDTSC; \
|
|
Me@13
|
200 movl %%eax, %0; \
|
|
Me@13
|
201 movl %%edx, %1;" \
|
|
Me@13
|
202 /* outputs */ : "=m" (low), "=m" (high)\
|
|
Me@13
|
203 /* inputs */ : \
|
|
Me@13
|
204 /* clobber */ : "%eax", "%edx" \
|
|
Me@13
|
205 );
|
|
Me@13
|
206
|
|
Me@13
|
207 inline TSCount getTSCount();
|
|
Me@13
|
208
|
|
Me@23
|
209 //===================== Debug ==========================
|
|
Me@13
|
210 int numProcrsCreated;
|
|
Me@0
|
211
|
|
Me@23
|
212
|
|
Me@0
|
213 #endif /* _VMS_H */
|
|
Me@0
|
214
|