Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view PR__structs.h @ 278:2fc69e6c14ea
Dev_ML -- works in both sequential and concurrent modes
author | Sean Halle <seanhalle@yahoo.com> |
---|---|
date | Fri, 08 Mar 2013 05:34:21 -0800 |
parents | 40e7625e57bd |
children | 7b6f8cf08b1f 15ee3fe10e3d |
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 (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
47 typedef void TopLevelFn ( 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 = 2,
125 SlvCreate = 3,
126 SlvDissipate = 4,
127 Language = 5,
128 Service = 6, //To invoke a PR provided equivalent of a language request (ex: probe)
129 Hardware = 7,
130 IO = 8,
131 OSCall = 9,
132 LangShutdown = 10,
133 ProcessEnd = 11,
134 PRShutdown = 12
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 TopLevelFnPtr 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
156 PRReqst *nextReqst;
157 };
158 //PRReqst
160 enum PRServiceReqType //These are equivalent to lang requests, but for
161 { // PR's services available directly to app, like OS
162 make_probe = 1, // and probe services -- like a PR-wide built-in lang
163 throw_excp,
164 openFile,
165 otherIO
166 };
168 typedef struct
169 { enum PRServiceReqType reqType;
170 SlaveVP *requestingSlv;
171 char *nameStr; //for create probe
172 char *msgStr; //for exception
173 void *exceptionData;
174 }
175 PRServiceReq;
178 //==================== Core data structures ===================
180 typedef struct
181 {
182 //for future expansion
183 }
184 SlotPerfInfo;
186 struct _AnimSlot
187 {
188 int32 workIsDone;
189 int32 needsWorkAssigned;
190 SlaveVP *slaveAssignedToSlot;
192 int32 slotIdx; //needed by Holistic Model's data gathering
193 int32 coreSlotIsOn;
194 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core
195 };
196 //AnimSlot
198 enum VPtype
199 { SlotTaskSlv = 1,//Slave tied to an anim slot, only animates tasks
200 FreeTaskSlv, //When a suspended task ends, the slave becomes this
201 GenericSlv, //the VP is explicitly seen in the app code, or task suspends
202 SeedSlv,
203 Master_VP,
204 ShutdownVP,
205 IdleVP
206 };
208 /*This structure embodies the state of a slaveVP. It is reused for masterVP
209 * and shutdownVPs.
210 */
211 struct _SlaveVP
212 { //The offsets of these fields are hard-coded into assembly
213 void *stackPtr; //save the core's stack ptr when suspend
214 void *framePtr; //save core's frame ptr when suspend
215 void *resumeInstrPtr; //save core's program-counter when suspend
216 void *coreCtlrFramePtr; //restore before jmp back to core controller
217 void *coreCtlrStackPtr; //restore before jmp back to core controller
219 //============ below this, no fields are used in asm =============
221 void *startOfStack; //used to free, and to point slave to Fn
222 PRProcess *processSlaveIsIn;
223 enum VPtype typeOfVP; //Slave vs Master vs Shutdown..
224 int32 slaveNum; //each slave given it's seq in creation
225 int32 *ID; //App defines meaning of each int in array
226 int32 coreAnimatedBy;
227 int32 numTimesAssignedToASlot; //Each assign is for one work-unit, so is an ID
228 //note, a scheduling decision is uniquely identified by the triple:
229 // <slaveNum, coreAnimatedBy, numTimesAssignedToASlot> -- used in record & replay
231 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin
232 AnimSlot *animSlotAssignedTo;
233 PRReqst *request; //wrapper lib puts in requests, plugin takes out
234 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib
236 //For language specific data that needs to be in the slave
237 //These are accessed directly for single-lang, but multi-lang places
238 // a holder here instead, then uses magic num to get lang's version
239 PRLangData **langDatas; //Lang saves lang-specific things in slave here
240 PRMetaTask **metaTasks;
242 //=========== MEASUREMENT STUFF ==========
243 MEAS__Insert_Meas_Fields_into_Slave;
244 float64 createPtInSecs; //time VP created, in seconds
245 //========================================
247 // int8 cacheLinePad[512 - sizeof(contents)]; //for false sharing
248 };
249 //SlaveVP
252 enum PRMode
253 { SingleLang = 1,
254 StandaloneWTasks,
255 MultiLang
256 };
258 /* The one and only global variable, holds many odds and ends
259 */
260 typedef struct
261 { //The offsets of these fields are hard-coded into assembly
262 void *coreCtlrReturnPt; //offset to this field used in asm
263 int8 falseSharePad1[256 - sizeof(void*)];
264 int32 masterLock; //offset to this field used in asm
265 int8 falseSharePad2[256 - sizeof(int32)];
266 //============ below this, no fields are used in asm =============
268 //Basic PR infrastructure
269 // enum PRMode mode;
270 SlaveVP **masterVPs;
271 AnimSlot ***allAnimSlots;
272 PrivQueueStruc *slaveRecycleQ;
273 SlaveVP *slotTaskSlvs[NUM_CORES][NUM_ANIM_SLOTS];
274 SlaveVP *idleSlv[NUM_CORES][NUM_ANIM_SLOTS];
276 //Memory management related
277 MallocArrays *freeLists;
278 int32 amtOfOutstandingMem;//total currently allocated
280 //Random number seeds -- random nums used in various places
281 uint32_t seed1;
282 uint32_t seed2;
284 PRSysMetaInfo *metaInfo; //info about this PR system -- vers, build, etc
286 //============== This only used by multi-lang mode ============
287 PRProcess **processes;
288 int32 numProcesses;
289 int32 currProcessIdx; //used to choose which process gets slot
290 int32 firstProcessReady; //use while starting up coreCtlr
292 //initialize flags for waiting for activity within PR to complete
293 bool32 allActivityIsDone;
294 pthread_mutex_t activityDoneLock;
295 pthread_cond_t activityDoneCond;
297 SlaveAssigner overrideAssigner;
299 //============== Below this is only used by single-lang mode ==============
300 void *protoLangEnv;
301 //Slave creation -- global count of slaves existing, across langs and processes
302 int32 numSlavesCreated; //used to give unique ID to processor
303 int32 numTasksCreated; //to give unique ID to a task
304 int32 numSlavesAlive;
306 bool32 *coreIsDone;
307 int32 numCoresDone;
308 int32 shutdownInitiated;
311 //=========== MEASUREMENT STUFF =============
312 IntervalProbe **intervalProbes;
313 PrivDynArrayInfo *dynIntervalProbesInfo;
314 HashTable *probeNameHashTbl;
315 int32 masterCreateProbeID;
316 float64 createPtInSecs; //real-clock time PR initialized
317 Histogram **measHists;
318 PrivDynArrayInfo *measHistsInfo;
319 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
320 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
321 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
322 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
323 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
324 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
325 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv;
326 //==========================================
327 }
328 TopEnv;
331 //===================== These are prologs ====================
332 //===A prolog is data immediately before pointer returned by a create function.
333 //=
334 struct _PRLangEnv
335 { //============== First two must match PRCollElem ==============
336 int32 langMagicNumber; //indexes into hash array of langEnvs in PRProcess
337 PRLangEnv *chainedLangEnv; //chains to langEnvs with same hash
338 //=============================================================
340 SlaveAssigner workAssigner;
341 LangShutdownHdlr shutdownHdlr; //called when lang ended or process shutdown
342 LangDataCreator langDataCreator;
343 LangMetaTaskCreator langMetaTaskCreator;
344 MakeSlaveReadyFn makeSlaveReadyFn;
345 MakeTaskReadyFn makeTaskReadyFn;
347 //when multi-lang, master polls lang env's to find one with work in it..
348 // in single-lang case, flag ignored, master always asks lang for work
349 int32 hasWork;
350 PRProcess *processEnvIsIn;
352 int32 idxInProcess; //index into array of langEnvs in the process
354 int32 numReadyWork;
356 int32 numLiveWork;
357 PrivQueueStruc *waitingForWorkToEndQ;
358 };
359 //PRLangEnv -- this is the prolog of every lang's lang env
361 enum PRTaskType
362 { GenericSlave = 1,
363 SlotTask,
364 FreeTask
365 };
367 struct _PRMetaTask
368 { //============== First two must match PRCollElem ==============
369 int32 langMagicNumber;
370 PRMetaTask *chainedMetaTask;
371 //=============================================================
372 enum PRTaskType taskType;
373 int32 *ID; //is standard PR ID
374 PRProcess *processTaskIsIn;
375 SlaveVP *slaveAssignedTo; //not valid until task animated
376 TopLevelFnPtr topLevelFn; //This is the Fn executes as the task
377 void *initData; //The data taken by the function
378 LangMetaTaskFreer freer;
379 bool32 goAheadAndFree;
381 //NOTE: info needed for "wait" functionality is inside lang's metaTask
382 };
383 //PRMetaTask -- prolog of every lang's meta task
385 struct _PRLangData
386 { //============== First two must match PRCollElem ==============
387 int32 langMagicNumber;
388 PRLangData *chainedLangData;
389 //=============================================================
390 LangDataFreer freer;
391 bool32 goAheadAndFree;
392 SlaveVP *slaveAssignedTo;
393 };
394 //PRLangData -- this is the prolog of each lang's lang data
396 struct _PRCollElem
397 {
398 int32 hash;
399 PRCollElem *chained;
400 };
401 //PRCollElem -- this is generic form of all the prologs
405 //========================= Extra Stuff Data Strucs =======================
406 typedef struct
407 {
409 }
410 PRExcp; //exception
412 //======================= OS Thread related ===============================
414 void * coreController( void *paramsIn ); //standard PThreads fn prototype
415 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype
416 void animationMaster( void *initData, SlaveVP *masterVP );
419 typedef struct
420 {
421 void *endThdPt;
422 unsigned int coreNum;
423 }
424 ThdParams;
426 #endif /* _PR__structs_H */