VMS/VMS_Implementations/VMS_impls/VMS__MC_shared_impl

view PR__structs.h @ 286:b02b34681414

VReo V2 -- saves checker and doer fn with the port, where triggered
author Sean Halle <seanhalle@yahoo.com>
date Wed, 10 Jul 2013 14:49:04 -0700
parents 2fc69e6c14ea
children 744b5ff9851e
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 _PR__structs_H
10 #define _PR__structs_H
11 #define _GNU_SOURCE
13 #include "PR_primitive_data_types.h"
15 #include <pthread.h>
16 #include <sys/time.h>
19 //================================ Typedefs =================================
20 //===
21 //=
22 #define ZERO 0
24 typedef unsigned long long TSCount;
26 typedef struct _AnimSlot AnimSlot;
27 typedef struct _PRReqst PRReqst;
28 typedef struct _SlaveVP SlaveVP;
29 typedef struct _MasterVP MasterVP;
30 typedef struct _IntervalProbe IntervalProbe;
31 typedef struct _PRLangEnv PRLangEnv; //a prolog
32 typedef struct _PRMetaTask PRMetaTask; //a prolog
33 typedef struct _PRLangData PRLangData; //a prolog
34 typedef struct _PRCollElem PRCollElem; //generic form of the prologs
36 typedef bool32 (*SlaveAssigner) ( void *, AnimSlot* ); //langEnv, slot for HW info
37 typedef void (*RequestHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv
38 typedef void *(*CreateHandler) ( void *, SlaveVP *, void * ); //req, slv, langEnv
39 typedef void (*LangShutdownHdlr) ( void * ); //langEnv
40 typedef void *(*LangDataCreator) ( SlaveVP * );
41 typedef void (*LangDataFreer) ( void * ); //lang data to free
42 typedef void *(*LangMetaTaskCreator)( SlaveVP * ); //when slave has no meta task for magic num
43 typedef void (*LangMetaTaskFreer) ( void * ); //lang meta task to free
44 typedef void (*MakeSlaveReadyFn) ( SlaveVP *, void * ); //slave and langEnv
45 typedef void (*MakeTaskReadyFn) ( void *, void * ); //langTask and langEnv
46 typedef void (*BirthFnPtr) ( void *, SlaveVP * ); //initData, animSlv
47 typedef void BirthFn ( void *, SlaveVP * ); //initData, animSlv
48 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
49 //=========== MEASUREMENT STUFF ==========
50 MEAS__Insert_Counter_Handler
51 //========================================
53 //============================ HW Dependent Fns ================================
55 #include "HW_Dependent_Primitives/PR__HW_measurement.h"
56 #include "HW_Dependent_Primitives/PR__primitives.h"
59 typedef struct
60 { //These are set by the plugin during startup and the application
61 char *assignerInfo;
62 char *appInfo;
63 char *inputInfo;
64 }
65 PRSysMetaInfo;
67 //===================== Process Data Struct ======================
69 /*This structure holds all the information PR needs to manage a program. PR
70 * stores information about what percent of CPU time the program is getting,
71 *
72 */
73 typedef struct
74 {
75 int32 numEnvsWithWork;
76 void *resultToReturn;
78 PRLangEnv **langEnvs; //used as a hash table
79 PRLangEnv **protoLangEnvsList; //for fast linear scan of envs
80 int32 numLangEnvs; //for fast linear scan of envs
82 SlaveVP *seedSlv;
84 int32 numLiveGenericSlvs;
85 int32 numLiveTasks;
87 SlaveAssigner overrideAssigner;
91 //These are used to coord with an OS thread waiting for process to end
92 bool32 hasWaitingToEnd;
93 bool32 executionIsComplete;
94 pthread_mutex_t doneLock;
95 pthread_cond_t doneCond;
96 pthread_mutex_t doneAckLock; //waiter gets, then releases when done waiting
98 //=========== MEASUREMENT STUFF =============
99 IntervalProbe **intervalProbes;
100 PrivDynArrayInfo *dynIntervalProbesInfo;
101 HashTable *probeNameHashTbl;
102 int32 masterCreateProbeID;
103 float64 createPtInSecs; //real-clock time PR initialized
104 Histogram **measHists;
105 PrivDynArrayInfo *measHistsInfo;
106 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
107 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
108 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
109 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
110 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
111 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
112 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
113 //==========================================
114 }
115 PRProcess;
118 //============= Request Related ===========
119 //
121 enum PRReqstType //avoid starting enums at 0, for debug reasons
122 {
123 TaskCreate = 1,
124 TaskEnd,
125 SlvCreate,
126 SlvDissipate,
127 Language,
128 Service, //To invoke a PR provided equivalent of a language request (ex: probe)
129 Hardware,
130 IO,
131 OSCall,
132 LangShutdown,
133 ProcessEnd,
134 PRShutdown
135 };
138 struct _PRReqst
139 {
140 enum PRReqstType reqType;//used for special forms that have PR behavior
141 void *langReq;
142 PRProcess *processReqIsIn;
143 int32 langMagicNumber;
144 SlaveVP *requestingSlave;
146 BirthFnPtr topLevelFn;
147 void *initData;
148 int32 *ID;
150 //The request handling structure is a bit messy.. for special forms,
151 // such as create and dissipate, the language inserts pointer to handler
152 // fn directly into the request.. might change to this for all requests
153 RequestHandler handler; //pointer to handler fn
154 CreateHandler createHdlr; //special because returns something
155 int32 createSuspendedGroup; //must be non-zero
157 PRReqst *nextReqst;
158 };
159 //PRReqst
161 enum PRServiceReqType //These are equivalent to lang requests, but for
162 { // PR's services available directly to app, like OS
163 make_probe = 1, // and probe services -- like a PR-wide built-in lang
164 throw_excp,
165 openFile,
166 otherIO
167 };
169 typedef struct
170 { enum PRServiceReqType reqType;
171 SlaveVP *requestingSlv;
172 char *nameStr; //for create probe
173 char *msgStr; //for exception
174 void *exceptionData;
175 }
176 PRServiceReq;
179 //==================== Core data structures ===================
181 typedef struct
182 {
183 //for future expansion
184 }
185 SlotPerfInfo;
187 struct _AnimSlot
188 {
189 int32 workIsDone;
190 int32 needsWorkAssigned;
191 SlaveVP *slaveAssignedToSlot;
193 int32 slotIdx; //needed by Holistic Model's data gathering
194 int32 coreSlotIsOn;
195 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
196 };
197 //AnimSlot
199 enum VPtype
200 { SlotTaskSlv = 1,//Slave tied to an anim slot, only animates tasks
201 FreeTaskSlv, //When a suspended task ends, the slave becomes this
202 GenericSlv, //the VP is explicitly seen in the app code, or task suspends
203 SeedSlv,
204 Master_VP,
205 ShutdownVP,
206 IdleVP
207 };
209 /*This structure embodies the state of a slaveVP. It is reused for masterVP
210 * and shutdownVPs.
211 */
212 struct _SlaveVP
213 { //The offsets of these fields are hard-coded into assembly
214 void *stackPtr; //save the core's stack ptr when suspend
215 void *framePtr; //save core's frame ptr when suspend
216 void *resumeInstrPtr; //save core's program-counter when suspend
217 void *coreCtlrFramePtr; //restore before jmp back to core controller
218 void *coreCtlrStackPtr; //restore before jmp back to core controller
220 //============ below this, no fields are used in asm =============
222 void *startOfStack; //used to free, and to point slave to Fn
223 PRProcess *processSlaveIsIn;
224 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
225 int32 slaveNum; //each slave given it's seq in creation
226 int32 *ID; //App defines meaning of each int in array
227 int32 coreAnimatedBy;
228 int32 numTimesAssignedToASlot; //Each assign is for one work-unit, so is an ID
229 //note, a scheduling decision is uniquely identified by the triple:
230 // <slaveNum, coreAnimatedBy, numTimesAssignedToASlot> -- used in record & replay
232 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
233 AnimSlot *animSlotAssignedTo;
234 PRReqst *request; //wrapper lib puts in requests, plugin takes out
235 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
237 //For language specific data that needs to be in the slave
238 //These are accessed directly for single-lang, but multi-lang places
239 // a holder here instead, then uses magic num to get lang's version
240 PRLangData **langDatas; //Lang saves lang-specific things in slave here
241 PRMetaTask **metaTasks;
243 //=========== MEASUREMENT STUFF ==========
244 MEAS__Insert_Meas_Fields_into_Slave;
245 float64 createPtInSecs; //time VP created, in seconds
246 //========================================
248 // int8 cacheLinePad[512 - sizeof(contents)]; //for false sharing
249 };
250 //SlaveVP
253 enum PRMode
254 { SingleLang = 1,
255 StandaloneWTasks,
256 MultiLang
257 };
259 /* The one and only global variable, holds many odds and ends
260 */
261 typedef struct
262 { //The offsets of these fields are hard-coded into assembly
263 void *coreCtlrReturnPt; //offset to this field used in asm
264 int8 falseSharePad1[256 - sizeof(void*)];
265 int32 masterLock; //offset to this field used in asm
266 int8 falseSharePad2[256 - sizeof(int32)];
267 int32 wrapperLock; //offset to this field used in asm
268 int8 falseSharePad3[256 - sizeof(int32)];
269 int32 mallocLock; //offset to this field used in asm
270 int8 falseSharePad4[256 - sizeof(int32)];
271 //============ below this, no fields are used in asm =============
273 //Basic PR infrastructure
274 // enum PRMode mode;
275 SlaveVP **masterVPs;
276 AnimSlot ***allAnimSlots;
277 PrivQueueStruc *slaveRecycleQ;
278 SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
279 SlaveVP *idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
281 //Memory management related
282 MallocArrays *freeLists;
283 int32 amtOfOutstandingMem;//total currently allocated
285 //Random number seeds -- random nums used in various places
286 uint32_t seed1;
287 uint32_t seed2;
289 PRSysMetaInfo *metaInfo; //info about this PR system -- vers, build, etc
291 //============== This only used by multi-lang mode ============
292 PRProcess **processes;
293 int32 numProcesses;
294 int32 currProcessIdx; //used to choose which process gets slot
295 int32 firstProcessReady; //use while starting up coreCtlr
297 //initialize flags for waiting for activity within PR to complete
298 bool32 allActivityIsDone;
299 pthread_mutex_t activityDoneLock;
300 pthread_cond_t activityDoneCond;
302 SlaveAssigner overrideAssigner;
304 //============== Below this is only used by single-lang mode ==============
305 void *protoLangEnv;
306 //Slave creation -- global count of slaves existing, across langs and processes
307 int32 numSlavesCreated; //used to give unique ID to processor
308 int32 numTasksCreated; //to give unique ID to a task
309 int32 numSlavesAlive;
311 bool32 *coreIsDone;
312 int32 numCoresDone;
313 int32 shutdownInitiated;
316 //=========== MEASUREMENT STUFF =============
317 IntervalProbe **intervalProbes;
318 PrivDynArrayInfo *dynIntervalProbesInfo;
319 HashTable *probeNameHashTbl;
320 int32 masterCreateProbeID;
321 float64 createPtInSecs; //real-clock time PR initialized
322 Histogram **measHists;
323 PrivDynArrayInfo *measHistsInfo;
324 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
325 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
326 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
327 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
328 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
329 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
330 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
331 //==========================================
332 }
333 TopEnv;
336 //===================== These are prologs ====================
337 //===A prolog is data immediately before pointer returned by a create function.
338 //=
339 struct _PRLangEnv
340 { //============== First two must match PRCollElem ==============
341 int32 langMagicNumber; //indexes into hash array of langEnvs in PRProcess
342 PRLangEnv *chainedLangEnv; //chains to langEnvs with same hash
343 //=============================================================
345 SlaveAssigner workAssigner;
346 LangShutdownHdlr shutdownHdlr; //called when lang ended or process shutdown
347 LangDataCreator langDataCreator;
348 LangMetaTaskCreator langMetaTaskCreator;
349 MakeSlaveReadyFn makeSlaveReadyFn;
350 MakeTaskReadyFn makeTaskReadyFn;
352 //when multi-lang, master polls lang env's to find one with work in it..
353 // in single-lang case, flag ignored, master always asks lang for work
354 int32 hasWork;
355 PRProcess *processEnvIsIn;
357 int32 idxInProcess; //index into array of langEnvs in the process
359 int32 numReadyWork;
361 int32 numLiveWork;
362 PrivQueueStruc *waitingForWorkToEndQ;
363 };
364 //PRLangEnv -- this is the prolog of every lang's lang env
366 enum PRTaskType
367 { GenericSlave = 1,
368 SlotTask,
369 FreeTask
370 };
372 struct _PRMetaTask
373 { //============== First two must match PRCollElem ==============
374 int32 langMagicNumber;
375 PRMetaTask *chainedMetaTask;
376 //=============================================================
377 enum PRTaskType taskType;
378 int32 *ID; //is standard PR ID
379 PRProcess *processTaskIsIn;
380 SlaveVP *slaveAssignedTo; //not valid until task animated
381 BirthFnPtr topLevelFn; //This is the Fn executes as the task
382 void *initData; //The data taken by the function
383 LangMetaTaskFreer freer;
384 bool32 goAheadAndFree;
386 //NOTE: info needed for "wait" functionality is inside lang's metaTask
387 };
388 //PRMetaTask -- prolog of every lang's meta task
390 struct _PRLangData
391 { //============== First two must match PRCollElem ==============
392 int32 langMagicNumber;
393 PRLangData *chainedLangData;
394 //=============================================================
395 LangDataFreer freer;
396 bool32 goAheadAndFree;
397 SlaveVP *slaveAssignedTo;
398 };
399 //PRLangData -- this is the prolog of each lang's lang data
401 struct _PRCollElem
402 {
403 int32 hash;
404 PRCollElem *chained;
405 };
406 //PRCollElem -- this is generic form of all the prologs
410 //========================= Extra Stuff Data Strucs =======================
411 typedef struct
412 {
414 }
415 PRExcp; //exception
417 //======================= OS Thread related ===============================
419 void * coreController( void *paramsIn ); //standard PThreads fn prototype
420 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
421 void animationMaster( void *initData, SlaveVP *masterVP );
424 typedef struct
425 {
426 void *endThdPt;
427 unsigned int coreNum;
428 }
429 ThdParams;
431 #endif /* _PR__structs_H */