Debian Codegraph @

src/mpid/ch3/channels/nemesis/include/mpidi_ch3_impl.h

raw
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #ifndef MPIDI_CH3_IMPL_H_INCLUDED
7 #define MPIDI_CH3_IMPL_H_INCLUDED
8
9 #include "mpidimpl.h"
10 #include "mpidu_generic_queue.h"
11 #include "utlist.h"
12
13 #if defined(HAVE_ASSERT_H)
14 #include <assert.h>
15 #endif
16
17 extern void *MPIDI_CH3_packet_buffer;
18 extern int MPIDI_CH3I_my_rank;
19
20 typedef GENERIC_Q_DECL(struct MPIR_Request) MPIDI_CH3I_shm_sendq_t;
21 extern MPIDI_CH3I_shm_sendq_t MPIDI_CH3I_shm_sendq;
22 extern struct MPIR_Request *MPIDI_CH3I_shm_active_send;
23
24 /* Send queue macros */
25 /* MT - not thread safe! */
26 #define MPIDI_CH3I_Sendq_empty(q) GENERIC_Q_EMPTY (q)
27 #define MPIDI_CH3I_Sendq_head(q) GENERIC_Q_HEAD (q)
28 #define MPIDI_CH3I_Sendq_enqueue(qp, ep) do { \
29 /* add refcount so req doesn't get freed before it's dequeued */ \
30 MPIR_Request_add_ref(ep); \
31 MPL_DBG_MSG_FMT(MPIDI_CH3_DBG_CHANNEL, VERBOSE, (MPL_DBG_FDEST, \
32 "MPIDI_CH3I_Sendq_enqueue req=%p (handle=%#x), queue=%p", \
33 ep, (ep)->handle, qp)); \
34 GENERIC_Q_ENQUEUE (qp, ep, next); \
35 } while (0)
36 #define MPIDI_CH3I_Sendq_dequeue(qp, ep) do { \
37 GENERIC_Q_DEQUEUE (qp, ep, next); \
38 MPL_DBG_MSG_FMT(MPIDI_CH3_DBG_CHANNEL, VERBOSE, (MPL_DBG_FDEST, \
39 "MPIDI_CH3I_Sendq_dequeuereq=%p (handle=%#x), queue=%p", \
40 *(ep), *(ep) ? (*(ep))->handle : -1, qp)); \
41 MPIR_Request_free(*(ep)); \
42 } while (0)
43 #define MPIDI_CH3I_Sendq_enqueue_multiple_no_refcount(qp, ep0, ep1) \
44 /* used to move reqs from one queue to another, so we don't update */ \
45 /* the refcounts */ \
46 GENERIC_Q_ENQUEUE_MULTIPLE(qp, ep0, ep1, next)
47
48 int MPIDI_CH3I_Shm_supported(void);
49 int MPIDI_CH3I_Progress_init(void);
50 int MPIDI_CH3I_Progress_finalize(void);
51 int MPIDI_CH3I_Shm_send_progress(void);
52 int MPIDI_CH3I_Complete_sendq_with_error(MPIDI_VC_t * vc);
53
54 int MPIDI_CH3I_SendNoncontig( MPIDI_VC_t *vc, MPIR_Request *sreq, void *header, intptr_t hdr_sz,
55 struct iovec *hdr_iov, int n_hdr_iov);
56
57 int MPID_nem_lmt_shm_initiate_lmt(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *rts_pkt, MPIR_Request *req);
58 int MPID_nem_lmt_shm_start_recv(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec s_cookie);
59 int MPID_nem_lmt_shm_start_send(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec r_cookie);
60 int MPID_nem_lmt_shm_handle_cookie(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec cookie);
61 int MPID_nem_lmt_shm_done_send(MPIDI_VC_t *vc, MPIR_Request *req);
62 int MPID_nem_lmt_shm_done_recv(MPIDI_VC_t *vc, MPIR_Request *req);
63 int MPID_nem_lmt_shm_vc_terminated(MPIDI_VC_t *vc);
64
65 int MPID_nem_lmt_dma_initiate_lmt(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *rts_pkt, MPIR_Request *req);
66 int MPID_nem_lmt_dma_start_recv(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec s_cookie);
67 int MPID_nem_lmt_dma_start_send(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec r_cookie);
68 int MPID_nem_lmt_dma_handle_cookie(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec cookie);
69 int MPID_nem_lmt_dma_done_send(MPIDI_VC_t *vc, MPIR_Request *req);
70 int MPID_nem_lmt_dma_done_recv(MPIDI_VC_t *vc, MPIR_Request *req);
71 int MPID_nem_lmt_dma_vc_terminated(MPIDI_VC_t *vc);
72
73 int MPID_nem_lmt_vmsplice_initiate_lmt(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *rts_pkt, MPIR_Request *req);
74 int MPID_nem_lmt_vmsplice_start_recv(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec s_cookie);
75 int MPID_nem_lmt_vmsplice_start_send(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec r_cookie);
76 int MPID_nem_lmt_vmsplice_handle_cookie(MPIDI_VC_t *vc, MPIR_Request *req, struct iovec cookie);
77 int MPID_nem_lmt_vmsplice_done_send(MPIDI_VC_t *vc, MPIR_Request *req);
78 int MPID_nem_lmt_vmsplice_done_recv(MPIDI_VC_t *vc, MPIR_Request *req);
79 int MPID_nem_lmt_vmsplice_vc_terminated(MPIDI_VC_t *vc);
80
81 int MPID_nem_handle_pkt(MPIDI_VC_t *vc, char *buf, intptr_t buflen);
82
83 /* Nemesis-provided RMA implementation */
84 int MPIDI_CH3_SHM_Win_shared_query(MPIR_Win *win_ptr, int target_rank, MPI_Aint *size, int *disp_unit, void *baseptr);
85 int MPIDI_CH3_SHM_Win_free(MPIR_Win **win_ptr);
86 int MPIDI_CH3_SHM_Init(void);
87 int MPIDI_CH3_SHM_Finalize(void);
88
89 /* Shared memory window atomic/accumulate mutex implementation */
90
91 #if !defined(HAVE_WINDOWS_H)
92 #define MPIDI_CH3I_SHM_MUTEX_LOCK(win_ptr) \
93 do { \
94 MPIR_AssertDeclValue(int pt_err, 0); \
95 pt_err = pthread_mutex_lock((win_ptr)->shm_mutex); \
96 MPIR_Assert(pt_err == 0); \
97 } while (0)
98
99 #define MPIDI_CH3I_SHM_MUTEX_UNLOCK(win_ptr) \
100 do { \
101 MPIR_AssertDeclValue(int pt_err, 0); \
102 pt_err = pthread_mutex_unlock((win_ptr)->shm_mutex); \
103 MPIR_Assert(pt_err == 0); \
104 } while (0)
105
106 #define MPIDI_CH3I_SHM_MUTEX_INIT(win_ptr) \
107 do { \
108 int pt_err; \
109 MPL_proc_mutex_create((win_ptr)->shm_mutex, &pt_err); \
110 MPIR_ERR_CHECK(pt_err); \
111 } while (0);
112
113 #define MPIDI_CH3I_SHM_MUTEX_DESTROY(win_ptr) \
114 do { \
115 int pt_err = pthread_mutex_destroy((win_ptr)->shm_mutex); \
116 MPIR_ERR_CHKANDJUMP1(pt_err, mpi_errno, MPI_ERR_OTHER, "**pthread_mutex", \
117 "**pthread_mutex %s", strerror(pt_err)); \
118 } while (0);
119
120 #define MPIDI_CH3I_SHM_MUTEX_DESTROY_DIRECT(shm_mutex) \
121 do { \
122 int pt_err = pthread_mutex_destroy(shm_mutex); \
123 MPIR_ERR_CHKANDJUMP1(pt_err, mpi_errno, MPI_ERR_OTHER, "**pthread_mutex", \
124 "**pthread_mutex %s", strerror(pt_err)); \
125 } while (0);
126 #else
127 #define HANDLE_WIN_MUTEX_ERROR() \
128 do { \
129 HLOCAL str; \
130 char error_msg[MPIR_STRERROR_BUF_SIZE]; \
131 DWORD error = GetLastError(); \
132 int num_bytes = FormatMessage( \
133 FORMAT_MESSAGE_FROM_SYSTEM | \
134 FORMAT_MESSAGE_ALLOCATE_BUFFER, \
135 0, \
136 error, \
137 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), \
138 (LPTSTR) &str, \
139 0,0); \
140 \
141 if (num_bytes != 0) { \
142 int pt_err = 1; \
143 int mpi_errno = MPI_ERR_OTHER; \
144 MPL_strncpy(error_msg, str, MPIR_STRERROR_BUF_SIZE); \
145 LocalFree(str); \
146 strtok(error_msg, "\r\n"); \
147 MPIR_ERR_CHKANDJUMP1(pt_err, mpi_errno, MPI_ERR_OTHER, "**windows_mutex", \
148 "**windows_mutex %s", error_msg); \
149 } \
150 } while (0);
151
152 #define MPIDI_CH3I_SHM_MUTEX_LOCK(win_ptr) \
153 do { \
154 DWORD result = WaitForSingleObject(*((win_ptr)->shm_mutex), INFINITE); \
155 if (result == WAIT_FAILED) { \
156 HANDLE_WIN_MUTEX_ERROR(); \
157 } \
158 } while (0);
159
160 #define MPIDI_CH3I_SHM_MUTEX_UNLOCK(win_ptr) \
161 do { \
162 BOOL result = ReleaseMutex(*((win_ptr)->shm_mutex)); \
163 if (!result) { \
164 HANDLE_WIN_MUTEX_ERROR(); \
165 } \
166 } while (0);
167
168 #define MPIDI_CH3I_SHM_MUTEX_INIT(win_ptr) \
169 do { \
170 *((win_ptr)->shm_mutex) = CreateMutex(NULL, FALSE, NULL); \
171 if (*((win_ptr)->shm_mutex) == NULL) { \
172 HANDLE_WIN_MUTEX_ERROR(); \
173 } \
174 } while (0);
175
176 #define MPIDI_CH3I_SHM_MUTEX_DESTROY(win_ptr) \
177 do { \
178 BOOL result = CloseHandle(*((win_ptr)->shm_mutex)); \
179 if (!result) { \
180 HANDLE_WIN_MUTEX_ERROR(); \
181 } \
182 } while (0);
183
184 #define MPIDI_CH3I_SHM_MUTEX_DESTROY_DIRECT(shm_mutex) \
185 do { \
186 BOOL result = CloseHandle(*(shm_mutex)); \
187 if (!result) { \
188 HANDLE_WIN_MUTEX_ERROR(); \
189 } \
190 } while (0);
191 #endif /* !defined(HAVE_WINDOWS_H) */
192
193
194 /* Starting of shared window list */
195
196 typedef struct MPIDI_SHM_Win {
197 struct MPIDI_SHM_Win *prev;
198 struct MPIDI_SHM_Win *next;
199 MPIR_Win *win;
200 } MPIDI_SHM_Win_t;
201
202 typedef MPIDI_SHM_Win_t *MPIDI_SHM_Wins_list_t;
203
204 extern MPIDI_SHM_Wins_list_t shm_wins_list;
205
206 #define MPIDI_SHM_Wins_next_and_continue(elem) {elem = elem->next; continue;}
207
208 static inline int MPIDI_CH3I_SHM_Wins_append(MPIDI_SHM_Wins_list_t * list, MPIR_Win * win)
209 {
210 int mpi_errno = MPI_SUCCESS;
211 MPIDI_SHM_Win_t *tmp_ptr;
212 MPIR_CHKPMEM_DECL();
213
214 /* FIXME: We should use a pool allocator here */
215 MPIR_CHKPMEM_MALLOC(tmp_ptr, sizeof(MPIDI_SHM_Win_t), MPL_MEM_SHM);
216
217 tmp_ptr->next = NULL;
218 tmp_ptr->win = win;
219
220 DL_APPEND(*list, tmp_ptr);
221
222 fn_exit:
223 MPIR_CHKPMEM_COMMIT();
224 return mpi_errno;
225 fn_fail:
226 MPIR_CHKPMEM_REAP();
227 goto fn_exit;
228 }
229
230 /* Unlink an element from the SHM window list
231 *
232 * @param IN list Pointer to the SHM window list
233 * @param IN elem Pointer to the element to be unlinked
234 */
235 static inline void MPIDI_CH3I_SHM_Wins_unlink(MPIDI_SHM_Wins_list_t * list, MPIR_Win * shm_win)
236 {
237 MPIDI_SHM_Win_t *elem = NULL;
238 MPIDI_SHM_Win_t *tmp_elem = NULL;
239
240 LL_SEARCH_SCALAR(*list, elem, win, shm_win);
241 if (elem != NULL) {
242 tmp_elem = elem;
243 DL_DELETE(*list, elem);
244 MPL_free(tmp_elem);
245 }
246 }
247
248 #endif /* MPIDI_CH3_IMPL_H_INCLUDED */