annotate VMS.h @ 29:0e008278fe3c

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