1ec456eddeb378fc736f493b855da9dc3f627476
[IRC.git] / Robust / src / Runtime / DSTM / interface / prefetch.h
1 #ifndef _PREFETCH_H_
2 #define _PREFETCH_H_
3 #include "queue.h"
4 #include "dstm.h"
5
6 #define GET_STRIDE(x) ((x & 0x7000) >> 12)
7 #define GET_RANGE(x) (x & 0x0fff)
8 #define GET_STRIDEINC(x) ((x & 0x8000) >> 15)
9 #define GET_OID(x) ((int *) (x))
10 #define GET_NUM_OFFSETS(x) ((short *) (x + sizeof(unsigned int)))
11 #define GET_OFFSETS(x) ((short *) (x + sizeof(unsigned int) + sizeof(short)))
12
13 /****** Global structure **********/
14 typedef struct objOffsetPile {
15   unsigned int oid;
16   short numoffset;
17   short *offsets;
18   struct objOffsetPile *next;
19 } objOffsetPile_t;
20
21 typedef struct perMcPrefetchList {
22   unsigned int mid;
23   objOffsetPile_t *list;
24   struct perMcPrefetchList *next;
25 } perMcPrefetchList_t;
26
27 typedef struct proPrefetchQ {
28   perMcPrefetchList_t *front, *rear;
29   pthread_mutex_t qlock;
30   pthread_mutexattr_t qlockattr;
31   pthread_cond_t qcond;
32 } proPrefetchQ_t;
33
34 typedef struct oidAtDepth {
35   int depth; //TODO Remove may not need since depth is never read
36   unsigned int oid;
37 } oidAtDepth_t;
38
39 // Global Prefetch Processing Queue
40 proPrefetchQ_t prefetchQ;
41
42 /**** Prefetch Queue to be processed functions ******/
43 void proPrefetchQDealloc(perMcPrefetchList_t *);
44
45 /******** Process Queue Element functions ***********/
46 void rangePrefetch(unsigned int, short, short *);
47 void *transPrefetchNew();
48 perMcPrefetchList_t* checkIfLocal(char *ptr);
49 int lookForObjs(int*, short *, int *, int *, int *, int *);
50 void insertPrefetch(int, unsigned int, short, short*, perMcPrefetchList_t **);
51
52 /******** Sending and Receiving Prefetches *******/
53 void sendRangePrefetchReq(perMcPrefetchList_t *, int sd);
54 int rangePrefetchReq(int acceptfd);
55 int processOidFound(objheader_t *, short *, int, int, int);
56 int processArrayOids(short *, objheader_t *, int *, int);
57 int findOidinStride(short *,  struct ArrayObject *, int, int, int, int, int, int);
58 int processLinkedListOids(short *, objheader_t *, int *, int);
59 int getRangePrefetchResponse(int sd);
60 objheader_t *searchObj(unsigned int);
61 void forwardRequest(unsigned int *, int*, int*, int*, short*);
62
63 /*********** Functions for computation at the participant end **********/
64 int getNextOid(short *, unsigned int*, int*, int*, oidAtDepth_t *, unsigned int);
65 unsigned int getNextArrayOid(short *, unsigned int *, int *, int*);
66 unsigned int getNextPointerOid(short *, unsigned int *, int *, int*);
67 int sendOidFound(unsigned int, int);
68 int sendOidNotFound(unsigned int oid, int sd);
69
70 /************* Internal functions *******************/
71 int getsize(short *ptr, int n);
72
73 #endif