annotate VMS.h @ 52:f59cfa31a579

fixed up probes just a bit
author Me
date Sat, 30 Oct 2010 21:53:55 -0700
parents 8f7141a9272e
children 42dd44df1bb0 420a09d3f32a
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@42 14 #include "Queue_impl/BlockingQueue.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@45 25 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
Me@42 26 // It still does co-routines and all the mechanisms are the same, it just
Me@42 27 // has only a single thread and animates VPs one at a time
Me@45 28 //#define SEQUENTIAL
Me@42 29
Me@52 30 //turns on the probe-instrumentation in the application -- when not
Me@52 31 // defined, the calls to the probe functions turn into comments
Me@52 32 #define STATS__ENABLE_PROBES
Me@52 33
Me@52 34
Me@50 35 #define PRINT_DEBUG(msg)// printf(msg); fflush(stdin);
Me@45 36 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin);
Me@45 37 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin);
Me@45 38
Me@50 39 #define PRINT_ERROR(msg) printf(msg); fflush(stdin);
Me@50 40 #define PRINT1_ERROR(msg, param) printf(msg, param); fflush(stdin);
Me@50 41 #define PRINT2_ERROR(msg, p1, p2) printf(msg, p1, p2); fflush(stdin);
Me@50 42
Me@50 43
Me@50 44 //=========================== STATS =======================
Me@50 45
Me@45 46 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
Me@42 47 // compiled-in that saves the low part of the time stamp count just before
Me@42 48 // suspending a processor and just after resuming that processor. It is
Me@42 49 // saved into a field added to VirtProcr. Have to sanity-check for
Me@42 50 // rollover of low portion into high portion.
Me@42 51 #define MEAS__TIME_STAMP_SUSP
Me@42 52 #define MEAS__TIME_MASTER
Me@42 53 #define MEAS__NUM_TIMES_TO_RUN 100000
Me@42 54
Me@45 55 #define NUM_TSC_ROUND_TRIPS 10
Me@45 56
Me@50 57
Me@50 58 //========================= Hardware related Constants =====================
Me@42 59 //This value is the number of hardware threads in the shared memory
Me@42 60 // machine
Me@42 61 #define NUM_CORES 4
Me@42 62
Me@45 63 // balance amortizing master fixed overhead vs imbalance potential
Me@42 64 #define NUM_SCHED_SLOTS 3
Me@42 65
Me@45 66 #define MIN_WORK_UNIT_CYCLES 20000
Me@45 67
Me@42 68 #define READYTOANIMATE_RETRIES 10000
Me@42 69
Me@42 70 // stack
Me@50 71 #define VIRT_PROCR_STACK_SIZE 0x4000
Me@42 72
Me@50 73 // memory for VMS__malloc -- 256M
Me@50 74 #define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000
Me@42 75
Me@50 76
Me@50 77 //==============================
Me@42 78
Me@42 79 #define SUCCESS 0
Me@42 80
Me@50 81 #define writeVMSQ writeSRSWQ
Me@50 82 #define readVMSQ readSRSWQ
Me@50 83 #define makeVMSQ makeSRSWQ
Me@50 84 #define VMSQueueStruc SRSWQueueStruc
Me@42 85
Me@42 86
Me@50 87
Me@50 88 //===========================================================================
Me@50 89 typedef unsigned long long TSCount;
Me@50 90
Me@50 91 typedef struct _SchedSlot SchedSlot;
Me@50 92 typedef struct _VMSReqst VMSReqst;
Me@50 93 typedef struct _VirtProcr VirtProcr;
Me@50 94 typedef struct _IntervalProbe IntervalProbe;
Me@42 95
Me@42 96 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
Me@42 97 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
Me@42 98 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
Me@42 99 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
Me@50 100 typedef void (*ResumePrFnPtr) ( VirtProcr *, void * );
Me@50 101
Me@50 102
Me@50 103 //============= Requests ===========
Me@50 104 //
Me@50 105
Me@50 106 enum VMSReqstType //avoid starting enums at 0, for debug reasons
Me@50 107 {
Me@50 108 semantic = 1,
Me@50 109 createReq,
Me@50 110 dissipate,
Me@50 111 VMSSemantic //goes with VMSSemReqst below
Me@50 112 };
Me@50 113
Me@50 114 struct _VMSReqst
Me@50 115 {
Me@50 116 enum VMSReqstType reqType;//used for dissipate and in future for IO requests
Me@50 117 void *semReqData;
Me@50 118
Me@50 119 VMSReqst *nextReqst;
Me@50 120 };
Me@50 121 //VMSReqst
Me@50 122
Me@50 123 enum VMSSemReqstType //These are equivalent to semantic requests, but for
Me@50 124 { // VMS's services available directly to app, like OS
Me@50 125 createProbe = 1, // and probe services -- like a VMS-wide built-in lang
Me@50 126 openFile,
Me@50 127 otherIO
Me@50 128 };
Me@42 129
Me@42 130 typedef struct
Me@50 131 { enum VMSSemReqstType reqType;
Me@50 132 VirtProcr *requestingPr;
Me@50 133 char *nameStr; //for create probe
Me@42 134 }
Me@50 135 VMSSemReq;
Me@42 136
Me@42 137
Me@50 138 //==================== Core data structures ===================
Me@50 139
Me@42 140 struct _SchedSlot
Me@42 141 {
Me@42 142 int workIsDone;
Me@42 143 int needsProcrAssigned;
Me@42 144 VirtProcr *procrAssignedToSlot;
Me@42 145 };
Me@42 146 //SchedSlot
Me@42 147
Me@42 148 struct _VirtProcr
Me@42 149 { int procrID; //for debugging -- count up each time create
Me@42 150 int coreAnimatedBy;
Me@42 151 void *startOfStack;
Me@42 152 void *stackPtr;
Me@42 153 void *framePtr;
Me@42 154 void *nextInstrPt;
Me@42 155
Me@42 156 void *coreLoopStartPt; //allows proto-runtime to be linked later
Me@42 157 void *coreLoopFramePtr; //restore before jmp back to core loop
Me@42 158 void *coreLoopStackPtr; //restore before jmp back to core loop
Me@42 159
Me@42 160 void *initialData;
Me@42 161
Me@42 162 SchedSlot *schedSlot;
Me@42 163 VMSReqst *requests;
Me@42 164
Me@50 165 void *semanticData; //this lives here for the life of VP
Me@50 166 void *dataReturnedFromReq;//values returned from plugin to VP go here
Me@42 167
Me@50 168 //=========== MEASUREMENT STUFF ==========
Me@42 169 #ifdef MEAS__TIME_STAMP_SUSP
Me@42 170 unsigned int preSuspTSCLow;
Me@42 171 unsigned int postSuspTSCLow;
Me@42 172 #endif
Me@42 173 #ifdef MEAS__TIME_MASTER
Me@42 174 unsigned int startMasterTSCLow;
Me@42 175 unsigned int endMasterTSCLow;
Me@42 176 #endif
Me@50 177
Me@50 178 float64 createPtInSecs; //have space but don't use on some configs
Me@42 179 };
Me@42 180 //VirtProcr
Me@42 181
Me@42 182
Me@42 183 typedef struct
Me@42 184 {
Me@42 185 SlaveScheduler slaveScheduler;
Me@42 186 RequestHandler requestHandler;
Me@42 187
Me@42 188 SchedSlot ***allSchedSlots;
Me@42 189 SRSWQueueStruc **readyToAnimateQs;
Me@42 190 VirtProcr **masterVPs;
Me@42 191
Me@42 192 void *semanticEnv;
Me@42 193 void *OSEventStruc; //for future, when add I/O to BLIS
Me@50 194 MallocProlog *freeListHead;
Me@50 195 int32 amtOfOutstandingMem; //total currently allocated
Me@42 196
Me@42 197 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
Me@42 198 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
Me@42 199
Me@50 200 int32 setupComplete;
Me@50 201 int32 masterLock;
Me@42 202
Me@50 203 int32 numMasterInARow[NUM_CORES];//detect back-to-back masterVP
Me@50 204 int32 numProcrsCreated; //gives ordering to processor creation
Me@50 205
Me@50 206 //=========== MEASUREMENT STUFF =============
Me@50 207 IntervalProbe **intervalProbes;
Me@50 208 DynArrayInfo *dynIntervalProbesInfo;
Me@50 209 HashTable *probeNameHashTbl;
Me@50 210 int32 masterCreateProbeID;
Me@50 211 float64 createPtInSecs;
Me@42 212 }
Me@42 213 MasterEnv;
Me@42 214
Me@42 215
Me@50 216
Me@50 217
Me@50 218 //======================= OS Thread related ===============================
Me@42 219
Me@42 220 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
Me@42 221 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
Me@42 222 void masterLoop( void *initData, VirtProcr *masterPr );
Me@42 223
Me@42 224
Me@50 225 typedef struct
Me@50 226 {
Me@50 227 void *endThdPt;
Me@50 228 unsigned int coreNum;
Me@50 229 }
Me@50 230 ThdParams;
Me@42 231
Me@42 232 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
Me@42 233 ThdParams *coreLoopThdParams [ NUM_CORES ];
Me@42 234 pthread_mutex_t suspendLock;
Me@42 235 pthread_cond_t suspend_cond;
Me@42 236
Me@50 237
Me@50 238
Me@50 239 //===================== Global Vars ===================
Me@50 240
Me@42 241 volatile MasterEnv *_VMSMasterEnv;
Me@42 242
Me@50 243
Me@50 244
Me@50 245
Me@50 246 //=========================== Function Prototypes =========================
Me@50 247
Me@50 248 //============== Setup and shutdown =============
Me@42 249 void
Me@42 250 VMS__init();
Me@42 251
Me@42 252 void
Me@42 253 VMS__init_Seq();
Me@42 254
Me@42 255 void
Me@42 256 VMS__start_the_work_then_wait_until_done();
Me@42 257
Me@42 258 void
Me@42 259 VMS__start_the_work_then_wait_until_done_Seq();
Me@42 260
Me@42 261 VirtProcr *
Me@42 262 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@42 263
Me@50 264 //Use this to create processor inside entry point & other places outside
Me@50 265 // the VMS system boundary (IE, not run in slave nor Master)
Me@50 266 VirtProcr *
Me@50 267 VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@50 268
Me@42 269 VirtProcr *
Me@42 270 VMS__create_the_shutdown_procr();
Me@42 271
Me@50 272 void
Me@50 273 VMS__cleanup_after_shutdown();
Me@50 274
Me@50 275
Me@50 276 //============== Request Related ===============
Me@50 277
Me@50 278 void
Me@50 279 VMS__suspend_procr( VirtProcr *callingPr );
Me@50 280
Me@42 281 inline void
Me@42 282 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
Me@42 283
Me@42 284 void
Me@50 285 VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
Me@42 286
Me@52 287 inline void
Me@52 288 VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
Me@52 289
Me@42 290 void
Me@42 291 VMS__free_request( VMSReqst *req );
Me@42 292
Me@42 293 void
Me@42 294 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
Me@42 295
Me@42 296 VMSReqst *
Me@50 297 VMS__take_next_request_out_of( VirtProcr *procrWithReq );
Me@42 298
Me@42 299 inline void *
Me@42 300 VMS__take_sem_reqst_from( VMSReqst *req );
Me@52 301 //
Me@52 302 //VMSReqst *
Me@52 303 //VMS__take_top_request_from( VirtProcr *reqstingPr );
Me@52 304 //
Me@52 305 //inline int
Me@52 306 //VMS__isSemanticReqst( VMSReqst *req );
Me@52 307 //
Me@52 308 //inline int
Me@52 309 //VMS__isDissipateReqst( VMSReqst *req );
Me@52 310 //
Me@52 311 //inline int
Me@52 312 //VMS__isCreateReqst( VMSReqst *req );
Me@42 313
Me@42 314 //==========================
Me@42 315
Me@50 316 void inline
Me@42 317 VMS__dissipate_procr( VirtProcr *prToDissipate );
Me@42 318
Me@42 319 void
Me@42 320 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
Me@42 321
Me@42 322
Me@42 323
Me@50 324 //===================== RDTSC wrapper ==================
Me@42 325
Me@42 326 #define saveTimeStampCountInto(low, high) \
Me@42 327 asm volatile("RDTSC; \
Me@42 328 movl %%eax, %0; \
Me@42 329 movl %%edx, %1;" \
Me@42 330 /* outputs */ : "=m" (low), "=m" (high)\
Me@42 331 /* inputs */ : \
Me@42 332 /* clobber */ : "%eax", "%edx" \
Me@42 333 );
Me@42 334
Me@42 335 #define saveLowTimeStampCountInto(low) \
Me@42 336 asm volatile("RDTSC; \
Me@42 337 movl %%eax, %0;" \
Me@42 338 /* outputs */ : "=m" (low) \
Me@42 339 /* inputs */ : \
Me@42 340 /* clobber */ : "%eax", "%edx" \
Me@42 341 );
Me@42 342
Me@50 343 //======================== STATS ======================
Me@42 344
Me@50 345 #include "probes.h"
Me@42 346
Me@42 347 #endif /* _VMS_H */
Me@42 348