This source file includes following definitions.
- ompi_osc_rdma_frag_complete
- ompi_osc_rdma_frag_alloc
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 #ifndef OSC_RDMA_FRAG_H
  14 #define OSC_RDMA_FRAG_H
  15 
  16 #include "osc_rdma.h"
  17 #include "opal/align.h"
  18 
  19 static inline void ompi_osc_rdma_frag_complete (ompi_osc_rdma_frag_t *frag)
  20 {
  21     OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "returning frag. pending = %d", frag->pending);
  22     if (0 == OPAL_THREAD_ADD_FETCH32(&frag->pending, -1)) {
  23         opal_atomic_rmb ();
  24 
  25         (void) opal_atomic_swap_32 (&frag->pending, 1);
  26 #if OPAL_HAVE_ATOMIC_MATH_64
  27         (void) opal_atomic_swap_64 (&frag->curr_index, 0);
  28 #else
  29         (void) opal_atomic_swap_32 (&frag->curr_index, 0);
  30 #endif
  31     }
  32 }
  33 
  34 
  35 
  36 
  37 static inline int ompi_osc_rdma_frag_alloc (ompi_osc_rdma_module_t *module, size_t request_len,
  38                                             ompi_osc_rdma_frag_t **buffer, char **ptr)
  39 {
  40     ompi_osc_rdma_frag_t *curr = module->rdma_frag;
  41     int64_t my_index;
  42     int ret;
  43 
  44     
  45     request_len = OPAL_ALIGN(request_len, 8, size_t);
  46 
  47     if (request_len > (mca_osc_rdma_component.buffer_size >> 1)) {
  48         return OMPI_ERR_VALUE_OUT_OF_BOUNDS;
  49     }
  50 
  51     if (NULL == curr) {
  52         opal_free_list_item_t *item = NULL;
  53 
  54         item = opal_free_list_get (&mca_osc_rdma_component.frags);
  55         if (OPAL_UNLIKELY(NULL == item)) {
  56             OPAL_THREAD_UNLOCK(&module->lock);
  57             return OMPI_ERR_OUT_OF_RESOURCE;
  58         }
  59 
  60         curr = (ompi_osc_rdma_frag_t *) item;
  61 
  62         curr->handle = NULL;
  63         curr->pending = 1;
  64         curr->module = module;
  65         curr->curr_index = 0;
  66 
  67         if (module->selected_btl->btl_register_mem) {
  68             ret = ompi_osc_rdma_register (module, MCA_BTL_ENDPOINT_ANY, curr->super.ptr, mca_osc_rdma_component.buffer_size,
  69                                           MCA_BTL_REG_FLAG_ACCESS_ANY, &curr->handle);
  70             if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
  71                 return OMPI_ERR_OUT_OF_RESOURCE;
  72             }
  73         }
  74 
  75         if (!opal_atomic_compare_exchange_strong_ptr ((opal_atomic_intptr_t *) &module->rdma_frag, &(intptr_t){0}, (intptr_t) curr)) {
  76             ompi_osc_rdma_deregister (module, curr->handle);
  77             curr->handle = NULL;
  78 
  79             opal_free_list_return (&mca_osc_rdma_component.frags, &curr->super);
  80 
  81             curr = module->rdma_frag;
  82         }
  83     }
  84 
  85     OSC_RDMA_VERBOSE(MCA_BASE_VERBOSE_INFO, "allocating frag. pending = %d", curr->pending);
  86     OPAL_THREAD_ADD_FETCH32(&curr->pending, 1);
  87 
  88 #if OPAL_HAVE_ATOMIC_MATH_64
  89     my_index = opal_atomic_fetch_add_64 (&curr->curr_index, request_len);
  90 #else
  91     my_index = opal_atomic_fetch_add_32 (&curr->curr_index, request_len);
  92 #endif
  93     if (my_index + request_len > mca_osc_rdma_component.buffer_size) {
  94         if (my_index <= mca_osc_rdma_component.buffer_size) {
  95             
  96             ompi_osc_rdma_frag_complete (curr);
  97         }
  98         ompi_osc_rdma_frag_complete (curr);
  99         return OPAL_ERR_OUT_OF_RESOURCE;
 100     }
 101 
 102     *ptr = (void *) ((intptr_t) curr->super.ptr + my_index);
 103     *buffer = curr;
 104 
 105     return OMPI_SUCCESS;
 106 }
 107 
 108 #endif