changeset 168:d7c0c0a8187a perf_counters

Merged default branch
author Merten Sach <msach@mailbox.tu-berlin.de>
date Wed, 02 Nov 2011 14:59:29 +0100
parents 395f58384a5c ad8213a8e916
children d83f59e6e2db
files CoreLoop.c VMS.c VMS.h VMS__DESIGN_NOTES.txt
diffstat 4 files changed, 631 insertions(+), 638 deletions(-) [+]
line diff
     1.1 --- a/.hgtags	Thu Sep 15 17:31:33 2011 +0200
     1.2 +++ b/.hgtags	Wed Nov 02 14:59:29 2011 +0100
     1.3 @@ -1,6 +1,1 @@
     1.4  9c3107044f86c36fea3a8f72f64910b1363555be Dec27_2010_about_to_add_sched_record
     1.5 -97e26095c01fef53783d2d89e11575856ce243c5 V0
     1.6 -21c95d402fe66570067000e484bfec9a5d92c9d0 malloc_touch
     1.7 -42d015d48eebc7ba49b24fa5f24cb1e66244e5e7 malloc_touch
     1.8 -42d015d48eebc7ba49b24fa5f24cb1e66244e5e7 malloc_touch
     1.9 -0000000000000000000000000000000000000000 malloc_touch
     2.1 --- a/VMS.c	Thu Sep 15 17:31:33 2011 +0200
     2.2 +++ b/VMS.c	Wed Nov 02 14:59:29 2011 +0100
     2.3 @@ -118,15 +118,15 @@
     2.4  
     2.5     //============================= MEASUREMENT STUFF ========================
     2.6     #ifdef MEAS__TIME_MALLOC
     2.7 -   _VMSMasterEnv->mallocTimeHist  = makeFixedBinHistExt( 100, 0, 100,
     2.8 +   _VMSMasterEnv->mallocTimeHist  = makeFixedBinHistExt( 100, 0, 30,
     2.9                                                         "malloc_time_hist");
    2.10 -   _VMSMasterEnv->freeTimeHist  = makeFixedBinHistExt( 80, 0, 100,
    2.11 +   _VMSMasterEnv->freeTimeHist  = makeFixedBinHistExt( 100, 0, 30,
    2.12                                                         "free_time_hist");
    2.13     #endif
    2.14     #ifdef MEAS__TIME_PLUGIN
    2.15 -   _VMSMasterEnv->reqHdlrLowTimeHist  = makeFixedBinHistExt( 1000, 0, 100,
    2.16 +   _VMSMasterEnv->reqHdlrLowTimeHist  = makeFixedBinHistExt( 100, 0, 200,
    2.17                                                       "plugin_low_time_hist");
    2.18 -   _VMSMasterEnv->reqHdlrHighTimeHist  = makeFixedBinHistExt( 1000, 0, 100,
    2.19 +   _VMSMasterEnv->reqHdlrHighTimeHist  = makeFixedBinHistExt( 100, 0, 200,
    2.20                                                      "plugin_high_time_hist");
    2.21     #endif
    2.22     //========================================================================
     3.1 --- a/VMS.h	Thu Sep 15 17:31:33 2011 +0200
     3.2 +++ b/VMS.h	Wed Nov 02 14:59:29 2011 +0100
     3.3 @@ -1,627 +1,627 @@
     3.4 -/*
     3.5 - *  Copyright 2009 OpenSourceStewardshipFoundation.org
     3.6 - *  Licensed under GNU General Public License version 2
     3.7 - *
     3.8 - * Author: seanhalle@yahoo.com
     3.9 - * 
    3.10 - */
    3.11 -
    3.12 -#ifndef _VMS_H
    3.13 -#define	_VMS_H
    3.14 -#define _GNU_SOURCE
    3.15 -
    3.16 -#include "VMS_primitive_data_types.h"
    3.17 -#include "Queue_impl/PrivateQueue.h"
    3.18 -#include "Histogram/Histogram.h"
    3.19 -#include "DynArray/DynArray.h"
    3.20 -#include "Hash_impl/PrivateHash.h"
    3.21 -#include "vmalloc.h"
    3.22 -#include "Counters/Counters.h"
    3.23 -#include "dependency.h"
    3.24 -
    3.25 -#include <pthread.h>
    3.26 -#include <sys/time.h>
    3.27 -
    3.28 -
    3.29 -//===============================  Debug  ===================================
    3.30 -//
    3.31 -//When SEQUENTIAL is defined, VMS does sequential exe in the main thread
    3.32 -// It still does co-routines and all the mechanisms are the same, it just
    3.33 -// has only a single thread and animates VPs one at a time
    3.34 -//#define SEQUENTIAL
    3.35 -
    3.36 -//#define USE_WORK_STEALING
    3.37 -
    3.38 -//turns on the probe-instrumentation in the application -- when not
    3.39 -// defined, the calls to the probe functions turn into comments
    3.40 -//#define STATS__ENABLE_PROBES
    3.41 -//#define TURN_ON_DEBUG_PROBES
    3.42 -
    3.43 -//These defines turn types of bug messages on and off
    3.44 -// be sure debug messages are un-commented (next block of defines)
    3.45 -#define dbgAppFlow   FALSE /* Top level flow of application code -- general*/
    3.46 -#define dbgProbes    FALSE /* for issues inside probes themselves*/
    3.47 -#define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
    3.48 -#define dbgRqstHdlr  FALSE /* in request handler code*/
    3.49 -#define dbgDependency TRUE /* in request handler code, print dependencies */
    3.50 -
    3.51 -//Comment or un- the substitute half to turn on/off types of debug message
    3.52 -#define DEBUG(  bool, msg)         \
    3.53 -  if( bool){ printf(msg); fflush(stdin);}
    3.54 -#define DEBUG1( bool, msg, param)  \
    3.55 -   if(bool){printf(msg, param); fflush(stdin);}
    3.56 -#define DEBUG2( bool, msg, p1, p2) \
    3.57 -   if(bool) {printf(msg, p1, p2); fflush(stdin);}
    3.58 -
    3.59 -#define ERROR(msg) printf(msg);
    3.60 -#define ERROR1(msg, param) printf(msg, param); 
    3.61 -#define ERROR2(msg, p1, p2) printf(msg, p1, p2);
    3.62 -
    3.63 -//===========================  STATS =======================
    3.64 -
    3.65 -   //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
    3.66 -   // compiled-in that saves the low part of the time stamp count just before
    3.67 -   // suspending a processor and just after resuming that processor.  It is
    3.68 -   // saved into a field added to VirtProcr.  Have to sanity-check for
    3.69 -   // rollover of low portion into high portion.
    3.70 -//#define MEAS__TIME_STAMP_SUSP
    3.71 -//#define MEAS__TIME_MASTER
    3.72 -//#define MEAS__TIME_PLUGIN
    3.73 -//#define MEAS__TIME_MALLOC
    3.74 -//#define MEAS__TIME_MASTER_LOCK
    3.75 -//#define MEAS__NUM_TIMES_TO_RUN 100000
    3.76 -
    3.77 -   //For code that calculates normalization-offset between TSC counts of
    3.78 -   // different cores.
    3.79 -//#define NUM_TSC_ROUND_TRIPS 10
    3.80 -
    3.81 -#define MEAS__PERF_COUNTERS
    3.82 -#define DETECT_DEPENDENCIES
    3.83 -
    3.84 -//=========================  Hardware related Constants =====================
    3.85 -   //This value is the number of hardware threads in the shared memory
    3.86 -   // machine
    3.87 -#define NUM_CORES        2
    3.88 -
    3.89 -   // tradeoff amortizing master fixed overhead vs imbalance potential
    3.90 -   // when work-stealing, can make bigger, at risk of losing cache affinity
    3.91 -#define NUM_SCHED_SLOTS  5
    3.92 -
    3.93 -#define MIN_WORK_UNIT_CYCLES 20000
    3.94 -
    3.95 -#define MASTERLOCK_RETRIES 10000
    3.96 -
    3.97 -   // stack size in virtual processors created
    3.98 -#define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */
    3.99 -
   3.100 -   // memory for VMS__malloc
   3.101 -#define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
   3.102 -
   3.103 -#define CACHE_LINE 64
   3.104 -#define PAGE_SIZE 4096
   3.105 -
   3.106 -
   3.107 -//==============================
   3.108 -
   3.109 -#define SUCCESS 0
   3.110 -
   3.111 -#define writeVMSQ     writePrivQ
   3.112 -#define readVMSQ      readPrivQ
   3.113 -#define makeVMSQ      makeVMSPrivQ
   3.114 -#define numInVMSQ     numInPrivQ
   3.115 -#define VMSQueueStruc PrivQueueStruc
   3.116 -
   3.117 -
   3.118 -
   3.119 -//===========================================================================
   3.120 -typedef unsigned long long TSCount;
   3.121 -
   3.122 -typedef struct _SchedSlot     SchedSlot;
   3.123 -typedef struct _VMSReqst      VMSReqst;
   3.124 -typedef struct _VirtProcr     VirtProcr;
   3.125 -typedef struct _IntervalProbe IntervalProbe;
   3.126 -typedef struct _GateStruc     GateStruc;
   3.127 -
   3.128 -
   3.129 -typedef VirtProcr * (*SlaveScheduler)  ( void *, int );   //semEnv, coreIdx
   3.130 -typedef void  (*RequestHandler)  ( VirtProcr *, void * ); //prWReqst, semEnv
   3.131 -typedef void  (*VirtProcrFnPtr)  ( void *, VirtProcr * ); //initData, animPr
   3.132 -typedef void    VirtProcrFn      ( void *, VirtProcr * ); //initData, animPr
   3.133 -typedef void  (*ResumePrFnPtr)   ( VirtProcr *, void * );
   3.134 -
   3.135 -
   3.136 -//============= Requests ===========
   3.137 -//
   3.138 -
   3.139 -enum VMSReqstType   //avoid starting enums at 0, for debug reasons
   3.140 - {
   3.141 -   semantic = 1,
   3.142 -   createReq,
   3.143 -   dissipate,
   3.144 -   VMSSemantic      //goes with VMSSemReqst below
   3.145 - };
   3.146 -
   3.147 -struct _VMSReqst
   3.148 - {
   3.149 -   enum VMSReqstType  reqType;//used for dissipate and in future for IO requests
   3.150 -   void              *semReqData;
   3.151 -
   3.152 -   VMSReqst *nextReqst;
   3.153 - };
   3.154 -//VMSReqst
   3.155 -
   3.156 -enum VMSSemReqstType   //These are equivalent to semantic requests, but for
   3.157 - {                     // VMS's services available directly to app, like OS
   3.158 -   createProbe = 1,    // and probe services -- like a VMS-wide built-in lang
   3.159 -   openFile,
   3.160 -   otherIO
   3.161 - };
   3.162 -
   3.163 -typedef struct
   3.164 - { enum VMSSemReqstType reqType;
   3.165 -   VirtProcr           *requestingPr;
   3.166 -   char                *nameStr;  //for create probe
   3.167 - }
   3.168 - VMSSemReq;
   3.169 -
   3.170 -
   3.171 -//====================  Core data structures  ===================
   3.172 -
   3.173 -struct _SchedSlot
   3.174 - {
   3.175 -   int         workIsDone;
   3.176 -   int         needsProcrAssigned;
   3.177 -   VirtProcr  *procrAssignedToSlot;
   3.178 - };
   3.179 -//SchedSlot
   3.180 -
   3.181 -/*WARNING: re-arranging this data structure could cause VP switching
   3.182 - *         assembly code to fail -- hard-codes offsets of fields
   3.183 - */
   3.184 -struct _VirtProcr
   3.185 - { int         procrID;  //for debugging -- count up each time create
   3.186 -   int         coreAnimatedBy;
   3.187 -   void       *startOfStack;
   3.188 -   void       *stackPtr;
   3.189 -   void       *framePtr;
   3.190 -   void       *nextInstrPt;
   3.191 -   
   3.192 -   void       *coreLoopStartPt;  //allows proto-runtime to be linked later
   3.193 -   void       *coreLoopFramePtr; //restore before jmp back to core loop
   3.194 -   void       *coreLoopStackPtr; //restore before jmp back to core loop
   3.195 -
   3.196 -   void       *initialData;
   3.197 -
   3.198 -   SchedSlot  *schedSlot;
   3.199 -   VMSReqst   *requests;
   3.200 -
   3.201 -   void       *semanticData; //this livesUSE_GNU here for the life of VP
   3.202 -   void       *dataRetFromReq;//values returned from plugin to VP go here
   3.203 -
   3.204 -      //=========== MEASUREMENT STUFF ==========
   3.205 -   #ifdef MEAS__TIME_STAMP_SUSP
   3.206 -   unsigned int preSuspTSCLow;
   3.207 -   unsigned int postSuspTSCLow;
   3.208 -   #endif
   3.209 -   #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
   3.210 -   unsigned int startMasterTSCLow;USE_GNU
   3.211 -   unsigned int endMasterTSCLow;
   3.212 -   #endif
   3.213 -   #ifdef MEAS__PERF_COUNTERS //
   3.214 -   CounterRecord** counter_history;
   3.215 -   PrivDynArrayInfo* counter_history_array_info;
   3.216 -   #endif
   3.217 -      //========================================
   3.218 -   
   3.219 -   float64      createPtInSecs;  //have space but don't use on some configs
   3.220 - };
   3.221 -//VirtProcr
   3.222 -
   3.223 -
   3.224 -/*WARNING: re-arranging this data structure could cause VP-switching
   3.225 - *         assembly code to fail -- hard-codes offsets of fields
   3.226 - *         (because -O3 messes with things otherwise)
   3.227 - */
   3.228 -typedef struct
   3.229 - {
   3.230 -   SlaveScheduler   slaveScheduler;
   3.231 -   RequestHandler   requestHandler;
   3.232 -   
   3.233 -   SchedSlot     ***allSchedSlots;
   3.234 -   VMSQueueStruc **readyToAnimateQs;
   3.235 -   VirtProcr      **masterVPs;
   3.236 -
   3.237 -   void            *semanticEnv;
   3.238 -   void            *OSEventStruc;   //for future, when add I/O to BLIS
   3.239 -   MallocProlog    *freeListHead;
   3.240 -   int32            amtOfOutstandingMem; //total currently allocated
   3.241 -
   3.242 -   void            *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
   3.243 -
   3.244 -   int32            setupComplete;
   3.245 -   volatile int32   masterLock;
   3.246 -
   3.247 -   int32            numMasterInARow[NUM_CORES];//detect back-to-back masterVP
   3.248 -   GateStruc       *workStealingGates[ NUM_CORES ]; //concurrent work-steal
   3.249 -   int32            workStealingLock;
   3.250 -   
   3.251 -   int32            numProcrsCreated; //gives ordering to processor creation
   3.252 -
   3.253 -      //=========== MEASUREMENT STUFF =============
   3.254 -   IntervalProbe  **intervalProbes;
   3.255 -   PrivDynArrayInfo    *dynIntervalProbesInfo;
   3.256 -   HashTable       *probeNameHashTbl;
   3.257 -   int32            masterCreateProbeID;
   3.258 -   float64          createPtInSecs;
   3.259 -   Histogram      **measHists;
   3.260 -   PrivDynArrayInfo *measHistsInfo;
   3.261 -   #ifdef MEAS__TIME_PLUGIN
   3.262 -   Histogram       *reqHdlrLowTimeHist;
   3.263 -   Histogram       *reqHdlrHighTimeHist;
   3.264 -   #endif
   3.265 -   #ifdef MEAS__TIME_MALLOC
   3.266 -   Histogram       *mallocTimeHist;
   3.267 -   Histogram       *freeTimeHist;
   3.268 -   #endif
   3.269 -   #ifdef MEAS__TIME_MASTER_LOCK
   3.270 -   Histogram       *masterLockLowTimeHist;
   3.271 -   Histogram       *masterLockHighTimeHist;
   3.272 -   #endif
   3.273 -   #ifdef MEAS__PERF_COUNTERS
   3.274 -   int cycles_counter_fd[NUM_CORES];
   3.275 -   int instrs_counter_fd[NUM_CORES];
   3.276 -   FILE* counteroutput;
   3.277 -   #endif
   3.278 -   #ifdef DETECT_DEPENDENCIES
   3.279 -   Dependency** dependencies;
   3.280 -   PrivDynArrayInfo* dependenciesInfo;
   3.281 -   #endif
   3.282 -   #ifdef MEAS__PERF_COUNTERS //
   3.283 -   CounterRecord** counter_history;
   3.284 -   PrivDynArrayInfo* counter_history_array_info;
   3.285 -   #endif
   3.286 - }
   3.287 -MasterEnv;
   3.288 -
   3.289 -//=========================  Extra Stuff Data Strucs  =======================
   3.290 -typedef struct
   3.291 - {
   3.292 -
   3.293 - }
   3.294 -VMSExcp;
   3.295 -
   3.296 -struct _GateStruc
   3.297 - {
   3.298 -   int32 gateClosed;
   3.299 -   int32 preGateProgress;
   3.300 -   int32 waitProgress;
   3.301 -   int32 exitProgress;
   3.302 - };
   3.303 -//GateStruc
   3.304 -
   3.305 -//=======================  OS Thread related  ===============================
   3.306 -
   3.307 -void * coreLoop( void *paramsIn );  //standard PThreads fn prototype
   3.308 -void * coreLoop_Seq( void *paramsIn );  //standard PThreads fn prototype
   3.309 -void masterLoop( void *initData, VirtProcr *masterPr );
   3.310 -
   3.311 -
   3.312 -typedef struct
   3.313 - {
   3.314 -   void           *endThdPt;
   3.315 -   unsigned int    coreNum;
   3.316 - }
   3.317 -ThdParams;
   3.318 -
   3.319 -pthread_t       coreLoopThdHandles[ NUM_CORES ];  //pthread's virt-procr state
   3.320 -ThdParams      *coreLoopThdParams [ NUM_CORES ];
   3.321 -pthread_mutex_t suspendLock;
   3.322 -pthread_cond_t  suspend_cond;
   3.323 -
   3.324 -
   3.325 -
   3.326 -//=====================  Global Vars ===================
   3.327 -
   3.328 -volatile MasterEnv      *_VMSMasterEnv;
   3.329 -
   3.330 -
   3.331 -
   3.332 -
   3.333 -//===========================  Function Prototypes  =========================
   3.334 -
   3.335 -
   3.336 -//========== Setup and shutdown ==========
   3.337 -void
   3.338 -VMS__init();
   3.339 -
   3.340 -void
   3.341 -VMS__init_Seq();
   3.342 -
   3.343 -void
   3.344 -VMS__start_the_work_then_wait_until_done();
   3.345 -
   3.346 -void
   3.347 -VMS__start_the_work_then_wait_until_done_Seq();
   3.348 -
   3.349 -inline VirtProcr *
   3.350 -VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
   3.351 -
   3.352 -void
   3.353 -VMS__dissipate_procr( VirtProcr *procrToDissipate );
   3.354 -
   3.355 -   //Use this to create processor inside entry point & other places outside
   3.356 -   // the VMS system boundary (IE, not run in slave nor Master)
   3.357 -VirtProcr *
   3.358 -VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
   3.359 -
   3.360 -void
   3.361 -VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
   3.362 -
   3.363 -void
   3.364 -VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
   3.365 -
   3.366 -void
   3.367 -VMS__shutdown();
   3.368 -
   3.369 -void
   3.370 -VMS__cleanup_at_end_of_shutdown();
   3.371 -
   3.372 -void *
   3.373 -VMS__give_sem_env_for( VirtProcr *animPr );
   3.374 -
   3.375 -
   3.376 -//==============  Request Related  ===============
   3.377 -
   3.378 -void
   3.379 -VMS__suspend_procr( VirtProcr *callingPr );
   3.380 -
   3.381 -inline void
   3.382 -VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
   3.383 -
   3.384 -/*inline*/ __attribute__ ((noinline)) void
   3.385 -VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
   3.386 -
   3.387 -void
   3.388 -VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
   3.389 -
   3.390 -void /*inline**/ __attribute__ ((noinline))
   3.391 -VMS__send_dissipate_req( VirtProcr *prToDissipate );
   3.392 -
   3.393 -/*inline**/ __attribute__ ((noinline)) void
   3.394 -VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
   3.395 -
   3.396 -VMSReqst *
   3.397 -VMS__take_next_request_out_of( VirtProcr *procrWithReq );
   3.398 -
   3.399 -inline void *
   3.400 -VMS__take_sem_reqst_from( VMSReqst *req );
   3.401 -
   3.402 -void inline
   3.403 -VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
   3.404 -                       ResumePrFnPtr resumePrFnPtr );
   3.405 -
   3.406 -//======================== STATS ======================
   3.407 -
   3.408 -//===== RDTSC wrapper ===== //Also runs with x86_64 code
   3.409 -
   3.410 -#define saveTimeStampCountInto(low, high) \
   3.411 -   asm volatile("RDTSC;                   \
   3.412 -                 movl %%eax, %0;          \
   3.413 -                 movl %%edx, %1;"         \
   3.414 -   /* outputs */ : "=m" (low), "=m" (high)\
   3.415 -   /* inputs  */ :                        \
   3.416 -   /* clobber */ : "%eax", "%edx"         \
   3.417 -                );
   3.418 -
   3.419 -#define saveLowTimeStampCountInto(low)    \
   3.420 -   asm volatile("RDTSC;                   \
   3.421 -                 movl %%eax, %0;"         \
   3.422 -   /* outputs */ : "=m" (low)             \
   3.423 -   /* inputs  */ :                        \
   3.424 -   /* clobber */ : "%eax", "%edx"         \
   3.425 -                );
   3.426 -
   3.427 -//====================
   3.428 -#define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
   3.429 -   makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
   3.430 -   _VMSMasterEnv->measHists[idx] =  \
   3.431 -                       makeFixedBinHist( numBins, startVal, binWidth, name );
   3.432 -
   3.433 -#define saveCyclesAndInstrs(core,cycles,instrs) do{ \
   3.434 -   int cycles_fd = _VMSMasterEnv->cycles_counter_fd[core]; \
   3.435 -   int instrs_fd = _VMSMasterEnv->instrs_counter_fd[core]; \
   3.436 -   int nread;                                           \
   3.437 -                                                        \
   3.438 -   nread = read(cycles_fd,&(cycles),sizeof(cycles));    \
   3.439 -   if(nread<0){                                         \
   3.440 -       perror("Error reading cycles counter");          \
   3.441 -       cycles = 0;                                      \
   3.442 -   }                                                    \
   3.443 -                                                        \
   3.444 -   nread = read(instrs_fd,&(instrs),sizeof(instrs));    \
   3.445 -   if(nread<0){                                         \
   3.446 -       perror("Error reading cycles counter");          \
   3.447 -       instrs = 0;                                      \
   3.448 -   }                                                    \
   3.449 -} while (0) 
   3.450 -
   3.451 -#define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{     \
   3.452 -void* frame_ptr0 = vp_ptr->framePtr;                               \
   3.453 -void* frame_ptr1 = *((void**)frame_ptr0);                          \
   3.454 -void* frame_ptr2 = *((void**)frame_ptr1);                          \
   3.455 -void* frame_ptr3 = *((void**)frame_ptr2);                          \
   3.456 -void* ret_addr = *((void**)frame_ptr3 + 1);                        \
   3.457 -*res_ptr = ret_addr;                                               \
   3.458 -} while (0)
   3.459 -
   3.460 -#define MEAS__SUB_CREATE  /*turn on/off subtraction of create from plugin*/
   3.461 -
   3.462 -#ifdef VPTHREAD
   3.463 -
   3.464 -//VPThread
   3.465 -#define createHistIdx      1
   3.466 -#define mutexLockHistIdx   2
   3.467 -#define mutexUnlockHistIdx 3
   3.468 -#define condWaitHistIdx    4
   3.469 -#define condSignalHistIdx  5
   3.470 -
   3.471 -#define MakeTheMeasHists() \
   3.472 -   _VMSMasterEnv->measHistsInfo = \
   3.473 -              makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
   3.474 -   makeAMeasHist( createHistIdx,      "create",        250, 0, 100 ) \
   3.475 -   makeAMeasHist( mutexLockHistIdx,   "mutex_lock",    50, 0, 100 ) \
   3.476 -   makeAMeasHist( mutexUnlockHistIdx, "mutex_unlock",  50, 0, 100 ) \
   3.477 -   makeAMeasHist( condWaitHistIdx,    "cond_wait",     50, 0, 100 ) \
   3.478 -   makeAMeasHist( condSignalHistIdx,  "cond_signal",   50, 0, 100 )
   3.479 -
   3.480 -#endif
   3.481 -
   3.482 -
   3.483 -#ifdef VCILK
   3.484 -
   3.485 -//VCilk
   3.486 -#define spawnHistIdx      1
   3.487 -#define syncHistIdx       2
   3.488 -
   3.489 -#define MakeTheMeasHists() \
   3.490 -   _VMSMasterEnv->measHistsInfo = \
   3.491 -              makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
   3.492 -    makeAMeasHist( spawnHistIdx,      "Spawn",        50, 0, 200 ) \
   3.493 -    makeAMeasHist( syncHistIdx,       "Sync",         50, 0, 200 )
   3.494 -
   3.495 -
   3.496 -#endif
   3.497 -
   3.498 -#ifdef SSR
   3.499 -
   3.500 -//SSR
   3.501 -#define SendFromToHistIdx      1
   3.502 -#define SendOfTypeHistIdx      2
   3.503 -#define ReceiveFromToHistIdx   3
   3.504 -#define ReceiveOfTypeHistIdx   4
   3.505 -
   3.506 -#define MakeTheMeasHists() \
   3.507 -   _VMSMasterEnv->measHistsInfo = \
   3.508 -              makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
   3.509 -    makeAMeasHist( SendFromToHistIdx,   "SendFromTo",    50, 0, 100 ) \
   3.510 -    makeAMeasHist( SendOfTypeHistIdx,   "SendOfType",    50, 0, 100 ) \
   3.511 -    makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
   3.512 -    makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
   3.513 -
   3.514 -#endif
   3.515 -
   3.516 -//===========================================================================
   3.517 -//VPThread
   3.518 -
   3.519 -
   3.520 -#define Meas_startCreate \
   3.521 -    int32 startStamp, endStamp; \
   3.522 -    saveLowTimeStampCountInto( startStamp ); \
   3.523 -
   3.524 -#define Meas_endCreate \
   3.525 -    saveLowTimeStampCountInto( endStamp ); \
   3.526 -    addIntervalToHist( startStamp, endStamp, \
   3.527 -                                 _VMSMasterEnv->measHists[ createHistIdx ] );
   3.528 -
   3.529 -#define Meas_startMutexLock \
   3.530 -    int32 startStamp, endStamp; \
   3.531 -    saveLowTimeStampCountInto( startStamp ); \
   3.532 -
   3.533 -#define Meas_endMutexLock \
   3.534 -    saveLowTimeStampCountInto( endStamp ); \
   3.535 -    addIntervalToHist( startStamp, endStamp, \
   3.536 -                              _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
   3.537 -
   3.538 -#define Meas_startMutexUnlock \
   3.539 -    int32 startStamp, endStamp; \
   3.540 -    saveLowTimeStampCountInto( startStamp ); \
   3.541 -
   3.542 -#define Meas_endMutexUnlock \
   3.543 -    saveLowTimeStampCountInto( endStamp ); \
   3.544 -    addIntervalToHist( startStamp, endStamp, \
   3.545 -                            _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
   3.546 -
   3.547 -#define Meas_startCondWait \
   3.548 -    int32 startStamp, endStamp; \
   3.549 -    saveLowTimeStampCountInto( startStamp ); \
   3.550 -
   3.551 -#define Meas_endCondWait \
   3.552 -    saveLowTimeStampCountInto( endStamp ); \
   3.553 -    addIntervalToHist( startStamp, endStamp, \
   3.554 -                               _VMSMasterEnv->measHists[ condWaitHistIdx ] );
   3.555 -
   3.556 -#define Meas_startCondSignal \
   3.557 -    int32 startStamp, endStamp; \
   3.558 -    saveLowTimeStampCountInto( startStamp ); \
   3.559 -
   3.560 -#define Meas_endCondSignal \
   3.561 -    saveLowTimeStampCountInto( endStamp ); \
   3.562 -    addIntervalToHist( startStamp, endStamp, \
   3.563 -                             _VMSMasterEnv->measHists[ condSignalHistIdx ] );
   3.564 -
   3.565 -//===========================================================================
   3.566 -// VCilk
   3.567 -#define Meas_startSpawn \
   3.568 -    int32 startStamp, endStamp; \
   3.569 -    saveLowTimeStampCountInto( startStamp ); \
   3.570 -
   3.571 -#define Meas_endSpawn \
   3.572 -    saveLowTimeStampCountInto( endStamp ); \
   3.573 -    addIntervalToHist( startStamp, endStamp, \
   3.574 -                             _VMSMasterEnv->measHists[ spawnHistIdx ] );
   3.575 -
   3.576 -#define Meas_startSync \
   3.577 -    int32 startStamp, endStamp; \
   3.578 -    saveLowTimeStampCountInto( startStamp ); \
   3.579 -
   3.580 -#define Meas_endSync \
   3.581 -    saveLowTimeStampCountInto( endStamp ); \
   3.582 -    addIntervalToHist( startStamp, endStamp, \
   3.583 -                             _VMSMasterEnv->measHists[ syncHistIdx ] );
   3.584 -
   3.585 -//===========================================================================
   3.586 -// SSR
   3.587 -#define Meas_startSendFromTo \
   3.588 -    int32 startStamp, endStamp; \
   3.589 -    saveLowTimeStampCountInto( startStamp ); \
   3.590 -
   3.591 -#define Meas_endSendFromTo \
   3.592 -    saveLowTimeStampCountInto( endStamp ); \
   3.593 -    addIntervalToHist( startStamp, endStamp, \
   3.594 -                             _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
   3.595 -
   3.596 -#define Meas_startSendOfType \
   3.597 -    int32 startStamp, endStamp; \
   3.598 -    saveLowTimeStampCountInto( startStamp ); \
   3.599 -
   3.600 -#define Meas_endSendOfType \
   3.601 -    saveLowTimeStampCountInto( endStamp ); \
   3.602 -    addIntervalToHist( startStamp, endStamp, \
   3.603 -                             _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
   3.604 -
   3.605 -#define Meas_startReceiveFromTo \
   3.606 -    int32 startStamp, endStamp; \
   3.607 -    saveLowTimeStampCountInto( startStamp ); \
   3.608 -
   3.609 -#define Meas_endReceiveFromTo \
   3.610 -    saveLowTimeStampCountInto( endStamp ); \
   3.611 -    addIntervalToHist( startStamp, endStamp, \
   3.612 -                             _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
   3.613 -
   3.614 -#define Meas_startReceiveOfType \
   3.615 -    int32 startStamp, endStamp; \
   3.616 -    saveLowTimeStampCountInto( startStamp ); \
   3.617 -
   3.618 -#define Meas_endReceiveOfType \
   3.619 -    saveLowTimeStampCountInto( endStamp ); \
   3.620 -    addIntervalToHist( startStamp, endStamp, \
   3.621 -                             _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
   3.622 -
   3.623 -//=====
   3.624 -
   3.625 -#include "ProcrContext.h"
   3.626 -#include "probes.h"
   3.627 -#include "vutilities.h"
   3.628 -
   3.629 -#endif	/* _VMS_H */
   3.630 -
   3.631 +/*
   3.632 + *  Copyright 2009 OpenSourceStewardshipFoundation.org
   3.633 + *  Licensed under GNU General Public License version 2
   3.634 + *
   3.635 + * Author: seanhalle@yahoo.com
   3.636 + * 
   3.637 + */
   3.638 +
   3.639 +#ifndef _VMS_H
   3.640 +#define	_VMS_H
   3.641 +#define _GNU_SOURCE
   3.642 +
   3.643 +#include "VMS_primitive_data_types.h"
   3.644 +#include "Queue_impl/PrivateQueue.h"
   3.645 +#include "Histogram/Histogram.h"
   3.646 +#include "DynArray/DynArray.h"
   3.647 +#include "Hash_impl/PrivateHash.h"
   3.648 +#include "vmalloc.h"
   3.649 +#include "Counters/Counters.h"
   3.650 +#include "dependency.h"
   3.651 +
   3.652 +#include <pthread.h>
   3.653 +#include <sys/time.h>
   3.654 +
   3.655 +
   3.656 +//===============================  Debug  ===================================
   3.657 +//
   3.658 +//When SEQUENTIAL is defined, VMS does sequential exe in the main thread
   3.659 +// It still does co-routines and all the mechanisms are the same, it just
   3.660 +// has only a single thread and animates VPs one at a time
   3.661 +//#define SEQUENTIAL
   3.662 +
   3.663 +//#define USE_WORK_STEALING
   3.664 +
   3.665 +//turns on the probe-instrumentation in the application -- when not
   3.666 +// defined, the calls to the probe functions turn into comments
   3.667 +//#define STATS__ENABLE_PROBES
   3.668 +//#define TURN_ON_DEBUG_PROBES
   3.669 +
   3.670 +//These defines turn types of bug messages on and off
   3.671 +// be sure debug messages are un-commented (next block of defines)
   3.672 +#define dbgAppFlow   FALSE /* Top level flow of application code -- general*/
   3.673 +#define dbgProbes    FALSE /* for issues inside probes themselves*/
   3.674 +#define dbgB2BMaster FALSE /* in coreloop, back to back master VPs*/
   3.675 +#define dbgRqstHdlr  FALSE /* in request handler code*/
   3.676 +#define dbgDependency TRUE /* in request handler code, print dependencies */
   3.677 +
   3.678 +//Comment or un- the substitute half to turn on/off types of debug message
   3.679 +#define DEBUG(  bool, msg)         \
   3.680 +  if( bool){ printf(msg); fflush(stdin);}
   3.681 +#define DEBUG1( bool, msg, param)  \
   3.682 +   if(bool){printf(msg, param); fflush(stdin);}
   3.683 +#define DEBUG2( bool, msg, p1, p2) \
   3.684 +   if(bool) {printf(msg, p1, p2); fflush(stdin);}
   3.685 +
   3.686 +#define ERROR(msg) printf(msg);
   3.687 +#define ERROR1(msg, param) printf(msg, param); 
   3.688 +#define ERROR2(msg, p1, p2) printf(msg, p1, p2);
   3.689 +
   3.690 +//===========================  STATS =======================
   3.691 +
   3.692 +   //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
   3.693 +   // compiled-in that saves the low part of the time stamp count just before
   3.694 +   // suspending a processor and just after resuming that processor.  It is
   3.695 +   // saved into a field added to VirtProcr.  Have to sanity-check for
   3.696 +   // rollover of low portion into high portion.
   3.697 +//#define MEAS__TIME_STAMP_SUSP
   3.698 +//#define MEAS__TIME_MASTER
   3.699 +//#define MEAS__TIME_PLUGIN
   3.700 +//#define MEAS__TIME_MALLOC
   3.701 +//#define MEAS__TIME_MASTER_LOCK
   3.702 +//#define MEAS__NUM_TIMES_TO_RUN 100000
   3.703 +
   3.704 +   //For code that calculates normalization-offset between TSC counts of
   3.705 +   // different cores.
   3.706 +//#define NUM_TSC_ROUND_TRIPS 10
   3.707 +
   3.708 +#define MEAS__PERF_COUNTERS
   3.709 +#define DETECT_DEPENDENCIES
   3.710 +
   3.711 +//=========================  Hardware related Constants =====================
   3.712 +   //This value is the number of hardware threads in the shared memory
   3.713 +   // machine
   3.714 +//#define NUM_CORES        8
   3.715 +
   3.716 +   // tradeoff amortizing master fixed overhead vs imbalance potential
   3.717 +   // when work-stealing, can make bigger, at risk of losing cache affinity
   3.718 +#define NUM_SCHED_SLOTS  5
   3.719 +
   3.720 +#define MIN_WORK_UNIT_CYCLES 20000
   3.721 +
   3.722 +#define MASTERLOCK_RETRIES 10000
   3.723 +
   3.724 +   // stack size in virtual processors created
   3.725 +#define VIRT_PROCR_STACK_SIZE 0x8000 /* 32K */
   3.726 +
   3.727 +   // memory for VMS__malloc
   3.728 +#define MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE 0x10000000 /* 256M */
   3.729 +
   3.730 +#define CACHE_LINE 64
   3.731 +#define PAGE_SIZE 4096
   3.732 +
   3.733 +
   3.734 +//==============================
   3.735 +
   3.736 +#define SUCCESS 0
   3.737 +
   3.738 +#define writeVMSQ     writePrivQ
   3.739 +#define readVMSQ      readPrivQ
   3.740 +#define makeVMSQ      makeVMSPrivQ
   3.741 +#define numInVMSQ     numInPrivQ
   3.742 +#define VMSQueueStruc PrivQueueStruc
   3.743 +
   3.744 +
   3.745 +
   3.746 +//===========================================================================
   3.747 +typedef unsigned long long TSCount;
   3.748 +
   3.749 +typedef struct _SchedSlot     SchedSlot;
   3.750 +typedef struct _VMSReqst      VMSReqst;
   3.751 +typedef struct _VirtProcr     VirtProcr;
   3.752 +typedef struct _IntervalProbe IntervalProbe;
   3.753 +typedef struct _GateStruc     GateStruc;
   3.754 +
   3.755 +
   3.756 +typedef VirtProcr * (*SlaveScheduler)  ( void *, int );   //semEnv, coreIdx
   3.757 +typedef void  (*RequestHandler)  ( VirtProcr *, void * ); //prWReqst, semEnv
   3.758 +typedef void  (*VirtProcrFnPtr)  ( void *, VirtProcr * ); //initData, animPr
   3.759 +typedef void    VirtProcrFn      ( void *, VirtProcr * ); //initData, animPr
   3.760 +typedef void  (*ResumePrFnPtr)   ( VirtProcr *, void * );
   3.761 +
   3.762 +
   3.763 +//============= Requests ===========
   3.764 +//
   3.765 +
   3.766 +enum VMSReqstType   //avoid starting enums at 0, for debug reasons
   3.767 + {
   3.768 +   semantic = 1,
   3.769 +   createReq,
   3.770 +   dissipate,
   3.771 +   VMSSemantic      //goes with VMSSemReqst below
   3.772 + };
   3.773 +
   3.774 +struct _VMSReqst
   3.775 + {
   3.776 +   enum VMSReqstType  reqType;//used for dissipate and in future for IO requests
   3.777 +   void              *semReqData;
   3.778 +
   3.779 +   VMSReqst *nextReqst;
   3.780 + };
   3.781 +//VMSReqst
   3.782 +
   3.783 +enum VMSSemReqstType   //These are equivalent to semantic requests, but for
   3.784 + {                     // VMS's services available directly to app, like OS
   3.785 +   createProbe = 1,    // and probe services -- like a VMS-wide built-in lang
   3.786 +   openFile,
   3.787 +   otherIO
   3.788 + };
   3.789 +
   3.790 +typedef struct
   3.791 + { enum VMSSemReqstType reqType;
   3.792 +   VirtProcr           *requestingPr;
   3.793 +   char                *nameStr;  //for create probe
   3.794 + }
   3.795 + VMSSemReq;
   3.796 +
   3.797 +
   3.798 +//====================  Core data structures  ===================
   3.799 +
   3.800 +struct _SchedSlot
   3.801 + {
   3.802 +   int         workIsDone;
   3.803 +   int         needsProcrAssigned;
   3.804 +   VirtProcr  *procrAssignedToSlot;
   3.805 + };
   3.806 +//SchedSlot
   3.807 +
   3.808 +/*WARNING: re-arranging this data structure could cause VP switching
   3.809 + *         assembly code to fail -- hard-codes offsets of fields
   3.810 + */
   3.811 +struct _VirtProcr
   3.812 + { int         procrID;  //for debugging -- count up each time create
   3.813 +   int         coreAnimatedBy;
   3.814 +   void       *startOfStack;
   3.815 +   void       *stackPtr;
   3.816 +   void       *framePtr;
   3.817 +   void       *nextInstrPt;
   3.818 +   
   3.819 +   void       *coreLoopStartPt;  //allows proto-runtime to be linked later
   3.820 +   void       *coreLoopFramePtr; //restore before jmp back to core loop
   3.821 +   void       *coreLoopStackPtr; //restore before jmp back to core loop
   3.822 +
   3.823 +   void       *initialData;
   3.824 +
   3.825 +   SchedSlot  *schedSlot;
   3.826 +   VMSReqst   *requests;
   3.827 +
   3.828 +   void       *semanticData; //this livesUSE_GNU here for the life of VP
   3.829 +   void       *dataRetFromReq;//values returned from plugin to VP go here
   3.830 +
   3.831 +      //=========== MEASUREMENT STUFF ==========
   3.832 +   #ifdef MEAS__TIME_STAMP_SUSP
   3.833 +   unsigned int preSuspTSCLow;
   3.834 +   unsigned int postSuspTSCLow;
   3.835 +   #endif
   3.836 +   #ifdef MEAS__TIME_MASTER /* in VirtProcr because multiple masterVPs*/
   3.837 +   unsigned int startMasterTSCLow;USE_GNU
   3.838 +   unsigned int endMasterTSCLow;
   3.839 +   #endif
   3.840 +   #ifdef MEAS__PERF_COUNTERS //
   3.841 +   CounterRecord** counter_history;
   3.842 +   PrivDynArrayInfo* counter_history_array_info;
   3.843 +   #endif
   3.844 +      //========================================
   3.845 +   
   3.846 +   float64      createPtInSecs;  //have space but don't use on some configs
   3.847 + };
   3.848 +//VirtProcr
   3.849 +
   3.850 +
   3.851 +/*WARNING: re-arranging this data structure could cause VP-switching
   3.852 + *         assembly code to fail -- hard-codes offsets of fields
   3.853 + *         (because -O3 messes with things otherwise)
   3.854 + */
   3.855 +typedef struct
   3.856 + {
   3.857 +   SlaveScheduler   slaveScheduler;
   3.858 +   RequestHandler   requestHandler;
   3.859 +   
   3.860 +   SchedSlot     ***allSchedSlots;
   3.861 +   VMSQueueStruc **readyToAnimateQs;
   3.862 +   VirtProcr      **masterVPs;
   3.863 +
   3.864 +   void            *semanticEnv;
   3.865 +   void            *OSEventStruc;   //for future, when add I/O to BLIS
   3.866 +   MallocProlog    *freeListHead;
   3.867 +   int32            amtOfOutstandingMem; //total currently allocated
   3.868 +
   3.869 +   void            *coreLoopReturnPt;//addr to jump to to re-enter coreLoop
   3.870 +
   3.871 +   int32            setupComplete;
   3.872 +   volatile int32   masterLock;
   3.873 +
   3.874 +   int32            numMasterInARow[NUM_CORES];//detect back-to-back masterVP
   3.875 +   GateStruc       *workStealingGates[ NUM_CORES ]; //concurrent work-steal
   3.876 +   int32            workStealingLock;
   3.877 +   
   3.878 +   int32            numProcrsCreated; //gives ordering to processor creation
   3.879 +
   3.880 +      //=========== MEASUREMENT STUFF =============
   3.881 +   IntervalProbe  **intervalProbes;
   3.882 +   PrivDynArrayInfo    *dynIntervalProbesInfo;
   3.883 +   HashTable       *probeNameHashTbl;
   3.884 +   int32            masterCreateProbeID;
   3.885 +   float64          createPtInSecs;
   3.886 +   Histogram      **measHists;
   3.887 +   PrivDynArrayInfo *measHistsInfo;
   3.888 +   #ifdef MEAS__TIME_PLUGIN
   3.889 +   Histogram       *reqHdlrLowTimeHist;
   3.890 +   Histogram       *reqHdlrHighTimeHist;
   3.891 +   #endif
   3.892 +   #ifdef MEAS__TIME_MALLOC
   3.893 +   Histogram       *mallocTimeHist;
   3.894 +   Histogram       *freeTimeHist;
   3.895 +   #endif
   3.896 +   #ifdef MEAS__TIME_MASTER_LOCK
   3.897 +   Histogram       *masterLockLowTimeHist;
   3.898 +   Histogram       *masterLockHighTimeHist;
   3.899 +   #endif
   3.900 +   #ifdef MEAS__PERF_COUNTERS
   3.901 +   int cycles_counter_fd[NUM_CORES];
   3.902 +   int instrs_counter_fd[NUM_CORES];
   3.903 +   FILE* counteroutput;
   3.904 +   #endif
   3.905 +   #ifdef DETECT_DEPENDENCIES
   3.906 +   Dependency** dependencies;
   3.907 +   PrivDynArrayInfo* dependenciesInfo;
   3.908 +   #endif
   3.909 +   #ifdef MEAS__PERF_COUNTERS //
   3.910 +   CounterRecord** counter_history;
   3.911 +   PrivDynArrayInfo* counter_history_array_info;
   3.912 +   #endif
   3.913 + }
   3.914 +MasterEnv;
   3.915 +
   3.916 +//=========================  Extra Stuff Data Strucs  =======================
   3.917 +typedef struct
   3.918 + {
   3.919 +
   3.920 + }
   3.921 +VMSExcp;
   3.922 +
   3.923 +struct _GateStruc
   3.924 + {
   3.925 +   int32 gateClosed;
   3.926 +   int32 preGateProgress;
   3.927 +   int32 waitProgress;
   3.928 +   int32 exitProgress;
   3.929 + };
   3.930 +//GateStruc
   3.931 +
   3.932 +//=======================  OS Thread related  ===============================
   3.933 +
   3.934 +void * coreLoop( void *paramsIn );  //standard PThreads fn prototype
   3.935 +void * coreLoop_Seq( void *paramsIn );  //standard PThreads fn prototype
   3.936 +void masterLoop( void *initData, VirtProcr *masterPr );
   3.937 +
   3.938 +
   3.939 +typedef struct
   3.940 + {
   3.941 +   void           *endThdPt;
   3.942 +   unsigned int    coreNum;
   3.943 + }
   3.944 +ThdParams;
   3.945 +
   3.946 +pthread_t       coreLoopThdHandles[ NUM_CORES ];  //pthread's virt-procr state
   3.947 +ThdParams      *coreLoopThdParams [ NUM_CORES ];
   3.948 +pthread_mutex_t suspendLock;
   3.949 +pthread_cond_t  suspend_cond;
   3.950 +
   3.951 +
   3.952 +
   3.953 +//=====================  Global Vars ===================
   3.954 +
   3.955 +volatile MasterEnv      *_VMSMasterEnv;
   3.956 +
   3.957 +
   3.958 +
   3.959 +
   3.960 +//===========================  Function Prototypes  =========================
   3.961 +
   3.962 +
   3.963 +//========== Setup and shutdown ==========
   3.964 +void
   3.965 +VMS__init();
   3.966 +
   3.967 +void
   3.968 +VMS__init_Seq();
   3.969 +
   3.970 +void
   3.971 +VMS__start_the_work_then_wait_until_done();
   3.972 +
   3.973 +void
   3.974 +VMS__start_the_work_then_wait_until_done_Seq();
   3.975 +
   3.976 +inline VirtProcr *
   3.977 +VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
   3.978 +
   3.979 +void
   3.980 +VMS__dissipate_procr( VirtProcr *procrToDissipate );
   3.981 +
   3.982 +   //Use this to create processor inside entry point & other places outside
   3.983 +   // the VMS system boundary (IE, not run in slave nor Master)
   3.984 +VirtProcr *
   3.985 +VMS_ext__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
   3.986 +
   3.987 +void
   3.988 +VMS_ext__dissipate_procr( VirtProcr *procrToDissipate );
   3.989 +
   3.990 +void
   3.991 +VMS__throw_exception( char *msgStr, VirtProcr *reqstPr, VMSExcp *excpData );
   3.992 +
   3.993 +void
   3.994 +VMS__shutdown();
   3.995 +
   3.996 +void
   3.997 +VMS__cleanup_at_end_of_shutdown();
   3.998 +
   3.999 +void *
  3.1000 +VMS__give_sem_env_for( VirtProcr *animPr );
  3.1001 +
  3.1002 +
  3.1003 +//==============  Request Related  ===============
  3.1004 +
  3.1005 +void
  3.1006 +VMS__suspend_procr( VirtProcr *callingPr );
  3.1007 +
  3.1008 +inline void
  3.1009 +VMS__add_sem_request_in_mallocd_VMSReqst( void *semReqData, VirtProcr *callingPr );
  3.1010 +
  3.1011 +/*inline*/ __attribute__ ((noinline)) void
  3.1012 +VMS__send_sem_request( void *semReqData, VirtProcr *callingPr );
  3.1013 +
  3.1014 +void
  3.1015 +VMS__send_create_procr_req( void *semReqData, VirtProcr *reqstingPr );
  3.1016 +
  3.1017 +void /*inline**/ __attribute__ ((noinline))
  3.1018 +VMS__send_dissipate_req( VirtProcr *prToDissipate );
  3.1019 +
  3.1020 +/*inline**/ __attribute__ ((noinline)) void
  3.1021 +VMS__send_VMSSem_request( void *semReqData, VirtProcr *callingPr );
  3.1022 +
  3.1023 +VMSReqst *
  3.1024 +VMS__take_next_request_out_of( VirtProcr *procrWithReq );
  3.1025 +
  3.1026 +inline void *
  3.1027 +VMS__take_sem_reqst_from( VMSReqst *req );
  3.1028 +
  3.1029 +void inline
  3.1030 +VMS__handle_VMSSemReq( VMSReqst *req, VirtProcr *requestingPr, void *semEnv,
  3.1031 +                       ResumePrFnPtr resumePrFnPtr );
  3.1032 +
  3.1033 +//======================== STATS ======================
  3.1034 +
  3.1035 +//===== RDTSC wrapper ===== //Also runs with x86_64 code
  3.1036 +
  3.1037 +#define saveTimeStampCountInto(low, high) \
  3.1038 +   asm volatile("RDTSC;                   \
  3.1039 +                 movl %%eax, %0;          \
  3.1040 +                 movl %%edx, %1;"         \
  3.1041 +   /* outputs */ : "=m" (low), "=m" (high)\
  3.1042 +   /* inputs  */ :                        \
  3.1043 +   /* clobber */ : "%eax", "%edx"         \
  3.1044 +                );
  3.1045 +
  3.1046 +#define saveLowTimeStampCountInto(low)    \
  3.1047 +   asm volatile("RDTSC;                   \
  3.1048 +                 movl %%eax, %0;"         \
  3.1049 +   /* outputs */ : "=m" (low)             \
  3.1050 +   /* inputs  */ :                        \
  3.1051 +   /* clobber */ : "%eax", "%edx"         \
  3.1052 +                );
  3.1053 +
  3.1054 +//====================
  3.1055 +#define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \
  3.1056 +   makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \
  3.1057 +   _VMSMasterEnv->measHists[idx] =  \
  3.1058 +                       makeFixedBinHist( numBins, startVal, binWidth, name );
  3.1059 +
  3.1060 +#define saveCyclesAndInstrs(core,cycles,instrs) do{ \
  3.1061 +   int cycles_fd = _VMSMasterEnv->cycles_counter_fd[core]; \
  3.1062 +   int instrs_fd = _VMSMasterEnv->instrs_counter_fd[core]; \
  3.1063 +   int nread;                                           \
  3.1064 +                                                        \
  3.1065 +   nread = read(cycles_fd,&(cycles),sizeof(cycles));    \
  3.1066 +   if(nread<0){                                         \
  3.1067 +       perror("Error reading cycles counter");          \
  3.1068 +       cycles = 0;                                      \
  3.1069 +   }                                                    \
  3.1070 +                                                        \
  3.1071 +   nread = read(instrs_fd,&(instrs),sizeof(instrs));    \
  3.1072 +   if(nread<0){                                         \
  3.1073 +       perror("Error reading cycles counter");          \
  3.1074 +       instrs = 0;                                      \
  3.1075 +   }                                                    \
  3.1076 +} while (0) 
  3.1077 +
  3.1078 +#define getReturnAddressBeforeLibraryCall(vp_ptr, res_ptr) do{     \
  3.1079 +void* frame_ptr0 = vp_ptr->framePtr;                               \
  3.1080 +void* frame_ptr1 = *((void**)frame_ptr0);                          \
  3.1081 +void* frame_ptr2 = *((void**)frame_ptr1);                          \
  3.1082 +void* frame_ptr3 = *((void**)frame_ptr2);                          \
  3.1083 +void* ret_addr = *((void**)frame_ptr3 + 1);                        \
  3.1084 +*res_ptr = ret_addr;                                               \
  3.1085 +} while (0)
  3.1086 +
  3.1087 +#define MEAS__SUB_CREATE  /*turn on/off subtraction of create from plugin*/
  3.1088 +
  3.1089 +#ifdef VPTHREAD
  3.1090 +
  3.1091 +//VPThread
  3.1092 +#define createHistIdx      0
  3.1093 +#define mutexLockHistIdx   1
  3.1094 +#define mutexUnlockHistIdx 2
  3.1095 +#define condWaitHistIdx    3
  3.1096 +#define condSignalHistIdx  4
  3.1097 +
  3.1098 +#define MakeTheMeasHists() \
  3.1099 +   _VMSMasterEnv->measHistsInfo = \
  3.1100 +              makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
  3.1101 +   makeAMeasHist( createHistIdx,      "create",        250, 0, 100 ) \
  3.1102 +   makeAMeasHist( mutexLockHistIdx,   "mutex_lock",    50, 0, 100 ) \
  3.1103 +   makeAMeasHist( mutexUnlockHistIdx, "mutex_unlock",  50, 0, 100 ) \
  3.1104 +   makeAMeasHist( condWaitHistIdx,    "cond_wait",     50, 0, 100 ) \
  3.1105 +   makeAMeasHist( condSignalHistIdx,  "cond_signal",   50, 0, 100 )
  3.1106 +
  3.1107 +#endif
  3.1108 +
  3.1109 +
  3.1110 +#ifdef VCILK
  3.1111 +
  3.1112 +//VCilk
  3.1113 +#define spawnHistIdx      0
  3.1114 +#define syncHistIdx       1
  3.1115 +
  3.1116 +#define MakeTheMeasHists() \
  3.1117 +   _VMSMasterEnv->measHistsInfo = \
  3.1118 +              makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
  3.1119 +    makeAMeasHist( spawnHistIdx,      "Spawn",        50, 0, 200 ) \
  3.1120 +    makeAMeasHist( syncHistIdx,       "Sync",         50, 0, 200 )
  3.1121 +
  3.1122 +
  3.1123 +#endif
  3.1124 +
  3.1125 +#ifdef SSR
  3.1126 +
  3.1127 +//SSR
  3.1128 +#define SendFromToHistIdx      0
  3.1129 +#define SendOfTypeHistIdx      1
  3.1130 +#define ReceiveFromToHistIdx   2
  3.1131 +#define ReceiveOfTypeHistIdx   3
  3.1132 +
  3.1133 +#define MakeTheMeasHists() \
  3.1134 +   _VMSMasterEnv->measHistsInfo = \
  3.1135 +              makePrivDynArrayOfSize( (void***)&(_VMSMasterEnv->measHists), 200); \
  3.1136 +    makeAMeasHist( SendFromToHistIdx,   "SendFromTo",    50, 0, 100 ) \
  3.1137 +    makeAMeasHist( SendOfTypeHistIdx,   "SendOfType",    50, 0, 100 ) \
  3.1138 +    makeAMeasHist( ReceiveFromToHistIdx,"ReceiveFromTo", 50, 0, 100 ) \
  3.1139 +    makeAMeasHist( ReceiveOfTypeHistIdx,"ReceiveOfType", 50, 0, 100 )
  3.1140 +
  3.1141 +#endif
  3.1142 +
  3.1143 +//===========================================================================
  3.1144 +//VPThread
  3.1145 +
  3.1146 +
  3.1147 +#define Meas_startCreate \
  3.1148 +    int32 startStamp, endStamp; \
  3.1149 +    saveLowTimeStampCountInto( startStamp ); \
  3.1150 +
  3.1151 +#define Meas_endCreate \
  3.1152 +    saveLowTimeStampCountInto( endStamp ); \
  3.1153 +    addIntervalToHist( startStamp, endStamp, \
  3.1154 +                                 _VMSMasterEnv->measHists[ createHistIdx ] );
  3.1155 +
  3.1156 +#define Meas_startMutexLock \
  3.1157 +    int32 startStamp, endStamp; \
  3.1158 +    saveLowTimeStampCountInto( startStamp ); \
  3.1159 +
  3.1160 +#define Meas_endMutexLock \
  3.1161 +    saveLowTimeStampCountInto( endStamp ); \
  3.1162 +    addIntervalToHist( startStamp, endStamp, \
  3.1163 +                              _VMSMasterEnv->measHists[ mutexLockHistIdx ] );
  3.1164 +
  3.1165 +#define Meas_startMutexUnlock \
  3.1166 +    int32 startStamp, endStamp; \
  3.1167 +    saveLowTimeStampCountInto( startStamp ); \
  3.1168 +
  3.1169 +#define Meas_endMutexUnlock \
  3.1170 +    saveLowTimeStampCountInto( endStamp ); \
  3.1171 +    addIntervalToHist( startStamp, endStamp, \
  3.1172 +                            _VMSMasterEnv->measHists[ mutexUnlockHistIdx ] );
  3.1173 +
  3.1174 +#define Meas_startCondWait \
  3.1175 +    int32 startStamp, endStamp; \
  3.1176 +    saveLowTimeStampCountInto( startStamp ); \
  3.1177 +
  3.1178 +#define Meas_endCondWait \
  3.1179 +    saveLowTimeStampCountInto( endStamp ); \
  3.1180 +    addIntervalToHist( startStamp, endStamp, \
  3.1181 +                               _VMSMasterEnv->measHists[ condWaitHistIdx ] );
  3.1182 +
  3.1183 +#define Meas_startCondSignal \
  3.1184 +    int32 startStamp, endStamp; \
  3.1185 +    saveLowTimeStampCountInto( startStamp ); \
  3.1186 +
  3.1187 +#define Meas_endCondSignal \
  3.1188 +    saveLowTimeStampCountInto( endStamp ); \
  3.1189 +    addIntervalToHist( startStamp, endStamp, \
  3.1190 +                             _VMSMasterEnv->measHists[ condSignalHistIdx ] );
  3.1191 +
  3.1192 +//===========================================================================
  3.1193 +// VCilk
  3.1194 +#define Meas_startSpawn \
  3.1195 +    int32 startStamp, endStamp; \
  3.1196 +    saveLowTimeStampCountInto( startStamp ); \
  3.1197 +
  3.1198 +#define Meas_endSpawn \
  3.1199 +    saveLowTimeStampCountInto( endStamp ); \
  3.1200 +    addIntervalToHist( startStamp, endStamp, \
  3.1201 +                             _VMSMasterEnv->measHists[ spawnHistIdx ] );
  3.1202 +
  3.1203 +#define Meas_startSync \
  3.1204 +    int32 startStamp, endStamp; \
  3.1205 +    saveLowTimeStampCountInto( startStamp ); \
  3.1206 +
  3.1207 +#define Meas_endSync \
  3.1208 +    saveLowTimeStampCountInto( endStamp ); \
  3.1209 +    addIntervalToHist( startStamp, endStamp, \
  3.1210 +                             _VMSMasterEnv->measHists[ syncHistIdx ] );
  3.1211 +
  3.1212 +//===========================================================================
  3.1213 +// SSR
  3.1214 +#define Meas_startSendFromTo \
  3.1215 +    int32 startStamp, endStamp; \
  3.1216 +    saveLowTimeStampCountInto( startStamp ); \
  3.1217 +
  3.1218 +#define Meas_endSendFromTo \
  3.1219 +    saveLowTimeStampCountInto( endStamp ); \
  3.1220 +    addIntervalToHist( startStamp, endStamp, \
  3.1221 +                             _VMSMasterEnv->measHists[ SendFromToHistIdx ] );
  3.1222 +
  3.1223 +#define Meas_startSendOfType \
  3.1224 +    int32 startStamp, endStamp; \
  3.1225 +    saveLowTimeStampCountInto( startStamp ); \
  3.1226 +
  3.1227 +#define Meas_endSendOfType \
  3.1228 +    saveLowTimeStampCountInto( endStamp ); \
  3.1229 +    addIntervalToHist( startStamp, endStamp, \
  3.1230 +                             _VMSMasterEnv->measHists[ SendOfTypeHistIdx ] );
  3.1231 +
  3.1232 +#define Meas_startReceiveFromTo \
  3.1233 +    int32 startStamp, endStamp; \
  3.1234 +    saveLowTimeStampCountInto( startStamp ); \
  3.1235 +
  3.1236 +#define Meas_endReceiveFromTo \
  3.1237 +    saveLowTimeStampCountInto( endStamp ); \
  3.1238 +    addIntervalToHist( startStamp, endStamp, \
  3.1239 +                             _VMSMasterEnv->measHists[ ReceiveFromToHistIdx ] );
  3.1240 +
  3.1241 +#define Meas_startReceiveOfType \
  3.1242 +    int32 startStamp, endStamp; \
  3.1243 +    saveLowTimeStampCountInto( startStamp ); \
  3.1244 +
  3.1245 +#define Meas_endReceiveOfType \
  3.1246 +    saveLowTimeStampCountInto( endStamp ); \
  3.1247 +    addIntervalToHist( startStamp, endStamp, \
  3.1248 +                             _VMSMasterEnv->measHists[ReceiveOfTypeHistIdx ] );
  3.1249 +
  3.1250 +//=====
  3.1251 +
  3.1252 +#include "ProcrContext.h"
  3.1253 +#include "probes.h"
  3.1254 +#include "vutilities.h"
  3.1255 +
  3.1256 +#endif	/* _VMS_H */
  3.1257 +
     4.1 --- a/VMS__DESIGN_NOTES.txt	Thu Sep 15 17:31:33 2011 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,2 +0,0 @@
     4.4 -
     4.5 
     4.6 -Implement VMS this way:
     4.7