annotate VMS.h @ 28:8b9e4c333fe6

Sequential Version -- first compile succeeded
author Me
date Mon, 26 Jul 2010 16:42:59 -0700
parents 668278fa7a63
children 0e008278fe3c
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@26 15 #include <pthread.h>
Me@0 16
Me@23 17 //This value is the number of hardware threads in the shared memory
Me@23 18 // machine
Me@23 19 #define NUM_CORES 4
Me@23 20
Me@23 21 // make double-num-cores scheduling slots, plus extra for master
Me@23 22 #define NUM_SCHED_SLOTS (2 * NUM_CORES + 1)
Me@23 23
Me@23 24 //128K stack.. compromise, want 10K virtPr
Me@26 25 #define VIRT_PROCR_STACK_SIZE 0x10000
Me@0 26
Me@0 27 #define SUCCESS 0
Me@0 28
Me@26 29 #define writeVMSQ writePThdQ
Me@26 30 #define readVMSQ readPThdQ
Me@26 31 #define makeVMSQ makePThdQ
Me@26 32 #define VMSQueueStruc PThdQueueStruc
Me@26 33
Me@13 34 //#define thdAttrs NULL //For PThreads
Me@0 35
Me@16 36 typedef struct _SchedSlot SchedSlot;
Me@26 37 typedef struct _VMSReqst VMSReqst;
Me@5 38 typedef struct _VirtProcr VirtProcr;
Me@0 39
Me@23 40 typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv
Me@23 41 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
Me@23 42 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
Me@23 43 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
Me@16 44
Me@0 45 typedef struct
Me@0 46 {
Me@7 47 void *endThdPt;
Me@7 48 unsigned int coreNum;
Me@16 49 // void *framePtr;
Me@16 50 // void *stackPtr;
Me@0 51 }
Me@0 52 ThdParams;
Me@0 53
Me@16 54
Me@5 55 struct _SchedSlot
Me@5 56 {
Me@5 57 int workIsDone;
Me@5 58 int needsProcrAssigned;
Me@5 59 VirtProcr *procrAssignedToSlot;
Me@5 60 };
Me@16 61 //SchedSlot
Me@16 62
Me@23 63 enum ReqstType
Me@23 64 {
Me@23 65 semantic = 1,
Me@23 66 dissipate,
Me@24 67 regCreated,
Me@23 68 IO
Me@23 69 };
Me@5 70
Me@24 71 struct _VMSReqst
Me@16 72 {
Me@23 73 // VirtProcr *virtProcrFrom;
Me@24 74 enum ReqstType reqType;//used for dissipate and in future for IO requests
Me@23 75 void *semReqData;
Me@16 76
Me@23 77 VMSReqst *nextReqst;
Me@16 78 };
Me@24 79 //VMSReqst
Me@5 80
Me@5 81 struct _VirtProcr
Me@13 82 { int procrID; //for debugging -- count up each time create
Me@16 83 int coreAnimatedBy;
Me@23 84 void *startOfStack;
Me@5 85 void *stackPtr;
Me@5 86 void *framePtr;
Me@5 87 void *nextInstrPt;
Me@16 88
Me@5 89 void *coreLoopStartPt; //allows proto-runtime to be linked later
Me@16 90 void *coreLoopFramePtr; //restore before jmp back to core loop
Me@16 91 void *coreLoopStackPtr; //restore before jmp back to core loop
Me@5 92
Me@5 93 void *initialData;
Me@5 94
Me@5 95 SchedSlot *schedSlot;
Me@23 96 VMSReqst *requests;
Me@5 97
Me@5 98 void *semanticData;
Me@5 99 };
Me@16 100 //VirtProcr
Me@5 101
Me@5 102
Me@16 103
Me@0 104 typedef struct
Me@0 105 {
Me@5 106 SlaveScheduler slaveScheduler;
Me@5 107 RequestHandler requestHandler;
Me@0 108
Me@5 109 SchedSlot **schedSlots;
Me@5 110 SchedSlot **filledSlots;
Me@26 111 int numToPrecede;
Me@5 112
Me@26 113 volatile int stillRunning;
Me@0 114
Me@5 115 VirtProcr *masterVirtPr;
Me@25 116
Me@0 117 void *semanticEnv;
Me@5 118 void *OSEventStruc; //for future, when add I/O to BLIS
Me@16 119
Me@16 120 void *coreLoopShutDownPt; //addr to jump to to shut down a coreLoop
Me@25 121
Me@26 122 int setupComplete;
Me@0 123 }
Me@0 124 MasterEnv;
Me@0 125
Me@0 126
Me@16 127 //==========================================================
Me@0 128
Me@25 129 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
Me@28 130 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
Me@7 131 void masterLoop( void *initData, VirtProcr *masterPr );
Me@0 132
Me@0 133
Me@0 134 //===================== Global Vars ===================
Me@0 135
Me@5 136
Me@26 137 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
Me@26 138 ThdParams *coreLoopThdParams [ NUM_CORES ];
Me@26 139 pthread_mutex_t suspendLock;
Me@26 140 pthread_cond_t suspend_cond;
Me@0 141
Me@13 142 volatile MasterEnv *_VMSMasterEnv;
Me@5 143
Me@5 144 //workQ is global, static, and volatile so that core loop has its location
Me@5 145 // hard coded, and reloads every time through the loop -- that way don't
Me@25 146 // need to save any regs used by core loop
Me@26 147 volatile VMSQueueStruc *_VMSWorkQ;
Me@0 148
Me@7 149 //==========================
Me@7 150 void
Me@7 151 VMS__init();
Me@7 152
Me@7 153 void
Me@28 154 VMS__init_Seq();
Me@28 155
Me@28 156 void
Me@24 157 VMS__start_the_work_then_wait_until_done();
Me@7 158
Me@28 159 void
Me@28 160 VMS__start_the_work_then_wait_until_done_Seq();
Me@28 161
Me@7 162 VirtProcr *
Me@7 163 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
Me@7 164
Me@23 165 VirtProcr *
Me@23 166 VMS__create_the_shutdown_procr();
Me@23 167
Me@24 168 //==========================
Me@7 169 inline void
Me@24 170 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
Me@7 171
Me@7 172 void
Me@24 173 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
Me@24 174 VirtProcr *reqstingPr );
Me@24 175
Me@24 176 void
Me@24 177 VMS__free_request( VMSReqst *req );
Me@23 178
Me@23 179 void
Me@23 180 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
Me@23 181
Me@24 182 VMSReqst *
Me@24 183 VMS__take_top_request_from( VirtProcr *reqstingPr );
Me@24 184
Me@24 185 inline void *
Me@24 186 VMS__take_sem_reqst_from( VMSReqst *req );
Me@24 187
Me@24 188 inline int
Me@24 189 VMS__isSemanticReqst( VMSReqst *req );
Me@24 190
Me@24 191 inline int
Me@24 192 VMS__isDissipateReqst( VMSReqst *req );
Me@24 193
Me@24 194 inline int
Me@24 195 VMS__isCreateReqst( VMSReqst *req );
Me@24 196
Me@24 197 //==========================
Me@24 198
Me@23 199 void
Me@23 200 VMS__suspend_procr( VirtProcr *callingPr );
Me@23 201
Me@23 202 void
Me@23 203 VMS__dissipate_procr( VirtProcr *prToDissipate );
Me@23 204
Me@23 205 void
Me@23 206 VMS__shutdown();
Me@7 207
Me@13 208 //============================= Statistics ==================================
Me@13 209
Me@13 210 typedef unsigned long long TSCount;
Me@13 211
Me@25 212 //Frequency of TS counts
Me@25 213 //TODO: change freq for each machine
Me@25 214 #define TSCOUNT_FREQ 3180000000
Me@25 215
Me@13 216 #define saveTimeStampCountInto(low, high) \
Me@13 217 asm volatile("RDTSC; \
Me@13 218 movl %%eax, %0; \
Me@13 219 movl %%edx, %1;" \
Me@13 220 /* outputs */ : "=m" (low), "=m" (high)\
Me@13 221 /* inputs */ : \
Me@13 222 /* clobber */ : "%eax", "%edx" \
Me@13 223 );
Me@13 224
Me@13 225 inline TSCount getTSCount();
Me@13 226
Me@23 227 //===================== Debug ==========================
Me@13 228 int numProcrsCreated;
Me@0 229
Me@23 230
Me@0 231 #endif /* _VMS_H */
Me@0 232