view VSs.h @ 35:daaf26b3ffe5

ML_dev -- works in both sequential and concurrent modes
author Sean Halle <seanhalle@yahoo.com>
date Fri, 08 Mar 2013 05:33:03 -0800
parents a40859b8dc33
children
line source
1 /*
2 * Copyright 2009 OpenSourceResearchInstitute.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 "PR_impl/PR.h"
15 #include "Measurement/dependency.h"
18 //===========================================================================
19 //uniquely identifies VSs -- should be a jenkins char-hash of "VSs" to int32
20 #define VSs_MAGIC_NUMBER 0000000002
22 #define NUM_STRUCS_IN_LANG_ENV 1000
24 //This is hardware dependent -- it's the number of cycles of scheduling
25 // overhead -- if a work unit is fewer than this, it is better being
26 // combined sequentially with other work
27 //This value depends on both PR overhead and VSs's plugin. At some point
28 // it will be derived by perf-counter measurements during init of VSs
29 #define MIN_WORK_UNIT_CYCLES 20000
31 //===========================================================================
32 /*This header defines everything specific to the VSs semantic plug-in
33 */
34 typedef struct _VSsLangReq VSsLangReq;
35 typedef struct _VSsTaskStub VSsTaskStub;
36 typedef void (*VSsTaskFnPtr ) ( void *, SlaveVP *);
37 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
38 //===========================================================================
40 #define NONCTLD 0
41 #define IN 1 /*Trick -- READER same as IN*/
42 #define OUT 2 /*Trick -- WRITER same as OUT and INOUT*/
43 #define INOUT 2 /*Trick -- WRITER same as OUT and INOUT*/
45 #define READER 1 /*Trick -- READER same as IN*/
46 #define WRITER 2 /*Trick -- WRITER same as OUT and INOUT*/
48 #define IS_A_THREAD NULL
49 #define IS_ENDED NULL
50 #define SEED_SLV NULL
52 #define NO_ID NULL
53 #define ANY_CORE -1
55 //===========================================================================
56 typedef struct
57 {
58 VSsTaskFnPtr fn;
59 int32 numTotalArgs;//the number of inputs to function
60 int32 numCtldArgs;//how many of args have dependencies
61 int32 *argTypes; //says reader, writer, or non-ctld
62 int32 *argSizes; //for detecting overlap
63 int32 sizeOfArgs; //for memcpy of args struct
64 }
65 VSsTaskType;
68 typedef struct
69 {
70 bool32 hasEnabledNonFinishedWriter;
71 int32 numEnabledNonDoneReaders;
72 PrivQueueStruc *waitersQ;
73 }
74 VSsPointerEntry;
76 /*This is VSs's "lang meta task"
77 *See the proto-runtime wiki entry to learn about "lang meta task"
78 *In essence, this holds all the meta information that VSs needs about a task
79 */
80 struct _VSsTaskStub
81 {
82 void **args; //ctld args must be the first ones (as ptrs)
83 VSsPointerEntry **ptrEntries;
84 int32 numBlockingProp;
86 VSsTaskType *taskType; //has VSs lang related info
88 VSsTaskStub *parentTaskStub; //for liveness, for the wait construct
89 int32 numLiveChildTasks;
90 int32 numLiveChildThreads;
91 bool32 isWaitingForChildTasksToEnd;
92 bool32 isWaitingForChildThreadsToEnd;
93 bool32 isEnded;
94 };
97 typedef struct
98 {
99 VSsTaskStub *taskStub;
100 int32 argNum;
101 int32 isReader;
102 }
103 VSsTaskStubCarrier;
106 /*Semantic layer-specific data sent inside a request from lib called in app
107 * to request handler called in AnimationMaster
108 */
110 typedef struct
111 {
112 SlaveVP *VPCurrentlyExecuting;
113 PrivQueueStruc *waitingVPQ;
114 }
115 VSsTrans;
117 /*WARNING: assembly hard-codes position of endInstrAddr as first field
118 */
119 typedef struct
120 {
121 void *endInstrAddr;
122 int32 hasBeenStarted;
123 int32 hasFinished;
124 PrivQueueStruc *waitQ;
125 }
126 VSsSingleton;
128 enum VSsReqType
129 {
130 submit_task = 1,
131 end_task = 2,
132 create_slave = 3,
133 create_slave_w_aff = 4,
134 dissipate_slave = 5,
135 //===============================
136 send_type_to = 6,
137 receive_type_to = 7,
138 send_from_to = 8,
139 receive_from_to = 9,
140 //===============================
141 taskwait = 10,
142 activity_cease_wait = 11,
143 wait_then_shutdown = 12,
144 shutdown = 13
145 };
147 struct _VSsLangReq
148 { enum VSsReqType reqType;
149 SlaveVP *callingSlv;
150 VSsTaskType *taskType;
151 void *args;
152 // VSsTaskStub *taskStub; //not needed -- get via PR accessor from slv
154 SlaveVP *senderSlv;
155 SlaveVP *receiverSlv;
156 int32 *senderID;
157 int32 *receiverID;
158 int32 msgType;
159 void *msg;
160 VSsLangReq *nextReqInHashEntry;
161 //In PRReq: int32 *taskID;
163 TopLevelFnPtr fnPtr;
164 void *initData;
165 int32 coreToAssignOnto;
167 //These, below, should move to util language..
168 int32 sizeToMalloc;
169 void *ptrToFree;
171 int32 singletonID;
172 VSsSingleton **singletonPtrAddr;
174 PtrToAtomicFn fnToExecInMaster;
175 void *dataForFn;
177 int32 transID;
178 }
179 /* VSsLangReq */;
182 typedef struct
183 {
184 PrivQueueStruc *slavesReadyToResumeQ; //Shared (slaves not pinned)
185 PrivQueueStruc *taskReadyQ; //Shared (tasks not pinned)
187 HashTable *argPtrHashTbl;
188 HashTable *commHashTbl;
189 int32 nextCoreToGetNewSlv;
190 int32 primitiveStartTime;
192 //fix limit on num with dynArray
193 VSsSingleton fnSingletons[NUM_STRUCS_IN_LANG_ENV];
194 VSsTrans transactionStrucs[NUM_STRUCS_IN_LANG_ENV];
196 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
197 ListOfArrays* unitList;
198 ListOfArrays* ctlDependenciesList;
199 ListOfArrays* commDependenciesList;
200 NtoN** ntonGroups;
201 PrivDynArrayInfo* ntonGroupsInfo;
202 ListOfArrays* dynDependenciesList;
203 Unit last_in_slot[NUM_CORES * NUM_ANIM_SLOTS];
204 ListOfArrays* hwArcs;
205 #endif
207 #ifdef HOLISTIC__TURN_ON_PERF_COUNTERS
208 ListOfArrays* counterList[NUM_CORES];
209 #endif
210 }
211 VSsLangEnv;
214 typedef struct _TransListElem TransListElem;
215 struct _TransListElem
216 {
217 int32 transID;
218 TransListElem *nextTrans;
219 };
220 //TransListElem
222 /* PR now handles what this used to be used for
223 enum VSsSlvType
224 { FreeTaskSlv = 1,
225 SlotTaskSlv,
226 ThreadSlv
227 };
228 */
230 typedef struct
231 {
232 int32 highestTransEntered;
233 TransListElem *lastTransEntered;
234 int32 primitiveStartTime;
235 // VSsTaskStub *taskStub; //get from slave via PR accessor
236 }
237 VSsLangData;
239 //===========================================================================
241 void
242 VSs__create_seed_slave_and_do_work( TopLevelFnPtr fn, void *initData );
244 int32
245 VSs__giveMinWorkUnitCycles( float32 percentOverhead );
247 void
248 VSs__begin_primitive();
250 int32
251 VSs__end_primitive_and_give_cycles();
253 int32
254 VSs__giveIdealNumWorkUnits();
256 int32
257 VSs__give_number_of_cores_to_schedule_onto();
259 //=======================
261 void
262 VSs__start( SlaveVP *seedSlv );
264 void
265 VSs__shutdown( SlaveVP *seedSlv );
267 void
268 VSs__wait_for_all_VSs_created_work_to_end( SlaveVP *seedSlv );
270 void
271 VSs__wait_until_activity_done_then_shutdown( SlaveVP *seedSlv );
273 //=======================
275 SlaveVP *
276 VSs__create_thread( TopLevelFnPtr fnPtr, void *initData,
277 SlaveVP *creatingThd );
279 void
280 VSs__end_thread( SlaveVP *thdToEnd );
282 //=======================
284 #define VSs__malloc( numBytes, callingSlave ) PR_App__malloc( numBytes, callingSlave)
286 #define VSs__free(ptrToFree, callingSlave ) PR_App__free( ptrToFree, callingSlave )
289 //=======================
290 void
291 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv);
293 //inline int32 *
294 //VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv );
296 void
297 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID,
298 SlaveVP *animSlv);
300 void
301 VSs__end_task( SlaveVP *animSlv );
303 //=========================
304 void
305 VSs__taskwait(SlaveVP *animSlv);
308 inline int32 *
309 VSs__give_self_taskID( SlaveVP *animSlv );
311 void
312 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID,
313 SlaveVP *senderSlv );
315 void
316 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv );
318 void *
319 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv );
321 void *
322 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv );
325 //========================= Internal use only =============================
327 bool32
328 VSs__assign_work_to_slot( void *_langEnv, AnimSlot *slot );
330 SlaveVP*
331 VSs__create_slave_helper( TopLevelFnPtr fnPtr, void *initData,
332 VSsLangEnv *langEnv, int32 coreToAssignOnto );
334 SlaveVP *
335 VSs__create_slave_with( TopLevelFnPtr fnPtr, void *initData,
336 SlaveVP *creatingSlv );
338 SlaveVP *
339 VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
340 SlaveVP *creatingSlv, int32 coreToAssignOnto);
342 void
343 VSs__cleanup_after_shutdown();
345 //===================== =====================
347 #include "VSs_Request_Handlers.h"
349 //===================== Measurement of Lang Overheads =====================
350 #include "Measurement/VSs_Measurement.h"
352 //===========================================================================
353 #endif /* _VSs_H */