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