8 #define CFENCE asm volatile ("" ::: "memory");
9 /***********************************************************
11 **********************************************************/
12 #define GET_SITEID(x) ((int *)(x))
13 #define GET_NTUPLES(x) ((int *)(x + sizeof(int)))
14 #define GET_PTR_OID(x) ((unsigned int *)(x + 2*sizeof(int)))
15 #define GET_PTR_EOFF(x,n) ((short *)(x + 2*sizeof(int) + (n*sizeof(unsigned int))))
16 #define GET_PTR_ARRYFLD(x,n) ((short *)(x + 2*sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
18 #define ENDEBUG(s) { printf("Inside %s()\n", s); fflush(stdout); }
19 #define EXDEBUG(s) {printf("Outside %s()\n", s); fflush(stdout); }
20 /*****************************************
21 * Coordinator Messages
22 ***************************************/
23 #define READ_REQUEST 1
24 #define READ_MULT_REQUEST 2
25 #define MOVE_REQUEST 3
26 #define MOVE_MULT_REQUEST 4
27 #define TRANS_REQUEST 5
29 #define TRANS_COMMIT 7
30 #define TRANS_PREFETCH 8
31 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING 9
33 /*********************************
34 * Participant Messages
35 *******************************/
36 #define OBJECT_FOUND 10
37 #define OBJECT_NOT_FOUND 11
38 #define OBJECTS_FOUND 12
39 #define OBJECTS_NOT_FOUND 13
40 #define TRANS_AGREE 17
41 #define TRANS_DISAGREE 18
42 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
43 #define TRANS_SOFT_ABORT 20
44 #define TRANS_SUCESSFUL 21
45 #define TRANS_PREFETCH_RESPONSE 22
46 #define START_REMOTE_THREAD 23
47 #define THREAD_NOTIFY_REQUEST 24
48 #define THREAD_NOTIFY_RESPONSE 25
49 #define TRANS_UNSUCESSFUL 26
50 #define CLOSE_CONNECTION 27
52 //Max number of objects
53 #define MAX_OBJECTS 20
54 //Transaction id per machine
56 #define LISTEN_PORT 2156
58 //Prefetch tuning paramters
59 //#define RETRYINTERVAL 20 //N (For Em3d, SOR, Moldyn benchmarks)
60 //#define SHUTDOWNINTERVAL 3 //M
61 #define RETRYINTERVAL 1 //N (For MatrixMultiply, 2DFFT, 2DConv benchmarks)
62 #define SHUTDOWNINTERVAL 75 //M
63 #define NUM_TRY_TO_COMMIT 2
64 #define MEM_ALLOC_THRESHOLD 20485760 //20MB
73 #include "threadnotify.h"
74 #include <arpa/inet.h>
75 #include <sys/types.h>
76 #include <sys/socket.h>
77 #include <sys/ioctl.h>
80 #include <netinet/in.h>
81 #include <sys/types.h>
89 #include "readstruct.h"
94 //bit designations for status field of objheader
100 /*******Global statistics *********/
101 extern int numprefetchsites;
103 /***********************************
104 * Global Variables for statistics
105 **********************************/
107 extern int numTransCommit;
108 extern int numTransAbort;
109 extern int nSoftAbort;
110 extern int nSoftAbortAbort;
111 extern int nSoftAbortCommit;
114 double idForTimeDelay; /* TODO Remove, necessary to get time delay for starting transRequest for this id */
115 int transCount; /* TODO Remove, necessary to the transaction id */
119 #include "structdefs.h"
121 typedef struct objheader {
122 threadlist_t *notifylist;
123 unsigned short version;
124 unsigned short rcount;
128 (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___))
131 ((void*)((((void *) x )!=NULL) ? (*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___)) : 0))
134 *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
136 #define STATUSPTR(x) \
137 ((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
140 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
142 #define GETSIZE(size, x) { \
144 if (type<NUMCLASSES) { \
145 size=classsize[type]; \
147 size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject); \
153 typedef struct objheader {
154 threadlist_t *notifylist;
157 unsigned short version;
158 unsigned short rcount;
162 #define OID(x) x->oid
163 #define TYPE(x) x->type
164 #define STATUS(x) x->status
165 #define STATUSPTR(x) &x->status
166 #define GETSIZE(size, x) size=classsize[TYPE(x)]
169 typedef struct objstr {
170 unsigned int size; //this many bytes are allocated after this header
176 typedef struct oidmidpair {
181 // Structure is a shared structure that keeps track of responses from the participants
182 typedef struct thread_response {
186 // Structure that holds fixed data to be sent along with TRANS_REQUEST
187 typedef struct fixed_data {
188 char control; /* control message */
189 char trans_id[TID_LEN]; /* transaction id */
190 int mcount; /* participant count */
191 unsigned int numread; /* no of objects read */
192 unsigned int nummod; /* no of objects modified */
193 unsigned int numcreated; /* no of objects created */
194 int sum_bytes; /* total bytes of modified objects in a transaction */
197 /* Structure that holds trans request information for each participant */
198 typedef struct trans_req_data {
199 fixed_data_t f; /* Holds first few fixed bytes of data sent during TRANS_REQUEST protcol*/
200 unsigned int *listmid; /* Pointer to array holding list of participants */
201 char *objread; /* Pointer to array holding oid and version number of objects that are only read */
202 unsigned int *oidmod; /* Pointer to array holding oids of objects that are modified */
203 unsigned int *oidcreated; /* Pointer to array holding oids of objects that are newly created */
206 /* Structure that holds information of objects that are not found in the participant
207 * and objs locked within a transaction during commit process */
208 typedef struct trans_commit_data {
209 unsigned int *objlocked; /* Pointer to array holding oids of objects locked inside a transaction */
210 unsigned int *objnotfound; /* Pointer to array holding oids of objects not found on the participant machine */
211 unsigned int *objvernotmatch; /* Pointer to array holding oids whose version doesn't match on the participant machine */
212 void *modptr; /* Pointer to the address in the mainobject store of the participant that holds all modified objects */
213 int numlocked; /* no of objects locked */
214 int numnotfound; /* no of objects not found */
215 int numvernotmatch; /* no of objects whose version doesn't match */
216 } trans_commit_data_t;
219 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
221 /* Initialize main object store and lookup tables, start server thread. */
223 void send_data(int fd, void *buf, int buflen);
224 void recv_data(int fd, void *buf, int buflen);
225 int recv_data_errorcode(int fd, void *buf, int buflen);
226 void recv_data_buf(int fd, struct readstruct *, void *, int);
228 /* Prototypes for object header */
229 unsigned int getNewOID(void);
230 /* end object header */
232 /* Prototypes for object store */
233 objstr_t *objstrCreate(unsigned int size); //size in bytes
234 void objstrDelete(objstr_t *store); //traverse and free entire list
235 void *objstrAlloc(objstr_t **store, unsigned int size); //size in bytes
236 void clearObjStore(); // TODO:currently only clears the prefetch cache object store
237 /* end object store */
239 /* Prototypes for server portion */
240 void *dstmListen(void *);
241 int startlistening();
242 void *dstmAccept(void *);
243 int readClientReq(trans_commit_data_t *, int, struct readstruct * readbuffer);
244 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int, struct readstruct *);
245 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
246 char decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
247 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
248 void processReqNotify(unsigned int numoid, unsigned int *oid, unsigned short *version, unsigned int mid, unsigned int threadid);
249 char getCommitCountForObjMod(unsigned int *, unsigned int *, unsigned int *, int *,
250 int *, int *, int *, int *, int *, int *, char *, unsigned int, unsigned short);
251 char getCommitCountForObjRead(unsigned int *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *,
252 int *, int *, char *, unsigned int, unsigned short);
254 void procRestObjs(char *, char *, int, int, int, unsigned int *, unsigned int *, int *, int *, int *, int *);
255 void processVerNoMatch(unsigned int *, unsigned int *, int *, int *, int *, int *, unsigned int, unsigned short);
257 /* end server portion */
259 /* Prototypes for transactions */
260 /* Function called at beginning. Passes in the first parameter. */
261 /* Returns 1 if this thread should run the main process */
263 int dstmStartup(const char *);
265 int processConfigFile();
266 void addHost(unsigned int);
267 void mapObjMethod(unsigned short);
271 //#define TRANSREAD(x,y,z) /* Use "z" which is program point at which TRANSREAD is generated, use this as transRead2(inputvalue,z) */
272 #define TRANSREAD(x,y) { \
273 unsigned int inputvalue; \
274 if ((inputvalue=(unsigned int)y)==0) x=NULL; \
276 chashlistnode_t * cnodetmp=&c_table[(inputvalue&c_mask)>>1]; \
278 if (cnodetmp->key==inputvalue) {x=(void *)& ((objheader_t*)cnodetmp->val)[1]; break; } \
279 cnodetmp=cnodetmp->next; \
280 if (cnodetmp==NULL) {x=(void *)transRead2(inputvalue); asm volatile ("" : "=m" (c_table),"=m" (c_mask)); break; } \
284 __attribute__((pure)) objheader_t *transRead(unsigned int);
285 __attribute__((pure)) objheader_t *transRead2(unsigned int);
286 //__attribute__((pure)) objheader_t *transRead2(unsigned int, char ptr[]);
287 objheader_t *transCreateObj(unsigned int); //returns oid header
288 int transCommit(); //return 0 if successful
289 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
290 char decideResponse(char *, char *, int); // Coordinator decides what response to send to the participant
291 void *getRemoteObj(unsigned int, unsigned int); // returns object header from main object store after object is copied into it from remote machine
292 void handleLocalReq(trans_req_data_t *, trans_commit_data_t *, char *);
293 int transComProcess(trans_req_data_t *, trans_commit_data_t *);
294 void doLocalProcess(char, trans_req_data_t *tdata, trans_commit_data_t *);
295 int transAbortProcess(trans_commit_data_t *);
297 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size);
298 void prefetch(int, int, unsigned int *, unsigned short *, short*);
299 void *transPrefetch(void *);
300 void *mcqProcess(void *);
301 prefetchpile_t *foundLocal(char *, int, int); // returns node with prefetch elements(oids, offsets, siteid)
302 int lookupObject(unsigned int * oid, short offset, int *);
303 int checkoid(unsigned int oid, int isLastOffset);
304 int transPrefetchProcess(int **, short);
305 void sendPrefetchReq(prefetchpile_t*, int, int);
306 void sendPrefetchReqnew(prefetchpile_t*, int);
307 int getPrefetchResponse(int, struct readstruct *);
308 unsigned short getObjType(unsigned int oid);
309 int startRemoteThread(unsigned int oid, unsigned int mid);
310 plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mid, int num_objs);
311 void commitCountForObjRead(char *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *, unsigned int, unsigned short);
312 void commitCountForObjMod(char *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *, unsigned int, unsigned short);
314 long long myrdtsc(void);
315 /* Sends notification request for thread join, if sucessful returns 0 else returns -1 */
316 int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int numoid);
317 void threadNotify(unsigned int oid, unsigned short version, unsigned int tid);
318 int notifyAll(threadlist_t **head, unsigned int oid, unsigned int version);
320 /* Internal functions from signal.c */
322 double getMax(double *array, int size);
323 double getMin(double *array, int size);
324 double getfast(int siteid, int threadid);
325 double getslowest(int siteid, int threadid);
326 double getavg(int siteid, int threadid);
327 double getavgperthd(int siteid, int threadid);
328 double avgfast(int siteid, int threadid);
329 double avgslow(int siteid, int threadid);
331 void swap(double *e1, double *e2);
332 double avgofthreads(int siteid, int threadid);
334 /* end transactions */