annotate VMS.h @ 209:0c83ea8adefc

Close to compilable version of common_ancestor -- still includes HW dep stuff
author Some Random Person <seanhalle@yahoo.com>
date Sun, 04 Mar 2012 14:26:35 -0800
parents eaf7e4c58c9e
children a18539c0bc37
rev   line source
seanhalle@208 1 /*
seanhalle@208 2 * Copyright 2009 OpenSourceStewardshipFoundation.org
seanhalle@208 3 * Licensed under GNU General Public License version 2
seanhalle@208 4 *
seanhalle@208 5 * Author: seanhalle@yahoo.com
seanhalle@208 6 *
seanhalle@208 7 */
seanhalle@208 8
seanhalle@208 9 #ifndef _VMS_H
seanhalle@208 10 #define _VMS_H
seanhalle@208 11 #define _GNU_SOURCE
seanhalle@208 12
seanhalle@208 13 #include "VMS_primitive_data_types.h"
seanhalle@208 14 #include "C_Libraries/DynArray/DynArray.h"
seanhalle@208 15 #include "C_Libraries/Hash_impl/PrivateHash.h"
seanhalle@208 16 #include "C_Libraries/Histogram/Histogram.h"
seanhalle@208 17 #include "C_Libraries/Queue_impl/PrivateQueue.h"
seanhalle@208 18 #include "vmalloc.h"
seanhalle@208 19
seanhalle@208 20 #include <pthread.h>
seanhalle@208 21 #include <sys/time.h>
seanhalle@208 22
seanhalle@209 23 #ifndef _LANG_NAME_
seanhalle@209 24 #define _LANG_NAME_ ""
seanhalle@209 25 #endif
seanhalle@209 26
seanhalle@208 27 //================= Defines: included from separate files =================
seanhalle@208 28 //
seanhalle@208 29 // Note: ALL defines are in other files, none are in here
seanhalle@208 30 //
seanhalle@208 31 #include "VMS_defs__main.h"
seanhalle@208 32
seanhalle@208 33
seanhalle@208 34 //================================ Typedefs =================================
seanhalle@208 35 //
seanhalle@208 36 typedef unsigned long long TSCount;
seanhalle@208 37 typedef union
seanhalle@208 38 { uint32 lowHigh[2];
seanhalle@208 39 uint64 longVal;
seanhalle@208 40 }
seanhalle@208 41 TSCountLowHigh;
seanhalle@208 42
seanhalle@208 43 typedef struct _SchedSlot SchedSlot;
seanhalle@208 44 typedef struct _VMSReqst VMSReqst;
seanhalle@208 45 typedef struct _SlaveVP SlaveVP;
seanhalle@208 46 typedef struct _MasterVP MasterVP;
seanhalle@208 47 typedef struct _IntervalProbe IntervalProbe;
seanhalle@208 48 typedef struct _GateStruc GateStruc;
seanhalle@208 49
seanhalle@208 50
seanhalle@209 51 typedef SlaveVP * (*Sched_Assigner) ( void *, int ); //semEnv, coreIdx
seanhalle@209 52 typedef void (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
seanhalle@209 53 typedef void (*TopLevelFnPtr) ( void *, SlaveVP * ); //initData, animSlv
seanhalle@209 54 typedef void TopLevelFn ( void *, SlaveVP * ); //initData, animSlv
seanhalle@209 55 typedef void (*ResumeSlvFnPtr) ( SlaveVP *, void * );
seanhalle@209 56
seanhalle@209 57 //============================ HW Dependent Fns ================================
seanhalle@209 58
seanhalle@209 59 #include "VMS__HW_dependent.h"
seanhalle@208 60
seanhalle@208 61 //============================= Statistics ==================================
seanhalle@208 62
seanhalle@208 63 inline TSCount getTSCount();
seanhalle@208 64
seanhalle@208 65 //============= Request Related ===========
seanhalle@208 66 //
seanhalle@208 67
seanhalle@208 68 enum VMSReqstType //avoid starting enums at 0, for debug reasons
seanhalle@208 69 {
seanhalle@208 70 semantic = 1,
seanhalle@208 71 createReq,
seanhalle@208 72 dissipate,
seanhalle@208 73 VMSSemantic //goes with VMSSemReqst below
seanhalle@208 74 };
seanhalle@208 75
seanhalle@208 76 struct _VMSReqst
seanhalle@208 77 {
seanhalle@208 78 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
seanhalle@208 79 void *semReqData;
seanhalle@208 80
seanhalle@208 81 VMSReqst *nextReqst;
seanhalle@208 82 };
seanhalle@208 83 //VMSReqst
seanhalle@208 84
seanhalle@208 85 enum VMSSemReqstType //These are equivalent to semantic requests, but for
seanhalle@208 86 { // VMS's services available directly to app, like OS
seanhalle@208 87 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
seanhalle@208 88 openFile,
seanhalle@208 89 otherIO
seanhalle@208 90 };
seanhalle@208 91
seanhalle@208 92 typedef struct
seanhalle@208 93 { enum VMSSemReqstType reqType;
seanhalle@209 94 SlaveVP *requestingSlv;
seanhalle@208 95 char *nameStr; //for create probe
seanhalle@208 96 }
seanhalle@208 97 VMSSemReq;
seanhalle@208 98
seanhalle@208 99
seanhalle@208 100 //==================== Core data structures ===================
seanhalle@208 101
seanhalle@208 102 struct _SchedSlot
seanhalle@208 103 {
seanhalle@208 104 int workIsDone;
seanhalle@209 105 int needsSlaveAssigned;
seanhalle@209 106 SlaveVP *slaveAssignedToSlot;
seanhalle@208 107 };
seanhalle@208 108 //SchedSlot
seanhalle@208 109
seanhalle@209 110 /*WARNING: re-arranging this data structure could cause Slv switching
seanhalle@208 111 * assembly code to fail -- hard-codes offsets of fields
seanhalle@208 112 */
seanhalle@208 113 struct _SlaveVP
seanhalle@208 114 { int procrID; //for debugging -- count up each time create
seanhalle@208 115 int coreAnimatedBy;
seanhalle@208 116 void *startOfStack;
seanhalle@208 117 void *stackPtr;
seanhalle@208 118 void *framePtr;
seanhalle@208 119 void *resumeInstrPtr;
seanhalle@208 120
seanhalle@208 121 void *coreLoopStartPt; //allows proto-runtime to be linked later
seanhalle@208 122 void *coreLoopFramePtr; //restore before jmp back to core loop
seanhalle@208 123 void *coreLoopStackPtr; //restore before jmp back to core loop
seanhalle@208 124
seanhalle@208 125 SchedSlot *schedSlot;
seanhalle@208 126 VMSReqst *requests;
seanhalle@208 127
seanhalle@209 128 void *semanticData; //this livesUSE_GNU here for the life of Slv
seanhalle@209 129 void *dataRetFromReq;//values returned from plugin to Slv go here
seanhalle@208 130
seanhalle@208 131 //=========== MEASUREMENT STUFF ==========
seanhalle@209 132 MEAS__Insert_Meas_Fields_into_Slave;
seanhalle@208 133 //========================================
seanhalle@208 134
seanhalle@208 135 float64 createPtInSecs; //have space but don't use on some configs
seanhalle@208 136 };
seanhalle@208 137 //SlaveVP
seanhalle@208 138
seanhalle@208 139
seanhalle@209 140 /*WARNING: re-arranging this data structure could cause Slv-switching
seanhalle@208 141 * assembly code to fail -- hard-codes offsets of fields
seanhalle@208 142 * (because -O3 messes with things otherwise)
seanhalle@208 143 */
seanhalle@208 144 typedef struct
seanhalle@208 145 {
seanhalle@209 146 Sched_Assigner slaveAssigner;
seanhalle@208 147 RequestHandler requestHandler;
seanhalle@208 148
seanhalle@208 149 SchedSlot ***allSchedSlots;
seanhalle@208 150 VMSQueueStruc **readyToAnimateQs;
seanhalle@208 151 SlaveVP **masterVPs;
seanhalle@208 152
seanhalle@208 153 void *semanticEnv;
seanhalle@208 154 void *OSEventStruc; //for future, when add I/O to BLIS
seanhalle@209 155 MallocArrays *freeLists;
seanhalle@208 156 int32 amtOfOutstandingMem; //total currently allocated
seanhalle@208 157
seanhalle@208 158 void *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
seanhalle@208 159
seanhalle@208 160 int32 setupComplete;
seanhalle@209 161 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
seanhalle@209 162 int32 masterLock __align_to_cacheline__;
seanhalle@208 163 GateStruc *workStealingGates[ NUM_CORES ]; //concurrent work-steal
seanhalle@208 164 int32 workStealingLock;
seanhalle@208 165
seanhalle@209 166 int32 numSlavesCreated; //gives ordering to processor creation
seanhalle@209 167 int32 numSlavesAlive; //used to detect when to shutdown
seanhalle@208 168
seanhalle@208 169 //=========== MEASUREMENT STUFF =============
seanhalle@208 170 IntervalProbe **intervalProbes;
seanhalle@208 171 PrivDynArrayInfo *dynIntervalProbesInfo;
seanhalle@208 172 HashTable *probeNameHashTbl;
seanhalle@208 173 int32 masterCreateProbeID;
seanhalle@208 174 float64 createPtInSecs;
seanhalle@208 175 Histogram **measHists;
seanhalle@208 176 PrivDynArrayInfo *measHistsInfo;
seanhalle@209 177 MEAS__Insert_Susp_Meas_Fields_into_MasterEnv;
seanhalle@209 178 MEAS__Insert_Master_Meas_Fields_into_MasterEnv;
seanhalle@209 179 MEAS__Insert_Master_Lock_Meas_Fields_into_MasterEnv;
seanhalle@209 180 MEAS__Insert_Malloc_Meas_Fields_into_MasterEnv;
seanhalle@209 181 MEAS__Insert_Plugin_Meas_Fields_into_MasterEnv;
seanhalle@209 182 MEAS__Insert_System_Meas_Fields_into_MasterEnv;
seanhalle@208 183 //==========================================
seanhalle@208 184 }
seanhalle@208 185 MasterEnv;
seanhalle@208 186
seanhalle@208 187 //========================= Extra Stuff Data Strucs =======================
seanhalle@208 188 typedef struct
seanhalle@208 189 {
seanhalle@208 190
seanhalle@208 191 }
seanhalle@208 192 VMSExcp;
seanhalle@208 193
seanhalle@208 194 struct _GateStruc
seanhalle@208 195 {
seanhalle@208 196 int32 gateClosed;
seanhalle@208 197 int32 preGateProgress;
seanhalle@208 198 int32 waitProgress;
seanhalle@208 199 int32 exitProgress;
seanhalle@208 200 };
seanhalle@208 201 //GateStruc
seanhalle@208 202
seanhalle@208 203 //======================= OS Thread related ===============================
seanhalle@208 204
seanhalle@208 205 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
seanhalle@208 206 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
seanhalle@208 207 void masterLoop( void *initData, SlaveVP *masterVP );
seanhalle@208 208
seanhalle@208 209
seanhalle@208 210 typedef struct
seanhalle@208 211 {
seanhalle@208 212 void *endThdPt;
seanhalle@208 213 unsigned int coreNum;
seanhalle@208 214 }
seanhalle@208 215 ThdParams;
seanhalle@208 216
seanhalle@209 217 //============================= Global Vars ================================
seanhalle@209 218
seanhalle@208 219 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
seanhalle@208 220 ThdParams *coreLoopThdParams [ NUM_CORES ];
seanhalle@208 221 pthread_mutex_t suspendLock;
seanhalle@208 222 pthread_cond_t suspend_cond;
seanhalle@208 223
seanhalle@208 224 volatile MasterEnv *_VMSMasterEnv __align_to_cacheline__;
seanhalle@208 225
seanhalle@208 226
seanhalle@208 227 //========================= Function Prototypes ===========================
seanhalle@208 228
seanhalle@209 229 /* MEANING OF WL PI SS int
seanhalle@209 230 * These indicate which places the function is safe to use. They stand for:
seanhalle@209 231 * WL: Wrapper Library
seanhalle@209 232 * PI: Plugin
seanhalle@209 233 * SS: Startup and Shutdown
seanhalle@209 234 * int: internal to the VMS implementation
seanhalle@209 235 */
seanhalle@208 236
seanhalle@208 237 //========== Setup and shutdown ==========
seanhalle@208 238 void
seanhalle@209 239 VMS_SS__init();
seanhalle@208 240
seanhalle@209 241 //Fix;
seanhalle@209 242 /*seed-procr creation -- put box around language, have lang register stuff
seanhalle@208 243 with VMS.
seanhalle@208 244 have main program explicitly INIT Lang! -- makes more sense to
seanhalle@208 245 C programmers -- makes it clear that there's a transition.
seanhalle@208 246 (might need to have the pthreads remain waiting for
seanhalle@208 247 cond until work is scheduled)
seanhalle@208 248 Have main do call to tell language to perform work -- like did with DKU
seanhalle@208 249
seanhalle@208 250 Ex: "HWSim__run_a_simulation(netlist, paramBag);"
seanhalle@208 251 "processID = SSR__run_program(seed_fn, seedData); "
seanhalle@208 252 "SSR__Wait_for_program_to_end(processID);"
seanhalle@208 253 "SSR__run_program_and_wait_till_it_ends(seed_fn, seedData);"
seanhalle@208 254
seanhalle@208 255 allows multiple languages to be started, and programs run in several,
seanhalle@208 256 overlapped, or one program to be run that uses multiple langs..?
seanhalle@208 257 So, each program is in separate directory:
seanhalle@208 258 "HWSim_ArchDef__PingPong" "SSR_Program__Blocked_Matrix_Mult"
seanhalle@208 259
seanhalle@208 260 Those programs can talk to each other, via VMS, by handles they each
seanhalle@208 261 return
seanhalle@208 262 "processIDs[0] = SSR__run_program(seed_fn1, seedData1);"
seanhalle@208 263 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
seanhalle@208 264 "SSR__link_programs(processIDs, 2);"
seanhalle@208 265 or even
seanhalle@208 266 "processIDs[0] = Vthread__run_program(seed_fn1, seedData1);"
seanhalle@208 267 "processIDs[1] = SSR__run_program(seed_fn2, seedData2);"
seanhalle@208 268 "VMS__link_programs(processIDs, 2);"
seanhalle@208 269 Then, the programs just know they sync with other prog, but use own
seanhalle@208 270 lang's sync constructs -- VMS uses message system to establish tie-pt,
seanhalle@208 271 each lang defines what a tie-point means to it.. (work with the
seanhalle@208 272 diff semantics?)
seanhalle@209 273 */
seanhalle@208 274 void
seanhalle@209 275 VMS_SS__start_the_work_then_wait_until_done();
seanhalle@208 276
seanhalle@208 277 void
seanhalle@209 278 VMS_SS__shutdown();
seanhalle@208 279
seanhalle@208 280 void
seanhalle@209 281 VMS_SS__cleanup_at_end_of_shutdown();
seanhalle@208 282
seanhalle@208 283
seanhalle@208 284 //============== ===============
seanhalle@208 285
seanhalle@208 286 inline SlaveVP *
seanhalle@209 287 VMS_int__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
seanhalle@209 288 #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
seanhalle@209 289 #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
seanhalle@208 290
seanhalle@208 291 inline void
seanhalle@209 292 VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
seanhalle@208 293 void *dataParam);
seanhalle@209 294 #define VMS_PI__point_slaveVP_to_Fn VMS_int__point_slaveVP_to_Fn
seanhalle@209 295 #define VMS_WL__point_slaveVP_to_Fn VMS_int__point_slaveVP_to_Fn
seanhalle@208 296
seanhalle@208 297 void
seanhalle@209 298 VMS_int__dissipate_SlaveVP( SlaveVP *slaveToDissipate );
seanhalle@209 299 #define VMS_PI__dissipate_SlaveVP VMS_int__dissipateSlaveVP
seanhalle@209 300 //From WL, dissipate a SlaveVP by sending a request
seanhalle@208 301
seanhalle@208 302 //Use this to create processor inside entry point & other places outside
seanhalle@208 303 // the VMS system boundary (IE, not run in slave nor Master)
seanhalle@208 304 SlaveVP *
seanhalle@209 305 VMS_ext__create_slaveVP( TopLevelFnPtr fnPtr, void *dataParam );
seanhalle@208 306
seanhalle@208 307 void
seanhalle@209 308 VMS_ext__dissipate_slaveVP( SlaveVP *slaveToDissipate );
seanhalle@208 309
seanhalle@208 310 void
seanhalle@209 311 VMS_int__throw_exception( char *msgStr, SlaveVP *reqstSlv, VMSExcp *excpData );
seanhalle@209 312 #define VMS_PI__throw_exception VMS_int__throw_exception
seanhalle@209 313 #define VMS_WL__throw_exception VMS_int__throw_exception
seanhalle@208 314
seanhalle@208 315 void *
seanhalle@209 316 VMS_int__give_sem_env_for( SlaveVP *animSlv );
seanhalle@209 317 #define VMS_PI__give_sem_env_for VMS_int__give_sem_env_for
seanhalle@209 318 #define VMS_SS__give_sem_env_for VMS_int__give_sem_env_for
seanhalle@209 319 //No WL version -- not safe! if use in WL, be sure data rd & wr is stable
seanhalle@208 320
seanhalle@208 321 //============== Request Related ===============
seanhalle@208 322
seanhalle@208 323 void
seanhalle@209 324 VMS_int__suspend_slaveVP_and_send_req( SlaveVP *callingSlv );
seanhalle@208 325
seanhalle@208 326 inline void
seanhalle@209 327 VMS_WL__add_sem_request_in_mallocd_VMSReqst( void *semReqData, SlaveVP *callingSlv );
seanhalle@208 328
seanhalle@208 329 inline void
seanhalle@209 330 VMS_WL__send_sem_request( void *semReqData, SlaveVP *callingSlv );
seanhalle@208 331
seanhalle@208 332 void
seanhalle@209 333 VMS_WL__send_create_slaveVP_req( void *semReqData, SlaveVP *reqstingSlv );
seanhalle@208 334
seanhalle@208 335 void inline
seanhalle@208 336 VMS_WL__send_dissipate_req( SlaveVP *prToDissipate );
seanhalle@208 337
seanhalle@208 338 inline void
seanhalle@209 339 VMS_WL__send_VMSSem_request( void *semReqData, SlaveVP *callingSlv );
seanhalle@208 340
seanhalle@208 341 VMSReqst *
seanhalle@209 342 VMS_PI__take_next_request_out_of( SlaveVP *slaveWithReq );
seanhalle@208 343
seanhalle@208 344 inline void *
seanhalle@208 345 VMS_PI__take_sem_reqst_from( VMSReqst *req );
seanhalle@208 346
seanhalle@208 347 void inline
seanhalle@209 348 VMS_PI__handle_VMSSemReq( VMSReqst *req, SlaveVP *requestingSlv, void *semEnv,
seanhalle@209 349 ResumeSlvFnPtr resumeSlvFnPtr );
seanhalle@208 350
seanhalle@208 351 //======================== MEASUREMENT ======================
seanhalle@208 352 uint64
seanhalle@208 353 VMS_WL__give_num_plugin_cycles();
seanhalle@208 354 uint32
seanhalle@208 355 VMS_WL__give_num_plugin_animations();
seanhalle@208 356
seanhalle@208 357
seanhalle@208 358 #include "probes.h"
seanhalle@208 359 #include "vutilities.h"
seanhalle@208 360
seanhalle@208 361 #endif /* _VMS_H */
seanhalle@208 362