8 /***********************************************************
10 **********************************************************/
11 #define GET_SITEID(x) ((int *)(x))
12 #define GET_NTUPLES(x) ((int *)(x + sizeof(int)))
13 #define GET_PTR_OID(x) ((unsigned int *)(x + 2*sizeof(int)))
14 #define GET_PTR_EOFF(x,n) ((short *)(x + 2*sizeof(int) + (n*sizeof(unsigned int))))
15 #define GET_PTR_ARRYFLD(x,n) ((short *)(x + 2*sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
17 #define ENDEBUG(s) { printf("Inside %s()\n", s); fflush(stdout);}
18 #define EXDEBUG(s) {printf("Outside %s()\n", s); fflush(stdout);}
19 /*****************************************
20 * Coordinator Messages
21 ***************************************/
22 #define READ_REQUEST 1
23 #define READ_MULT_REQUEST 2
24 #define MOVE_REQUEST 3
25 #define MOVE_MULT_REQUEST 4
26 #define TRANS_REQUEST 5
28 #define TRANS_COMMIT 7
29 #define TRANS_PREFETCH 8
30 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING 9
32 /*********************************
33 * Participant Messages
34 *******************************/
35 #define OBJECT_FOUND 10
36 #define OBJECT_NOT_FOUND 11
37 #define OBJECTS_FOUND 12
38 #define OBJECTS_NOT_FOUND 13
39 #define TRANS_AGREE 17
40 #define TRANS_DISAGREE 18
41 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
42 #define TRANS_SOFT_ABORT 20
43 #define TRANS_SUCESSFUL 21
44 #define TRANS_PREFETCH_RESPONSE 22
45 #define START_REMOTE_THREAD 23
46 #define THREAD_NOTIFY_REQUEST 24
47 #define THREAD_NOTIFY_RESPONSE 25
48 #define TRANS_UNSUCESSFUL 26
49 #define CLOSE_CONNECTION 27
51 //Max number of objects
52 #define MAX_OBJECTS 20
53 //Transaction id per machine
55 #define LISTEN_PORT 2156
57 //Prefetch tuning paramters
58 //#define RETRYINTERVAL 20 //N (For Em3d, SOR, Moldyn benchmarks)
59 //#define SHUTDOWNINTERVAL 3 //M
60 #define RETRYINTERVAL 20 //N (For MatrixMultiply, 2DFFT benchmarks)
61 #define SHUTDOWNINTERVAL 1 //M
70 #include "threadnotify.h"
71 #include <arpa/inet.h>
72 #include <sys/types.h>
73 #include <sys/socket.h>
74 #include <sys/ioctl.h>
77 #include <netinet/in.h>
78 #include <sys/types.h>
86 #include "readstruct.h"
91 //bit designations for status field of objheader
97 /*******Global statistics *********/
98 extern int numprefetchsites;
100 /***********************************
101 * Global Variables for statistics
102 **********************************/
104 extern int numTransCommit;
105 extern int numTransAbort;
106 extern int nSoftAbort;
107 extern int nSoftAbortAbort;
108 extern int nSoftAbortCommit;
111 double idForTimeDelay; /* TODO Remove, necessary to get time delay for starting transRequest for this id */
112 int transCount; /* TODO Remove, necessary to the transaction id */
116 #include "structdefs.h"
118 typedef struct objheader {
119 threadlist_t *notifylist;
120 unsigned short version;
121 unsigned short rcount;
125 (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___))
128 ((void*)((((void *) x )!=NULL) ? (*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___)) : 0))
131 *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
133 #define STATUSPTR(x) \
134 ((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
137 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
139 #define GETSIZE(size, x) { \
141 if (type<NUMCLASSES) { \
142 size=classsize[type]; \
144 size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject); \
150 typedef struct objheader {
151 threadlist_t *notifylist;
154 unsigned short version;
155 unsigned short rcount;
159 #define OID(x) x->oid
160 #define TYPE(x) x->type
161 #define STATUS(x) x->status
162 #define STATUSPTR(x) &x->status
163 #define GETSIZE(size, x) size=classsize[TYPE(x)]
166 typedef struct objstr {
167 unsigned int size; //this many bytes are allocated after this header
173 typedef struct oidmidpair {
178 // Structure is a shared structure that keeps track of responses from the participants
179 typedef struct thread_response {
183 // Structure that holds fixed data to be sent along with TRANS_REQUEST
184 typedef struct fixed_data {
185 char control; /* control message */
186 char trans_id[TID_LEN]; /* transaction id */
187 int mcount; /* participant count */
188 unsigned int numread; /* no of objects read */
189 unsigned int nummod; /* no of objects modified */
190 unsigned int numcreated; /* no of objects created */
191 int sum_bytes; /* total bytes of modified objects in a transaction */
194 /* Structure that holds trans request information for each participant */
195 typedef struct trans_req_data {
196 fixed_data_t f; /* Holds first few fixed bytes of data sent during TRANS_REQUEST protcol*/
197 unsigned int *listmid; /* Pointer to array holding list of participants */
198 char *objread; /* Pointer to array holding oid and version number of objects that are only read */
199 unsigned int *oidmod; /* Pointer to array holding oids of objects that are modified */
200 unsigned int *oidcreated; /* Pointer to array holding oids of objects that are newly created */
203 /* Structure that holds information of objects that are not found in the participant
204 * and objs locked within a transaction during commit process */
205 typedef struct trans_commit_data {
206 unsigned int *objlocked; /* Pointer to array holding oids of objects locked inside a transaction */
207 unsigned int *objnotfound; /* Pointer to array holding oids of objects not found on the participant machine */
208 unsigned int *objvernotmatch; /* Pointer to array holding oids whose version doesn't match on the participant machine */
209 void *modptr; /* Pointer to the address in the mainobject store of the participant that holds all modified objects */
210 int numlocked; /* no of objects locked */
211 int numnotfound; /* no of objects not found */
212 int numvernotmatch; /* no of objects whose version doesn't match */
213 } trans_commit_data_t;
216 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
218 /* Initialize main object store and lookup tables, start server thread. */
220 void send_data(int fd, void *buf, int buflen);
221 void recv_data(int fd, void *buf, int buflen);
222 int recv_data_errorcode(int fd, void *buf, int buflen);
224 /* Prototypes for object header */
225 unsigned int getNewOID(void);
226 /* end object header */
228 /* Prototypes for object store */
229 objstr_t *objstrCreate(unsigned int size); //size in bytes
230 void objstrDelete(objstr_t *store); //traverse and free entire list
231 void *objstrAlloc(objstr_t **store, unsigned int size); //size in bytes
232 void clearObjStore(); // TODO:currently only clears the prefetch cache object store
233 /* end object store */
235 /* Prototypes for server portion */
236 void *dstmListen(void *);
237 int startlistening();
238 void *dstmAccept(void *);
239 int readClientReq(trans_commit_data_t *, int, struct readstruct * readbuffer);
240 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int, struct readstruct *);
241 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
242 char decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
243 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
244 void processReqNotify(unsigned int numoid, unsigned int *oid, unsigned short *version, unsigned int mid, unsigned int threadid);
245 void getCommitCountForObjMod(unsigned int *, unsigned int *, unsigned int *, int *,
246 int *, int *, int *, int *, int *, int *, char *, unsigned int, unsigned short);
247 void getCommitCountForObjRead(unsigned int *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *,
248 int *, int *, char *, unsigned int, unsigned short);
249 /* end server portion */
251 /* Prototypes for transactions */
252 /* Function called at beginning. Passes in the first parameter. */
253 /* Returns 1 if this thread should run the main process */
255 int dstmStartup(const char *);
257 int processConfigFile();
258 void addHost(unsigned int);
259 void mapObjMethod(unsigned short);
263 #define TRANSREAD(x,y) { \
264 unsigned int inputvalue;\
265 if ((inputvalue=(unsigned int)y)==0) x=NULL;\
267 chashlistnode_t * cnodetmp=&c_table[(inputvalue&c_mask)>>1]; \
269 if (cnodetmp->key==inputvalue) {x=(void *)&((objheader_t*)cnodetmp->val)[1];break;} \
270 cnodetmp=cnodetmp->next;\
271 if (cnodetmp==NULL) {x=(void *)transRead2(inputvalue); asm volatile("":"=m"(c_table),"=m"(c_mask));break;} \
275 __attribute__((pure)) objheader_t *transRead(unsigned int);
276 __attribute__((pure)) objheader_t *transRead2(unsigned int);
277 objheader_t *transCreateObj(unsigned int); //returns oid header
278 int transCommit(); //return 0 if successful
279 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
280 char decideResponse(char *, char *, int); // Coordinator decides what response to send to the participant
281 void *getRemoteObj(unsigned int, unsigned int); // returns object header from main object store after object is copied into it from remote machine
282 void handleLocalReq(trans_req_data_t *, trans_commit_data_t *, char *);
283 int transComProcess(trans_req_data_t *, trans_commit_data_t *);
284 void doLocalProcess(char, trans_req_data_t *tdata, trans_commit_data_t *);
285 int transAbortProcess(trans_commit_data_t *);
287 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size);
288 void prefetch(int, int, unsigned int *, unsigned short *, short*);
289 void *transPrefetch(void *);
290 void *mcqProcess(void *);
291 prefetchpile_t *foundLocal(char *, int); // returns node with prefetch elements(oids, offsets)
292 int lookupObject(unsigned int * oid, short offset);
293 int checkoid(unsigned int oid);
294 int transPrefetchProcess(int **, short);
295 void sendPrefetchReq(prefetchpile_t*, int);
296 void sendPrefetchReqnew(prefetchpile_t*, int);
297 int getPrefetchResponse(int, struct readstruct *);
298 unsigned short getObjType(unsigned int oid);
299 int startRemoteThread(unsigned int oid, unsigned int mid);
300 plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mid, int num_objs);
301 void commitCountForObjRead(char *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *, unsigned int, unsigned short);
302 void commitCountForObjMod(char *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *, unsigned int, unsigned short);
304 /* Sends notification request for thread join, if sucessful returns 0 else returns -1 */
305 int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int numoid);
306 void threadNotify(unsigned int oid, unsigned short version, unsigned int tid);
307 int notifyAll(threadlist_t **head, unsigned int oid, unsigned int version);
309 /* Internal functions from signal.c */
311 double getMax(double *array, int size);
312 double getMin(double *array, int size);
313 double getfast(int siteid, int threadid);
314 double getslowest(int siteid, int threadid);
315 double getavg(int siteid, int threadid);
316 double getavgperthd(int siteid, int threadid);
317 double avgfast(int siteid, int threadid);
318 double avgslow(int siteid, int threadid);
320 void swap(double *e1, double *e2);
321 double avgofthreads(int siteid, int threadid);
323 /* end transactions */