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
7 http://www.apache.org/licenses/LICENSE-2.0
\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
16 * gscpipc.h:: defines the interface of the IPC channels used in
\r
17 * the GS-lite framework to communicate tuples between different
\r
24 #include "gsconfig.h"
\r
25 #include "gstypes.h"
\r
28 #define RESERVED_FOR_LOW_LEVEL 0
\r
30 #define FTACALLBACK 1
\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
41 /* shared ringbuffer data structure used */
\r
43 #if defined(__sparc__) && defined(__sun__)
\r
52 gs_uint32_t alignment;
\r
55 }__attribute__ ((__packed__));
\r
64 gs_uint32_t alignment;
\r
69 }__attribute__ ((__packed__));
\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
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
78 *used to contact the clearinghouse process returns the MSGID of
\r
79 * the current process negative result indicates a problem
\r
82 gs_retval_t gscpipc_init(gs_int32_t clearinghouse);
\r
84 /* used to disassociate process from clearinghouse */
\r
85 gs_retval_t gscpipc_free();
\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
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
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
98 struct ringbuf * gscpipc_createshm(FTAID f, gs_int32_t length);
\r
100 /* finds a ringbuffer to send which was allocated by
\r
101 * gscpipc_creatshm and return 0 on an error */
\r
103 struct ringbuf * gscpipc_getshm(FTAID f);
\r
105 /* frees shared memory to a particular proccess identified
\r
106 * by ftaid if reference counter reaches 0
\r
108 gs_retval_t gscpipc_freeshm(FTAID f);
\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
116 gs_retval_t gscpipc_mqhint();
\r
118 /* Access macros for ringbuffer */
\r
121 #define UP64(x) ((((x)+7)/8)*8)
\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
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