1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
16 * gscpipc.h:: defines the interface of the IPC channels used in
17 * the GS-lite framework to communicate tuples between different
28 #define RESERVED_FOR_LOW_LEVEL 0
32 extern gs_uint64_t intupledrop;
33 extern gs_uint64_t outtupledrop;
34 extern gs_uint64_t intuple;
35 extern gs_uint64_t outtuple;
36 extern gs_uint64_t inbytes;
37 extern gs_uint64_t outbytes;
38 extern gs_uint64_t cycles;
41 /* shared ringbuffer data structure used */
43 #if defined(__sparc__) && defined(__sun__)
52 gs_uint32_t alignment;
55 }__attribute__ ((__packed__));
64 gs_uint32_t alignment;
69 }__attribute__ ((__packed__));
71 /* adds a buffer to the end of the sidequeue*/
72 gs_retval_t sidequeue_append(FTAID ftaid, gs_sp_t buf, gs_int32_t length);
74 /* removes a buffer from the top of the sidequeue*/
75 gs_retval_t sidequeue_pop(FTAID * ftaid, gs_sp_t buf, gs_int32_t * length);
78 *used to contact the clearinghouse process returns the MSGID of
79 * the current process negative result indicates a problem
82 gs_retval_t gscpipc_init(gs_int32_t clearinghouse);
84 /* used to disassociate process from clearinghouse */
85 gs_retval_t gscpipc_free();
87 /* sends a message to a process */
88 gs_retval_t gscpipc_send(FTAID f, gs_int32_t operation, gs_sp_t buf, gs_int32_t length, gs_int32_t block);
90 /* retrieve a message buf has to be at least of size MAXMSGSZ returns 0
91 if no message is available -1 on an error and 1 on sucess*/
92 gs_retval_t gscpipc_read(FTAID * f, gs_int32_t * operation, gs_sp_t buf, gs_int32_t * lenght, gs_int32_t block);
94 /* allocate a ringbuffer which allows receiving data from
95 * the other process returns 0 if didn't succeed.
96 * returns an existing buffer if it exists and increments the refcnt*/
98 struct ringbuf * gscpipc_createshm(FTAID f, gs_int32_t length);
100 /* finds a ringbuffer to send which was allocated by
101 * gscpipc_creatshm and return 0 on an error */
103 struct ringbuf * gscpipc_getshm(FTAID f);
105 /* frees shared memory to a particular proccess identified
106 * by ftaid if reference counter reaches 0
108 gs_retval_t gscpipc_freeshm(FTAID f);
111 /* returns true if on any sending ringbuffer the mqhint bit is true
112 * can be used in lfta rts to indicate that the message queue should
116 gs_retval_t gscpipc_mqhint();
118 /* Access macros for ringbuffer */
121 #define UP64(x) ((((x)+7)/8)*8)
126 #define CURWRITE(buf) ((struct tuple *)(&((buf)->start[(buf)->writer])))
127 #define ADVANCEWRITE(buf) CURWRITE(buf)->next=\
128 ((buf)->end > ((buf)->writer+UP64(CURWRITE(buf)->sz))+sizeof(struct tuple)-1)\
129 ? ((buf)->writer+UP64(CURWRITE(buf)->sz)+sizeof(struct tuple)-1) : 0; \
130 (buf)->writer=CURWRITE(buf)->next;
131 #define CURREAD(buf) ((struct tuple *)(&((buf)->start[(buf)->reader])))
132 #define ADVANCEREAD(buf) (buf)->reader=\
134 #define UNREAD(buf) ((buf)->reader != (buf)->writer)
135 #define SPACETOWRITE(buf) ((((buf)->reader <= (buf)->writer) \
136 && ((buf)->reader+(buf)->end-(buf)->writer) > MAXTUPLESZ)\
137 || (((buf)->reader > (buf)->writer) && (((buf)->reader-(buf)->writer)>MAXTUPLESZ)))
138 #define HOWFULL(buf) (((((buf)->writer)-(buf)->reader)%((buf)->end)*1000)/((buf)->end))
139 /* conservative estimate of how many tuples of size tuplesz fit in a ringbuffer */
140 #define TUPLEFIT(buf,tuplesz) ((((((buf)->writer)-(buf)->reader)%((buf)->end))-MAXTUPLESZ)/ \
141 ((UP64(tuplesz))+sizeof(struct tuple)-1))