annotate VMS.h @ 55:3bac84e4e56e

Works with correct matrix mult Nov 4 -- switch animators macros, many updates Changed all queues back to VMSQ variants #defines correct, protected, work-stealing, with compiler switch in and out
author Me
date Thu, 04 Nov 2010 18:13:18 -0700
parents f8508572f3de
children 26d53313a8f2
rev   line source
Me@42 1 /*
Me@42 2 * Copyright 2009 OpenSourceStewardshipFoundation.org
Me@42 3 * Licensed under GNU General Public License version 2
Me@42 4 *
Me@42 5 * Author: seanhalle@yahoo.com
Me@42 6 *
Me@42 7 */
Me@42 8
Me@42 9 #ifndef _VMS_H
Me@42 10 #define _VMS_H
Me@42 11 #define __USE_GNU
Me@42 12
Me@42 13 #include "VMS_primitive_data_types.h"
Me@55 14 #include "Queue_impl/PrivateQueue.h"
Me@42 15 #include "Histogram/Histogram.h"
Me@50 16 #include "DynArray/DynArray.h"
Me@50 17 #include "Hash_impl/PrivateHash.h"
Me@50 18 #include "vmalloc.h"
Me@50 19
Me@42 20 #include <pthread.h>
Me@50 21 #include <sys/time.h>
Me@42 22
Me@50 23
Me@50 24 //=============================== Debug ===================================
Me@55 25 //
Me@45 26 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
Me@42 27 // It still does co-routines and all the mechanisms are the same, it just
Me@42 28 // has only a single thread and animates VPs one at a time
Me@45 29 //#define SEQUENTIAL
Me@42 30
Me@55 31 //#define USE_WORK_STEALING
Me@55 32
Me@52 33 //turns on the probe-instrumentation in the application -- when not
Me@52 34 // defined, the calls to the probe functions turn into comments
Me@52 35 #define STATS__ENABLE_PROBES
Me@52 36
Me@55 37 //These defines turn types of bug messages on and off
Me@55 38 // be sure debug messages are un-commented (next block of defines)
Me@55 39 #define dbgProbes FALSE /* for issues inside probes themselves*/
Me@55 40 #define dbgAppFlow TRUE /* Top level flow of application code -- general*/
Me@55 41 #define dbgB2BMaster FALSE/* in coreloop, back to back master VPs*/
Me@55 42 #define dbgRqstHdlr FALSE /* in request handler code*/
Me@52 43
Me@55 44 //Comment or un- the substitute half to turn on/off types of debug message
Me@55 45 #define DEBUG( bool, msg) \
Me@55 46 if( bool){ printf(msg); fflush(stdin);}
Me@55 47 #define DEBUG1( bool, msg, param) \
Me@55 48 if(bool){printf(msg, param); fflush(stdin);}
Me@55 49 #define DEBUG2( bool, msg, p1, p2) \
Me@55 50 //if(bool) {printf(msg, p1, p2); fflush(stdin);}
Me@45 51
Me@55 52 #define ERROR(msg) printf(msg); fflush(stdin);
Me@55 53 #define ERROR1(msg, param) printf(msg, param); fflush(stdin);
Me@55 54 #define ERROR2(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
Me@50 55
Me@50 56 //=========================== STATS =======================
Me@50 57
Me@45 58 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
Me@42 59 // compiled-in that saves the low part of the time stamp count just before
Me@42 60 // suspending a processor and just after resuming that processor. It is
Me@42 61 // saved into a field added to VirtProcr. Have to sanity-check for
Me@42 62 // rollover of low portion into high portion.
Me@42 63 #define MEAS__TIME_STAMP_SUSP
Me@42 64 #define MEAS__TIME_MASTER
Me@42 65 #define MEAS__NUM_TIMES_TO_RUN 100000
Me@42 66
Me@55 67 //For code that calculates normalization-offset between TSC counts of
Me@55 68 // different cores.
Me@45 69 #define NUM_TSC_ROUND_TRIPS 10
Me@45 70
Me@50 71
Me@50 72 //========================= Hardware related Constants =====================
Me@42 73 //This value is the number of hardware threads in the shared memory
Me@42 74 // machine
Me@42 75 #define NUM_CORES 4
Me@42 76
Me@55 77 // tradeoff amortizing master fixed overhead vs imbalance potential
Me@55 78 // when work-stealing, can make bigger, at risk of losing cache affinity
Me@55 79 #define NUM_SCHED_SLOTS 5
Me@42 80
Me@45 81 #define MIN_WORK_UNIT_CYCLES 20000
Me@45 82
Me@53 83 #define MASTERLOCK_RETRIES 10000
Me@42 84
Me@54 85 // stack size in virtual processors created
Me@54 86 #define VIRT_PROCR_STACK_SIZE 0x4000 /* 16K */
Me@42 87
Me@54 88 // memory for VMS__malloc
Me@54 89 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
Me@42 90
Me@50 91
Me@50 92 //==============================
Me@42 93
Me@42 94 #define SUCCESS 0
Me@42 95
Me@55 96 #define writeVMSQ writePrivQ
Me@55 97 #define readVMSQ readPrivQ
Me@55 98 #define makeVMSQ makePrivQ
Me@55 99 #define numInVMSQ numInPrivQ
Me@55 100 #define VMSQueueStruc PrivQueueStruc
Me@42 101
Me@42 102
Me@50 103
Me@50 104 //===========================================================================
Me@50 105 typedef unsigned long long TSCount;
Me@50 106
Me@50 107 typedef struct _SchedSlot SchedSlot;
Me@50 108 typedef struct _VMSReqst VMSReqst;
Me@50 109 typedef struct _VirtProcr VirtProcr;
Me@50 110 typedef struct _IntervalProbe IntervalProbe;
Me@55 111 typedef struct _GateStruc GateStruc;
Me@55 112
Me@42 113
Me@42 114 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
Me@42 115 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
Me@42 116 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
Me@42 117 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
Me@50 118 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
Me@50 119
Me@50 120
Me@50 121 //============= Requests ===========
Me@50 122 //
Me@50 123
Me@50 124 enum VMSReqstType //avoid starting enums at 0, for debug reasons
Me@50 125 {
Me@50 126 semantic = 1,
Me@50 127 createReq,
Me@50 128 dissipate,
Me@50 129 VMSSemantic //goes with VMSSemReqst below
Me@50 130 };
Me@50 131
Me@50 132 struct _VMSReqst
Me@50 133 {
Me@50 134 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
Me@50 135 void *semReqData;
Me@50 136
Me@50 137 VMSReqst *nextReqst;
Me@50 138 };
Me@50 139 //VMSReqst
Me@50 140
Me@50 141 enum VMSSemReqstType //These are equivalent to semantic requests, but for
Me@50 142 { // VMS's services available directly to app, like OS
Me@50 143 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
Me@50 144 openFile,
Me@50 145 otherIO
Me@50 146 };
Me@42 147
Me@42 148 typedef struct
Me@50 149 { enum VMSSemReqstType reqType;
Me@50 150 VirtProcr *requestingPr;
Me@50 151 char *nameStr; //for create probe
Me@42 152 }
Me@50 153 VMSSemReq;
Me@42 154
Me@42 155
Me@50 156 //==================== Core data structures ===================
Me@50 157
Me@42 158 struct _SchedSlot
Me@42 159 {
Me@42 160 int workIsDone;
Me@42 161 int needsProcrAssigned;
Me@42 162 VirtProcr *procrAssignedToSlot;
Me@42 163 };
Me@42 164 //SchedSlot
Me@42 165
Me@42 166 struct _VirtProcr
Me@42 167 { int procrID; //for debugging -- count up each time create
Me@42 168 int coreAnimatedBy;
Me@42 169 void *startOfStack;
Me@42 170 void *stackPtr;
Me@42 171 void *framePtr;
Me@42 172 void *nextInstrPt;
Me@42 173
Me@42 174 void *coreLoopStartPt; //allows proto-runtime to be linked later
Me@42 175 void *coreLoopFramePtr; //restore before jmp back to core loop
Me@42 176 void *coreLoopStackPtr; //restore before jmp back to core loop
Me@42 177
Me@42 178 void *initialData;
Me@42 179
Me@42 180 SchedSlot *schedSlot;
Me@42 181 VMSReqst *requests;
Me@42 182
Me@50 183 void *semanticData; //this lives here for the life of VP
Me@53 184 void *dataRetFromReq;//values returned from plugin to VP go here
Me@42 185
Me@50 186 //=========== MEASUREMENT STUFF ==========
Me@42 187 #ifdef MEAS__TIME_STAMP_SUSP
Me@42 188 unsigned int preSuspTSCLow;
Me@42 189 unsigned int postSuspTSCLow;
Me@42 190 #endif
Me@42 191 #ifdef MEAS__TIME_MASTER
Me@42 192 unsigned int startMasterTSCLow;
Me@42 193 unsigned int endMasterTSCLow;
Me@42 194 #endif
Me@50 195
Me@50 196 float64 createPtInSecs; //have space but don't use on some configs
Me@42 197 };
Me@42 198 //VirtProcr
Me@42 199
Me@42 200
Me@42 201 typedef struct
Me@42 202 {
Me@42 203 SlaveScheduler slaveScheduler;
Me@42 204 RequestHandler requestHandler;
Me@42 205
Me@42 206 SchedSlot ***allSchedSlots;
Me@55 207 VMSQueueStruc **readyToAnimateQs;
Me@42 208 VirtProcr **masterVPs;
Me@42 209
Me@42 210 void *semanticEnv;
Me@42 211 void *OSEventStruc; //for future, when add I/O to BLIS
Me@50 212 MallocProlog *freeListHead;
Me@50 213 int32 amtOfOutstandingMem; //total currently allocated
Me@42 214
Me@42 215 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
Me@42 216 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
Me@42 217
Me@50 218 int32 setupComplete;
Me@50 219 int32 masterLock;
Me@42 220
Me@50 221 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
Me@55 222 GateStruc **workStealingGates[ NUM_CORES ]; //concurrent work-steal
Me@55 223 int32 workStealingLock;
Me@55 224
Me@50 225 int32 numProcrsCreated; //gives ordering to processor creation
Me@50 226
Me@50 227 //=========== MEASUREMENT STUFF =============
Me@50 228 IntervalProbe **intervalProbes;
Me@53 229 PrivDynArrayInfo *dynIntervalProbesInfo;
Me@50 230 HashTable *probeNameHashTbl;
Me@50 231 int32 masterCreateProbeID;
Me@50 232 float64 createPtInSecs;
Me@42 233 }
Me@42 234 MasterEnv;
Me@42 235
Me@55 236 //========================= Extra Stuff Data Strucs =======================
Me@54 237 typedef struct
Me@54 238 {
Me@42 239
Me@54 240 }
Me@54 241 VMSExcp;
Me@50 242
Me@55 243 struct _GateStruc
Me@55 244 {
Me@55 245 int32 gateClosed;
Me@55 246 int32 preGateProgress;
Me@55 247 int32 waitProgress;
Me@55 248 int32 exitProgress;
Me@55 249 };
Me@55 250 //GateStruc
Me@50 251
Me@50 252 //======================= OS Thread related ===============================
Me@42 253
Me@42 254 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
Me@42 255 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
Me@42 256 void masterLoop( void *initData, VirtProcr *masterPr );
Me@42 257
Me@42 258
Me@50 259 typedef struct
Me@50 260 {
Me@50 261 void *endThdPt;
Me@50 262 unsigned int coreNum;
Me@50 263 }
Me@50 264 ThdParams;
Me@42 265
Me@42 266 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
Me@42 267 ThdParams *coreLoopThdParams [ NUM_CORES ];
Me@42 268 pthread_mutex_t suspendLock;
Me@42 269 pthread_cond_t suspend_cond;
Me@42 270
Me@50 271
Me@50 272
Me@50 273 //===================== Global Vars ===================
Me@50 274
Me@42 275 volatile MasterEnv *_VMSMasterEnv;
Me@42 276
Me@50 277
Me@50 278
Me@50 279
Me@50 280 //=========================== Function Prototypes =========================
Me@50 281
Me@53 282
Me@53 283 //========== Setup and shutdown ==========
Me@42 284 void
Me@42 285 VMS__init();
Me@42 286
Me@42 287 void
Me@42 288 VMS__init_Seq();
Me@42 289
Me@42 290 void
Me@42 291 VMS__start_the_work_then_wait_until_done();
Me@42 292
Me@42 293 void
Me@42 294 VMS__start_the_work_then_wait_until_done_Seq();
Me@42 295
Me@42 296 VirtProcr *
Me@42 297 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@42 298
Me@53 299 void
Me@53 300 VMS__dissipate_procr( VirtProcr *procrToDissipate );
Me@53 301
Me@50 302 //Use this to create processor inside entry point & other places outside
Me@50 303 // the VMS system boundary (IE, not run in slave nor Master)
Me@50 304 VirtProcr *
Me@50 305 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@50 306
Me@53 307 void
Me@53 308 VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
Me@42 309
Me@50 310 void
Me@54 311 VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
Me@54 312
Me@54 313 void
Me@53 314 VMS__shutdown();
Me@53 315
Me@53 316 void
Me@53 317 VMS__cleanup_at_end_of_shutdown();
Me@50 318
Me@50 319
Me@50 320 //============== Request Related ===============
Me@50 321
Me@50 322 void
Me@50 323 VMS__suspend_procr( VirtProcr *callingPr );
Me@50 324
Me@42 325 inline void
Me@53 326 VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
Me@53 327
Me@53 328 inline void
Me@53 329 VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
Me@42 330
Me@42 331 void
Me@50 332 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
Me@42 333
Me@53 334 void inline
Me@53 335 VMS__send_dissipate_req( VirtProcr *prToDissipate );
Me@53 336
Me@52 337 inline void
Me@52 338 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
Me@52 339
Me@42 340 VMSReqst *
Me@50 341 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
Me@42 342
Me@42 343 inline void *
Me@42 344 VMS__take_sem_reqst_from( VMSReqst *req );
Me@42 345
Me@42 346
Me@42 347
Me@53 348 //======================== STATS ======================
Me@42 349
Me@53 350 //===== RDTSC wrapper =====
Me@42 351
Me@42 352 #define saveTimeStampCountInto(low, high) \
Me@42 353 asm volatile("RDTSC; \
Me@42 354 movl %%eax, %0; \
Me@42 355 movl %%edx, %1;" \
Me@42 356 /* outputs */ : "=m" (low), "=m" (high)\
Me@42 357 /* inputs */ : \
Me@42 358 /* clobber */ : "%eax", "%edx" \
Me@42 359 );
Me@42 360
Me@42 361 #define saveLowTimeStampCountInto(low) \
Me@42 362 asm volatile("RDTSC; \
Me@42 363 movl %%eax, %0;" \
Me@42 364 /* outputs */ : "=m" (low) \
Me@42 365 /* inputs */ : \
Me@42 366 /* clobber */ : "%eax", "%edx" \
Me@42 367 );
Me@53 368 //=====
Me@42 369
Me@55 370 #include "SwitchAnimators.h"
Me@50 371 #include "probes.h"
Me@42 372
Me@42 373 #endif /* _VMS_H */
Me@42 374