root/oshmem/mca/memheap/memheap.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. mca_memheap_base_mkey_is_shm
  2. mca_memheap_base_can_local_copy

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2013      Mellanox Technologies, Inc.
   4  *                         All rights reserved.
   5  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
   6  *                         reserved.
   7  * $COPYRIGHT$
   8  *
   9  * Additional copyrights may follow
  10  *
  11  * $HEADER$
  12  */
  13 
  14 #ifndef MCA_MEMHEAP_H
  15 #define MCA_MEMHEAP_H
  16 #include "oshmem/mca/mca.h"
  17 #include "oshmem/constants.h"
  18 #include "oshmem/proc/proc.h"
  19 
  20 #include "oshmem/mca/sshmem/sshmem.h"
  21 #include "oshmem/mca/spml/spml.h"
  22 
  23 
  24 BEGIN_C_DECLS
  25 struct mca_memheap_base_module_t;
  26 
  27 typedef struct memheap_context
  28 {
  29     void*   user_base_addr;
  30     void*   private_base_addr;
  31     size_t  user_size;
  32     size_t  private_size;
  33 } memheap_context_t;
  34 
  35 /**
  36  * Component initialize
  37  */
  38 typedef int (*mca_memheap_base_component_init_fn_t)(memheap_context_t *);
  39 
  40 /*
  41  * Symmetric heap allocation. Malloc like interface
  42  */
  43 typedef int (*mca_memheap_base_module_alloc_fn_t)(size_t, void**);
  44 
  45 typedef int (*mca_memheap_base_module_memalign_fn_t)(size_t align,
  46                                                      size_t size,
  47                                                      void**);
  48 
  49 typedef int (*mca_memheap_base_module_realloc_fn_t)(size_t newsize,
  50                                                     void *,
  51                                                     void **);
  52 
  53 /*
  54  * Symmetric heap free.
  55  */
  56 typedef int (*mca_memheap_base_module_free_fn_t)(void*);
  57 
  58 /**
  59  * Service functions
  60  */
  61 
  62 typedef sshmem_mkey_t * (*mca_memheap_base_module_get_local_mkey_fn_t)(void* va,
  63                                                                          int transport_id);
  64 
  65 /*
  66  * Symmetric heap destructor.
  67  */
  68 typedef int (*mca_memheap_base_module_finalize_fn_t)(void);
  69 
  70 typedef int (*mca_memheap_base_is_memheap_addr_fn_t)(const void* va);
  71 
  72 /* get mkeys from all ranks */
  73 typedef void (*mca_memheap_base_mkey_exchange_fn_t)(void);
  74 
  75 /*
  76  * memheap component descriptor. Contains component version, information and
  77  * init functions
  78  */
  79 struct mca_memheap_base_component_2_0_0_t {
  80     mca_base_component_t memheap_version; /**< version */
  81     mca_base_component_data_t memheap_data; /**< metadata */
  82     mca_memheap_base_component_init_fn_t memheap_init; /**<init function */
  83 };
  84 typedef struct mca_memheap_base_component_2_0_0_t mca_memheap_base_component_2_0_0_t;
  85 typedef struct mca_memheap_base_component_2_0_0_t mca_memheap_base_component_t;
  86 
  87 /**
  88  * memheap module descriptor
  89  */
  90 struct mca_memheap_base_module_t {
  91     mca_memheap_base_component_t                   *memheap_component;  /** Memory Heap Management Componenet */
  92     mca_memheap_base_module_finalize_fn_t           memheap_finalize;
  93     mca_memheap_base_module_alloc_fn_t              memheap_alloc;
  94     mca_memheap_base_module_memalign_fn_t           memheap_memalign;
  95     mca_memheap_base_module_realloc_fn_t            memheap_realloc;
  96     mca_memheap_base_module_free_fn_t               memheap_free;
  97 
  98     /*
  99      * alloc/free that should be used for internal allocation.
 100      * Internal memory does not count towards
 101      *  symmetric heap memory
 102      */
 103     mca_memheap_base_module_alloc_fn_t              memheap_private_alloc;
 104     mca_memheap_base_module_free_fn_t               memheap_private_free;
 105 
 106     mca_memheap_base_module_get_local_mkey_fn_t     memheap_get_local_mkey;
 107     mca_memheap_base_is_memheap_addr_fn_t           memheap_is_symmetric_addr;
 108     mca_memheap_base_mkey_exchange_fn_t             memheap_get_all_mkeys;
 109 
 110     /*
 111      * Total size of user available memheap
 112      */
 113     long                                            memheap_size;
 114 };
 115 
 116 typedef struct mca_memheap_base_module_t mca_memheap_base_module_t;
 117 
 118 /*
 119  * Macro for use in components that are of type rcache
 120  */
 121 #define MCA_MEMHEAP_BASE_VERSION_2_0_0 \
 122     OSHMEM_MCA_BASE_VERSION_2_1_0("memheap", 2, 0, 0)
 123 
 124 /*
 125  * macro for doing direct call / call through struct
 126  */
 127 #if MCA_oshmem_memheap_DIRECT_CALL
 128 
 129 #include MCA_oshmem_memheap_DIRECT_CALL_HEADER
 130 
 131 #define MCA_MEMHEAP_CALL_STAMP(a, b) mca_memheap_ ## a ## _ ## b
 132 #define MCA_MEMHEAP_CALL_EXPANDER(a, b) MCA_MEMHEAP_CALL_STAMP(a,b)
 133 #define MCA_MEMHEAP_CALL(a) MCA_MEMHEAP_CALL_EXPANDER(MCA_oshmem_memheap_DIRECT_CALL_COMPONENT, a)
 134 
 135 #else
 136 #define MCA_MEMHEAP_CALL(a) mca_memheap.memheap_ ## a
 137 #endif
 138 
 139 OSHMEM_DECLSPEC extern mca_memheap_base_module_t mca_memheap;
 140 
 141 int mca_memheap_alloc_with_hint(size_t size, long hint, void**);
 142 
 143 static inline int mca_memheap_base_mkey_is_shm(sshmem_mkey_t *mkey)
 144 {
 145     return (0 == mkey->len) && (MAP_SEGMENT_SHM_INVALID != (int)mkey->u.key);
 146 }
 147 
 148 /**
 149  * check if memcpy() can be used to copy data to dst_addr
 150  * must be memheap address and segment must be mapped
 151  */
 152 static inline int mca_memheap_base_can_local_copy(sshmem_mkey_t *mkey, void *dst_addr) {
 153     return mca_memheap.memheap_is_symmetric_addr(dst_addr) &&
 154         mca_memheap_base_mkey_is_shm(mkey);
 155 }
 156 
 157 
 158 END_C_DECLS
 159 
 160 #endif /* MCA_MEMHEAP_H */

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