1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #ifndef MCA_BTL_TCP_H
28 #define MCA_BTL_TCP_H
29
30 #include "opal_config.h"
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
33 #endif
34 #ifdef HAVE_SYS_SOCKET_H
35 #include <sys/socket.h>
36 #endif
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
39 #endif
40 #ifdef HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif
43
44
45 #include "opal/mca/event/event.h"
46 #include "opal/class/opal_free_list.h"
47 #include "opal/mca/btl/btl.h"
48 #include "opal/mca/btl/base/base.h"
49 #include "opal/mca/mpool/mpool.h"
50 #include "opal/class/opal_hash_table.h"
51 #include "opal/util/fd.h"
52
53 #define MCA_BTL_TCP_STATISTICS 0
54 BEGIN_C_DECLS
55
56 extern opal_event_base_t* mca_btl_tcp_event_base;
57
58 #define MCA_BTL_TCP_COMPLETE_FRAG_SEND(frag) \
59 do { \
60 int btl_ownership = (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP); \
61 if( frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK ) { \
62 frag->base.des_cbfunc(&frag->endpoint->endpoint_btl->super, frag->endpoint, \
63 &frag->base, frag->rc); \
64 } \
65 if( btl_ownership ) { \
66 MCA_BTL_TCP_FRAG_RETURN(frag); \
67 } \
68 } while (0)
69 #define MCA_BTL_TCP_RECV_TRIGGER_CB(frag) \
70 do { \
71 if( MCA_BTL_TCP_HDR_TYPE_SEND == frag->hdr.type ) { \
72 mca_btl_active_message_callback_t* reg; \
73 reg = mca_btl_base_active_message_trigger + frag->hdr.base.tag; \
74 reg->cbfunc(&frag->endpoint->endpoint_btl->super, frag->hdr.base.tag, &frag->base, reg->cbdata); \
75 } \
76 } while (0)
77
78 extern opal_list_t mca_btl_tcp_ready_frag_pending_queue;
79 extern opal_mutex_t mca_btl_tcp_ready_frag_mutex;
80 extern int mca_btl_tcp_pipe_to_progress[2];
81 extern int mca_btl_tcp_progress_thread_trigger;
82
83 #define MCA_BTL_TCP_CRITICAL_SECTION_ENTER(name) \
84 opal_mutex_atomic_lock((name))
85 #define MCA_BTL_TCP_CRITICAL_SECTION_LEAVE(name) \
86 opal_mutex_atomic_unlock((name))
87
88 #define MCA_BTL_TCP_ACTIVATE_EVENT(event, value) \
89 do { \
90 if(0 < mca_btl_tcp_progress_thread_trigger) { \
91 opal_event_t* _event = (opal_event_t*)(event); \
92 (void) opal_fd_write( mca_btl_tcp_pipe_to_progress[1], sizeof(opal_event_t*), \
93 &_event); \
94 } \
95 else { \
96 opal_event_add(event, (value)); \
97 } \
98 } while (0)
99
100
101
102
103
104 struct mca_btl_tcp_component_t {
105 mca_btl_base_component_3_0_0_t super;
106 uint32_t tcp_addr_count;
107 uint32_t tcp_num_btls;
108 unsigned int tcp_num_links;
109 struct mca_btl_tcp_module_t **tcp_btls;
110 int tcp_free_list_num;
111 int tcp_free_list_max;
112 int tcp_free_list_inc;
113 int tcp_endpoint_cache;
114 opal_proc_table_t tcp_procs;
115 opal_mutex_t tcp_lock;
116 opal_list_t tcp_events;
117
118 opal_event_t tcp_recv_event;
119 int tcp_listen_sd;
120 unsigned short tcp_listen_port;
121 int tcp_port_min;
122 int tcp_port_range;
123 #if OPAL_ENABLE_IPV6
124 opal_event_t tcp6_recv_event;
125 int tcp6_listen_sd;
126 unsigned short tcp6_listen_port;
127 int tcp6_port_min;
128 int tcp6_port_range;
129 #endif
130
131
132 char* tcp_if_include;
133 char* tcp_if_exclude;
134 int tcp_sndbuf;
135 int tcp_rcvbuf;
136 int tcp_disable_family;
137
138
139 opal_free_list_t tcp_frag_eager;
140 opal_free_list_t tcp_frag_max;
141 opal_free_list_t tcp_frag_user;
142
143 int tcp_enable_progress_thread;
144
145 opal_event_t tcp_recv_thread_async_event;
146 opal_mutex_t tcp_frag_eager_mutex;
147 opal_mutex_t tcp_frag_max_mutex;
148 opal_mutex_t tcp_frag_user_mutex;
149
150 int tcp_not_use_nodelay;
151
152
153
154
155 bool report_all_unfound_interfaces;
156 };
157 typedef struct mca_btl_tcp_component_t mca_btl_tcp_component_t;
158
159 OPAL_MODULE_DECLSPEC extern mca_btl_tcp_component_t mca_btl_tcp_component;
160
161
162
163
164 struct mca_btl_tcp_module_t {
165 mca_btl_base_module_t super;
166 uint16_t tcp_ifkindex;
167 struct sockaddr_storage tcp_ifaddr;
168
169
170
171
172 uint32_t tcp_ifmask;
173
174 opal_mutex_t tcp_endpoints_mutex;
175 opal_list_t tcp_endpoints;
176
177 mca_btl_base_module_error_cb_fn_t tcp_error_cb;
178 #if MCA_BTL_TCP_STATISTICS
179 size_t tcp_bytes_sent;
180 size_t tcp_bytes_recv;
181 size_t tcp_send_handler;
182 #endif
183 };
184 typedef struct mca_btl_tcp_module_t mca_btl_tcp_module_t;
185 extern mca_btl_tcp_module_t mca_btl_tcp_module;
186
187 #define CLOSE_THE_SOCKET(socket) {(void)shutdown(socket, SHUT_RDWR); (void)close(socket);}
188
189
190
191
192
193
194
195
196 extern mca_btl_base_module_t** mca_btl_tcp_component_init(
197 int *num_btl_modules,
198 bool allow_multi_user_threads,
199 bool have_hidden_threads
200 );
201
202
203
204
205
206
207
208
209
210 extern int mca_btl_tcp_finalize(
211 struct mca_btl_base_module_t* btl
212 );
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227 extern int mca_btl_tcp_add_procs(
228 struct mca_btl_base_module_t* btl,
229 size_t nprocs,
230 struct opal_proc_t **procs,
231 struct mca_btl_base_endpoint_t** peers,
232 opal_bitmap_t* reachable
233 );
234
235
236
237
238
239
240
241
242
243
244
245
246 extern int mca_btl_tcp_del_procs(
247 struct mca_btl_base_module_t* btl,
248 size_t nprocs,
249 struct opal_proc_t **procs,
250 struct mca_btl_base_endpoint_t** peers
251 );
252
253
254
255
256
257
258
259
260
261
262
263 extern int mca_btl_tcp_send(
264 struct mca_btl_base_module_t* btl,
265 struct mca_btl_base_endpoint_t* btl_peer,
266 struct mca_btl_base_descriptor_t* descriptor,
267 mca_btl_base_tag_t tag
268 );
269
270
271
272
273
274
275 int mca_btl_tcp_put (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address,
276 uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
277 mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags,
278 int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata);
279
280
281
282
283
284
285 int mca_btl_tcp_get (mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint, void *local_address,
286 uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
287 mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags,
288 int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata);
289
290
291
292
293
294
295
296
297
298
299 extern mca_btl_base_descriptor_t* mca_btl_tcp_alloc(
300 struct mca_btl_base_module_t* btl,
301 struct mca_btl_base_endpoint_t* endpoint,
302 uint8_t order,
303 size_t size,
304 uint32_t flags);
305
306
307
308
309
310
311
312
313
314 extern int mca_btl_tcp_free(
315 struct mca_btl_base_module_t* btl,
316 mca_btl_base_descriptor_t* des);
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333 mca_btl_base_descriptor_t* mca_btl_tcp_prepare_src(
334 struct mca_btl_base_module_t* btl,
335 struct mca_btl_base_endpoint_t* peer,
336 struct opal_convertor_t* convertor,
337 uint8_t order,
338 size_t reserve,
339 size_t* size,
340 uint32_t flags
341 );
342
343 extern void
344 mca_btl_tcp_dump(struct mca_btl_base_module_t* btl,
345 struct mca_btl_base_endpoint_t* endpoint,
346 int verbose);
347
348
349
350
351
352
353 int mca_btl_tcp_ft_event(int state);
354
355
356
357
358
359
360 int mca_btl_tcp_send_blocking(int sd, const void* data, size_t size);
361
362
363
364
365
366
367
368
369
370
371 int mca_btl_tcp_recv_blocking(int sd, void* data, size_t size);
372
373 END_C_DECLS
374 #endif