view VMS.h @ 46:41fdebd737bf

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