root/opal/mca/btl/vader/btl_vader_get.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_btl_vader_get_xpmem
  2. mca_btl_vader_get_cma
  3. mca_btl_vader_get_knem
  4. mca_btl_vader_sc_emu_get_complete
  5. mca_btl_vader_get_sc_emu

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2010-2014 Los Alamos National Security, LLC. All rights
   4  *                         reserved.
   5  * Copyright (c) 2018      Research Organization for Information Science
   6  *                         and Technology (RIST).  All rights reserved.
   7  * $COPYRIGHT$
   8  *
   9  * Additional copyrights may follow
  10  *
  11  * $HEADER$
  12  */
  13 
  14 #include "opal_config.h"
  15 
  16 #include "btl_vader.h"
  17 #include "btl_vader_frag.h"
  18 #include "btl_vader_endpoint.h"
  19 #include "btl_vader_xpmem.h"
  20 
  21 #if OPAL_BTL_VADER_HAVE_CMA
  22 #include <sys/uio.h>
  23 
  24 #if OPAL_CMA_NEED_SYSCALL_DEFS
  25 #include "opal/sys/cma.h"
  26 #endif /* OPAL_CMA_NEED_SYSCALL_DEFS */
  27 
  28 
  29 #endif
  30 
  31 /**
  32  * Initiate an synchronous get.
  33  *
  34  * @param btl (IN)         BTL module
  35  * @param endpoint (IN)    BTL addressing information
  36  * @param descriptor (IN)  Description of the data to be transferred
  37  */
  38 #if OPAL_BTL_VADER_HAVE_XPMEM
  39 int mca_btl_vader_get_xpmem (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address,
  40                              uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
  41                              mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags,
  42                              int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
  43 {
  44     mca_rcache_base_registration_t *reg;
  45     void *rem_ptr;
  46 
  47     /* silence warning about unused arguments */
  48     (void) local_handle;
  49     (void) remote_handle;
  50 
  51     reg = vader_get_registation (endpoint, (void *)(intptr_t) remote_address, size, 0, &rem_ptr);
  52     if (OPAL_UNLIKELY(NULL == rem_ptr)) {
  53         return OPAL_ERROR;
  54     }
  55 
  56     vader_memmove (local_address, rem_ptr, size);
  57 
  58     vader_return_registration (reg, endpoint);
  59 
  60     /* always call the callback function */
  61     cbfunc (btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS);
  62 
  63     return OPAL_SUCCESS;
  64 }
  65 #endif
  66 
  67 #if OPAL_BTL_VADER_HAVE_CMA
  68 int mca_btl_vader_get_cma (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address,
  69                            uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
  70                            mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags,
  71                            int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
  72 {
  73     struct iovec src_iov = {.iov_base = (void *)(intptr_t) remote_address, .iov_len = size};
  74     struct iovec dst_iov = {.iov_base = local_address, .iov_len = size};
  75     ssize_t ret;
  76 
  77     /*
  78      * According to the man page :
  79      * "On success, process_vm_readv() returns the number of bytes read and
  80      * process_vm_writev() returns the number of bytes written.  This return
  81      * value may be less than the total number of requested bytes, if a
  82      * partial read/write occurred.  (Partial transfers apply at the
  83      * granularity of iovec elements.  These system calls won't perform a
  84      * partial transfer that splits a single iovec element.)".
  85      * So since we use a single iovec element, the returned size should either
  86      * be 0 or size, and the do loop should not be needed here.
  87      * We tried on various Linux kernels with size > 2 GB, and surprisingly,
  88      * the returned value is always 0x7ffff000 (fwiw, it happens to be the size
  89      * of the larger number of pages that fits a signed 32 bits integer).
  90      * We do not know whether this is a bug from the kernel, the libc or even
  91      * the man page, but for the time being, we do as is process_vm_readv() could
  92      * return any value.
  93      */
  94     do {
  95         ret = process_vm_readv (endpoint->segment_data.other.seg_ds->seg_cpid, &dst_iov, 1, &src_iov, 1, 0);
  96         if (0 > ret) {
  97             opal_output(0, "Read %ld, expected %lu, errno = %d\n", (long)ret, (unsigned long)size, errno);
  98             return OPAL_ERROR;
  99         }
 100         src_iov.iov_base = (void *)((char *)src_iov.iov_base + ret);
 101         src_iov.iov_len -= ret;
 102         dst_iov.iov_base = (void *)((char *)dst_iov.iov_base + ret);
 103         dst_iov.iov_len -= ret;
 104     } while (0 < src_iov.iov_len);
 105 
 106     /* always call the callback function */
 107     cbfunc (btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS);
 108 
 109     return OPAL_SUCCESS;
 110 }
 111 #endif
 112 
 113 #if OPAL_BTL_VADER_HAVE_KNEM
 114 int mca_btl_vader_get_knem (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address,
 115                             uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
 116                             mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags,
 117                             int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
 118 {
 119     struct knem_cmd_param_iovec recv_iovec;
 120     struct knem_cmd_inline_copy icopy;
 121 
 122     /* Fill in the ioctl data fields.  There's no async completion, so
 123        we don't need to worry about getting a slot, etc. */
 124     recv_iovec.base = (uintptr_t) local_address;
 125     recv_iovec.len = size;
 126     icopy.local_iovec_array = (uintptr_t) &recv_iovec;
 127     icopy.local_iovec_nr    = 1;
 128     icopy.remote_cookie     = remote_handle->cookie;
 129     icopy.remote_offset     = remote_address - remote_handle->base_addr;
 130     icopy.write             = 0;
 131     icopy.flags             = 0;
 132 
 133     /* Use the DMA flag if knem supports it *and* the segment length
 134      * is greater than the cutoff. Not that if DMA is not supported
 135      * or the user specified 0 for knem_dma_min the knem_dma_min was
 136      * set to UINT_MAX in mca_btl_vader_knem_init. */
 137     if (mca_btl_vader_component.knem_dma_min <= size) {
 138         icopy.flags = KNEM_FLAG_DMA;
 139     }
 140     /* synchronous flags only, no need to specify icopy.async_status_index */
 141 
 142     /* When the ioctl returns, the transfer is done and we can invoke
 143        the btl callback and return the frag */
 144     if (OPAL_UNLIKELY(0 != ioctl (mca_btl_vader.knem_fd, KNEM_CMD_INLINE_COPY, &icopy))) {
 145         return OPAL_ERROR;
 146     }
 147 
 148     if (KNEM_STATUS_FAILED == icopy.current_status) {
 149         return OPAL_ERROR;
 150     }
 151 
 152     /* always call the callback function */
 153     cbfunc (btl, endpoint, local_address, local_handle, cbcontext, cbdata, OPAL_SUCCESS);
 154 
 155     return OPAL_SUCCESS;
 156 }
 157 #endif
 158 
 159 static void mca_btl_vader_sc_emu_get_complete (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint,
 160                                                mca_btl_base_descriptor_t *desc, int status)
 161 {
 162     mca_btl_vader_frag_t *frag = (mca_btl_vader_frag_t *) desc;
 163     mca_btl_vader_sc_emu_hdr_t *hdr;
 164     void *local_address = frag->rdma.local_address;
 165     size_t len = frag->segments[0].seg_len - sizeof (*hdr);
 166     void *context = frag->rdma.context;
 167     void *cbdata = frag->rdma.cbdata;
 168     mca_btl_base_rdma_completion_fn_t cbfunc = frag->rdma.cbfunc;
 169     void *data;
 170 
 171     hdr = (mca_btl_vader_sc_emu_hdr_t *) frag->segments[0].seg_addr.pval;
 172     data = (void *) (hdr + 1);
 173 
 174     memcpy (local_address, data, len);
 175 
 176     /* return the fragment before calling the callback */
 177     MCA_BTL_VADER_FRAG_RETURN(frag);
 178 
 179     cbfunc (btl, endpoint, local_address, NULL, context, cbdata, status);
 180 }
 181 
 182 int mca_btl_vader_get_sc_emu (mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint, void *local_address,
 183                               uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
 184                               mca_btl_base_registration_handle_t *remote_handle, size_t size, int flags,
 185                               int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
 186 {
 187     mca_btl_vader_frag_t *frag;
 188 
 189     if (size > mca_btl_vader.super.btl_get_limit) {
 190         return OPAL_ERR_NOT_AVAILABLE;
 191     }
 192 
 193     frag = mca_btl_vader_rdma_frag_alloc (btl, endpoint, MCA_BTL_VADER_OP_GET, 0, 0, 0, order, flags, size,
 194                                           local_address, remote_address, cbfunc, cbcontext, cbdata,
 195                                           mca_btl_vader_sc_emu_get_complete);
 196     if (OPAL_UNLIKELY(NULL == frag)) {
 197         return OPAL_ERR_OUT_OF_RESOURCE;
 198     }
 199 
 200     /* send is always successful */
 201     (void) mca_btl_vader_send (btl, endpoint, &frag->base, MCA_BTL_TAG_VADER);
 202 
 203     return OPAL_SUCCESS;
 204 }

/* [<][>][^][v][top][bottom][index][help] */