bug fixes and add machine pile queue DS that saves oids and offsets meant for
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.h
1 #ifndef _DSTM_H_
2 #define _DSTM_H_
3
4 #ifdef MAC
5 #define MSG_NOSIGNAL 0
6 #endif
7
8 #define GET_NTUPLES(x)  ((int *)(x + sizeof(prefetchqelem_t)))
9 #define GET_PTR_OID(x)  ((unsigned int *)(x + sizeof(prefetchqelem_t) + sizeof(int)))
10 #define GET_PTR_EOFF(x,n) ((short *)(x + sizeof(prefetchqelem_t) + sizeof(int) + (n*sizeof(unsigned int))))
11 #define GET_PTR_ARRYFLD(x,n) ((short *)(x + sizeof(prefetchqelem_t) + sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
12
13
14 //Coordinator Messages
15 #define READ_REQUEST            1
16 #define READ_MULT_REQUEST       2
17 #define MOVE_REQUEST            3
18 #define MOVE_MULT_REQUEST       4
19 #define TRANS_REQUEST           5
20 #define TRANS_ABORT             6
21 #define TRANS_COMMIT            7
22 #define TRANS_PREFETCH          8
23 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING    9
24
25 //Participant Messages
26 #define OBJECT_FOUND                    10
27 #define OBJECT_NOT_FOUND                11
28 #define OBJECTS_FOUND                   12
29 #define OBJECTS_NOT_FOUND               13
30 #define TRANS_AGREE                     17
31 #define TRANS_DISAGREE                  18
32 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
33 #define TRANS_SOFT_ABORT                20
34 #define TRANS_SUCESSFUL                 21
35
36 //Control bits for status of objects in Machine pile
37 #define OBJ_LOCKED_BUT_VERSION_MATCH    14
38 #define OBJ_UNLOCK_BUT_VERSION_MATCH    15
39 #define VERSION_NO_MATCH                16
40
41 //Max number of objects 
42 #define MAX_OBJECTS  20
43
44
45 #include <stdlib.h>
46 #include <stdio.h>
47 #include <string.h>
48 #include <pthread.h>
49 #include "clookup.h"
50 #include "queue.h"
51 #include "mcpileq.h"
52
53 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
54 #define TID_LEN 20
55 //bit designations for status field of objheader
56 #define DIRTY 0x01
57 #define NEW   0x02
58 #define LOCK  0x04
59 #define LOCAL  0x08
60
61 typedef struct objheader {
62         unsigned int oid;
63         unsigned short type;
64         unsigned short version;
65         unsigned short rcount;
66         char status;
67 } objheader_t;
68
69 typedef struct objstr {
70         unsigned int size; //this many bytes are allocated after this header
71         void *top;
72         struct objstr *next;
73 } objstr_t;
74
75 typedef struct transrecord {
76         objstr_t *cache;
77         chashtable_t *lookupTable;
78 } transrecord_t;
79 // Structure that keeps track of responses from the participants
80 typedef struct thread_response {
81         char rcv_status;
82 }thread_response_t;
83
84 // Structure that holds  fixed data sizes to be sent along with TRANS_REQUEST
85 typedef struct fixed_data {
86         char control;
87         char trans_id[TID_LEN]; 
88         int mcount;             // Machine count
89         short numread;          // Number of objects read
90         short nummod;           // Number of objects modified
91         int sum_bytes;  // Total bytes modified
92 }fixed_data_t;
93
94 // Structure that holds  variable data sizes per machine participant
95 typedef struct trans_req_data {
96         fixed_data_t f;
97         unsigned int *listmid;
98         char *objread;
99         unsigned int *oidmod;
100 }trans_req_data_t;
101
102 // Structure passed to dstmAcceptinfo() on server side to complete TRANS_COMMIT process 
103 typedef struct trans_commit_data{
104         unsigned int *objmod;
105         unsigned int *objlocked;
106         unsigned int *objnotfound;
107         void *modptr;
108         int nummod;
109         int numlocked;
110         int numnotfound;
111 }trans_commit_data_t;
112
113
114 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
115 //structure for passing multiple arguments to thread
116 typedef struct thread_data_array {
117         int thread_id;
118         int mid;    
119         int pilecount;
120         trans_req_data_t *buffer;
121         thread_response_t *recvmsg;//shared datastructure to keep track of the control message receiv
122         pthread_cond_t *threshold; //threshhold for waking up a thread
123         pthread_mutex_t *lock;    //lock the count variable
124         int *count;             //variable to count responses of TRANS_REQUEST protocol from all participants
125         char *replyctrl;        //shared ctrl message that stores the reply to be sent, filled by decideResp
126         char *replyretry;       //shared variable to find out if we need retry (TRANS_COMMIT case) 
127         transrecord_t *rec;     // To send modified objects
128 } thread_data_array_t;
129
130
131 //Structure for passing arguments to the local m/c thread
132 typedef struct local_thread_data_array {
133         thread_data_array_t *tdata;
134         trans_commit_data_t *transinfo; //Required for trans commit process
135 } local_thread_data_array_t;
136
137 // Structure to save information about an oid necesaary for the decideControl()
138 typedef struct objinfo {
139         unsigned int oid;
140         int poss_val; //Status of object(locked but version matches, version mismatch, oid not present in machine etc) 
141 }objinfo_t;
142
143 //Structure for members within prefetch tuples
144 typedef struct member {
145         short offset;
146         short index;
147         struct member *next;
148 }trans_member_t;
149
150 /*
151 //Structure that holds the compiler generated prefetch data
152 typedef struct compprefetchdata {
153 transrecord_t *record;
154 } compprefetchdata_t;
155 */
156
157 /* Initialize main object store and lookup tables, start server thread. */
158 int dstmInit(void);
159
160 /* Prototypes for object header */
161 unsigned int getNewOID(void);
162 unsigned int objSize(objheader_t *object);
163 /* end object header */
164
165 /* Prototypes for object store */
166 objstr_t *objstrCreate(unsigned int size); //size in bytes
167 void objstrDelete(objstr_t *store); //traverse and free entire list
168 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
169 /* end object store */
170
171 /* Prototypes for server portion */
172 void *dstmListen();
173 void *dstmAccept(void *);
174 int readClientReq(trans_commit_data_t *, int);
175 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, int);
176 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
177 int decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, unsigned int *, int);
178 int transCommitProcess(trans_commit_data_t *, int);
179 /* end server portion */
180
181 /* Prototypes for transactions */
182 void randomdelay(void);
183 transrecord_t *transStart();
184 objheader_t *transRead(transrecord_t *, unsigned int);
185 objheader_t *transCreateObj(transrecord_t *, unsigned short); //returns oid
186 int transCommit(transrecord_t *record); //return 0 if successful
187 void *transRequest(void *);     //the C routine that the thread will execute when TRANS_REQUEST begins
188 void *handleLocalReq(void *);   //the C routine that the local m/c thread will execute 
189 int decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant
190 char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants
191 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
192 int transAbortProcess(void *, unsigned int *, int, int, int);
193 int transComProcess(trans_commit_data_t *);
194 void prefetch(int, unsigned int *, short *, short*);
195 void *transPrefetch(void *);
196 void checkPrefetchTuples(prefetchqelem_t *);
197 void foundLocal(prefetchqelem_t *);
198 void makePreGroups(prefetchqelem_t *node);
199 void checkPreCache(prefetchqelem_t *, int *, int, int, unsigned int, int, int, int);
200 int transPrefetchProcess(transrecord_t *, int **, short);
201 void *sendPrefetchReq(void *);
202 /* end transactions */
203 #endif