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