view VSs.h @ 12:f56e3beac86b

wasn't a double free, some tasks have 0 args -> ptrEntries=NULL
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Mon, 20 Aug 2012 13:42:19 +0200
parents ed268fc7376a b13fbd445e0a
children 2bf83f932705
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"
18 //===========================================================================
19 #define NUM_STRUCS_IN_SEM_ENV 1000
21 //This is hardware dependent -- it's the number of cycles of scheduling
22 // overhead -- if a work unit is fewer than this, it is better being
23 // combined sequentially with other work
24 //This value depends on both VMS overhead and VSs's plugin. At some point
25 // it will be derived by perf-counter measurements during init of VSs
26 #define MIN_WORK_UNIT_CYCLES 20000
28 //===========================================================================
29 /*This header defines everything specific to the VSs semantic plug-in
30 */
31 typedef struct _VSsSemReq VSsSemReq;
32 typedef void (*VSsTaskFnPtr ) ( void *, SlaveVP *);
33 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
34 //===========================================================================
36 #define NONCTLD 0
37 #define IN 1 /*Trick -- READER same as IN*/
38 #define OUT 2 /*Trick -- WRITER same as OUT and INOUT*/
39 #define INOUT 2 /*Trick -- WRITER same as OUT and INOUT*/
41 #define READER 1 /*Trick -- READER same as IN*/
42 #define WRITER 2 /*Trick -- WRITER same as OUT and INOUT*/
44 #define IS_A_THREAD NULL
45 #define IS_ENDED NULL
46 #define SEED_SLV NULL
48 typedef struct
49 {
50 VSsTaskFnPtr fn;
51 int32 numTotalArgs;//the number of inputs to function
52 int32 numCtldArgs;//how many of args have dependencies
53 int32 *argTypes; //says reader, writer, or non-ctld
54 int32 *argSizes; //for detecting overlap
55 int32 sizeOfArgs; //for memcpy of args struct
56 }
57 VSsTaskType;
60 typedef struct
61 {
62 bool32 hasEnabledNonFinishedWriter;
63 int32 numEnabledNonDoneReaders;
64 PrivQueueStruc *waitersQ;
65 }
66 VSsPointerEntry;
68 typedef struct
69 {
70 void **args; //ctld args must come first, as ptrs
71 VSsTaskType *taskType;
72 int32 *taskID;
73 int32 numBlockingProp;
74 SlaveVP *slaveAssignedTo; //only valid before end task (thread)
75 VSsPointerEntry **ptrEntries;
76 void* parentTaskStub;
77 int32 numLiveChildTasks;
78 int32 numLiveChildThreads;
79 bool32 isWaitingForChildTasksToEnd;
80 bool32 isWaitingForChildThreadsToEnd;
81 bool32 isEnded;
82 }
83 VSsTaskStub;
86 typedef struct
87 {
88 VSsTaskStub *taskStub;
89 int32 argNum;
90 int32 isReader;
91 }
92 VSsTaskStubCarrier;
95 typedef struct
96 {
97 int32 type;
98 VSsTaskStub *taskStub;
99 }
100 VSsWaiterCarrier;
102 /*Semantic layer-specific data sent inside a request from lib called in app
103 * to request handler called in AnimationMaster
104 */
106 typedef struct
107 {
108 SlaveVP *VPCurrentlyExecuting;
109 PrivQueueStruc *waitingVPQ;
110 }
111 VSsTrans;
113 /*WARNING: assembly hard-codes position of endInstrAddr as first field
114 */
115 typedef struct
116 {
117 void *endInstrAddr;
118 int32 hasBeenStarted;
119 int32 hasFinished;
120 PrivQueueStruc *waitQ;
121 }
122 VSsSingleton;
124 enum VSsReqType
125 {
126 submit_task = 1,
127 end_task,
128 create_slave,
129 create_slave_w_aff,
130 dissipate_slave,
131 //===============================
132 send_type_to,
133 receive_type_to,
134 send_from_to,
135 receive_from_to,
136 //===============================
137 taskwait,
138 malloc_req,
139 free_req,
140 singleton_fn_start,
141 singleton_fn_end,
142 singleton_data_start,
143 singleton_data_end,
144 atomic,
145 trans_start,
146 trans_end
147 };
149 struct _VSsSemReq
150 { enum VSsReqType reqType;
151 SlaveVP *callingSlv;
152 VSsTaskType *taskType;
153 void *args;
154 VSsTaskStub *taskStub;
156 SlaveVP *senderSlv;
157 SlaveVP *receiverSlv;
158 int32 *senderID;
159 int32 *receiverID;
160 int32 msgType;
161 void *msg;
162 VSsSemReq *nextReqInHashEntry;
163 int32 *taskID;
165 TopLevelFnPtr fnPtr;
166 void *initData;
167 int32 coreToAssignOnto;
169 int32 sizeToMalloc;
170 void *ptrToFree;
172 int32 singletonID;
173 VSsSingleton **singletonPtrAddr;
175 PtrToAtomicFn fnToExecInMaster;
176 void *dataForFn;
178 int32 transID;
179 }
180 /* VSsSemReq */;
183 typedef struct
184 {
185 PrivQueueStruc *slavesReadyToResumeQ; //Shared (slaves not pinned)
186 PrivQueueStruc *freeExtraTaskSlvQ; //Shared
187 PrivQueueStruc *taskReadyQ; //Shared (tasks not pinned)
188 SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
189 HashTable *argPtrHashTbl;
190 HashTable *commHashTbl;
191 int32 numLiveExtraTaskSlvs;
192 int32 numLiveThreadSlvs;
193 int32 nextCoreToGetNewSlv;
194 int32 primitiveStartTime;
196 //fix limit on num with dynArray
197 VSsSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
198 VSsTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
200 bool32 *coreIsDone;
201 int32 numCoresDone;
203 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
204 ListOfArrays* unitList;
205 ListOfArrays* ctlDependenciesList;
206 ListOfArrays* commDependenciesList;
207 NtoN** ntonGroups;
208 PrivDynArrayInfo* ntonGroupsInfo;
209 ListOfArrays* dynDependenciesList;
210 Unit last_in_slot[NUM_CORES * NUM_ANIM_SLOTS];
211 ListOfArrays* hwArcs;
212 #endif
214 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
215 ListOfArrays* counterList[NUM_CORES];
216 #endif
217 SlaveVP* idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
218 int shutdownInitiated;
219 }
220 VSsSemEnv;
223 typedef struct _TransListElem TransListElem;
224 struct _TransListElem
225 {
226 int32 transID;
227 TransListElem *nextTrans;
228 };
229 //TransListElem
231 enum VSsSlvType
232 { ExtraTaskSlv = 1,
233 SlotTaskSlv,
234 ThreadSlv
235 };
237 typedef struct
238 {
239 int32 highestTransEntered;
240 TransListElem *lastTransEntered;
241 bool32 needsTaskAssigned;
242 VSsTaskStub *taskStub;
243 enum VSsSlvType slaveType;
244 }
245 VSsSemData;
247 //===========================================================================
249 void
250 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fn, void *initData );
252 int32
253 VSs__giveMinWorkUnitCycles( float32 percentOverhead );
255 void
256 VSs__start_primitive();
258 int32
259 VSs__end_primitive_and_give_cycles();
261 int32
262 VSs__giveIdealNumWorkUnits();
264 int32
265 VSs__give_number_of_cores_to_schedule_onto();
267 //=======================
269 void
270 VSs__init();
272 void
273 VSs__cleanup_after_shutdown();
275 //=======================
277 SlaveVP *
278 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
279 SlaveVP *creatingThd );
281 void
282 VSs__end_thread( SlaveVP *thdToEnd );
284 //=======================
286 #define VSs__malloc( numBytes, callingSlave ) VMS_App__malloc( numBytes, callingSlave)
288 #define VSs__free(ptrToFree, callingSlave ) VMS_App__free( ptrToFree, callingSlave )
291 //=======================
292 void
293 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv);
295 inline int32 *
296 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv );
298 void
299 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
300 SlaveVP *animSlv);
302 void
303 VSs__end_task( SlaveVP *animSlv );
305 //=========================
306 void
307 VSs__taskwait(SlaveVP *animSlv);
310 inline int32 *
311 VSs__give_self_taskID( SlaveVP *animSlv );
313 void
314 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
315 SlaveVP *senderSlv );
317 void
318 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv );
320 void *
321 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv );
323 void *
324 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv );
326 //======================= Concurrency Stuff ======================
327 void
328 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv );
330 void
331 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv );
333 void
334 VSs__start_data_singleton( VSsSingleton **singeltonAddr, SlaveVP *animSlv );
336 void
337 VSs__end_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv );
339 void
340 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
341 void *data, SlaveVP *animSlv );
343 void
344 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv );
346 void
347 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv );
350 //========================= Internal use only =============================
351 void
352 VSs__Request_Handler( SlaveVP *requestingSlv, void *_semEnv );
354 SlaveVP *
355 VSs__assign_slaveVP_to_slot( void *_semEnv, AnimSlot *slot );
357 SlaveVP*
358 VSs__create_slave_helper( TopLevelFnPtr fnPtr, void *initData,
359 VSsSemEnv *semEnv, int32 coreToAssignOnto );
361 VSsTaskStub *
362 create_thread_task_stub( void *initData );
365 SlaveVP *
366 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
367 SlaveVP *creatingSlv );
369 SlaveVP *
370 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
371 SlaveVP *creatingSlv, int32 coreToAssignOnto);
373 void
374 idle_fn(void* data, SlaveVP *animatingSlv);
376 //===================== Measurement of Lang Overheads =====================
377 #include "Measurement/VSs_Measurement.h"
379 //===========================================================================
380 #endif /* _VSs_H */