annotate 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
rev   line source
Me@0 1 /*
Me@0 2 * Copyright 2009 OpenSourceStewardshipFoundation.org
Me@0 3 * Licensed under GNU General Public License version 2
Me@0 4 *
Me@0 5 * Author: seanhalle@yahoo.com
Me@0 6 *
Me@0 7 */
Me@0 8
Me@0 9 #ifndef _VPThread_H
Me@0 10 #define _VPThread_H
Me@0 11
Me@0 12 #include "VMS/VMS.h"
Me@0 13 #include "VMS/Queue_impl/PrivateQueue.h"
Me@0 14 #include "VMS/DynArray/DynArray.h"
Me@0 15
Me@0 16
SeanHalle@1 17 /*This header defines everything specific to the VPThread semantic plug-in
SeanHalle@1 18 */
SeanHalle@1 19
SeanHalle@1 20
Me@0 21 //===========================================================================
Me@0 22 #define INIT_NUM_MUTEX 10000
Me@0 23 #define INIT_NUM_COND 10000
SeanHalle@1 24
SeanHalle@1 25 #define NUM_STRUCS_IN_SEM_ENV 1000
Me@0 26 //===========================================================================
Me@0 27
SeanHalle@1 28 //===========================================================================
SeanHalle@1 29 typedef struct _VPThreadSemReq VPThdSemReq;
SeanHalle@1 30 typedef void (*PtrToAtomicFn ) ( void * ); //executed atomically in master
SeanHalle@1 31 //===========================================================================
Me@0 32
Me@0 33
Me@3 34 /*WARNING: assembly hard-codes position of endInstrAddr as first field
Me@3 35 */
Me@3 36 typedef struct
Me@3 37 {
Me@3 38 void *endInstrAddr;
Me@3 39 int32 hasBeenStarted;
Me@3 40 int32 hasFinished;
Me@3 41 PrivQueueStruc *waitQ;
Me@3 42 }
Me@3 43 VPThdSingleton;
Me@3 44
Me@0 45 /*Semantic layer-specific data sent inside a request from lib called in app
Me@0 46 * to request handler called in MasterLoop
Me@0 47 */
Me@0 48 enum VPThreadReqType
Me@0 49 {
Me@0 50 make_mutex = 1,
Me@0 51 mutex_lock,
Me@0 52 mutex_unlock,
Me@0 53 make_cond,
Me@0 54 cond_wait,
Me@0 55 cond_signal,
SeanHalle@1 56 make_procr,
SeanHalle@1 57 malloc_req,
SeanHalle@1 58 free_req,
Me@3 59 singleton_fn_start,
Me@3 60 singleton_fn_end,
Me@3 61 singleton_data_start,
Me@3 62 singleton_data_end,
SeanHalle@1 63 atomic,
SeanHalle@1 64 trans_start,
SeanHalle@1 65 trans_end
Me@0 66 };
Me@0 67
Me@0 68 struct _VPThreadSemReq
Me@0 69 { enum VPThreadReqType reqType;
Me@0 70 VirtProcr *requestingPr;
Me@0 71 int32 mutexIdx;
Me@0 72 int32 condIdx;
SeanHalle@1 73
Me@0 74 void *initData;
Me@0 75 VirtProcrFnPtr fnPtr;
SeanHalle@1 76 int32 coreToScheduleOnto;
SeanHalle@1 77
msach@6 78 size_t sizeToMalloc;
SeanHalle@1 79 void *ptrToFree;
SeanHalle@1 80
SeanHalle@1 81 int32 singletonID;
Me@3 82 VPThdSingleton **singletonPtrAddr;
SeanHalle@1 83
SeanHalle@1 84 PtrToAtomicFn fnToExecInMaster;
SeanHalle@1 85 void *dataForFn;
SeanHalle@1 86
SeanHalle@1 87 int32 transID;
Me@0 88 }
Me@0 89 /* VPThreadSemReq */;
Me@0 90
SeanHalle@1 91
SeanHalle@1 92 typedef struct
SeanHalle@1 93 {
SeanHalle@1 94 VirtProcr *VPCurrentlyExecuting;
SeanHalle@1 95 PrivQueueStruc *waitingVPQ;
SeanHalle@1 96 }
SeanHalle@1 97 VPThdTrans;
SeanHalle@1 98
Me@0 99
Me@0 100 typedef struct
Me@0 101 {
Me@0 102 int32 mutexIdx;
Me@0 103 VirtProcr *holderOfLock;
Me@0 104 PrivQueueStruc *waitingQueue;
Me@0 105 }
SeanHalle@1 106 VPThdMutex;
Me@0 107
Me@0 108
Me@0 109 typedef struct
Me@0 110 {
Me@0 111 int32 condIdx;
Me@0 112 PrivQueueStruc *waitingQueue;
SeanHalle@1 113 VPThdMutex *partnerMutex;
Me@0 114 }
SeanHalle@1 115 VPThdCond;
SeanHalle@1 116
SeanHalle@1 117 typedef struct _TransListElem TransListElem;
SeanHalle@1 118 struct _TransListElem
SeanHalle@1 119 {
SeanHalle@1 120 int32 transID;
SeanHalle@1 121 TransListElem *nextTrans;
SeanHalle@1 122 };
SeanHalle@1 123 //TransListElem
SeanHalle@1 124
SeanHalle@1 125 typedef struct
SeanHalle@1 126 {
SeanHalle@1 127 int32 highestTransEntered;
SeanHalle@1 128 TransListElem *lastTransEntered;
SeanHalle@1 129 }
SeanHalle@1 130 VPThdSemData;
Me@0 131
Me@0 132
Me@2 133 typedef struct
Me@2 134 {
Me@2 135 //Standard stuff will be in most every semantic env
Me@2 136 PrivQueueStruc **readyVPQs;
Me@2 137 int32 numVirtPr;
Me@2 138 int32 nextCoreToGetNewPr;
Me@2 139 int32 primitiveStartTime;
msach@25 140 char padding[CACHELINE_SIZE];
Me@2 141
Me@2 142 //Specific to this semantic layer
Me@2 143 VPThdMutex **mutexDynArray;
Me@2 144 PrivDynArrayInfo *mutexDynArrayInfo;
Me@2 145
Me@2 146 VPThdCond **condDynArray;
Me@2 147 PrivDynArrayInfo *condDynArrayInfo;
Me@2 148
Me@2 149 void *applicationGlobals;
Me@2 150
Me@2 151 //fix limit on num with dynArray
Me@3 152 VPThdSingleton fnSingletons[NUM_STRUCS_IN_SEM_ENV];
Me@2 153
Me@2 154 VPThdTrans transactionStrucs[NUM_STRUCS_IN_SEM_ENV];
Me@2 155 }
Me@2 156 VPThdSemEnv;
Me@2 157
Me@2 158
Me@0 159 //===========================================================================
Me@0 160
SeanHalle@1 161 inline void
Me@0 162 VPThread__create_seed_procr_and_do_work( VirtProcrFnPtr fn, void *initData );
Me@0 163
Me@0 164 //=======================
Me@0 165
Me@0 166 inline VirtProcr *
Me@0 167 VPThread__create_thread( VirtProcrFnPtr fnPtr, void *initData,
Me@0 168 VirtProcr *creatingPr );
Me@0 169
msach@17 170 inline void
SeanHalle@1 171 VPThread__create_thread_with_affinity( VirtProcrFnPtr fnPtr, void *initData,
SeanHalle@1 172 VirtProcr *creatingPr, int32 coreToScheduleOnto );
SeanHalle@1 173
SeanHalle@1 174 inline void
Me@0 175 VPThread__dissipate_thread( VirtProcr *procrToDissipate );
Me@0 176
Me@0 177 //=======================
SeanHalle@1 178 inline void
Me@0 179 VPThread__set_globals_to( void *globals );
Me@0 180
SeanHalle@1 181 inline void *
Me@0 182 VPThread__give_globals();
Me@0 183
Me@0 184 //=======================
SeanHalle@1 185 inline int32
Me@0 186 VPThread__make_mutex( VirtProcr *animPr );
Me@0 187
SeanHalle@1 188 inline void
Me@0 189 VPThread__mutex_lock( int32 mutexIdx, VirtProcr *acquiringPr );
Me@0 190
SeanHalle@1 191 inline void
Me@0 192 VPThread__mutex_unlock( int32 mutexIdx, VirtProcr *releasingPr );
Me@0 193
Me@0 194
Me@0 195 //=======================
SeanHalle@1 196 inline int32
Me@0 197 VPThread__make_cond( int32 ownedMutexIdx, VirtProcr *animPr);
Me@0 198
SeanHalle@1 199 inline void
Me@0 200 VPThread__cond_wait( int32 condIdx, VirtProcr *waitingPr);
Me@0 201
msach@17 202 inline void
Me@0 203 VPThread__cond_signal( int32 condIdx, VirtProcr *signallingPr );
Me@0 204
Me@0 205
Me@2 206 //=======================
Me@3 207 void
Me@3 208 VPThread__start_fn_singleton( int32 singletonID, VirtProcr *animPr );
Me@2 209
Me@2 210 void
Me@3 211 VPThread__end_fn_singleton( int32 singletonID, VirtProcr *animPr );
Me@2 212
Me@3 213 void
Me@3 214 VPThread__start_data_singleton( VPThdSingleton **singeltonAddr, VirtProcr *animPr );
Me@3 215
Me@3 216 void
Me@3 217 VPThread__end_data_singleton( VPThdSingleton **singletonAddr, VirtProcr *animPr );
Me@2 218
Me@2 219 void
Me@2 220 VPThread__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
Me@2 221 void *data, VirtProcr *animPr );
Me@2 222
Me@2 223 void
Me@2 224 VPThread__start_transaction( int32 transactionID, VirtProcr *animPr );
Me@2 225
Me@2 226 void
Me@2 227 VPThread__end_transaction( int32 transactionID, VirtProcr *animPr );
Me@2 228
Me@0 229
Me@0 230
Me@0 231 //========================= Internal use only =============================
SeanHalle@1 232 inline void
Me@0 233 VPThread__Request_Handler( VirtProcr *requestingPr, void *_semEnv );
Me@0 234
SeanHalle@1 235 inline VirtProcr *
Me@0 236 VPThread__schedule_virt_procr( void *_semEnv, int coreNum );
Me@0 237
Me@0 238 //=======================
SeanHalle@1 239 inline void
SeanHalle@1 240 VPThread__free_semantic_request( VPThdSemReq *semReq );
Me@0 241
Me@0 242 //=======================
Me@0 243
msach@6 244 void *
msach@6 245 VPThread__malloc( size_t sizeToMalloc, VirtProcr *animPr );
msach@6 246
Me@0 247 void
msach@17 248 VPThread__free( void *ptrToFree, VirtProcr *animPr );
msach@17 249
msach@17 250 void
Me@0 251 VPThread__init();
Me@0 252
Me@0 253 void
Me@0 254 VPThread__cleanup_after_shutdown();
Me@0 255
Me@3 256 void inline
Me@3 257 resume_procr( VirtProcr *procr, VPThdSemEnv *semEnv );
Me@3 258
msach@17 259 //=======================
msach@17 260
msach@17 261 inline int32
msach@17 262 VPThread__giveMinWorkUnitCycles( float32 percentOverhead );
msach@17 263
msach@17 264 inline int32
msach@17 265 VPThread__giveIdealNumWorkUnits();
msach@17 266
msach@17 267 inline int32
msach@17 268 VPThread__give_number_of_cores_to_schedule_onto();
msach@17 269
msach@17 270 inline void
msach@17 271 VPThread__start_primitive();
msach@17 272
msach@17 273 inline int32
msach@17 274 VPThread__end_primitive_and_give_cycles();
msach@17 275
Me@0 276 #endif /* _VPThread_H */
Me@0 277