Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view 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 |
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 DEBUG 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 //when MEAS__TAKE_SUSP_TSC is defined, causes code to be inserted and
24 // compiled-in that saves the low part of the time stamp count just before
25 // suspending a processor and just after resuming that processor. It is
26 // saved into a field added to VirtProcr. Have to sanity-check for
27 // rollover of low portion into high portion.
28 #define MEAS__TIME_STAMP_SUSP
29 #define MEAS__TIME_MASTER
30 #define MEAS__NUM_TIMES_TO_RUN 100000
32 //This value is the number of hardware threads in the shared memory
33 // machine
34 #define NUM_CORES 4
36 // make double-num-cores scheduling slots, plus extra for master
37 //#define NUM_SCHED_SLOTS (2 * NUM_CORES + 1)
38 #define NUM_SCHED_SLOTS 3
40 #define READYTOANIMATE_RETRIES 10000
42 // stack
43 #define VIRT_PROCR_STACK_SIZE 0x10000
45 //256M of total memory for VMS__malloc
46 #define MASSIVE_MALLOC_SIZE 0x10000000
48 #define NUM_PREPEND_BYTES sizeof(FreeListElem) + sizeof(ownerElem);
50 #define SUCCESS 0
52 #define writeVMSQ writeCASQ
53 #define readVMSQ readCASQ
54 #define makeVMSQ makeCASQ
55 #define VMSQueueStruc CASQueueStruc
57 //#define thdAttrs NULL //For PThreads
59 typedef struct _SchedSlot SchedSlot;
60 typedef struct _VMSReqst VMSReqst;
61 typedef struct _VirtProcr VirtProcr;
63 typedef VirtProcr * (*SlaveScheduler) ( void *, int ); //semEnv, coreIdx
64 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
65 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
66 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
68 typedef struct
69 {
70 void *endThdPt;
71 unsigned int coreNum;
72 }
73 ThdParams;
76 struct _SchedSlot
77 {
78 int workIsDone;
79 int needsProcrAssigned;
80 VirtProcr *procrAssignedToSlot;
81 };
82 //SchedSlot
84 enum ReqstType
85 {
86 semantic = 1,
87 dissipate,
88 regCreated,
89 IO
90 };
92 struct _VMSReqst
93 {
94 // VirtProcr *virtProcrFrom;
95 enum ReqstType reqType;//used for dissipate and in future for IO requests
96 void *semReqData;
98 VMSReqst *nextReqst;
99 };
100 //VMSReqst
102 struct _VirtProcr
103 { int procrID; //for debugging -- count up each time create
104 int coreAnimatedBy;
105 void *startOfStack;
106 void *stackPtr;
107 void *framePtr;
108 void *nextInstrPt;
110 void *coreLoopStartPt; //allows proto-runtime to be linked later
111 void *coreLoopFramePtr; //restore before jmp back to core loop
112 void *coreLoopStackPtr; //restore before jmp back to core loop
114 void *initialData;
116 SchedSlot *schedSlot;
117 VMSReqst *requests;
119 void *semanticData;
121 //============================= MEASUREMENT STUFF ========================
122 #ifdef MEAS__TIME_STAMP_SUSP
123 unsigned int preSuspTSCLow;
124 unsigned int postSuspTSCLow;
125 #endif
126 #ifdef MEAS__TIME_MASTER
127 unsigned int startMasterTSCLow;
128 unsigned int endMasterTSCLow;
129 #endif
130 //========================================================================
131 };
132 //VirtProcr
136 typedef struct
137 {
138 SlaveScheduler slaveScheduler;
139 RequestHandler requestHandler;
141 SchedSlot ***allSchedSlots;
142 SRSWQueueStruc **readyToAnimateQs;
143 VirtProcr **masterVPs;
145 void *semanticEnv;
146 void *OSEventStruc; //for future, when add I/O to BLIS
148 void *coreLoopStartPt;//addr to jump to to re-enter coreLoop
149 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
151 int setupComplete;
152 int masterLock;
154 }
155 MasterEnv;
158 //==========================================================
160 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
161 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
162 void masterLoop( void *initData, VirtProcr *masterPr );
165 //===================== Global Vars ===================
168 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
169 ThdParams *coreLoopThdParams [ NUM_CORES ];
170 pthread_mutex_t suspendLock;
171 pthread_cond_t suspend_cond;
173 volatile MasterEnv *_VMSMasterEnv;
175 //==========================
176 void
177 VMS__init();
179 void
180 VMS__init_Seq();
182 void
183 VMS__start_the_work_then_wait_until_done();
185 void
186 VMS__start_the_work_then_wait_until_done_Seq();
188 VirtProcr *
189 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
191 VirtProcr *
192 VMS__create_the_shutdown_procr();
194 //==========================
195 inline void
196 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
198 void
199 VMS__send_req_to_register_new_procr( VirtProcr *newPrToRegister,
200 VirtProcr *reqstingPr );
202 void
203 VMS__free_request( VMSReqst *req );
205 void
206 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
208 VMSReqst *
209 VMS__take_top_request_from( VirtProcr *reqstingPr );
211 VMSReqst *
212 VMS__free_top_and_give_next_request_from( VirtProcr *procrWithReq );
214 inline void *
215 VMS__take_sem_reqst_from( VMSReqst *req );
217 inline int
218 VMS__isSemanticReqst( VMSReqst *req );
220 inline int
221 VMS__isDissipateReqst( VMSReqst *req );
223 inline int
224 VMS__isCreateReqst( VMSReqst *req );
226 //==========================
228 void
229 VMS__suspend_procr( VirtProcr *callingPr );
231 void
232 VMS__dissipate_procr( VirtProcr *prToDissipate );
234 void
235 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
237 void
238 VMS__cleanup_after_shutdown();
240 //============================= Statistics ==================================
242 typedef unsigned long long TSCount;
244 //Frequency of TS counts
245 //TODO: change freq for each machine
246 #define TSCOUNT_FREQ 3180000000
248 #define saveTimeStampCountInto(low, high) \
249 asm volatile("RDTSC; \
250 movl %%eax, %0; \
251 movl %%edx, %1;" \
252 /* outputs */ : "=m" (low), "=m" (high)\
253 /* inputs */ : \
254 /* clobber */ : "%eax", "%edx" \
255 );
257 #define saveLowTimeStampCountInto(low) \
258 asm volatile("RDTSC; \
259 movl %%eax, %0;" \
260 /* outputs */ : "=m" (low) \
261 /* inputs */ : \
262 /* clobber */ : "%eax", "%edx" \
263 );
265 inline TSCount getTSCount();
267 //===================== Debug ==========================
268 int numProcrsCreated;
271 #endif /* _VMS_H */
