Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > Vthread_impls > Vthread_MC_shared_impl
view VPThread.h @ 25:64a2c6ae21db
padding before mutexes in semantic environment
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 20 Dec 2011 16:48:20 +0100 |
| parents | bb2500771be8 |
| children |
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 _VPThread_H
10 #define _VPThread_H
12 #include "VMS/VMS.h"
13 #include "VMS/Queue_impl/PrivateQueue.h"
14 #include "VMS/DynArray/DynArray.h"
17 /*This header defines everything specific to the VPThread semantic plug-in
18 */
21 //===========================================================================
22 #define INIT_NUM_MUTEX 10000
23 #define INIT_NUM_COND 10000
25 #define NUM_STRUCS_IN_SEM_ENV 1000
26 //===========================================================================
28 //===========================================================================
29 typedef struct _VPThreadSemReq VPThdSemReq;
30 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
31 //===========================================================================
34 /*WARNING: assembly hard-codes position of endInstrAddr as first field
35 */
36 typedef struct
37 {
38 void *endInstrAddr;
39 int32 hasBeenStarted;
40 int32 hasFinished;
41 PrivQueueStruc *waitQ;
42 }
43 VPThdSingleton;
45 /*Semantic layer-specific data sent inside a request from lib called in app
46 * to request handler called in MasterLoop
47 */
48 enum VPThreadReqType
49 {
50 make_mutex = 1,
51 mutex_lock,
52 mutex_unlock,
53 make_cond,
54 cond_wait,
55 cond_signal,
56 make_procr,
57 malloc_req,
58 free_req,
59 singleton_fn_start,
60 singleton_fn_end,
61 singleton_data_start,
62 singleton_data_end,
63 atomic,
64 trans_start,
65 trans_end
66 };
68 struct _VPThreadSemReq
69 { enum VPThreadReqType reqType;
70 VirtProcr *requestingPr;
71 int32 mutexIdx;
72 int32 condIdx;
74 void *initData;
75 VirtProcrFnPtr fnPtr;
76 int32 coreToScheduleOnto;
78 size_t sizeToMalloc;
79 void *ptrToFree;
81 int32 singletonID;
82 VPThdSingleton **singletonPtrAddr;
84 PtrToAtomicFn fnToExecInMaster;
85 void *dataForFn;
87 int32 transID;
88 }
89 /* VPThreadSemReq */;
92 typedef struct
93 {
94 VirtProcr *VPCurrentlyExecuting;
95 PrivQueueStruc *waitingVPQ;
96 }
97 VPThdTrans;
100 typedef struct
101 {
102 int32 mutexIdx;
103 VirtProcr *holderOfLock;
104 PrivQueueStruc *waitingQueue;
105 }
106 VPThdMutex;
109 typedef struct
110 {
111 int32 condIdx;
112 PrivQueueStruc *waitingQueue;
113 VPThdMutex *partnerMutex;
114 }
115 VPThdCond;
117 typedef struct _TransListElem TransListElem;
118 struct _TransListElem
119 {
120 int32 transID;
121 TransListElem *nextTrans;
122 };
123 //TransListElem
125 typedef struct
126 {
127 int32 highestTransEntered;
128 TransListElem *lastTransEntered;
129 }
130 VPThdSemData;
133 typedef struct
134 {
135 //Standard stuff will be in most every semantic env
136 PrivQueueStruc **readyVPQs;
137 int32 numVirtPr;
138 int32 nextCoreToGetNewPr;
139 int32 primitiveStartTime;
140 char padding[CACHELINE_SIZE];
142 //Specific to this semantic layer
143 VPThdMutex **mutexDynArray;
144 PrivDynArrayInfo *mutexDynArrayInfo;
146 VPThdCond **condDynArray;
147 PrivDynArrayInfo *condDynArrayInfo;
149 void *applicationGlobals;
151 //fix limit on num with dynArray
152 VPThdSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
154 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
155 }
156 VPThdSemEnv;
159 //===========================================================================
161 inline void
162 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
164 //=======================
166 inline VirtProcr *
167 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
168 VirtProcr *creatingPr );
170 inline void
171 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
172 VirtProcr *creatingPr, int32 coreToScheduleOnto );
174 inline void
175 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
177 //=======================
178 inline void
179 VPThread__set_globals_to( void *globals );
181 inline void *
182 VPThread__give_globals();
184 //=======================
185 inline int32
186 VPThread__make_mutex( VirtProcr *animPr );
188 inline void
189 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
191 inline void
192 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
195 //=======================
196 inline int32
197 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
199 inline void
200 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
202 inline void
203 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
206 //=======================
207 void
208 VPThread__start_fn_singleton( int32 singletonID, VirtProcr *animPr );
210 void
211 VPThread__end_fn_singleton( int32 singletonID, VirtProcr *animPr );
213 void
214 VPThread__start_data_singleton( VPThdSingleton **singeltonAddr, VirtProcr *animPr );
216 void
217 VPThread__end_data_singleton( VPThdSingleton **singletonAddr, VirtProcr *animPr );
219 void
220 VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
221 void *data, VirtProcr *animPr );
223 void
224 VPThread__start_transaction( int32 transactionID, VirtProcr *animPr );
226 void
227 VPThread__end_transaction( int32 transactionID, VirtProcr *animPr );
231 //========================= Internal use only =============================
232 inline void
233 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
235 inline VirtProcr *
236 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
238 //=======================
239 inline void
240 VPThread__free_semantic_request( VPThdSemReq *semReq );
242 //=======================
244 void *
245 VPThread__malloc( size_t sizeToMalloc, VirtProcr *animPr );
247 void
248 VPThread__free( void *ptrToFree, VirtProcr *animPr );
250 void
251 VPThread__init();
253 void
254 VPThread__cleanup_after_shutdown();
256 void inline
257 resume_procr( VirtProcr *procr, VPThdSemEnv *semEnv );
259 //=======================
261 inline int32
262 VPThread__giveMinWorkUnitCycles( float32 percentOverhead );
264 inline int32
265 VPThread__giveIdealNumWorkUnits();
267 inline int32
268 VPThread__give_number_of_cores_to_schedule_onto();
270 inline void
271 VPThread__start_primitive();
273 inline int32
274 VPThread__end_primitive_and_give_cycles();
276 #endif /* _VPThread_H */
