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