root/ompi/mca/osc/rdma/osc_rdma_types.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ompi_osc_rdma_lock_add
  2. ompi_osc_rdma_lock_compare_exchange
  3. ompi_osc_rdma_lock_add
  4. ompi_osc_rdma_lock_compare_exchange

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2014-2018 Los Alamos National Security, LLC.  All rights
   4  *                         reserved.
   5  * $COPYRIGHT$
   6  *
   7  * Additional copyrights may follow
   8  *
   9  * $HEADER$
  10  */
  11 
  12 #ifndef OMPI_OSC_RDMA_TYPES_H
  13 #define OMPI_OSC_RDMA_TYPES_H
  14 
  15 #include "ompi_config.h"
  16 
  17 /* forward declarations of some other component types */
  18 struct ompi_osc_rdma_frag_t;
  19 struct ompi_osc_rdma_sync_t;
  20 struct ompi_osc_rdma_peer_t;
  21 
  22 #if OPAL_HAVE_ATOMIC_MATH_64
  23 
  24 typedef int64_t osc_rdma_base_t;
  25 typedef int64_t osc_rdma_size_t;
  26 typedef int64_t osc_rdma_counter_t;
  27 typedef opal_atomic_int64_t osc_rdma_atomic_counter_t;
  28 
  29 #define ompi_osc_rdma_counter_add opal_atomic_add_fetch_64
  30 
  31 #else
  32 
  33 typedef int32_t osc_rdma_base_t;
  34 typedef int32_t osc_rdma_size_t;
  35 typedef int32_t osc_rdma_counter_t;
  36 typedef opal_atomic_int32_t osc_rdma_atomic_counter_t;
  37 
  38 #define ompi_osc_rdma_counter_add opal_atomic_add_fetch_32
  39 
  40 #endif
  41 
  42 #if OPAL_HAVE_ATOMIC_MATH_64
  43 
  44 #define OMPI_OSC_RDMA_LOCK_EXCLUSIVE   0x8000000000000000l
  45 
  46 typedef int64_t  ompi_osc_rdma_lock_t;
  47 typedef opal_atomic_int64_t  ompi_osc_rdma_atomic_lock_t;
  48 
  49 static inline int64_t ompi_osc_rdma_lock_add (opal_atomic_int64_t *p, int64_t value)
  50 {
  51     int64_t new;
  52 
  53     opal_atomic_mb ();
  54     new = opal_atomic_add_fetch_64 (p, value) - value;
  55     opal_atomic_mb ();
  56 
  57     return new;
  58 }
  59 
  60 static inline int ompi_osc_rdma_lock_compare_exchange (opal_atomic_int64_t *p, int64_t *comp, int64_t value)
  61 {
  62     int ret;
  63 
  64     opal_atomic_mb ();
  65     ret = opal_atomic_compare_exchange_strong_64 (p, comp, value);
  66     opal_atomic_mb ();
  67 
  68     return ret;
  69 }
  70 
  71 #else
  72 
  73 #define OMPI_OSC_RDMA_LOCK_EXCLUSIVE 0x80000000l
  74 
  75 typedef int32_t  ompi_osc_rdma_lock_t;
  76 typedef opal_atomic_int32_t  ompi_osc_rdma_atomic_lock_t;
  77 
  78 static inline int32_t ompi_osc_rdma_lock_add (opal_atomic_int32_t *p, int32_t value)
  79 {
  80     int32_t new;
  81 
  82     opal_atomic_mb ();
  83     /* opal_atomic_add_fetch_32 differs from normal atomics in that is returns the new value */
  84     new = opal_atomic_add_fetch_32 (p, value) - value;
  85     opal_atomic_mb ();
  86 
  87     return new;
  88 }
  89 
  90 static inline int ompi_osc_rdma_lock_compare_exchange (opal_atomic_int32_t *p, int32_t *comp, int32_t value)
  91 {
  92     int ret;
  93 
  94     opal_atomic_mb ();
  95     ret = opal_atomic_compare_exchange_strong_32 (p, comp, value);
  96     opal_atomic_mb ();
  97 
  98     return ret;
  99 }
 100 
 101 #endif /* OPAL_HAVE_ATOMIC_MATH_64 */
 102 
 103 /**
 104  * @brief structure describing a window memory region
 105  */
 106 struct ompi_osc_rdma_region_t {
 107     /** base of the region */
 108     osc_rdma_base_t base;
 109     /** length (in bytes) of the region */
 110     osc_rdma_size_t len;
 111     /** BTL segment for the region (may be empty) */
 112     unsigned char   btl_handle_data[];
 113 };
 114 typedef struct ompi_osc_rdma_region_t ompi_osc_rdma_region_t;
 115 
 116 /**
 117  * @brief data handle for dynamic memory regions
 118  *
 119  * This structure holds the btl handle (if one exists) and the
 120  * reference count for a dynamically attached region. The reference
 121  * count is used to keep track of the number of times a memory
 122  * region associated with a page (or set of pages) has been attached.
 123  */
 124 struct ompi_osc_rdma_handle_t {
 125     /** btl handle for the memory region */
 126     mca_btl_base_registration_handle_t *btl_handle;
 127     /** number of attaches assocated with this region */
 128     int refcnt;
 129 };
 130 typedef struct ompi_osc_rdma_handle_t ompi_osc_rdma_handle_t;
 131 
 132 /**
 133  * @brief number of state buffers that can be used for storing
 134  *        post messages.
 135  *
 136  * This value was chosen because post exposure epochs are expected to be
 137  * small relative to the size of the communicator. The value is constant
 138  * and not exposed as an MCA variable to keep the layout of the
 139  * \ref ompi_osc_rdma_state_t structure simple.
 140  */
 141 #define OMPI_OSC_RDMA_POST_PEER_MAX 32
 142 
 143 /**
 144  * @brief window state structure
 145  *
 146  * This structure holds the information relevant to the window state
 147  * of a peer. The structure synchronization data and includes useful
 148  * information that can be remotely read by other peers in the window.
 149  */
 150 struct ompi_osc_rdma_state_t {
 151     /** used when rdma is in use to handle excusive locks and global shared locks (lock_all) */
 152     ompi_osc_rdma_lock_t global_lock;
 153     /** lock state for this node. the top bit indicates if a exclusive lock exists and the
 154      * remaining bits count the number of shared locks */
 155     ompi_osc_rdma_lock_t local_lock;
 156     /** lock for the accumulate state to ensure ordering and consistency */
 157     ompi_osc_rdma_lock_t accumulate_lock;
 158     /** current index to post to. compare-and-swap must be used to ensure
 159      * the index is free */
 160     osc_rdma_counter_t post_index;
 161     /** post buffers */
 162     osc_rdma_counter_t post_peers[OMPI_OSC_RDMA_POST_PEER_MAX];
 163     /** counter for number of post messages received  */
 164     osc_rdma_atomic_counter_t num_post_msgs;
 165     /** counter for number of complete messages received */
 166     osc_rdma_counter_t num_complete_msgs;
 167     /** lock for the region state to ensure consistency */
 168     ompi_osc_rdma_lock_t regions_lock;
 169     /** displacement unit for this process */
 170     int64_t            disp_unit;
 171     /** number of attached regions. this count will be 1 in non-dynamic regions */
 172     osc_rdma_counter_t region_count;
 173     /** attached memory regions */
 174     unsigned char      regions[];
 175 };
 176 typedef struct ompi_osc_rdma_state_t ompi_osc_rdma_state_t;
 177 
 178 typedef void (*ompi_osc_rdma_pending_op_cb_fn_t) (void *, void *, int);
 179 
 180 struct ompi_osc_rdma_pending_op_t {
 181     opal_list_item_t super;
 182     struct ompi_osc_rdma_module_t *module;
 183     struct ompi_osc_rdma_frag_t *op_frag;
 184     void *op_buffer;
 185     void *op_result;
 186     size_t op_size;
 187     volatile bool op_complete;
 188     ompi_osc_rdma_pending_op_cb_fn_t cbfunc;
 189     void *cbdata;
 190     void *cbcontext;
 191 };
 192 
 193 typedef struct ompi_osc_rdma_pending_op_t ompi_osc_rdma_pending_op_t;
 194 
 195 OBJ_CLASS_DECLARATION(ompi_osc_rdma_pending_op_t);
 196 
 197 /** Communication buffer for packing messages */
 198 struct ompi_osc_rdma_frag_t {
 199     opal_free_list_item_t super;
 200 
 201     /* Number of operations which have started writing into the frag, but not yet completed doing so */
 202     opal_atomic_int32_t pending;
 203 #if OPAL_HAVE_ATOMIC_MATH_64
 204     opal_atomic_int64_t curr_index;
 205 #else
 206     opal_atomic_int32_t curr_index;
 207 #endif
 208 
 209     struct ompi_osc_rdma_module_t *module;
 210     mca_btl_base_registration_handle_t *handle;
 211 };
 212 typedef struct ompi_osc_rdma_frag_t ompi_osc_rdma_frag_t;
 213 OBJ_CLASS_DECLARATION(ompi_osc_rdma_frag_t);
 214 
 215 #define OSC_RDMA_VERBOSE(x, ...) OPAL_OUTPUT_VERBOSE((x, ompi_osc_base_framework.framework_output, __VA_ARGS__))
 216 
 217 #endif /* OMPI_OSC_RDMA_TYPES_H */

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