Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison PR.h @ 260:999f2966a3e5
new branch -- Dev_ML -- for making VMS take langlets whose constructs can be mixed
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Wed, 19 Sep 2012 23:12:44 -0700 |
| parents | |
| children | dafae55597ce |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b13e745dfc18 |
|---|---|
| 1 /* | |
| 2 * Copyright 2009 OpenSourceStewardshipFoundation.org | |
| 3 * Licensed under GNU General Public License version 2 | |
| 4 * | |
| 5 * Author: seanhalle@yahoo.com | |
| 6 * | |
| 7 */ | |
| 8 | |
| 9 #ifndef _PR_H | |
| 10 #define _PR_H | |
| 11 #define _GNU_SOURCE | |
| 12 | |
| 13 #include "DynArray/DynArray.h" | |
| 14 #include "Hash_impl/PrivateHash.h" | |
| 15 #include "Histogram/Histogram.h" | |
| 16 #include "Queue_impl/PrivateQueue.h" | |
| 17 | |
| 18 #include "PR_primitive_data_types.h" | |
| 19 #include "Services_Offered_by_PR/Memory_Handling/vmalloc.h" | |
| 20 | |
| 21 #include <pthread.h> | |
| 22 #include <sys/time.h> | |
| 23 | |
| 24 //================= Defines: included from separate files ================= | |
| 25 // | |
| 26 // Note: ALL defines are in other files, none are in here | |
| 27 // | |
| 28 #include "Defines/PR_defs.h" | |
| 29 | |
| 30 | |
| 31 //================================ Typedefs ================================= | |
| 32 // | |
| 33 typedef unsigned long long TSCount; | |
| 34 | |
| 35 typedef struct _AnimSlot AnimSlot; | |
| 36 typedef struct _PRReqst PRReqst; | |
| 37 typedef struct _SlaveVP SlaveVP; | |
| 38 typedef struct _MasterVP MasterVP; | |
| 39 typedef struct _IntervalProbe IntervalProbe; | |
| 40 | |
| 41 | |
| 42 typedef SlaveVP *(*SlaveAssigner) ( void *, AnimSlot*); //semEnv, slot for HW info | |
| 43 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv | |
| 44 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv | |
| 45 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv | |
| 46 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * ); | |
| 47 //=========== MEASUREMENT STUFF ========== | |
| 48 MEAS__Insert_Counter_Handler | |
| 49 //======================================== | |
| 50 | |
| 51 //============================ HW Dependent Fns ================================ | |
| 52 | |
| 53 #include "HW_Dependent_Primitives/PR__HW_measurement.h" | |
| 54 #include "HW_Dependent_Primitives/PR__primitives.h" | |
| 55 | |
| 56 | |
| 57 //============= Request Related =========== | |
| 58 // | |
| 59 | |
| 60 enum PRReqstType //avoid starting enums at 0, for debug reasons | |
| 61 { | |
| 62 semantic = 1, | |
| 63 createReq, | |
| 64 dissipate, | |
| 65 PRSemantic //goes with PRSemReqst below | |
| 66 }; | |
| 67 | |
| 68 struct _PRReqst | |
| 69 { | |
| 70 enum PRReqstType reqType;//used for dissipate and in future for IO requests | |
| 71 void *semReqData; | |
| 72 | |
| 73 PRReqst *nextReqst; | |
| 74 }; | |
| 75 //PRReqst | |
| 76 | |
| 77 enum PRSemReqstType //These are equivalent to semantic requests, but for | |
| 78 { // PR's services available directly to app, like OS | |
| 79 make_probe = 1, // and probe services -- like a PR-wide built-in lang | |
| 80 throw_excp, | |
| 81 openFile, | |
| 82 otherIO | |
| 83 }; | |
| 84 | |
| 85 typedef struct | |
| 86 { enum PRSemReqstType reqType; | |
| 87 SlaveVP *requestingSlv; | |
| 88 char *nameStr; //for create probe | |
| 89 char *msgStr; //for exception | |
| 90 void *exceptionData; | |
| 91 } | |
| 92 PRSemReq; | |
| 93 | |
| 94 | |
| 95 //==================== Core data structures =================== | |
| 96 | |
| 97 typedef struct | |
| 98 { | |
| 99 //for future expansion | |
| 100 } | |
| 101 SlotPerfInfo; | |
| 102 | |
| 103 struct _AnimSlot | |
| 104 { | |
| 105 int workIsDone; | |
| 106 int needsSlaveAssigned; | |
| 107 SlaveVP *slaveAssignedToSlot; | |
| 108 | |
| 109 int slotIdx; //needed by Holistic Model's data gathering | |
| 110 int coreSlotIsOn; | |
| 111 SlotPerfInfo *perfInfo; //used by assigner to pick best slave for core | |
| 112 }; | |
| 113 //AnimSlot | |
| 114 | |
| 115 enum VPtype | |
| 116 { TaskSlotSlv = 1,//Slave tied to an anim slot, only animates tasks | |
| 117 TaskExtraSlv, //When a suspended task ends, the slave becomes this | |
| 118 PersistentSlv, //the VP is explicitly seen in the app code, or task suspends | |
| 119 Slave, //to be removed | |
| 120 Master, | |
| 121 Shutdown, | |
| 122 Idle | |
| 123 }; | |
| 124 | |
| 125 /*This structure embodies the state of a slaveVP. It is reused for masterVP | |
| 126 * and shutdownVPs. | |
| 127 */ | |
| 128 struct _SlaveVP | |
| 129 { //The offsets of these fields are hard-coded into assembly | |
| 130 void *stackPtr; //save the core's stack ptr when suspend | |
| 131 void *framePtr; //save core's frame ptr when suspend | |
| 132 void *resumeInstrPtr; //save core's program-counter when suspend | |
| 133 void *coreCtlrFramePtr; //restore before jmp back to core controller | |
| 134 void *coreCtlrStackPtr; //restore before jmp back to core controller | |
| 135 | |
| 136 //============ below this, no fields are used in asm ============= | |
| 137 | |
| 138 int slaveID; //each slave given a globally unique ID | |
| 139 int coreAnimatedBy; | |
| 140 void *startOfStack; //used to free, and to point slave to Fn | |
| 141 enum VPtype typeOfVP; //Slave vs Master vs Shutdown.. | |
| 142 int assignCount; //Each assign is for one work-unit, so IDs it | |
| 143 //note, a scheduling decision is uniquely identified by the triple: | |
| 144 // <slaveID, coreAnimatedBy, assignCount> -- used in record & replay | |
| 145 | |
| 146 //for comm -- between master and coreCtlr & btwn wrapper lib and plugin | |
| 147 AnimSlot *animSlotAssignedTo; | |
| 148 PRReqst *request; //wrapper lib puts in requests, plugin takes out | |
| 149 void *dataRetFromReq;//Return vals from plugin to Wrapper Lib | |
| 150 | |
| 151 //For using Slave as carrier for data | |
| 152 void *semanticData; //Lang saves lang-specific things in slave here | |
| 153 | |
| 154 //=========== MEASUREMENT STUFF ========== | |
| 155 MEAS__Insert_Meas_Fields_into_Slave; | |
| 156 float64 createPtInSecs; //time VP created, in seconds | |
| 157 //======================================== | |
| 158 }; | |
| 159 //SlaveVP | |
| 160 | |
| 161 | |
| 162 /* The one and only global variable, holds many odds and ends | |
| 163 */ | |
| 164 typedef struct | |
| 165 { //The offsets of these fields are hard-coded into assembly | |
| 166 void *coreCtlrReturnPt; //offset to this field used in asm | |
| 167 int8 falseSharePad1[256 - sizeof(void*)]; | |
| 168 int32 masterLock; //offset to this field used in asm | |
| 169 int8 falseSharePad2[256 - sizeof(int32)]; | |
| 170 //============ below this, no fields are used in asm ============= | |
| 171 | |
| 172 //Basic PR infrastructure | |
| 173 SlaveVP **masterVPs; | |
| 174 AnimSlot ***allAnimSlots; | |
| 175 | |
| 176 //plugin related | |
| 177 PRSemEnv **langlets; | |
| 178 | |
| 179 //Slave creation -- global count of slaves existing, across langs and processes | |
| 180 int32 numSlavesCreated; //used to give unique ID to processor | |
| 181 //no reasonable way to do fail-safe when have mult langlets and processes.. have to detect for each langlet separately | |
| 182 // int32 numSlavesAlive; //used to detect fail-safe shutdown | |
| 183 | |
| 184 //Initialization related | |
| 185 int32 setupComplete; //use while starting up coreCtlr | |
| 186 | |
| 187 //Memory management related | |
| 188 MallocArrays *freeLists; | |
| 189 int32 amtOfOutstandingMem;//total currently allocated | |
| 190 | |
| 191 //Random number seeds -- random nums used in various places | |
| 192 uint32_t seed1; | |
| 193 uint32_t seed2; | |
| 194 | |
| 195 //=========== MEASUREMENT STUFF ============= | |
| 196 IntervalProbe **intervalProbes; | |
| 197 PtrToPrivDynArray *dynIntervalProbesInfo; | |
| 198 HashTable *probeNameHashTbl; | |
| 199 int32 masterCreateProbeID; | |
| 200 float64 createPtInSecs; //real-clock time PR initialized | |
| 201 Histogram **measHists; | |
| 202 PtrToPrivDynArray *measHistsInfo; | |
| 203 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv; | |
| 204 MEAS__Insert_Master_Meas_Fields_into_MasterEnv; | |
| 205 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv; | |
| 206 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv; | |
| 207 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv; | |
| 208 MEAS__Insert_System_Meas_Fields_into_MasterEnv; | |
| 209 MEAS__Insert_Counter_Meas_Fields_into_MasterEnv; | |
| 210 //========================================== | |
| 211 } | |
| 212 MasterEnv; | |
| 213 | |
| 214 //===================== | |
| 215 typedef struct | |
| 216 { int32 langletID; //acts as index into array of langlets in master env | |
| 217 void *langletSemEnv; | |
| 218 int32 langMagicNumber; | |
| 219 SlaveAssigner slaveAssigner; | |
| 220 RequestHandler requestHandler; | |
| 221 EndTaskHandler endTaskHandler; | |
| 222 | |
| 223 //Tack slaves created, separately for each langlet (in each process) | |
| 224 int32 numSlavesCreated; //gives ordering to processor creation | |
| 225 int32 numSlavesAlive; //used to detect fail-safe shutdown | |
| 226 | |
| 227 //when multi-lang, master polls sem env's to find one with work in it.. | |
| 228 // in single-lang case, flag ignored, master always asks lang for work | |
| 229 int32 hasWork; | |
| 230 } | |
| 231 PRSemEnv; | |
| 232 | |
| 233 //===================== Top Processor level Data Strucs ====================== | |
| 234 typedef struct | |
| 235 { | |
| 236 | |
| 237 } | |
| 238 PRProcess; | |
| 239 /*This structure holds all the information PR needs to manage a program. PR | |
| 240 * stores information about what percent of CPU time the program is getting, | |
| 241 * | |
| 242 */ | |
| 243 typedef struct | |
| 244 { //void *semEnv; | |
| 245 //RequestHdlrFnPtr requestHandler; | |
| 246 //SlaveAssignerFnPtr slaveAssigner; | |
| 247 int32 numSlavesLive; | |
| 248 void *resultToReturn; | |
| 249 | |
| 250 SlaveVP *seedSlv; | |
| 251 | |
| 252 //These are used to coordinate within the main function..? | |
| 253 bool32 executionIsComplete; | |
| 254 pthread_mutex_t doneLock; //? not sure need these..? | |
| 255 pthread_cond_t doneCond; | |
| 256 } | |
| 257 PRProcess; | |
| 258 | |
| 259 | |
| 260 //========================= Extra Stuff Data Strucs ======================= | |
| 261 typedef struct | |
| 262 { | |
| 263 | |
| 264 } | |
| 265 PRExcp; //exception | |
| 266 | |
| 267 //======================= OS Thread related =============================== | |
| 268 | |
| 269 void * coreController( void *paramsIn ); //standard PThreads fn prototype | |
| 270 void * coreCtlr_Seq( void *paramsIn ); //standard PThreads fn prototype | |
| 271 void animationMaster( void *initData, SlaveVP *masterVP ); | |
| 272 | |
| 273 | |
| 274 typedef struct | |
| 275 { | |
| 276 void *endThdPt; | |
| 277 unsigned int coreNum; | |
| 278 } | |
| 279 ThdParams; | |
| 280 | |
| 281 //============================= Global Vars ================================ | |
| 282 | |
| 283 volatile MasterEnv *_PRMasterEnv __align_to_cacheline__; | |
| 284 | |
| 285 //these are global, but only used for startup and shutdown | |
| 286 pthread_t coreCtlrThdHandles[ NUM_CORES ]; //pthread's virt-procr state | |
| 287 ThdParams *coreCtlrThdParams [ NUM_CORES ]; | |
| 288 | |
| 289 pthread_mutex_t suspendLock; | |
| 290 pthread_cond_t suspendCond; | |
| 291 | |
| 292 //========================= Function Prototypes =========================== | |
| 293 /* MEANING OF WL PI SS int PROS | |
| 294 * These indicate which places the function is safe to use. They stand for: | |
| 295 * | |
| 296 * WL Wrapper Library -- wrapper lib code should only use these | |
| 297 * PI Plugin -- plugin code should only use these | |
| 298 * SS Startup and Shutdown -- designates these relate to startup & shutdown | |
| 299 * int internal to PR -- should not be used in wrapper lib or plugin | |
| 300 * PROS means "OS functions for applications to use" | |
| 301 * | |
| 302 * PR_int__ functions touch internal PR data structs and are only safe | |
| 303 * to be used inside the master lock. However, occasionally, they appear | |
| 304 * in wrapper-lib or plugin code. In those cases, very careful analysis | |
| 305 * has been done to be sure no concurrency issues could arise. | |
| 306 * | |
| 307 * PR_WL__ functions are all safe for use outside the master lock. | |
| 308 * | |
| 309 * PROS are only safe for applications to use -- they're like a second | |
| 310 * language mixed in -- but they can't be used inside plugin code, and | |
| 311 * aren't meant for use in wrapper libraries, because they are themselves | |
| 312 * wrapper-library calls! | |
| 313 */ | |
| 314 //========== Startup and shutdown ========== | |
| 315 void | |
| 316 PR__start(); | |
| 317 | |
| 318 void | |
| 319 PR_SS__start_the_work_then_wait_until_done(); | |
| 320 | |
| 321 SlaveVP* | |
| 322 PR_SS__create_shutdown_slave(); | |
| 323 | |
| 324 void | |
| 325 PR_SS__shutdown(); | |
| 326 | |
| 327 void | |
| 328 PR_SS__cleanup_at_end_of_shutdown(); | |
| 329 | |
| 330 void | |
| 331 PR_SS__register_langlets_semEnv( PRSemEnv *semEnv, int32 VSs_MAGIC_NUMBER, | |
| 332 SlaveVP *seedVP ); | |
| 333 | |
| 334 | |
| 335 //============== =============== | |
| 336 | |
| 337 inline SlaveVP * | |
| 338 PR_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam ); | |
| 339 #define PR_PI__create_slaveVP PR_int__create_slaveVP | |
| 340 #define PR_WL__create_slaveVP PR_int__create_slaveVP | |
| 341 | |
| 342 //Use this to create processor inside entry point & other places outside | |
| 343 // the PR system boundary (IE, don't animate with a SlaveVP or MasterVP) | |
| 344 SlaveVP * | |
| 345 PR_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam ); | |
| 346 | |
| 347 inline SlaveVP * | |
| 348 PR_int__create_slaveVP_helper( SlaveVP *newSlv, TopLevelFnPtr fnPtr, | |
| 349 void *dataParam, void *stackLocs ); | |
| 350 | |
| 351 inline void | |
| 352 PR_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr, | |
| 353 void *dataParam); | |
| 354 | |
| 355 inline void | |
| 356 PR_int__point_slaveVP_to_OneParamFn( SlaveVP *slaveVP, void *fnPtr, | |
| 357 void *param); | |
| 358 | |
| 359 inline void | |
| 360 PR_int__point_slaveVP_to_TwoParamFn( SlaveVP *slaveVP, void *fnPtr, | |
| 361 void *param1, void *param2); | |
| 362 | |
| 363 void | |
| 364 PR_int__dissipate_slaveVP( SlaveVP *slaveToDissipate ); | |
| 365 #define PR_PI__dissipate_slaveVP PR_int__dissipate_slaveVP | |
| 366 //WL: dissipate a SlaveVP by sending a request | |
| 367 | |
| 368 void | |
| 369 PR_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate ); | |
| 370 | |
| 371 void | |
| 372 PR_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, PRExcp *excpData ); | |
| 373 #define PR_PI__throw_exception PR_int__throw_exception | |
| 374 void | |
| 375 PR_WL__throw_exception( char *msgStr, SlaveVP *reqstSlv, PRExcp *excpData ); | |
| 376 #define PR_App__throw_exception PR_WL__throw_exception | |
| 377 | |
| 378 void * | |
| 379 PR_int__give_sem_env_for( SlaveVP *animSlv ); | |
| 380 #define PR_PI__give_sem_env_for PR_int__give_sem_env_for | |
| 381 #define PR_SS__give_sem_env_for PR_int__give_sem_env_for | |
| 382 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable | |
| 383 | |
| 384 | |
| 385 inline void | |
| 386 PR_int__get_master_lock(); | |
| 387 | |
| 388 #define PR_int__release_master_lock() _PRMasterEnv->masterLock = UNLOCKED | |
| 389 | |
| 390 inline uint32_t | |
| 391 PR_int__randomNumber(); | |
| 392 | |
| 393 //============== Request Related =============== | |
| 394 | |
| 395 void | |
| 396 PR_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv ); | |
| 397 | |
| 398 inline void | |
| 399 PR_WL__add_sem_request_in_mallocd_PRReqst( void *semReqData, SlaveVP *callingSlv ); | |
| 400 | |
| 401 inline void | |
| 402 PR_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv ); | |
| 403 | |
| 404 void | |
| 405 PR_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv ); | |
| 406 | |
| 407 void inline | |
| 408 PR_WL__send_dissipate_req( SlaveVP *prToDissipate ); | |
| 409 | |
| 410 inline void | |
| 411 PR_WL__send_PRSem_request( void *semReqData, SlaveVP *callingSlv ); | |
| 412 | |
| 413 PRReqst * | |
| 414 PR_PI__take_next_request_out_of( SlaveVP *slaveWithReq ); | |
| 415 //#define PR_PI__take_next_request_out_of( slave ) slave->requests | |
| 416 | |
| 417 //inline void * | |
| 418 //PR_PI__take_sem_reqst_from( PRReqst *req ); | |
| 419 #define PR_PI__take_sem_reqst_from( req ) req->semReqData | |
| 420 | |
| 421 void inline | |
| 422 PR_PI__handle_PRSemReq( PRReqst *req, SlaveVP *requestingSlv, void *semEnv, | |
| 423 ResumeSlvFnPtr resumeSlvFnPtr ); | |
| 424 | |
| 425 //======================== MEASUREMENT ====================== | |
| 426 uint64 | |
| 427 PR_WL__give_num_plugin_cycles(); | |
| 428 uint32 | |
| 429 PR_WL__give_num_plugin_animations(); | |
| 430 | |
| 431 | |
| 432 //========================= Utilities ======================= | |
| 433 inline char * | |
| 434 PR_int__strDup( char *str ); | |
| 435 | |
| 436 | |
| 437 //========================= Probes ======================= | |
| 438 #include "Services_Offered_by_PR/Measurement_and_Stats/probes.h" | |
| 439 | |
| 440 //================================================ | |
| 441 #endif /* _PR_H */ | |
| 442 |
