3838#include <stdlib.h>
3939#include <string.h>
4040
41- # include <stdint.h>
41+ #include <stdint.h>
4242#ifdef HAVE_SCHED_H
43- # include <sched.h>
44- #endif /* HAVE_SCHED_H */
43+ # include <sched.h>
44+ #endif /* HAVE_SCHED_H */
4545#ifdef HAVE_UNISTD_H
46- # include <unistd.h>
46+ # include <unistd.h>
4747#endif /* HAVE_UNISTD_H */
4848
4949#include "opal/mca/shmem/base/base.h"
5050
51- #include "opal/class/opal_free_list.h"
52- #include "opal/sys/atomic.h"
53- #include "opal/mca/btl/btl.h"
54- #include "opal/mca/rcache/rcache.h"
55- #include "opal/mca/rcache/base/rcache_base_vma.h"
5651#include "opal/mca/btl/base/base.h"
57- #include "opal/mca/rcache/rcache.h"
58- #include "opal/mca/rcache/base/base.h"
5952#include "opal/mca/btl/base/btl_base_error.h"
53+ #include "opal/mca/btl/btl.h"
54+ #include "opal/mca/btl/sm/btl_sm_types.h"
6055#include "opal/mca/mpool/base/base.h"
56+ #include "opal/mca/rcache/base/base.h"
57+ #include "opal/mca/rcache/base/rcache_base_vma.h"
58+ #include "opal/mca/rcache/rcache.h"
59+ #include "opal/sys/atomic.h"
6160#include "opal/util/proc.h"
62- #include "btl_sm_endpoint.h"
6361
6462#include "opal/mca/pmix/pmix-internal.h"
6563
66- #include "btl_sm_xpmem.h"
6764#include "btl_sm_knem.h"
65+ #include "btl_sm_xpmem.h"
6866
6967BEGIN_C_DECLS
7068
71- #define min (a ,b ) ((a) < (b) ? (a) : (b))
69+ #define min (a , b ) ((a) < (b) ? (a) : (b))
7270
7371/*
7472 * Shared Memory resource managment
7573 */
7674
7775struct sm_fifo_t ;
7876
79- /*
80- * Modex data
81- */
82- union sm_modex_t {
83- #if OPAL_BTL_SM_HAVE_XPMEM
84- struct sm_modex_xpmem_t {
85- xpmem_segid_t seg_id ;
86- void * segment_base ;
87- uintptr_t address_max ;
88- } xpmem ;
89- #endif
90- struct sm_modex_other_t {
91- ino_t user_ns_id ;
92- int seg_ds_size ;
93- /* seg_ds needs to be the last element */
94- opal_shmem_ds_t seg_ds ;
95- } other ;
96- };
97-
98- /**
99- * Single copy mechanisms
100- */
101- enum {
102- MCA_BTL_SM_XPMEM = 0 ,
103- MCA_BTL_SM_CMA = 1 ,
104- MCA_BTL_SM_KNEM = 2 ,
105- MCA_BTL_SM_NONE = 3 ,
106- };
107-
108- /**
109- * Shared Memory (SM) BTL module.
110- */
111- struct mca_btl_sm_component_t {
112- mca_btl_base_component_3_0_0_t super ; /**< base BTL component */
113- int sm_free_list_num ; /**< initial size of free lists */
114- int sm_free_list_max ; /**< maximum size of free lists */
115- int sm_free_list_inc ; /**< number of elements to alloc when growing free lists */
116- #if OPAL_BTL_SM_HAVE_XPMEM
117- xpmem_segid_t my_seg_id ; /**< this rank's xpmem segment id */
118- uintptr_t my_address_max ; /**< largest address */
119- mca_rcache_base_vma_module_t * vma_module ; /**< registration cache for xpmem segments */
120- #endif
121- opal_shmem_ds_t seg_ds ; /**< this rank's shared memory segment (when not using xpmem) */
122-
123- opal_mutex_t lock ; /**< lock to protect concurrent updates to this structure's members */
124- char * my_segment ; /**< this rank's base pointer */
125- size_t segment_size ; /**< size of my_segment */
126- int32_t num_smp_procs ; /**< current number of smp procs on this host */
127- opal_free_list_t sm_frags_eager ; /**< free list of sm send frags */
128- opal_free_list_t sm_frags_max_send ; /**< free list of sm max send frags (large fragments) */
129- opal_free_list_t sm_frags_user ; /**< free list of small inline frags */
130- opal_free_list_t sm_fboxes ; /**< free list of available fast-boxes */
131-
132- unsigned int fbox_threshold ; /**< number of sends required before we setup a send fast box for a peer */
133- unsigned int fbox_max ; /**< maximum number of send fast boxes to allocate */
134- unsigned int fbox_size ; /**< size of each peer fast box allocation */
135-
136- int single_copy_mechanism ; /**< single copy mechanism to use */
137-
138- int memcpy_limit ; /**< Limit where we switch from memmove to memcpy */
139- int log_attach_align ; /**< Log of the alignment for xpmem segments */
140- unsigned int max_inline_send ; /**< Limit for copy-in-copy-out fragments */
141-
142- mca_btl_base_endpoint_t * endpoints ; /**< array of local endpoints (one for each local peer including myself) */
143- mca_btl_base_endpoint_t * * fbox_in_endpoints ; /**< array of fast box in endpoints */
144- unsigned int num_fbox_in_endpoints ; /**< number of fast boxes to poll */
145- struct sm_fifo_t * my_fifo ; /**< pointer to the local fifo */
146-
147- opal_list_t pending_endpoints ; /**< list of endpoints with pending fragments */
148- opal_list_t pending_fragments ; /**< fragments pending remote completion */
149-
150- char * backing_directory ; /**< directory to place shared memory backing files */
151-
152- /* knem stuff */
153- #if OPAL_BTL_SM_HAVE_KNEM
154- unsigned int knem_dma_min ; /**< minimum size to enable DMA for knem transfers (0 disables) */
155- #endif
156- mca_mpool_base_module_t * mpool ;
157- };
158- typedef struct mca_btl_sm_component_t mca_btl_sm_component_t ;
15977OPAL_MODULE_DECLSPEC extern mca_btl_sm_component_t mca_btl_sm_component ;
160-
161- /**
162- * SM BTL Interface
163- */
164- struct mca_btl_sm_t {
165- mca_btl_base_module_t super ; /**< base BTL interface */
166- bool btl_inited ; /**< flag indicating if btl has been inited */
167- mca_btl_base_module_error_cb_fn_t error_cb ;
168- #if OPAL_BTL_SM_HAVE_KNEM
169- int knem_fd ;
170-
171- /* registration cache */
172- mca_rcache_base_module_t * knem_rcache ;
173- #endif
174- };
175- typedef struct mca_btl_sm_t mca_btl_sm_t ;
17678OPAL_MODULE_DECLSPEC extern mca_btl_sm_t mca_btl_sm ;
17779
17880/* number of peers on the node (not including self) */
@@ -183,12 +85,12 @@ OPAL_MODULE_DECLSPEC extern mca_btl_sm_t mca_btl_sm;
18385
18486/* memcpy is faster at larger sizes but is undefined if the
18587 pointers are aliased (TODO -- readd alias check) */
186- static inline void sm_memmove (void * dst , void * src , size_t size )
88+ static inline void sm_memmove (void * dst , void * src , size_t size )
18789{
18890 if (size >= (size_t ) mca_btl_sm_component .memcpy_limit ) {
189- memcpy (dst , src , size );
91+ memcpy (dst , src , size );
19092 } else {
191- memmove (dst , src , size );
93+ memmove (dst , src , size );
19294 }
19395}
19496
@@ -198,24 +100,19 @@ static inline void sm_memmove (void *dst, void *src, size_t size)
198100 * @param btl (IN) BTL module
199101 * @param peer (IN) BTL peer addressing
200102 */
201- int mca_btl_sm_send (struct mca_btl_base_module_t * btl ,
202- struct mca_btl_base_endpoint_t * endpoint ,
203- struct mca_btl_base_descriptor_t * descriptor ,
204- mca_btl_base_tag_t tag );
103+ int mca_btl_sm_send (struct mca_btl_base_module_t * btl , struct mca_btl_base_endpoint_t * endpoint ,
104+ struct mca_btl_base_descriptor_t * descriptor , mca_btl_base_tag_t tag );
205105
206106/**
207107 * Initiate an inline send to the peer.
208108 *
209109 * @param btl (IN) BTL module
210110 * @param peer (IN) BTL peer addressing
211111 */
212- int mca_btl_sm_sendi (struct mca_btl_base_module_t * btl ,
213- struct mca_btl_base_endpoint_t * endpoint ,
214- struct opal_convertor_t * convertor ,
215- void * header , size_t header_size ,
216- size_t payload_size , uint8_t order ,
217- uint32_t flags , mca_btl_base_tag_t tag ,
218- mca_btl_base_descriptor_t * * descriptor );
112+ int mca_btl_sm_sendi (struct mca_btl_base_module_t * btl , struct mca_btl_base_endpoint_t * endpoint ,
113+ struct opal_convertor_t * convertor , void * header , size_t header_size ,
114+ size_t payload_size , uint8_t order , uint32_t flags , mca_btl_base_tag_t tag ,
115+ mca_btl_base_descriptor_t * * descriptor );
219116
220117/**
221118 * Initiate an synchronous put.
@@ -225,24 +122,30 @@ int mca_btl_sm_sendi (struct mca_btl_base_module_t *btl,
225122 * @param descriptor (IN) Description of the data to be transferred
226123 */
227124#if OPAL_BTL_SM_HAVE_XPMEM
228- int mca_btl_sm_put_xpmem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint , void * local_address ,
229- uint64_t remote_address , mca_btl_base_registration_handle_t * local_handle ,
230- mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
231- int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext , void * cbdata );
125+ int mca_btl_sm_put_xpmem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint ,
126+ void * local_address , uint64_t remote_address ,
127+ mca_btl_base_registration_handle_t * local_handle ,
128+ mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
129+ int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext ,
130+ void * cbdata );
232131#endif
233132
234133#if OPAL_BTL_SM_HAVE_CMA
235- int mca_btl_sm_put_cma (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint , void * local_address ,
236- uint64_t remote_address , mca_btl_base_registration_handle_t * local_handle ,
237- mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
238- int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext , void * cbdata );
134+ int mca_btl_sm_put_cma (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint ,
135+ void * local_address , uint64_t remote_address ,
136+ mca_btl_base_registration_handle_t * local_handle ,
137+ mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
138+ int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext ,
139+ void * cbdata );
239140#endif
240141
241142#if OPAL_BTL_SM_HAVE_KNEM
242- int mca_btl_sm_put_knem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint , void * local_address ,
243- uint64_t remote_address , mca_btl_base_registration_handle_t * local_handle ,
244- mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
245- int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext , void * cbdata );
143+ int mca_btl_sm_put_knem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint ,
144+ void * local_address , uint64_t remote_address ,
145+ mca_btl_base_registration_handle_t * local_handle ,
146+ mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
147+ int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext ,
148+ void * cbdata );
246149#endif
247150
248151/**
@@ -253,24 +156,30 @@ int mca_btl_sm_put_knem (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *en
253156 * @param descriptor (IN) Description of the data to be transferred
254157 */
255158#if OPAL_BTL_SM_HAVE_XPMEM
256- int mca_btl_sm_get_xpmem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint , void * local_address ,
257- uint64_t remote_address , mca_btl_base_registration_handle_t * local_handle ,
258- mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
259- int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext , void * cbdata );
159+ int mca_btl_sm_get_xpmem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint ,
160+ void * local_address , uint64_t remote_address ,
161+ mca_btl_base_registration_handle_t * local_handle ,
162+ mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
163+ int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext ,
164+ void * cbdata );
260165#endif
261166
262167#if OPAL_BTL_SM_HAVE_CMA
263- int mca_btl_sm_get_cma (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint , void * local_address ,
264- uint64_t remote_address , mca_btl_base_registration_handle_t * local_handle ,
265- mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
266- int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext , void * cbdata );
168+ int mca_btl_sm_get_cma (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint ,
169+ void * local_address , uint64_t remote_address ,
170+ mca_btl_base_registration_handle_t * local_handle ,
171+ mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
172+ int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext ,
173+ void * cbdata );
267174#endif
268175
269176#if OPAL_BTL_SM_HAVE_KNEM
270- int mca_btl_sm_get_knem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint , void * local_address ,
271- uint64_t remote_address , mca_btl_base_registration_handle_t * local_handle ,
272- mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
273- int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext , void * cbdata );
177+ int mca_btl_sm_get_knem (mca_btl_base_module_t * btl , mca_btl_base_endpoint_t * endpoint ,
178+ void * local_address , uint64_t remote_address ,
179+ mca_btl_base_registration_handle_t * local_handle ,
180+ mca_btl_base_registration_handle_t * remote_handle , size_t size , int flags ,
181+ int order , mca_btl_base_rdma_completion_fn_t cbfunc , void * cbcontext ,
182+ void * cbdata );
274183#endif
275184
276185ino_t mca_btl_sm_get_user_ns_id (void );
@@ -281,18 +190,17 @@ ino_t mca_btl_sm_get_user_ns_id(void);
281190 * @param btl (IN) BTL module
282191 * @param size (IN) Request segment size.
283192 */
284- mca_btl_base_descriptor_t * mca_btl_sm_alloc (struct mca_btl_base_module_t * btl ,
285- struct mca_btl_base_endpoint_t * endpoint ,
286- uint8_t order , size_t size , uint32_t flags );
193+ mca_btl_base_descriptor_t * mca_btl_sm_alloc (struct mca_btl_base_module_t * btl ,
194+ struct mca_btl_base_endpoint_t * endpoint , uint8_t order ,
195+ size_t size , uint32_t flags );
287196
288197/**
289198 * Return a segment allocated by this BTL.
290199 *
291200 * @param btl (IN) BTL module
292201 * @param segment (IN) Allocated segment.
293202 */
294- int mca_btl_sm_free (struct mca_btl_base_module_t * btl , mca_btl_base_descriptor_t * des );
295-
203+ int mca_btl_sm_free (struct mca_btl_base_module_t * btl , mca_btl_base_descriptor_t * des );
296204
297205END_C_DECLS
298206
0 commit comments