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))))
16 #define ENDEBUG(s) { printf("Inside %s()\n", s); fflush(stdout);}
17 #define EXDEBUG(s) {printf("Outside %s()\n", s); fflush(stdout);}
18 /*****************************************
19 * Coordinator Messages
20 ***************************************/
21 #define READ_REQUEST 1
22 #define READ_MULT_REQUEST 2
23 #define MOVE_REQUEST 3
24 #define MOVE_MULT_REQUEST 4
25 #define TRANS_REQUEST 5
27 #define TRANS_COMMIT 7
28 #define TRANS_PREFETCH 8
29 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING 9
31 /*********************************
32 * Participant Messages
33 *******************************/
34 #define OBJECT_FOUND 10
35 #define OBJECT_NOT_FOUND 11
36 #define OBJECTS_FOUND 12
37 #define OBJECTS_NOT_FOUND 13
38 #define TRANS_AGREE 17
39 #define TRANS_DISAGREE 18
40 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
41 #define TRANS_SOFT_ABORT 20
42 #define TRANS_SUCESSFUL 21
43 #define TRANS_PREFETCH_RESPONSE 22
44 #define START_REMOTE_THREAD 23
45 #define THREAD_NOTIFY_REQUEST 24
46 #define THREAD_NOTIFY_RESPONSE 25
47 #define TRANS_UNSUCESSFUL 26
48 #define CLOSE_CONNECTION 27
50 //Max number of objects
51 #define MAX_OBJECTS 20
52 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
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 100 //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>
87 //bit designations for status field of objheader
93 /*******Global statistics *********/
94 extern int numprefetchsites;
96 double idForTimeDelay; /* TODO Remove, necessary to get time delay for starting transRequest for this id */
97 int transCount; /* TODO Remove, necessary to the transaction id */
101 #include "structdefs.h"
103 typedef struct objheader {
104 threadlist_t *notifylist;
105 unsigned short version;
106 unsigned short rcount;
110 (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___))
113 ((void*)((((void *) x )!=NULL) ? (*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___)) : 0))
116 *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
118 #define STATUSPTR(x) \
119 ((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
122 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
124 #define GETSIZE(size, x) { \
126 if (type<NUMCLASSES) { \
127 size=classsize[type]; \
129 size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject); \
135 typedef struct objheader {
136 threadlist_t *notifylist;
139 unsigned short version;
140 unsigned short rcount;
144 #define OID(x) x->oid
145 #define TYPE(x) x->type
146 #define STATUS(x) x->status
147 #define STATUSPTR(x) &x->status
148 #define GETSIZE(size, x) size=classsize[TYPE(x)]
151 typedef struct objstr {
152 unsigned int size; //this many bytes are allocated after this header
157 typedef struct oidmidpair {
162 typedef struct transrecord {
164 chashtable_t *lookupTable;
166 struct ___Object___ * revertlist;
170 // Structure is a shared structure that keeps track of responses from the participants
171 typedef struct thread_response {
175 // Structure that holds fixed data to be sent along with TRANS_REQUEST
176 typedef struct fixed_data {
177 char control; /* control message */
178 char trans_id[TID_LEN]; /* transaction id */
179 int mcount; /* participant count */
180 unsigned int numread; /* no of objects read */
181 unsigned int nummod; /* no of objects modified */
182 unsigned int numcreated; /* no of objects created */
183 int sum_bytes; /* total bytes of modified objects in a transaction */
186 /* Structure that holds trans request information for each participant */
187 typedef struct trans_req_data {
188 fixed_data_t f; /* Holds first few fixed bytes of data sent during TRANS_REQUEST protcol*/
189 unsigned int *listmid; /* Pointer to array holding list of participants */
190 char *objread; /* Pointer to array holding oid and version number of objects that are only read */
191 unsigned int *oidmod; /* Pointer to array holding oids of objects that are modified */
192 unsigned int *oidcreated; /* Pointer to array holding oids of objects that are newly created */
195 /* Structure that holds information of objects that are not found in the participant
196 * and objs locked within a transaction during commit process */
197 typedef struct trans_commit_data {
198 unsigned int *objlocked; /* Pointer to array holding oids of objects locked inside a transaction */
199 unsigned int *objnotfound; /* Pointer to array holding oids of objects not found on the participant machine */
200 unsigned int *objvernotmatch; /* Pointer to array holding oids whose version doesn't match on the participant machine */
201 void *modptr; /* Pointer to the address in the mainobject store of the participant that holds all modified objects */
202 int numlocked; /* no of objects locked */
203 int numnotfound; /* no of objects not found */
204 int numvernotmatch; /* no of objects whose version doesn't match */
205 } trans_commit_data_t;
208 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
209 /* Structure for passing multiple arguments to a thread
210 * spawned to process each transaction on a machine */
211 typedef struct thread_data_array {
214 trans_req_data_t *buffer; /* Holds trans request information sent to a participant, based on threadid */
215 thread_response_t *recvmsg; /* Shared datastructure to keep track of the participants response to a trans request */
216 pthread_cond_t *threshold; /* Condition var to wake up a thread */
217 pthread_mutex_t *lock; /* Lock for counting participants response */
218 int *count; /* Shared variable to count responses from all participants to the TRANS_REQUEST protocol */
219 char *replyctrl; /* Shared ctrl message that stores the reply to be sent to participants, filled by decideResponse() */
220 char *replyretry; /* Shared variable that keep track if coordinator needs retry */
221 transrecord_t *rec; /* Shared variable transaction record send to all thread data */
222 } thread_data_array_t;
225 //Structure for passing arguments to the local m/c thread
226 typedef struct local_thread_data_array {
227 thread_data_array_t *tdata; /* Holds all the arguments send to a thread that is spawned when transaction commits */
228 trans_commit_data_t *transinfo; /* Holds information of objects locked and not found in the participant */
229 } local_thread_data_array_t;
231 //Structure to store mid and socketid information
232 typedef struct midSocketInfo {
233 unsigned int mid; /* To communicate with mid use sockid in this data structure */
237 /* Initialize main object store and lookup tables, start server thread. */
239 void send_data(int fd, void *buf, int buflen);
240 void recv_data(int fd, void *buf, int buflen);
241 int recv_data_errorcode(int fd, void *buf, int buflen);
243 /* Prototypes for object header */
244 unsigned int getNewOID(void);
245 /* end object header */
247 /* Prototypes for object store */
248 objstr_t *objstrCreate(unsigned int size); //size in bytes
249 void objstrDelete(objstr_t *store); //traverse and free entire list
250 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
251 void clearObjStore(); // TODO:currently only clears the prefetch cache object store
252 /* end object store */
254 /* Prototypes for server portion */
255 void *dstmListen(void *);
256 int startlistening();
257 void *dstmAccept(void *);
258 int readClientReq(trans_commit_data_t *, int);
259 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int);
260 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
261 char decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
262 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
263 void processReqNotify(unsigned int numoid, unsigned int *oid, unsigned short *version, unsigned int mid, unsigned int threadid);
264 void getCommitCountForObjMod(unsigned int *, unsigned int *, unsigned int *, int *,
265 int *, int *, int *, int *, int *, int *, char *, unsigned int, unsigned short);
266 void getCommitCountForObjRead(unsigned int *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *,
267 int *, int *, char *, unsigned int, unsigned short);
268 /* end server portion */
270 /* Prototypes for transactions */
271 /* Function called at beginning. Passes in the first parameter. */
272 /* Returns 1 if this thread should run the main process */
274 int dstmStartup(const char *);
276 int processConfigFile();
277 void addHost(unsigned int);
278 void mapObjMethod(unsigned short);
281 transrecord_t *transStart();
282 __attribute__((pure)) objheader_t *transRead(transrecord_t *, unsigned int);
283 objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid header
284 int transCommit(transrecord_t *record); //return 0 if successful
285 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
286 char decideResponse(char *, char *, transrecord_t *, int); // Coordinator decides what response to send to the participant
287 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int); // returns object header from main object store after object is copied into it from remote machine
288 void handleLocalReq(trans_req_data_t *, trans_commit_data_t *, transrecord_t *, char *);
289 int transComProcess(trans_req_data_t *, trans_commit_data_t *, transrecord_t *);
290 void doLocalProcess(char, trans_req_data_t *tdata, trans_commit_data_t *, transrecord_t *);
291 int transAbortProcess(trans_commit_data_t *);
292 void transAbort(transrecord_t *trans);
293 void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size);
294 void prefetch(int, int, unsigned int *, unsigned short *, short*);
295 void *transPrefetch(void *);
296 void *mcqProcess(void *);
297 prefetchpile_t *foundLocal(char *); // returns node with prefetch elements(oids, offsets)
298 int lookupObject(unsigned int * oid, short offset);
299 int checkoid(unsigned int oid);
300 int transPrefetchProcess(transrecord_t *, int **, short);
301 void sendPrefetchReq(prefetchpile_t*, int);
302 void sendPrefetchReqnew(prefetchpile_t*, int);
303 int getPrefetchResponse(int);
304 unsigned short getObjType(unsigned int oid);
305 int startRemoteThread(unsigned int oid, unsigned int mid);
306 plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mid, int num_objs);
307 void commitCountForObjRead(char *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *, unsigned int, unsigned short);
308 void commitCountForObjMod(char *, unsigned int *, unsigned int *, int *, int *, int *, int *, int *, unsigned int, unsigned short);
310 /* Sends notification request for thread join, if sucessful returns 0 else returns -1 */
311 int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int numoid);
312 void threadNotify(unsigned int oid, unsigned short version, unsigned int tid);
313 int notifyAll(threadlist_t **head, unsigned int oid, unsigned int version);
315 /* Internal functions from signal.c */
317 double getMax(double *array, int size);
318 double getMin(double *array, int size);
319 double getfast(int siteid, int threadid);
320 double getslowest(int siteid, int threadid);
321 double getavg(int siteid, int threadid);
322 double getavgperthd(int siteid, int threadid);
323 double avgfast(int siteid, int threadid);
324 double avgslow(int siteid, int threadid);
326 void swap(double *e1, double *e2);
327 double avgofthreads(int siteid, int threadid);
329 /* end transactions */