OpenMPI  0.1.1
mpool.h
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /**
3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
4  * University Research and Technology
5  * Corporation. All rights reserved.
6  * Copyright (c) 2004-2007 The University of Tennessee and The University
7  * of Tennessee Research Foundation. All rights
8  * reserved.
9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10  * University of Stuttgart. All rights reserved.
11  * Copyright (c) 2004-2005 The Regents of the University of California.
12  * All rights reserved.
13  * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
14  * Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
15  * $COPYRIGHT$
16  *
17  * Additional copyrights may follow
18  *
19  * $HEADER$
20  */
21 /**
22  * @file
23  * Description of the Memory Pool framework
24  */
25 #ifndef MCA_MPOOL_H
26 #define MCA_MPOOL_H
27 #include "ompi_config.h"
28 #include "opal/mca/mca.h"
29 #include "ompi/info/info.h"
30 #include "ompi/class/ompi_free_list.h"
31 
32 #include "opal/mca/crs/crs.h"
33 #include "opal/mca/crs/base/base.h"
34 
35 #define MCA_MPOOL_FLAGS_CACHE_BYPASS 0x1
36 #define MCA_MPOOL_FLAGS_PERSIST 0x2
37 #define MCA_MPOOL_FLAGS_MPI_ALLOC_MEM 0x4
38 #define MCA_MPOOL_FLAGS_INVALID 0x8
39 #define MCA_MPOOL_FLAGS_SO_MEM 0x10
40 #define MCA_MPOOL_FLAGS_CUDA_REGISTER_MEM 0x20
41 
43 
45  ompi_free_list_item_t super;
46  struct mca_mpool_base_module_t *mpool;
47  unsigned char* base;
48  unsigned char* bound;
49  unsigned char* alloc_base;
50  int32_t ref_count;
51  uint32_t flags;
52 };
53 
55 
57 
58 /**
59  * component initialize
60  */
61 typedef struct mca_mpool_base_module_t* (*mca_mpool_base_component_init_fn_t)(
63 
64 /**
65  * allocate function typedef
66  */
67 typedef void* (*mca_mpool_base_module_alloc_fn_t)(
68  struct mca_mpool_base_module_t* mpool,
69  size_t size,
70  size_t align,
71  uint32_t flags,
72  mca_mpool_base_registration_t** registration);
73 
74 /**
75  * realloc function typedef
76  */
77 typedef void* (*mca_mpool_base_module_realloc_fn_t)(
78  struct mca_mpool_base_module_t* mpool,
79  void* addr,
80  size_t size,
81  mca_mpool_base_registration_t** registration);
82 
83 /**
84  * free function typedef
85  */
87  struct mca_mpool_base_module_t* mpool,
88  void *addr,
89  mca_mpool_base_registration_t* registration);
90 
91 /**
92  * register memory
93  */
95  struct mca_mpool_base_module_t* mpool,
96  void * addr,
97  size_t size,
98  uint32_t flags,
99  mca_mpool_base_registration_t** registration);
100 
101 /**
102  * deregister memory
103  */
105  struct mca_mpool_base_module_t* mpool,
106  mca_mpool_base_registration_t* registration);
107 
108 /**
109  * find registration in this memory pool
110  */
111 
113  struct mca_mpool_base_module_t* mpool, void* addr, size_t size,
115 
116 /**
117  * release registration
118  */
119 
121  struct mca_mpool_base_module_t* mpool,
122  mca_mpool_base_registration_t* registration);
123 
124 
125 /**
126  * release memory region
127  */
129  struct mca_mpool_base_module_t* mpool, void *base, size_t size);
130 
131 /**
132  * if appropriate - returns base address of memory pool
133  */
134 typedef void* (*mca_mpool_base_module_address_fn_t)(struct mca_mpool_base_module_t* mpool);
135 
136 /**
137  * finalize
138  */
140 
141 
142 /**
143  * Fault Tolerance Event Notification Function
144  * @param state Checkpoint Stae
145  * @return OMPI_SUCCESS or failure status
146  */
147 typedef int (*mca_mpool_base_module_ft_event_fn_t)(int state);
148 
149 
150 /**
151  * mpool component descriptor. Contains component version information
152  * and open/close/init functions.
153  */
157 
159 };
160 /**
161  * Convenience typedef.
162  */
164 /**
165  * Convenience typedef
166  */
168 
169 /**
170  * mpool module descriptor. Contains the interface functions exported
171  * by the component. This does not expose memory management
172  * details.
173  */
175  mca_mpool_base_component_t *mpool_component; /**< component stuct */
176  mca_mpool_base_module_address_fn_t mpool_base; /**< returns the base address */
182  mca_mpool_base_module_find_fn_t mpool_find; /**< find regisrations in the cache */
183  mca_mpool_base_module_release_fn_t mpool_release; /**< release a registration from the cache */
184  mca_mpool_base_module_release_memory_fn_t mpool_release_memory; /**< release memor region from the cache */
187  struct mca_rcache_base_module_t *rcache; /* the rcache associated with this mpool */
188  uint32_t flags; /**< mpool flags */
189 };
190 /**
191  * Convenience typedef
192  */
194 
195 
196 /**
197  * Function to allocate special memory according to what the user requests in
198  * the info object.
199  *
200  * If the user passes in a valid info structure then the function will
201  * try to allocate the memory and register it with every mpool that there is a
202  * key for it in the info struct. If it fails at registering the memory with
203  * one of the requested mpools, an error will be returned. Also, if there is a
204  * key in info that does not match any mpool, an error will be returned.
205  *
206  * If the info parameter is MPI_INFO_NULL, then this function will try to allocate
207  * the memory and register it wih as many mpools as possible. However,
208  * if any of the registratons fail the mpool will simply be ignored.
209  *
210  * @param size the size of the memory area to allocate
211  * @param info an info object which tells us what kind of memory to allocate
212  *
213  * @retval pointer to the allocated memory
214  * @retval NULL on failure
215  */
216 OMPI_DECLSPEC void * mca_mpool_base_alloc(size_t size, struct ompi_info_t * info);
217 
218 /**
219  * Function to free memory previously allocated by mca_mpool_base_alloc
220  *
221  * @param base pointer to the memory to free
222  *
223  * @retval OMPI_SUCCESS
224  * @retval OMPI_ERR_BAD_PARAM if the passed base pointer was invalid
225  */
226 OMPI_DECLSPEC int mca_mpool_base_free(void * base);
227 
228 /**
229  * Function for the red black tree to compare 2 keys
230  *
231  * @param key1 a pointer to the 1st key
232  * @param key2 a pointer to the second key
233  *
234  * @retval -1 if key1 is below key2
235  * @retval 1 if key 1 is above key2
236  * @retval 0 if the keys are the same
237  */
238 OMPI_DECLSPEC int mca_mpool_base_tree_node_compare(void * key1, void * key2);
239 
240 
241 OMPI_DECLSPEC int mca_mpool_base_insert(
242  void * addr,
243  size_t size,
244  mca_mpool_base_module_t* mpool,
245  void* user_in,
246  mca_mpool_base_registration_t* registration);
247 
248 OMPI_DECLSPEC int mca_mpool_base_remove(void * base);
249 
250 /**
251  * Macro for use in components that are of type mpool
252  */
253 #define MCA_MPOOL_BASE_VERSION_2_0_0 \
254  MCA_BASE_VERSION_2_0_0, \
255  "mpool", 2, 0, 0
256 
257 #endif /* MCA_MPOOL_H */
258 
OMPI_DECLSPEC int mca_mpool_base_tree_node_compare(void *key1, void *key2)
Function for the red black tree to compare 2 keys.
Definition: mpool_base_tree.c:57
Common type for all MCA components.
Definition: mca.h:250
int(* mca_mpool_base_module_release_fn_t)(struct mca_mpool_base_module_t *mpool, mca_mpool_base_registration_t *registration)
release registration
Definition: mpool.h:120
rcache module descriptor
Definition: rcache.h:83
mca_base_component_t mpool_version
version
Definition: mpool.h:155
int(* mca_mpool_base_module_register_fn_t)(struct mca_mpool_base_module_t *mpool, void *addr, size_t size, uint32_t flags, mca_mpool_base_registration_t **registration)
register memory
Definition: mpool.h:94
struct mca_mpool_base_module_t *(* mca_mpool_base_component_init_fn_t)(struct mca_mpool_base_resources_t *)
component initialize
Definition: mpool.h:61
uint32_t flags
mpool flags
Definition: mpool.h:188
Definition: mpool.h:44
mpool component descriptor.
Definition: mpool.h:154
mca_mpool_base_module_find_fn_t mpool_find
find regisrations in the cache
Definition: mpool.h:182
mca_mpool_base_module_ft_event_fn_t mpool_ft_event
ft_event
Definition: mpool.h:186
Top-level interface for all MCA components.
Definition: info.h:38
void(* mca_mpool_base_module_finalize_fn_t)(struct mca_mpool_base_module_t *)
finalize
Definition: mpool.h:139
void *(* mca_mpool_base_module_address_fn_t)(struct mca_mpool_base_module_t *mpool)
if appropriate - returns base address of memory pool
Definition: mpool.h:134
mca_mpool_base_module_finalize_fn_t mpool_finalize
finalize
Definition: mpool.h:185
mca_mpool_base_module_release_memory_fn_t mpool_release_memory
release memor region from the cache
Definition: mpool.h:184
mca_mpool_base_module_free_fn_t mpool_free
free function
Definition: mpool.h:179
OMPI_DECLSPEC int mca_mpool_base_free(void *base)
Function to free memory previously allocated by mca_mpool_base_alloc.
Definition: mpool_base_alloc.c:275
mca_mpool_base_module_address_fn_t mpool_base
returns the base address
Definition: mpool.h:176
int(* mca_mpool_base_module_ft_event_fn_t)(int state)
Fault Tolerance Event Notification Function.
Definition: mpool.h:147
int(* mca_mpool_base_module_find_fn_t)(struct mca_mpool_base_module_t *mpool, void *addr, size_t size, mca_mpool_base_registration_t **reg)
find registration in this memory pool
Definition: mpool.h:112
int(* mca_mpool_base_module_deregister_fn_t)(struct mca_mpool_base_module_t *mpool, mca_mpool_base_registration_t *registration)
deregister memory
Definition: mpool.h:104
mca_mpool_base_module_register_fn_t mpool_register
register memory
Definition: mpool.h:180
mca_mpool_base_module_deregister_fn_t mpool_deregister
deregister memory
Definition: mpool.h:181
Definition: ompi_free_list.h:62
OMPI_DECLSPEC void * mca_mpool_base_alloc(size_t size, struct ompi_info_t *info)
Function to allocate special memory according to what the user requests in the info object...
Definition: mpool_base_alloc.c:97
void *(* mca_mpool_base_module_realloc_fn_t)(struct mca_mpool_base_module_t *mpool, void *addr, size_t size, mca_mpool_base_registration_t **registration)
realloc function typedef
Definition: mpool.h:77
Meta data for MCA v2.0.0 components.
Definition: mca.h:309
mca_mpool_base_module_realloc_fn_t mpool_realloc
reallocate function
Definition: mpool.h:178
mca_mpool_base_component_t * mpool_component
component stuct
Definition: mpool.h:175
mca_mpool_base_module_alloc_fn_t mpool_alloc
allocate function
Definition: mpool.h:177
mca_mpool_base_module_release_fn_t mpool_release
release a registration from the cache
Definition: mpool.h:183
void(* mca_mpool_base_module_free_fn_t)(struct mca_mpool_base_module_t *mpool, void *addr, mca_mpool_base_registration_t *registration)
free function typedef
Definition: mpool.h:86
void *(* mca_mpool_base_module_alloc_fn_t)(struct mca_mpool_base_module_t *mpool, size_t size, size_t align, uint32_t flags, mca_mpool_base_registration_t **registration)
allocate function typedef
Definition: mpool.h:67
mca_mpool_base_component_init_fn_t mpool_init
init function
Definition: mpool.h:158
Checkpoint and Restart Service (CRS) Interface.
mca_base_component_data_t mpool_data
metadata
Definition: mpool.h:156
int(* mca_mpool_base_module_release_memory_fn_t)(struct mca_mpool_base_module_t *mpool, void *base, size_t size)
release memory region
Definition: mpool.h:128
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236
Definition: mpool_fake.h:38
mpool module descriptor.
Definition: mpool.h:174