view VSs.h @ 47:a7c77d69d127

update for api v. nanox-0.7
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Fri, 05 Jul 2013 15:36:42 +0200
parents 37bb39da5ff1
children
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 extern 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 5
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 * );
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 numDeps;//how many of args have dependencies
62 int32 *depsTypes; //says reader, writer, or non-ctld
63 size_t *depsSizes; //for detecting overlap
64 int32 sizeOfArgs; //for memcpy of args struct
65 }
66 VSsTaskType;
69 typedef struct
70 {
71 bool32 hasEnabledNonFinishedWriter;
72 int32 numEnabledNonDoneReaders;
73 PrivQueueStruc *waitersQ;
74 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
75 Unit lastWriter;
76 ListOfArrays* readersSinceLastWriter;
77 #endif
78 }
79 VSsPointerEntry;
81 typedef struct {
82 void **args; //for calling only, can contain values
83 void** depsAddrs; //pointers only
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 *depsMask;
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 barrier
176 };
178 struct _VSsSemReq
179 { enum VSsReqType reqType;
180 SlaveVP *callingSlv;
181 VSsTaskType *taskType;
182 void *args;
183 void *deps;
184 VSsTaskStub *taskStub;
186 SlaveVP *senderSlv;
187 SlaveVP *receiverSlv;
188 int32 *senderID;
189 int32 *receiverID;
190 int32 msgType;
191 void *msg;
192 VSsSemReq *nextReqInHashEntry;
193 int32 *taskID;
195 TopLevelFnPtr fnPtr;
196 void *initData;
197 int32 coreToAssignOnto;
199 int32 sizeToMalloc;
200 void *ptrToFree;
202 int32 singletonID;
203 VSsSingleton **singletonPtrAddr;
205 PtrToAtomicFn fnToExecInMaster;
206 void *dataForFn;
208 int32 transID;
209 void* criticalID;
210 }
211 /* VSsSemReq */;
214 typedef struct
215 {
216 PrivQueueStruc *slavesReadyToResumeQ; //Shared (slaves not pinned)
217 PrivQueueStruc *freeExtraTaskSlvQ; //Shared
218 PrivQueueStruc *taskReadyQ; //Shared (tasks not pinned)
219 PrivQueueStruc *barrierQ;
220 SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
221 HashTable *argPtrHashTbl;
222 HashTable *commHashTbl;
223 HashTable *criticalHashTbl;
224 int32 numLiveExtraTaskSlvs;
225 int32 numLiveThreadSlvs;
226 int32 nextCoreToGetNewSlv;
227 int32 primitiveStartTime;
229 //fix limit on num with dynArray
230 VSsSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
231 VSsTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
234 bool32 *coreIsDone;
236 int numInFlightTasks;
237 PrivQueueStruc *deferredSubmitsQ;
238 int numDeferred;
240 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
241 ListOfArrays* unitList;
242 ListOfArrays* ctlDependenciesList;
243 ListOfArrays* commDependenciesList;
244 ListOfArrays* dataDependenciesList;
245 ListOfArrays* warDependenciesList;
246 NtoN** ntonGroups;
247 PrivDynArrayInfo* ntonGroupsInfo;
248 ListOfArrays* dynDependenciesList;
249 ListOfArrays* singletonDependenciesList;
250 Unit last_in_slot[NUM_CORES * NUM_ANIM_SLOTS];
251 ListOfArrays* hwArcs;
252 #endif
254 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
255 ListOfArrays* counterList[NUM_CORES];
256 #endif
257 #ifdef IDLE_SLAVES
258 SlaveVP* idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
259 #endif
260 //int shutdownInitiated;
261 }
262 VSsSemEnv;
265 typedef struct _TransListElem TransListElem;
266 struct _TransListElem
267 {
268 int32 transID;
269 TransListElem *nextTrans;
270 };
271 //TransListElem
273 enum VSsSlvType
274 { ExtraTaskSlv = 1,
275 SlotTaskSlv,
276 ThreadSlv
277 };
279 typedef struct
280 {
281 int32 highestTransEntered;
282 TransListElem *lastTransEntered;
283 bool32 needsTaskAssigned;
284 VSsTaskStub *taskStub;
285 enum VSsSlvType slaveType;
286 }
287 VSsSemData;
289 //===========================================================================
291 void
292 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fn, void *initData );
294 int32
295 VSs__giveMinWorkUnitCycles( float32 percentOverhead );
297 void
298 VSs__start_primitive();
300 int32
301 VSs__end_primitive_and_give_cycles();
303 int32
304 VSs__giveIdealNumWorkUnits();
306 int32
307 VSs__give_number_of_cores_to_schedule_onto();
309 //=======================
311 void
312 VSs__init();
314 void
315 VSs__cleanup_after_shutdown();
317 //=======================
319 SlaveVP *
320 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
321 SlaveVP *creatingThd );
323 void VSs__run_thread(TopLevelFnPtr fnPtr, void *initData);
325 void
326 VSs__end_thread();
328 //=======================
330 #define VSs__malloc( numBytes, callingSlave ) VMS_App__malloc( numBytes, callingSlave)
332 #define VSs__free(ptrToFree, callingSlave ) VMS_App__free( ptrToFree, callingSlave )
335 //=======================
336 void
337 VSs__submit_task( VSsTaskType *taskType, void *args, void* deps);
339 int32 *
340 VSs__create_taskID_of_size( int32 numInts);
342 void
343 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, void* deps, int32 *taskID);
345 void VSs__run_task(TopLevelFnPtr fnPtr, void *initData);
347 void
348 VSs__end_task();
350 //=========================
351 void
352 VSs__taskwait();
354 void
355 VSs__taskwait_on(void* ptr);
357 void
358 VSs__start_critical(void* name);
360 void
361 VSs__end_critical(void* name);
363 int32 *
364 VSs__give_self_taskID();
366 void
367 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID);
369 void
370 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID);
372 void *
373 VSs__receive_type_to( const int32 type, int32* receiverID );
375 void *
376 VSs__receive_from_to( int32 *senderID, int32 *receiverID );
378 //======================= Concurrency Stuff ======================
379 void
380 VSs__start_fn_singleton( int32 singletonID );
382 void
383 VSs__end_fn_singleton( int32 singletonID );
385 void
386 VSs__start_data_singleton( VSsSingleton **singeltonAddr );
388 void
389 VSs__end_data_singleton( VSsSingleton **singletonAddr );
391 void
392 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
393 void *data );
395 void
396 VSs__start_transaction( int32 transactionID );
398 void
399 VSs__end_transaction( int32 transactionID );
402 //========================= Internal use only =============================
403 void
404 VSs__Request_Handler( SlaveVP *requestingSlv, void *_semEnv );
406 SlaveVP *
407 VSs__assign_slaveVP_to_slot( void *_semEnv, AnimSlot *slot );
409 SlaveVP*
410 VSs__create_slave_helper(TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr, void *initData,
411 VSsSemEnv *semEnv, int32 coreToAssignOnto );
413 VSsTaskStub *
414 create_thread_task_stub( void *initData );
417 SlaveVP *
418 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
419 SlaveVP *creatingSlv );
421 SlaveVP *
422 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
423 SlaveVP *creatingSlv, int32 coreToAssignOnto);
425 void
426 idle_fn(void* data);
428 void
429 resume_slaveVP(SlaveVP *slave, VSsSemEnv *semEnv);
431 //===================== Measurement of Lang Overheads =====================
432 #include "Measurement/VSs_Measurement.h"
434 //===========================================================================
436 /* Hide entry point trick */
438 typedef struct {
439 int argc;
440 char** argv;
441 } __main_args;
443 extern int __main_ret;
445 int __program_main(int argc, char** argv);
447 void __entry_point(void* _args);
449 int main(int argc, char** argv);
452 #define main __program_main
454 #endif /* _VSs_H */