Debian Codegraph @

src/mpid/ch3/channels/nemesis/netmod/tcp/tcp_impl.h

raw
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #ifndef TCP_IMPL_H_INCLUDED
7 #define TCP_IMPL_H_INCLUDED
8
9 #include "mpid_nem_impl.h"
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #include <netinet/in.h>
13 #include <errno.h>
14 #include <netinet/tcp.h>
15 #include <netdb.h>
16 #include "socksm.h"
17
18 /* globals */
19 extern struct pollfd *MPID_nem_tcp_plfd_tbl;
20 extern sockconn_t MPID_nem_tcp_g_lstn_sc;
21 extern struct pollfd MPID_nem_tcp_g_lstn_plfd;
22
23 extern MPL_dbg_class MPIDI_NEM_TCP_DBG_DET;
24
25 typedef enum { MPID_NEM_TCP_VC_STATE_DISCONNECTED,
26 MPID_NEM_TCP_VC_STATE_CONNECTED,
27 MPID_NEM_TCP_VC_STATE_ERROR
28 } MPID_nem_tcp_vc_state_t;
29
30 #define MPIDI_NEM_TCP_MAX_CONNECT_RETRIES 100
31
32 typedef GENERIC_Q_DECL(struct MPIR_Request) MPIDI_nem_tcp_request_queue_t;
33
34 /* The vc provides a generic buffer in which network modules can store
35 private fields This removes all dependencies from the VC struction
36 on the network module, facilitating dynamic module loading. */
37 typedef struct {
38 struct sockaddr_in sock_id;
39 MPID_nem_tcp_vc_state_t state;
40 struct MPID_nem_new_tcp_sockconn *sc;
41 int send_paused;
42 MPIDI_nem_tcp_request_queue_t send_queue;
43 MPIDI_nem_tcp_request_queue_t paused_send_queue;
44 /* this is a count of how many sc objects refer to this vc */
45 int sc_ref_count;
46 int connect_retry_count; /* number of times we've tried to connect */
47 } MPID_nem_tcp_vc_area;
48
49 /* macro for tcp private in VC */
50 #define VC_TCP(vc) ((MPID_nem_tcp_vc_area *)vc->ch.netmod_area.padding)
51
52 #define ASSIGN_SC_TO_VC(vc_tcp_, sc_) do { \
53 (vc_tcp_)->sc = (sc_); \
54 } while (0)
55
56 /* functions */
57 int MPID_nem_tcp_init(MPIDI_PG_t * pg_p, int pg_rank, char **bc_val_p, int *val_max_sz_p);
58 int MPID_nem_tcp_finalize(void);
59
60 #ifdef ENABLE_CHECKPOINTING
61 int MPID_nem_tcp_ckpt_pause_send_vc(MPIDI_VC_t * vc);
62 int MPID_nem_tcp_ckpt_continue_vc(MPIDI_VC_t * vc);
63 int MPID_nem_tcp_ckpt_restart_vc(MPIDI_VC_t * vc);
64 int MPID_nem_tcp_ckpt_shutdown(void);
65 #endif
66
67 int MPID_nem_tcp_get_business_card(int my_rank, char **bc_val_p, int *val_max_sz_p);
68 int MPID_nem_tcp_connect_to_root(const char *business_card, MPIDI_VC_t * new_vc);
69 int MPID_nem_tcp_vc_init(MPIDI_VC_t * vc);
70 int MPID_nem_tcp_vc_destroy(MPIDI_VC_t * vc);
71 int MPID_nem_tcp_vc_terminate(MPIDI_VC_t * vc);
72
73 /* completion counter is atomically decremented when operation completes */
74 int MPID_nem_tcp_get(void *target_p, void *source_p, int source_node, int len, int *completion_ctr);
75 int MPID_nem_tcp_put(void *target_p, int target_node, void *source_p, int len, int *completion_ctr);
76
77 int MPID_nem_tcp_send_init(void);
78 int MPID_nem_tcp_connect(struct MPIDI_VC *const vc);
79 int MPID_nem_tcp_connpoll(int in_blocking_poll);
80 int MPID_nem_tcp_sm_init(void);
81 int MPID_nem_tcp_sm_finalize(void);
82 int MPID_nem_tcp_set_sockopts(int fd);
83 int MPID_nem_tcp_check_sock_status(const struct pollfd *const plfd);
84 int MPID_nem_tcp_send_finalize(void);
85 int MPID_nem_tcp_bind(int sockfd);
86 int MPID_nem_tcp_conn_est(MPIDI_VC_t * vc);
87 int MPID_nem_tcp_get_conninfo(struct MPIDI_VC *vc, struct sockaddr_in *addr, char **pg_id,
88 int *pg_rank);
89 int MPID_nem_tcp_get_vc_from_conninfo(char *pg_id, int pg_rank, struct MPIDI_VC **vc);
90 int MPID_nem_tcp_is_sock_connected(int fd);
91 int MPID_nem_tcp_disconnect(struct MPIDI_VC *const vc);
92 int MPID_nem_tcp_cleanup(struct MPIDI_VC *const vc);
93 int MPID_nem_tcp_cleanup_on_error(MPIDI_VC_t * const vc, int req_errno);
94 int MPID_nem_tcp_error_out_send_queue(struct MPIDI_VC *const vc, int req_errno);
95 int MPID_nem_tcp_ckpt_cleanup(void);
96 int MPID_nem_tcp_state_listening_handler(struct pollfd *const l_plfd, sockconn_t * const l_sc);
97 int MPID_nem_tcp_send_queued(MPIDI_VC_t * vc, MPIDI_nem_tcp_request_queue_t * send_queue);
98
99 int MPID_nem_tcp_iSendContig(MPIDI_VC_t * vc, MPIR_Request * sreq, void *hdr, intptr_t hdr_sz,
100 void *data, intptr_t data_sz);
101 int MPID_nem_tcp_iStartContigMsg(MPIDI_VC_t * vc, void *hdr, intptr_t hdr_sz, void *data,
102 intptr_t data_sz, MPIR_Request ** sreq_ptr);
103 int MPID_nem_tcp_iStartContigMsg_paused(MPIDI_VC_t * vc, void *hdr, intptr_t hdr_sz, void *data,
104 intptr_t data_sz, MPIR_Request ** sreq_ptr);
105 int MPID_nem_tcp_SendNoncontig(MPIDI_VC_t * vc, MPIR_Request * sreq, void *header, intptr_t hdr_sz,
106 struct iovec * hdr_iov, int n_hdr_iov);
107 int MPID_nem_tcp_iSendIov(MPIDI_VC_t * vc, MPIR_Request * sreq, void *hdr, intptr_t hdr_sz,
108 struct iovec * iov, int n_iov);
109 int MPID_nem_tcp_get_addr_port_from_bc(const char *business_card, struct in_addr *addr,
110 in_port_t * port);
111
112 void MPID_nem_tcp_vc_dbg_print_sendq(FILE * stream, MPIDI_VC_t * vc);
113
114 int MPID_nem_tcp_socksm_finalize(void);
115 int MPID_nem_tcp_socksm_init(void);
116 int MPID_nem_tcp_vc_terminated(MPIDI_VC_t * vc);
117 int MPID_nem_tcp_get_ordering(int *ordering);
118
119
120 int MPID_nem_tcp_pkt_unpause_handler(MPIDI_VC_t * vc, MPIDI_CH3_Pkt_t * pkt,
121 void *data ATTRIBUTE((unused)),
122 intptr_t * buflen, MPIR_Request ** rreqp);
123
124
125 /* Macros */
126
127 /* system call wrapper -- This retries the syscall each time it is interrupted.
128 Example usage: instead of writing "ret = write(fd, buf, len);"
129 use: "CHECK_EINTR(ret, write(fd, buf, len));
130 Caution:
131 (1) Some of the system calls have value-result parameters. Those system calls
132 should not be used within CHECK_EINTR macro or should be used with CARE.
133 For eg. accept, the last parameter (addrlen) is a value-result one. So, even if the
134 system call is interrupted, addrlen should be initialized to appropriate value before
135 calling it again.
136
137 (2) connect should not be called within a loop. In case, the connect is interrupted after
138 the TCP handshake is initiated, calling connect again will only fail. So, select/poll
139 should be called to check the status of the socket.
140 I don't know what will happen, if a connect is interrupted even before the system call
141 tries to initiate TCP handshake. No book/manual doesn't seem to explain this scenario.
142 */
143 #define CHECK_EINTR(var, func) do { \
144 (var) = (func); \
145 } while ((var) == -1 && errno == EINTR)
146
147 #define Q_EMPTY(q) GENERIC_Q_EMPTY (q)
148 #define Q_HEAD(q) GENERIC_Q_HEAD (q)
149 #define Q_ENQUEUE_EMPTY(qp, ep) GENERIC_Q_ENQUEUE_EMPTY (qp, ep, next)
150 #define Q_ENQUEUE(qp, ep) GENERIC_Q_ENQUEUE (qp, ep, next)
151 #define Q_ENQUEUE_EMPTY_MULTIPLE(qp, ep0, ep1) GENERIC_Q_ENQUEUE_EMPTY_MULTIPLE (qp, ep0, ep1, next)
152 #define Q_ENQUEUE_MULTIPLE(qp, ep0, ep1) GENERIC_Q_ENQUEUE_MULTIPLE (qp, ep0, ep1, next)
153 #define Q_DEQUEUE(qp, ep) GENERIC_Q_DEQUEUE (qp, ep, next)
154 #define Q_REMOVE_ELEMENTS(qp, ep0, ep1) GENERIC_Q_REMOVE_ELEMENTS (qp, ep0, ep1, next)
155
156
157 /* VC list macros */
158 #define VC_L_EMPTY(q) GENERIC_L_EMPTY (q)
159 #define VC_L_HEAD(q) GENERIC_L_HEAD (q)
160 #define SET_PLFD(vc_tcp) MPID_nem_tcp_plfd_tbl[(vc_tcp)->sc->index].events |= POLLOUT
161 #define UNSET_PLFD(vc_tcp) MPID_nem_tcp_plfd_tbl[(vc_tcp)->sc->index].events &= ~POLLOUT
162
163 /* stack macros */
164 #define S_EMPTY(s) GENERIC_S_EMPTY (s)
165 #define S_TOP(s) GENERIC_S_TOP (s)
166 #define S_PUSH(sp, ep) GENERIC_S_PUSH (sp, ep, next)
167 #define S_PUSH_MULTIPLE(sp, ep0, ep1) GENERIC_S_PUSH_MULTIPLE (sp, ep0, ep1, next)
168 #define S_POP(sp, ep) GENERIC_S_POP (sp, ep, next)
169
170 /* Keys for business cards */
171 #define MPIDI_CH3I_PORT_KEY "port"
172 #define MPIDI_CH3I_HOST_DESCRIPTION_KEY "description"
173 #define MPIDI_CH3I_IFNAME_KEY "ifname"
174
175
176
177 /* tcp-local packet types */
178
179 typedef enum MPIDI_nem_tcp_pkt_type {
180 #ifdef ENABLE_CHECKPOINTING
181 MPIDI_NEM_TCP_PKT_UNPAUSE,
182 #endif
183 MPIDI_NEM_TCP_PKT_NUM_TYPES,
184 MPIDI_NEM_TCP_PKT_INVALID = -1 /* force signed, to avoid warnings */
185 } MPIDI_nem_tcp_pkt_type_t;
186
187 #ifdef ENABLE_CHECKPOINTING
188 typedef struct MPIDI_nem_tcp_pkt_unpause {
189 MPIDI_CH3_Pkt_type_t type;
190 unsigned subtype;
191 } MPIDI_nem_tcp_pkt_unpause_t;
192 #endif
193
194
195
196 #endif /* TCP_IMPL_H_INCLUDED */