annotate VMS.h @ 45:5388f1c2da6f

added MIN_WORK_UNIT_CYCLES and updated comments
author Me
date Thu, 14 Oct 2010 17:07:23 -0700
parents 6c9f314daf24
children 72373405c816 8f7141a9272e
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@42 16 #include <pthread.h>
Me@42 17
Me@45 18 //When SEQUENTIAL is defined, VMS does sequential exe in the main thread
Me@42 19 // It still does co-routines and all the mechanisms are the same, it just
Me@42 20 // has only a single thread and animates VPs one at a time
Me@45 21 //#define SEQUENTIAL
Me@42 22
Me@45 23 #define PRINT_DEBUG(msg) //printf(msg); fflush(stdin);
Me@45 24 #define PRINT1_DEBUG(msg, param) //printf(msg, param); fflush(stdin);
Me@45 25 #define PRINT2_DEBUG(msg, p1, p2) //printf(msg, p1, p2); fflush(stdin);
Me@45 26
Me@45 27 //when MEAS__TIME_STAMP_SUSP is defined, causes code to be inserted and
Me@42 28 // compiled-in that saves the low part of the time stamp count just before
Me@42 29 // suspending a processor and just after resuming that processor. It is
Me@42 30 // saved into a field added to VirtProcr. Have to sanity-check for
Me@42 31 // rollover of low portion into high portion.
Me@42 32 #define MEAS__TIME_STAMP_SUSP
Me@42 33 #define MEAS__TIME_MASTER
Me@42 34 #define MEAS__NUM_TIMES_TO_RUN 100000
Me@42 35
Me@45 36 #define NUM_TSC_ROUND_TRIPS 10
Me@45 37
Me@42 38 //This value is the number of hardware threads in the shared memory
Me@42 39 // machine
Me@42 40 #define NUM_CORES 4
Me@42 41
Me@45 42 // balance amortizing master fixed overhead vs imbalance potential
Me@42 43 #define NUM_SCHED_SLOTS 3
Me@42 44
Me@45 45 #define MIN_WORK_UNIT_CYCLES 20000
Me@45 46
Me@42 47 #define READYTOANIMATE_RETRIES 10000
Me@42 48
Me@42 49 // stack
Me@42 50 #define VIRT_PROCR_STACK_SIZE 0x10000
Me@42 51
Me@42 52 //256M of total memory for VMS__malloc
Me@42 53 #define MASSIVE_MALLOC_SIZE 0x10000000
Me@42 54
Me@42 55 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
Me@42 56
Me@42 57 #define SUCCESS 0
Me@42 58
Me@42 59 #define writeVMSQ writeCASQ
Me@42 60 #define readVMSQ readCASQ
Me@42 61 #define makeVMSQ makeCASQ
Me@42 62 #define VMSQueueStruc CASQueueStruc
Me@42 63
Me@42 64 //#define thdAttrs NULL //For PThreads
Me@42 65
Me@42 66 typedef struct _SchedSlot SchedSlot;
Me@42 67 typedef struct _VMSReqst VMSReqst;
Me@42 68 typedef struct _VirtProcr VirtProcr;
Me@42 69
Me@42 70 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
Me@42 71 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
Me@42 72 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
Me@42 73 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
Me@42 74
Me@42 75 typedef struct
Me@42 76 {
Me@42 77 void *endThdPt;
Me@42 78 unsigned int coreNum;
Me@42 79 }
Me@42 80 ThdParams;
Me@42 81
Me@42 82
Me@42 83 struct _SchedSlot
Me@42 84 {
Me@42 85 int workIsDone;
Me@42 86 int needsProcrAssigned;
Me@42 87 VirtProcr *procrAssignedToSlot;
Me@42 88 };
Me@42 89 //SchedSlot
Me@42 90
Me@42 91 enum ReqstType
Me@42 92 {
Me@42 93 semantic = 1,
Me@42 94 dissipate,
Me@42 95 regCreated,
Me@42 96 IO
Me@42 97 };
Me@42 98
Me@42 99 struct _VMSReqst
Me@42 100 {
Me@42 101 // VirtProcr *virtProcrFrom;
Me@42 102 enum ReqstType reqType;//used for dissipate and in future for IO requests
Me@42 103 void *semReqData;
Me@42 104
Me@42 105 VMSReqst *nextReqst;
Me@42 106 };
Me@42 107 //VMSReqst
Me@42 108
Me@42 109 struct _VirtProcr
Me@42 110 { int procrID; //for debugging -- count up each time create
Me@42 111 int coreAnimatedBy;
Me@42 112 void *startOfStack;
Me@42 113 void *stackPtr;
Me@42 114 void *framePtr;
Me@42 115 void *nextInstrPt;
Me@42 116
Me@42 117 void *coreLoopStartPt; //allows proto-runtime to be linked later
Me@42 118 void *coreLoopFramePtr; //restore before jmp back to core loop
Me@42 119 void *coreLoopStackPtr; //restore before jmp back to core loop
Me@42 120
Me@42 121 void *initialData;
Me@42 122
Me@42 123 SchedSlot *schedSlot;
Me@42 124 VMSReqst *requests;
Me@42 125
Me@42 126 void *semanticData;
Me@42 127
Me@42 128 //============================= MEASUREMENT STUFF ========================
Me@42 129 #ifdef MEAS__TIME_STAMP_SUSP
Me@42 130 unsigned int preSuspTSCLow;
Me@42 131 unsigned int postSuspTSCLow;
Me@42 132 #endif
Me@42 133 #ifdef MEAS__TIME_MASTER
Me@42 134 unsigned int startMasterTSCLow;
Me@42 135 unsigned int endMasterTSCLow;
Me@42 136 #endif
Me@42 137 //========================================================================
Me@42 138 };
Me@42 139 //VirtProcr
Me@42 140
Me@42 141
Me@42 142
Me@42 143 typedef struct
Me@42 144 {
Me@42 145 SlaveScheduler slaveScheduler;
Me@42 146 RequestHandler requestHandler;
Me@42 147
Me@42 148 SchedSlot ***allSchedSlots;
Me@42 149 SRSWQueueStruc **readyToAnimateQs;
Me@42 150 VirtProcr **masterVPs;
Me@42 151
Me@42 152 void *semanticEnv;
Me@42 153 void *OSEventStruc; //for future, when add I/O to BLIS
Me@42 154
Me@42 155 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
Me@42 156 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
Me@42 157
Me@42 158 int setupComplete;
Me@42 159 int masterLock;
Me@42 160
Me@42 161 }
Me@42 162 MasterEnv;
Me@42 163
Me@42 164
Me@42 165 //==========================================================
Me@42 166
Me@42 167 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
Me@42 168 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
Me@42 169 void masterLoop( void *initData, VirtProcr *masterPr );
Me@42 170
Me@42 171
Me@42 172 //===================== Global Vars ===================
Me@42 173
Me@42 174
Me@42 175 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
Me@42 176 ThdParams *coreLoopThdParams [ NUM_CORES ];
Me@42 177 pthread_mutex_t suspendLock;
Me@42 178 pthread_cond_t suspend_cond;
Me@42 179
Me@42 180 volatile MasterEnv *_VMSMasterEnv;
Me@42 181
Me@42 182 //==========================
Me@42 183 void
Me@42 184 VMS__init();
Me@42 185
Me@42 186 void
Me@42 187 VMS__init_Seq();
Me@42 188
Me@42 189 void
Me@42 190 VMS__start_the_work_then_wait_until_done();
Me@42 191
Me@42 192 void
Me@42 193 VMS__start_the_work_then_wait_until_done_Seq();
Me@42 194
Me@42 195 VirtProcr *
Me@42 196 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@42 197
Me@42 198 VirtProcr *
Me@42 199 VMS__create_the_shutdown_procr();
Me@42 200
Me@42 201 //==========================
Me@42 202 inline void
Me@42 203 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
Me@42 204
Me@42 205 void
Me@42 206 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister,
Me@42 207 VirtProcr *reqstingPr );
Me@42 208
Me@42 209 void
Me@42 210 VMS__free_request( VMSReqst *req );
Me@42 211
Me@42 212 void
Me@42 213 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
Me@42 214
Me@42 215 VMSReqst *
Me@42 216 VMS__take_top_request_from( VirtProcr *reqstingPr );
Me@42 217
Me@42 218 VMSReqst *
Me@42 219 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq );
Me@42 220
Me@42 221 inline void *
Me@42 222 VMS__take_sem_reqst_from( VMSReqst *req );
Me@42 223
Me@42 224 inline int
Me@42 225 VMS__isSemanticReqst( VMSReqst *req );
Me@42 226
Me@42 227 inline int
Me@42 228 VMS__isDissipateReqst( VMSReqst *req );
Me@42 229
Me@42 230 inline int
Me@42 231 VMS__isCreateReqst( VMSReqst *req );
Me@42 232
Me@42 233 //==========================
Me@42 234
Me@42 235 void
Me@42 236 VMS__suspend_procr( VirtProcr *callingPr );
Me@42 237
Me@42 238 void
Me@42 239 VMS__dissipate_procr( VirtProcr *prToDissipate );
Me@42 240
Me@42 241 void
Me@42 242 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
Me@42 243
Me@42 244 void
Me@42 245 VMS__cleanup_after_shutdown();
Me@42 246
Me@42 247 //============================= Statistics ==================================
Me@42 248
Me@42 249 typedef unsigned long long TSCount;
Me@42 250
Me@42 251 //Frequency of TS counts
Me@42 252 //TODO: change freq for each machine
Me@42 253 #define TSCOUNT_FREQ 3180000000
Me@42 254
Me@42 255 #define saveTimeStampCountInto(low, high) \
Me@42 256 asm volatile("RDTSC; \
Me@42 257 movl %%eax, %0; \
Me@42 258 movl %%edx, %1;" \
Me@42 259 /* outputs */ : "=m" (low), "=m" (high)\
Me@42 260 /* inputs */ : \
Me@42 261 /* clobber */ : "%eax", "%edx" \
Me@42 262 );
Me@42 263
Me@42 264 #define saveLowTimeStampCountInto(low) \
Me@42 265 asm volatile("RDTSC; \
Me@42 266 movl %%eax, %0;" \
Me@42 267 /* outputs */ : "=m" (low) \
Me@42 268 /* inputs */ : \
Me@42 269 /* clobber */ : "%eax", "%edx" \
Me@42 270 );
Me@42 271
Me@42 272 inline TSCount getTSCount();
Me@42 273
Me@42 274 //===================== Debug ==========================
Me@42 275 int numProcrsCreated;
Me@42 276
Me@42 277
Me@42 278 #endif /* _VMS_H */
Me@42 279