annotate VMS.h @ 31:e69579a0e797

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