Added quantiling UDAFs
[com/gs-lite.git] / src / lib / gscphost / include / gscpipc.h
1 /* ------------------------------------------------\r
2  Copyright 2014 AT&T Intellectual Property\r
3  Licensed under the Apache License, Version 2.0 (the "License");\r
4  you may not use this file except in compliance with the License.\r
5  You may obtain a copy of the License at\r
6 \r
7  http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9  Unless required by applicable law or agreed to in writing, software\r
10  distributed under the License is distributed on an "AS IS" BASIS,\r
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12  See the License for the specific language governing permissions and\r
13  limitations under the License.\r
14  ------------------------------------------- */\r
15 /*\r
16  * gscpipc.h:: defines the interface of the IPC channels used in\r
17  * the GS-lite framework to communicate tuples between different\r
18  * processes\r
19  */\r
20 \r
21 #ifndef GSCPIPC_H\r
22 #define GSCPIPC_H\r
23 \r
24 #include "gsconfig.h"\r
25 #include "gstypes.h"\r
26 #include "fta.h"\r
27 \r
28 #define RESERVED_FOR_LOW_LEVEL 0\r
29 \r
30 #define FTACALLBACK 1\r
31 \r
32 extern gs_uint64_t intupledrop;\r
33 extern gs_uint64_t outtupledrop;\r
34 extern gs_uint64_t intuple;\r
35 extern gs_uint64_t outtuple;\r
36 extern gs_uint64_t inbytes;\r
37 extern gs_uint64_t outbytes;\r
38 extern gs_uint64_t cycles;\r
39 \r
40 \r
41 /* shared ringbuffer data structure used */\r
42 \r
43 #if defined(__sparc__) && defined(__sun__)\r
44 #define ALIGN64\r
45 #endif\r
46 \r
47 struct tuple {\r
48     FTAID f;\r
49     gs_int32_t  sz;\r
50     gs_uint32_t  next;\r
51 #ifdef ALIGN64\r
52     gs_uint32_t  alignment;\r
53 #endif\r
54     gs_int8_t  data[1];\r
55 }__attribute__ ((__packed__));\r
56 \r
57 struct ringbuf {\r
58     gs_uint32_t   mqhint;\r
59     gs_uint32_t   writer;\r
60     gs_uint32_t   reader;\r
61     gs_uint32_t   end;\r
62     gs_int32_t  length;\r
63 #ifdef ALIGN64\r
64     gs_uint32_t  alignment;\r
65 #endif\r
66     FTAID  srcid;\r
67     FTAID  destid;\r
68     gs_int8_t  start[1];\r
69 }__attribute__ ((__packed__));\r
70 \r
71 /* adds a buffer to the end of the sidequeue*/\r
72 gs_retval_t sidequeue_append(FTAID ftaid, gs_sp_t buf, gs_int32_t length);\r
73 \r
74 /* removes a buffer from the top of the sidequeue*/\r
75 gs_retval_t sidequeue_pop(FTAID * ftaid, gs_sp_t buf, gs_int32_t * length);\r
76 \r
77 /*\r
78  *used to contact the clearinghouse process returns the MSGID of\r
79  * the current process negative result indicates a problem\r
80  */\r
81 \r
82 gs_retval_t  gscpipc_init(gs_int32_t  clearinghouse);\r
83 \r
84 /* used to disassociate process from clearinghouse */\r
85 gs_retval_t  gscpipc_free();\r
86 \r
87 /* sends a message to a process */\r
88 gs_retval_t  gscpipc_send(FTAID f, gs_int32_t  operation, gs_sp_t buf, gs_int32_t  length, gs_int32_t  block);\r
89 \r
90 /* retrieve a message buf has to be at least of size MAXMSGSZ returns 0\r
91  if no message is available -1 on an error and 1 on sucess*/\r
92 gs_retval_t  gscpipc_read(FTAID * f, gs_int32_t  * operation, gs_sp_t buf, gs_int32_t  * lenght, gs_int32_t  block);\r
93 \r
94 /* allocate a ringbuffer which allows receiving data from\r
95  * the other process returns 0 if didn't succeed.\r
96  * returns an existing buffer if it exists  and increments the refcnt*/\r
97 \r
98 struct ringbuf * gscpipc_createshm(FTAID f, gs_int32_t  length);\r
99 \r
100 /* finds a ringbuffer to send which was allocated by\r
101  * gscpipc_creatshm and return 0 on an error */\r
102 \r
103 struct ringbuf * gscpipc_getshm(FTAID f);\r
104 \r
105 /* frees shared memory to a particular proccess identified\r
106  * by ftaid if reference counter reaches 0\r
107  */\r
108 gs_retval_t  gscpipc_freeshm(FTAID f);\r
109 \r
110 \r
111 /* returns true if on any sending ringbuffer the mqhint bit is true\r
112  * can be used in lfta rts to indicate that the message queue should\r
113  * be checked.\r
114  */\r
115 \r
116 gs_retval_t  gscpipc_mqhint();\r
117 \r
118 /* Access macros for ringbuffer */\r
119 \r
120 #ifdef ALIGN64\r
121 #define UP64(x) ((((x)+7)/8)*8)\r
122 #else\r
123 #define UP64(x) x\r
124 #endif\r
125 \r
126 #define CURWRITE(buf)  ((struct tuple *)(&((buf)->start[(buf)->writer])))\r
127 #define ADVANCEWRITE(buf)  CURWRITE(buf)->next=\\r
128 ((buf)->end > ((buf)->writer+UP64(CURWRITE(buf)->sz))+sizeof(struct tuple)-1)\\r
129 ? ((buf)->writer+UP64(CURWRITE(buf)->sz)+sizeof(struct tuple)-1) : 0; \\r
130 (buf)->writer=CURWRITE(buf)->next;\r
131 #define CURREAD(buf)  ((struct tuple *)(&((buf)->start[(buf)->reader])))\r
132 #define ADVANCEREAD(buf) (buf)->reader=\\r
133 CURREAD(buf)->next\r
134 #define UNREAD(buf) ((buf)->reader != (buf)->writer)\r
135 #define SPACETOWRITE(buf)   ((((buf)->reader <= (buf)->writer) \\r
136 && ((buf)->reader+(buf)->end-(buf)->writer) > MAXTUPLESZ)\\r
137 || (((buf)->reader > (buf)->writer) && (((buf)->reader-(buf)->writer)>MAXTUPLESZ)))\r
138 #define HOWFULL(buf) (((((buf)->writer)-(buf)->reader)%((buf)->end)*1000)/((buf)->end))\r
139 /* conservative estimate of how many tuples of size tuplesz fit in a ringbuffer */\r
140 #define TUPLEFIT(buf,tuplesz) ((((((buf)->writer)-(buf)->reader)%((buf)->end))-MAXTUPLESZ)/ \\r
141 ((UP64(tuplesz))+sizeof(struct tuple)-1))\r
142 #endif\r