annotate VMS.h @ 41:cf3e9238aeb0

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