Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VSs_impls > VSs__MC_shared_impl
view VSs.h @ 36:94911329b067
fix access after free in reqHdlr
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 15 Apr 2013 16:41:31 +0200 |
| parents | b787a5234406 |
| children | c8d4f6d3c7d3 |
line source
1 /*
2 * Copyright 2009 OpenSourceStewardshipFoundation.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
9 #ifndef _VSs_H
10 #define _VSs_H
12 #include "Queue_impl/PrivateQueue.h"
13 #include "Hash_impl/PrivateHash.h"
14 #include "VMS_impl/VMS.h"
15 #include "Measurement/dependency.h"
17 void free_pointer_entry(void* ptrEntry);
18 /* Switch for Nexus support
19 * Note: nexus incompatible with holistic recording (constraints not accessible)
20 * But counter recording still functional, can build constraintless display
21 * with wallclock time
22 */
23 //#define EXTERNAL_SCHEDULER
24 //#define SIMULATE_EXTERNAL_SCHEDULER
26 //===========================================================================
27 #define NUM_STRUCS_IN_SEM_ENV 1000
29 #define MAX_TASKS_NUM 256
31 //This is hardware dependent -- it's the number of cycles of scheduling
32 // overhead -- if a work unit is fewer than this, it is better being
33 // combined sequentially with other work
34 //This value depends on both VMS overhead and VSs's plugin. At some point
35 // it will be derived by perf-counter measurements during init of VSs
36 #define MIN_WORK_UNIT_CYCLES 20000
38 //===========================================================================
39 /*This header defines everything specific to the VSs semantic plug-in
40 */
41 typedef struct _VSsSemReq VSsSemReq;
42 typedef void (*VSsTaskFnPtr ) ( void *, SlaveVP *);
43 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
44 //===========================================================================
46 #define NONCTLD 0
47 #define IN 1 /*Trick -- READER same as IN*/
48 #define OUT 2 /*Trick -- WRITER same as OUT and INOUT*/
49 #define INOUT 2 /*Trick -- WRITER same as OUT and INOUT*/
51 #define READER 1 /*Trick -- READER same as IN*/
52 #define WRITER 2 /*Trick -- WRITER same as OUT and INOUT*/
54 #define IS_A_THREAD NULL
55 #define IS_ENDED NULL
56 #define SEED_SLV NULL
58 typedef struct
59 {
60 VSsTaskFnPtr fn;
61 int32 numTotalArgs;//the number of inputs to function
62 int32 numCtldArgs;//how many of args have dependencies
63 int32 *argTypes; //says reader, writer, or non-ctld
64 int32 *argSizes; //for detecting overlap
65 int32 sizeOfArgs; //for memcpy of args struct
66 }
67 VSsTaskType;
70 typedef struct
71 {
72 bool32 hasEnabledNonFinishedWriter;
73 int32 numEnabledNonDoneReaders;
74 PrivQueueStruc *waitersQ;
75 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
76 Unit lastWriter;
77 ListOfArrays* readersSinceLastWriter;
78 #endif
79 }
80 VSsPointerEntry;
82 typedef struct {
83 void **args; //ctld args must come first, as ptrs
84 VSsTaskType *taskType;
85 int32 *taskID;
86 int32 numBlockingProp;
87 SlaveVP *slaveAssignedTo; //only valid before end task (thread)
88 VSsPointerEntry **ptrEntries;
89 void* parentTaskStub;
90 int32 numLiveChildTasks;
91 int32 numLiveChildThreads;
92 bool32 isWaitingForChildTasksToEnd;
93 bool32 isWaitingForChildThreadsToEnd;
94 bool32 isEnded;
95 int *argsMask;
96 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
97 Unit parentUnit;
98 Unit firstOfTask;
99 #endif
100 }
101 VSsTaskStub;
104 typedef struct
105 {
106 VSsTaskStub *taskStub;
107 int32 argNum;
108 int32 isReader;
109 bool32 isSuspended;
110 }
111 VSsTaskStubCarrier;
114 /*Semantic layer-specific data sent inside a request from lib called in app
115 * to request handler called in AnimationMaster
116 */
118 typedef struct
119 {
120 SlaveVP *VPCurrentlyExecuting;
121 PrivQueueStruc *waitingVPQ;
122 }
123 VSsTrans;
125 /*WARNING: assembly hard-codes position of endInstrAddr as first field
126 */
127 typedef struct
128 {
129 void *endInstrAddr;
130 int32 hasBeenStarted;
131 int32 hasFinished;
132 PrivQueueStruc *waitQ;
133 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
134 Unit executingUnit;
135 #endif
136 }
137 VSsSingleton;
139 typedef struct
140 {
141 int32 isOccupied;
142 PrivQueueStruc *waitQ;
143 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
144 Unit previous;
145 #endif
146 }
147 VSsCritical;
149 enum VSsReqType
150 {
151 submit_task = 1,
152 end_task,
153 create_slave,
154 create_slave_w_aff,
155 dissipate_slave,
156 //===============================
157 send_type_to,
158 receive_type_to,
159 send_from_to,
160 receive_from_to,
161 //===============================
162 taskwait,
163 taskwait_on,
164 critical_start,
165 critical_end,
166 malloc_req,
167 free_req,
168 singleton_fn_start,
169 singleton_fn_end,
170 singleton_data_start,
171 singleton_data_end,
172 atomic,
173 trans_start,
174 trans_end
175 };
177 struct _VSsSemReq
178 { enum VSsReqType reqType;
179 SlaveVP *callingSlv;
180 VSsTaskType *taskType;
181 void *args;
182 VSsTaskStub *taskStub;
184 SlaveVP *senderSlv;
185 SlaveVP *receiverSlv;
186 int32 *senderID;
187 int32 *receiverID;
188 int32 msgType;
189 void *msg;
190 VSsSemReq *nextReqInHashEntry;
191 int32 *taskID;
193 TopLevelFnPtr fnPtr;
194 void *initData;
195 int32 coreToAssignOnto;
197 int32 sizeToMalloc;
198 void *ptrToFree;
200 int32 singletonID;
201 VSsSingleton **singletonPtrAddr;
203 PtrToAtomicFn fnToExecInMaster;
204 void *dataForFn;
206 int32 transID;
207 int32 criticalID;
208 }
209 /* VSsSemReq */;
212 typedef struct
213 {
214 PrivQueueStruc *slavesReadyToResumeQ; //Shared (slaves not pinned)
215 PrivQueueStruc *freeExtraTaskSlvQ; //Shared
216 PrivQueueStruc *taskReadyQ; //Shared (tasks not pinned)
217 SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
218 HashTable *argPtrHashTbl;
219 HashTable *commHashTbl;
220 int32 numLiveExtraTaskSlvs;
221 int32 numLiveThreadSlvs;
222 int32 nextCoreToGetNewSlv;
223 int32 primitiveStartTime;
225 //fix limit on num with dynArray
226 VSsSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
227 VSsTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
228 VSsCritical criticalSection[NUM_STRUCS_IN_SEM_ENV];
230 bool32 *coreIsDone;
231 int32 numCoresDone;
233 int numInFlightTasks;
234 PrivQueueStruc *deferredSubmitsQ;
235 int numDeferred;
237 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
238 ListOfArrays* unitList;
239 ListOfArrays* ctlDependenciesList;
240 ListOfArrays* commDependenciesList;
241 ListOfArrays* dataDependenciesList;
242 ListOfArrays* warDependenciesList;
243 NtoN** ntonGroups;
244 PrivDynArrayInfo* ntonGroupsInfo;
245 ListOfArrays* dynDependenciesList;
246 ListOfArrays* singletonDependenciesList;
247 Unit last_in_slot[NUM_CORES * NUM_ANIM_SLOTS];
248 ListOfArrays* hwArcs;
249 #endif
251 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
252 ListOfArrays* counterList[NUM_CORES];
253 #endif
254 #ifdef IDLE_SLAVES
255 SlaveVP* idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
256 #endif
257 //int shutdownInitiated;
258 }
259 VSsSemEnv;
262 typedef struct _TransListElem TransListElem;
263 struct _TransListElem
264 {
265 int32 transID;
266 TransListElem *nextTrans;
267 };
268 //TransListElem
270 enum VSsSlvType
271 { ExtraTaskSlv = 1,
272 SlotTaskSlv,
273 ThreadSlv
274 };
276 typedef struct
277 {
278 int32 highestTransEntered;
279 TransListElem *lastTransEntered;
280 bool32 needsTaskAssigned;
281 VSsTaskStub *taskStub;
282 enum VSsSlvType slaveType;
283 }
284 VSsSemData;
286 //===========================================================================
288 void
289 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fn, void *initData );
291 int32
292 VSs__giveMinWorkUnitCycles( float32 percentOverhead );
294 void
295 VSs__start_primitive();
297 int32
298 VSs__end_primitive_and_give_cycles();
300 int32
301 VSs__giveIdealNumWorkUnits();
303 int32
304 VSs__give_number_of_cores_to_schedule_onto();
306 //=======================
308 void
309 VSs__init();
311 void
312 VSs__cleanup_after_shutdown();
314 //=======================
316 SlaveVP *
317 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
318 SlaveVP *creatingThd );
320 void
321 VSs__end_thread( SlaveVP *thdToEnd );
323 //=======================
325 #define VSs__malloc( numBytes, callingSlave ) VMS_App__malloc( numBytes, callingSlave)
327 #define VSs__free(ptrToFree, callingSlave ) VMS_App__free( ptrToFree, callingSlave )
330 //=======================
331 void
332 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv);
334 int32 *
335 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv );
337 void
338 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
339 SlaveVP *animSlv);
341 void
342 VSs__end_task( SlaveVP *animSlv );
344 //=========================
345 void
346 VSs__taskwait(SlaveVP *animSlv);
348 void
349 VSs__taskwait_on(SlaveVP *animSlv,void* ptr);
351 void
352 VSs__start_critical(SlaveVP *animSlv,int32 name);
354 void
355 VSs__end_critical(SlaveVP *animSlv,int32 name);
357 int32 *
358 VSs__give_self_taskID( SlaveVP *animSlv );
360 void
361 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
362 SlaveVP *senderSlv );
364 void
365 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv );
367 void *
368 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv );
370 void *
371 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv );
373 //======================= Concurrency Stuff ======================
374 void
375 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv );
377 void
378 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv );
380 void
381 VSs__start_data_singleton( VSsSingleton **singeltonAddr, SlaveVP *animSlv );
383 void
384 VSs__end_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv );
386 void
387 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
388 void *data, SlaveVP *animSlv );
390 void
391 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv );
393 void
394 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv );
397 //========================= Internal use only =============================
398 void
399 VSs__Request_Handler( SlaveVP *requestingSlv, void *_semEnv );
401 SlaveVP *
402 VSs__assign_slaveVP_to_slot( void *_semEnv, AnimSlot *slot );
404 SlaveVP*
405 VSs__create_slave_helper( TopLevelFnPtr fnPtr, void *initData,
406 VSsSemEnv *semEnv, int32 coreToAssignOnto );
408 VSsTaskStub *
409 create_thread_task_stub( void *initData );
412 SlaveVP *
413 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
414 SlaveVP *creatingSlv );
416 SlaveVP *
417 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
418 SlaveVP *creatingSlv, int32 coreToAssignOnto);
420 void
421 idle_fn(void* data, SlaveVP *animatingSlv);
423 void
424 resume_slaveVP(SlaveVP *slave, VSsSemEnv *semEnv);
426 //===================== Measurement of Lang Overheads =====================
427 #include "Measurement/VSs_Measurement.h"
429 //===========================================================================
430 #endif /* _VSs_H */
