Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
view 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 |
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)
23 #define NUM_SCHED_SLOTS 3
25 //128K stack.. compromise, want 10K virtPr
26 #define VIRT_PROCR_STACK_SIZE 0x10000
28 #define SUCCESS 0
30 #define writeVMSQ writePThdQ
31 #define readVMSQ readPThdQ
32 #define makeVMSQ makePThdQ
33 #define VMSQueueStruc PThdQueueStruc
35 //#define thdAttrs NULL //For PThreads
37 typedef struct _SchedSlot SchedSlot;
38 typedef struct _VMSReqst VMSReqst;
39 typedef struct _VirtProcr VirtProcr;
41 typedef VirtProcr * (*SlaveScheduler) ( void * ); //semEnv
42 typedef void (*RequestHandler) ( VirtProcr *, void * ); //prWReqst, semEnv
43 typedef void (*VirtProcrFnPtr) ( void *, VirtProcr * ); //initData, animPr
44 typedef void VirtProcrFn ( void *, VirtProcr * ); //initData, animPr
46 typedef struct
47 {
48 void *endThdPt;
49 unsigned int coreNum;
50 // void *framePtr;
51 // void *stackPtr;
52 }
53 ThdParams;
56 struct _SchedSlot
57 {
58 int workIsDone;
59 int needsProcrAssigned;
60 VirtProcr *procrAssignedToSlot;
61 };
62 //SchedSlot
64 enum ReqstType
65 {
66 semantic = 1,
67 dissipate,
68 regCreated,
69 IO
70 };
72 struct _VMSReqst
73 {
74 // VirtProcr *virtProcrFrom;
75 enum ReqstType reqType;//used for dissipate and in future for IO requests
76 void *semReqData;
78 VMSReqst *nextReqst;
79 };
80 //VMSReqst
82 struct _VirtProcr
83 { int procrID; //for debugging -- count up each time create
84 int coreAnimatedBy;
85 void *startOfStack;
86 void *stackPtr;
87 void *framePtr;
88 void *nextInstrPt;
90 void *coreLoopStartPt; //allows proto-runtime to be linked later
91 void *coreLoopFramePtr; //restore before jmp back to core loop
92 void *coreLoopStackPtr; //restore before jmp back to core loop
94 void *initialData;
96 SchedSlot *schedSlot;
97 VMSReqst *requests;
99 void *semanticData;
100 };
101 //VirtProcr
105 typedef struct
106 {
107 SlaveScheduler slaveScheduler;
108 RequestHandler requestHandler;
110 SchedSlot **schedSlots;
111 SchedSlot **filledSlots;
112 int numToPrecede;
114 volatile int stillRunning;
116 VirtProcr *masterVirtPr;
118 void *semanticEnv;
119 void *OSEventStruc; //for future, when add I/O to BLIS
121 void *coreLoopEndPt; //addr to jump to to shut down a coreLoop
123 int setupComplete;
124 }
125 MasterEnv;
128 //==========================================================
130 void * coreLoop( void *paramsIn ); //standard PThreads fn prototype
131 void * coreLoop_Seq( void *paramsIn ); //standard PThreads fn prototype
132 void masterLoop( void *initData, VirtProcr *masterPr );
135 //===================== Global Vars ===================
138 pthread_t coreLoopThdHandles[ NUM_CORES ]; //pthread's virt-procr state
139 ThdParams *coreLoopThdParams [ NUM_CORES ];
140 pthread_mutex_t suspendLock;
141 pthread_cond_t suspend_cond;
143 volatile MasterEnv *_VMSMasterEnv;
145 //workQ is global, static, and volatile so that core loop has its location
146 // hard coded, and reloads every time through the loop -- that way don't
147 // need to save any regs used by core loop
148 volatile VMSQueueStruc *_VMSWorkQ;
150 //==========================
151 void
152 VMS__init();
154 void
155 VMS__init_Seq();
157 void
158 VMS__start_the_work_then_wait_until_done();
160 void
161 VMS__start_the_work_then_wait_until_done_Seq();
163 VirtProcr *
164 VMS__create_procr( VirtProcrFnPtr fnPtr, void *initialData );
166 VirtProcr *
167 VMS__create_the_shutdown_procr();
169 //==========================
170 inline void
171 VMS__add_sem_request( void *semReqData, VirtProcr *callingPr );
173 void
174 VMS__send_register_new_procr_request( VirtProcr *newPrToRegister,
175 VirtProcr *reqstingPr );
177 void
178 VMS__free_request( VMSReqst *req );
180 void
181 VMS__remove_and_free_top_request( VirtProcr *reqstingPr );
183 VMSReqst *
184 VMS__take_top_request_from( VirtProcr *reqstingPr );
186 inline void *
187 VMS__take_sem_reqst_from( VMSReqst *req );
189 inline int
190 VMS__isSemanticReqst( VMSReqst *req );
192 inline int
193 VMS__isDissipateReqst( VMSReqst *req );
195 inline int
196 VMS__isCreateReqst( VMSReqst *req );
198 //==========================
200 void
201 VMS__suspend_procr( VirtProcr *callingPr );
203 void
204 VMS__dissipate_procr( VirtProcr *prToDissipate );
206 void
207 VMS__handle_dissipate_reqst( VirtProcr *procrToDissipate );
209 void
210 VMS__cleanup_after_shutdown();
212 //============================= Statistics ==================================
214 typedef unsigned long long TSCount;
216 //Frequency of TS counts
217 //TODO: change freq for each machine
218 #define TSCOUNT_FREQ 3180000000
220 #define saveTimeStampCountInto(low, high) \
221 asm volatile("RDTSC; \
222 movl %%eax, %0; \
223 movl %%edx, %1;" \
224 /* outputs */ : "=m" (low), "=m" (high)\
225 /* inputs */ : \
226 /* clobber */ : "%eax", "%edx" \
227 );
229 inline TSCount getTSCount();
231 //===================== Debug ==========================
232 int numProcrsCreated;
235 #endif /* _VMS_H */
