1
1
This commit was SVN r1639.
Этот коммит содержится в:
Tim Prins 2004-07-12 20:05:29 +00:00
родитель a7fb89d698
Коммит f4d9cea614
7 изменённых файлов: 126 добавлений и 90 удалений

Просмотреть файл

@ -2,31 +2,33 @@
* $HEADER$ * $HEADER$
*/ */
/** /**
* @file * @file
* The public definition of the MCA Allocator framework.
*/ */
#ifndef MCA_ALLOCATOR_H #ifndef MCA_ALLOCATOR_H
#define MCA_ALLOCATOR_H #define MCA_ALLOCATOR_H
#include "mca/mca.h" #include "mca/mca.h"
/* Here so that we can use mca_allocator_t in the function typedefs */
struct mca_allocator_t; struct mca_allocator_t;
/** /**
* allocate function typedef * The allocate function typedef for the functrion to be provided by the component.
*/ */
typedef void* (*mca_allocator_alloc_fn_t)(struct mca_allocator_t*, size_t size, size_t align); typedef void* (*mca_allocator_alloc_fn_t)(struct mca_allocator_t*, size_t size, size_t align);
/** /**
* realloc function typedef * The realloc function typedef
*/ */
typedef void* (*mca_allocator_realloc_fn_t)(struct mca_allocator_t*, void*, size_t); typedef void* (*mca_allocator_realloc_fn_t)(struct mca_allocator_t*, void*, size_t);
/** /**
* free function typedef * Free function typedef
*/ */
typedef void(*mca_allocator_free_fn_t)(struct mca_allocator_t*, void *); typedef void(*mca_allocator_free_fn_t)(struct mca_allocator_t*, void *);
/* /**
* compact/return memory to higher level allocator * compact/return memory to higher level allocator
*/ */
@ -35,7 +37,7 @@ typedef int (*mca_allocator_return_fn_t)(
); );
/* /**
* cleanup (free) any resources held by allocator * cleanup (free) any resources held by allocator
*/ */
@ -43,48 +45,63 @@ typedef int (*mca_allocator_finalize_fn_t)(
struct mca_allocator_t* allocator struct mca_allocator_t* allocator
); );
/**
* The data structure for each component.
*/
struct mca_allocator_t { struct mca_allocator_t {
mca_allocator_alloc_fn_t alc_alloc; mca_allocator_alloc_fn_t alc_alloc; /**< Allocate memory */
mca_allocator_realloc_fn_t alc_realloc; mca_allocator_realloc_fn_t alc_realloc; /**< Reallocate memory */
mca_allocator_free_fn_t alc_free; mca_allocator_free_fn_t alc_free; /**< Free memory */
mca_allocator_return_fn_t alc_return; mca_allocator_return_fn_t alc_return; /**< Return memory */
mca_allocator_finalize_fn_t alc_finalize; mca_allocator_finalize_fn_t alc_finalize; /**< Finalize and free everything */
}; };
/**
* Convenience typedef.
*/
typedef struct mca_allocator_t mca_allocator_t; typedef struct mca_allocator_t mca_allocator_t;
/** /**
* * A function to get more memory from the system. This function is to be
* provided by the module to the allocator framework.
*/ */
typedef void* (*mca_allocator_segment_alloc_fn_t)(size_t* size); typedef void* (*mca_allocator_segment_alloc_fn_t)(size_t* size);
/** /**
* * A function to free memory from the control of the allocator framework
* back to the system. This function is to be provided by the module to the
* allocator frmaework.
*/ */
typedef void* (*mca_allocator_segment_free_fn_t)(void* segment); typedef void* (*mca_allocator_segment_free_fn_t)(void* segment);
/** /**
* module initialization function * The function used to initialize the module.
*/ */
typedef struct mca_allocator_t* (*mca_allocator_base_module_init_fn_t)( typedef struct mca_allocator_t* (*mca_allocator_base_module_init_fn_t)(
bool *allow_multi_user_threads, bool *allow_multi_user_threads,
mca_allocator_segment_alloc_fn_t segment_alloc, mca_allocator_segment_alloc_fn_t segment_alloc,
mca_allocator_segment_free_fn_t segment_free mca_allocator_segment_free_fn_t segment_free
); );
/**
* The data structure provided by each component to the framework which
* describes the component.
*/
struct mca_allocator_base_module_1_0_0_t { struct mca_allocator_base_module_1_0_0_t {
mca_base_module_t allocator_version; mca_base_module_t allocator_version; /**< The version of the module */
mca_base_module_data_1_0_0_t allocator_data; mca_base_module_data_1_0_0_t allocator_data; /**< The module metadata */
mca_allocator_base_module_init_fn_t allocator_init; mca_allocator_base_module_init_fn_t allocator_init;
/**< The module initialization function. */
}; };
/**
* Convenience typedef.
*/
typedef struct mca_allocator_base_module_1_0_0_t mca_allocator_base_module_t; typedef struct mca_allocator_base_module_1_0_0_t mca_allocator_base_module_t;
/* /**
* Macro for use in modules that are of type ptl v1.0.0 * Macro for use in modules that are of type allocator v1.0.0
*/ */
#define MCA_ALLOCATOR_BASE_VERSION_1_0_0 \ #define MCA_ALLOCATOR_BASE_VERSION_1_0_0 \
/* mpool v1.0 is chained to MCA v1.0 */ \ /* mpool v1.0 is chained to MCA v1.0 */ \
@ -92,6 +109,9 @@ typedef struct mca_allocator_base_module_1_0_0_t mca_allocator_base_module_t;
/* ptl v1.0 */ \ /* ptl v1.0 */ \
"allocator", 1, 0, 0 "allocator", 1, 0, 0
/**
* The output integer used for the mca base
*/
extern int mca_allocator_base_output; extern int mca_allocator_base_output;
#endif /* MCA_ALLOCATOR_H */ #endif /* MCA_ALLOCATOR_H */

Просмотреть файл

@ -12,7 +12,11 @@
#include "mca/allocator/allocator.h" #include "mca/allocator/allocator.h"
#include "mca/allocator/base/base.h" #include "mca/allocator/base/base.h"
/**
* Closes all the remaining modules.
*
* @retval OMPI_SUCCESS
*/
int mca_allocator_base_close(void) int mca_allocator_base_close(void)
{ {
/* Close all remaining available modules (may be one if this is a /* Close all remaining available modules (may be one if this is a

Просмотреть файл

@ -38,7 +38,15 @@ int mca_allocator_base_open(void)
&mca_allocator_base_components); &mca_allocator_base_components);
} }
/**
* Traverses through the list of available modules, calling their init functions
* until it finds the module that has the specified name. It then returns the found
* module.
*
* @param name the name of the module that is being searched for.
* @retval mca_allocator_base_module_t* pointer to the requested module
* @retval NULL if the requested module is not found
*/
mca_allocator_base_module_t* mca_allocator_component_lookup(const char* name) mca_allocator_base_module_t* mca_allocator_component_lookup(const char* name)
{ {
/* Traverse the list of available modules; call their init functions. */ /* Traverse the list of available modules; call their init functions. */

Просмотреть файл

@ -13,19 +13,27 @@
#include "mca/mca.h" #include "mca/mca.h"
#include "mca/allocator/allocator.h" #include "mca/allocator/allocator.h"
/**
* Structure which describes a selected module.
*/
struct mca_allocator_base_selected_module_t { struct mca_allocator_base_selected_module_t {
ompi_list_item_t super; ompi_list_item_t super; /**< Makes this an object of type ompi_list_item */
mca_allocator_base_module_t *allocator_component; mca_allocator_base_module_t *allocator_component; /**< Info about the module */
mca_allocator_t *allocator_module; mca_allocator_t *allocator_module; /**< The function pointers for all the module's functions. */
}; };
/**
* Convenience typedef.
*/
typedef struct mca_allocator_base_selected_module_t mca_allocator_base_selected_module_t; typedef struct mca_allocator_base_selected_module_t mca_allocator_base_selected_module_t;
/**
* Declaces mca_mpool_base_selected_module_t as a class.
*/
OBJ_CLASS_DECLARATION(mca_mpool_base_selected_module_t); OBJ_CLASS_DECLARATION(mca_mpool_base_selected_module_t);
/* /*
* Global functions for MCA: overall PTL open and close * Global functions for MCA: overall allocator open and close
*/ */
#if defined(c_plusplus) || defined(__cplusplus) #if defined(c_plusplus) || defined(__cplusplus)
@ -42,7 +50,9 @@ extern "C" {
/* /*
* Globals * Globals
*/ */
/**
* The list of all the selected components.
*/
extern ompi_list_t mca_allocator_base_components; extern ompi_list_t mca_allocator_base_components;
#endif /* MCA_ALLOCATOR_BASE_H */ #endif /* MCA_ALLOCATOR_BASE_H */

Просмотреть файл

@ -3,9 +3,7 @@
*/ */
/** @file /** @file
* A generic memory allocator. * A generic memory bucket allocator.
*
*
**/ **/
#ifndef ALLOCATOR_BUCKET_ALLOC_H #ifndef ALLOCATOR_BUCKET_ALLOC_H
@ -18,26 +16,19 @@
#include "class/ompi_object.h" #include "class/ompi_object.h"
#include "mca/allocator/allocator.h" #include "mca/allocator/allocator.h"
/**
* Typedef so we can add a pointer to mca_allocator_bucket_chunk_header_t in
* mca_allocator_bucket_chunk_header_t
*/
typedef struct mca_allocator_bucket_chunk_header_t * mca_allocator_bucket_chunk_header_ptr_t;
/** /**
* Structure for the header of each memory chunk * Structure for the header of each memory chunk
*/ */
struct mca_allocator_bucket_chunk_header_t { struct mca_allocator_bucket_chunk_header_t {
mca_allocator_bucket_chunk_header_ptr_t next_in_segment; /**< The next chunk in the struct mca_allocator_bucket_chunk_header_t * next_in_segment;
memory segment */ /**< The next chunk in the memory segment */
/** /**
* Union which holds either a pointer to the next free chunk * Union which holds either a pointer to the next free chunk
* or the bucket number * or the bucket number
*/ */
union u { union u {
mca_allocator_bucket_chunk_header_ptr_t next_free; /**< if the chunk is free this struct mca_allocator_bucket_chunk_header_t * next_free;
will point to the next free /**< if the chunk is free this will point to the next free chunk in the bucket */
chunk in the bucket */
int bucket; /**< the bucket number it belongs to */ int bucket; /**< the bucket number it belongs to */
} u; /**< the union */ } u; /**< the union */
}; };
@ -46,17 +37,12 @@ struct mca_allocator_bucket_chunk_header_t {
*/ */
typedef struct mca_allocator_bucket_chunk_header_t mca_allocator_bucket_chunk_header_t; typedef struct mca_allocator_bucket_chunk_header_t mca_allocator_bucket_chunk_header_t;
/**
* Typedef so we can reference a pointer to mca_allocator_bucket_segment_head_t from itself
*/
typedef struct mca_allocator_bucket_segment_head_t * mca_allocator_bucket_segment_head_ptr;
/** /**
* Structure that heads each segment * Structure that heads each segment
*/ */
struct mca_allocator_bucket_segment_head_t { struct mca_allocator_bucket_segment_head_t {
mca_allocator_bucket_chunk_header_t * first_chunk; /**< the first chunk of the header */ struct mca_allocator_bucket_chunk_header_t * first_chunk; /**< the first chunk of the header */
mca_allocator_bucket_segment_head_ptr next_segment; /**< the next segment in the struct mca_allocator_bucket_segment_head_t * next_segment; /**< the next segment in the
bucket */ bucket */
}; };
/** /**
@ -81,13 +67,13 @@ typedef struct mca_allocator_bucket_bucket_t mca_allocator_bucket_bucket_t;
* Structure that holds the necessary information for each area of memory * Structure that holds the necessary information for each area of memory
*/ */
struct mca_allocator_bucket_t { struct mca_allocator_bucket_t {
mca_allocator_t super; mca_allocator_t super; /**< makes this a child of class mca_allocator_t */
mca_allocator_bucket_bucket_t * buckets; /**< the array of buckets */ mca_allocator_bucket_bucket_t * buckets; /**< the array of buckets */
int num_buckets; /**< the number of buckets */ int num_buckets; /**< the number of buckets */
mca_allocator_segment_alloc_fn_t get_mem_fn; /**< pointer to the function to get mca_allocator_segment_alloc_fn_t get_mem_fn;
more memory */ /**< pointer to the function to get more memory */
mca_allocator_segment_free_fn_t free_mem_fn; /**< pointer to the function to free mca_allocator_segment_free_fn_t free_mem_fn;
memory */ /**< pointer to the function to free memory */
}; };
/** /**
* Typedef so we don't have to use struct * Typedef so we don't have to use struct
@ -100,7 +86,8 @@ extern "C" {
/** /**
* Initializes the mca_allocator_bucket_options_t data structure for the passed * Initializes the mca_allocator_bucket_options_t data structure for the passed
* parameters. * parameters.
* @param numBuckets The number of buckets the allocator will use * @param mem a pointer to the mca_allocator_t struct to be filled in
* @param num_buckets The number of buckets the allocator will use
* @param get_mem_funct A pointer to the function that the allocator * @param get_mem_funct A pointer to the function that the allocator
* will use to get more memory * will use to get more memory
* @param free_mem_funct A pointer to the function that the allocator * @param free_mem_funct A pointer to the function that the allocator
@ -118,27 +105,24 @@ extern "C" {
* mca_allocator_bucket_options_t struct and returns a pointer to memory in that * mca_allocator_bucket_options_t struct and returns a pointer to memory in that
* region or NULL if there was an error * region or NULL if there was an error
* *
* @param mem_options A pointer to the appropriate struct for the area of * @param mem A pointer to the appropriate struct for the area of memory.
* memory.
* @param size The size of the requested area of memory * @param size The size of the requested area of memory
* *
* @retval Pointer to the area of memory if the allocation was successful * @retval Pointer to the area of memory if the allocation was successful
* @retval NULL if the allocation was unsuccessful * @retval NULL if the allocation was unsuccessful
*
*/ */
void * mca_allocator_bucket_alloc(mca_allocator_t * mem, size_t size); void * mca_allocator_bucket_alloc(mca_allocator_t * mem, size_t size);
/** /**
* Accepts a request for memory in a specific region defined by the * Accepts a request for memory in a specific region defined by the
* mca_allocator_bucket_options_t struct and aligned by the specified amount and returns a * mca_allocator_bucket_options_t struct and aligned by the specified amount and
* pointer to memory in that region or NULL if there was an error * returns a pointer to memory in that region or NULL if there was an error
* *
* @param mem_options A pointer to the appropriate struct for the area of * @param mem A pointer to the appropriate struct for the area of
* memory. * memory.
* @param size The size of the requested area of memory * @param size The size of the requested area of memory
* @param alignment The requested alignment of the new area of memory. This * @param alignment The requested alignment of the new area of memory. This
* MUST be a power of 2. If it is 0 then the memory is aligned on a page * MUST be a power of 2.
* boundry
* *
* @retval Pointer to the area of memory if the allocation was successful * @retval Pointer to the area of memory if the allocation was successful
* @retval NULL if the allocation was unsuccessful * @retval NULL if the allocation was unsuccessful
@ -152,7 +136,7 @@ extern "C" {
* region. If it is unsuccessful, it will return NULL and the passed area of * region. If it is unsuccessful, it will return NULL and the passed area of
* memory will be untouched. * memory will be untouched.
* *
* @param mem_options A pointer to the appropriate struct for the area of * @param mem A pointer to the appropriate struct for the area of
* memory. * memory.
* @param size The size of the requested area of memory * @param size The size of the requested area of memory
* @param ptr A pointer to the region of memory to be resized * @param ptr A pointer to the region of memory to be resized
@ -167,7 +151,7 @@ extern "C" {
/** /**
* Frees the passed region of memory * Frees the passed region of memory
* *
* @param mem_options A pointer to the appropriate struct for the area of * @param mem A pointer to the appropriate struct for the area of
* memory. * memory.
* @param ptr A pointer to the region of memory to be freed * @param ptr A pointer to the region of memory to be freed
* *
@ -181,7 +165,7 @@ extern "C" {
* this function only frees memory that was previously freed with * this function only frees memory that was previously freed with
* mca_allocator_bucket_free(). * mca_allocator_bucket_free().
* *
* @param mem_options A pointer to the appropriate struct for the area of * @param mem A pointer to the appropriate struct for the area of
* memory. * memory.
* *
* @retval None * @retval None
@ -192,7 +176,7 @@ extern "C" {
/** /**
* Cleanup all resources held by this allocator. * Cleanup all resources held by this allocator.
* *
* @param mem_options A pointer to the appropriate struct for the area of * @param mem A pointer to the appropriate struct for the area of
* memory. * memory.
* *
* @retval None * @retval None

Просмотреть файл

@ -24,7 +24,7 @@ typedef struct mca_mpool_base_selected_module_t mca_mpool_base_selected_module_t
OBJ_CLASS_DECLARATION(mca_mpool_base_selected_module_t); OBJ_CLASS_DECLARATION(mca_mpool_base_selected_module_t);
/* /*
* Global functions for MCA: overall PTL open and close * Global functions for MCA: overall mpool open and close
*/ */
#if defined(c_plusplus) || defined(__cplusplus) #if defined(c_plusplus) || defined(__cplusplus)

Просмотреть файл

@ -3,6 +3,7 @@
*/ */
/** /**
* @file * @file
* Description of the Memory Pool framework
*/ */
#ifndef MCA_MPOOL_H #ifndef MCA_MPOOL_H
#define MCA_MPOOL_H #define MCA_MPOOL_H
@ -53,40 +54,49 @@ typedef void (*mca_mpool_base_finalize_fn_t)(struct mca_mpool_t*);
/** /**
* mpool component descriptor. Contains component version information * initialize
* and open/close/init functions.
*/ */
typedef struct mca_mpool_t* (*mca_mpool_base_init_fn_t)(bool *allow_multi_user_threads); typedef struct mca_mpool_t* (*mca_mpool_base_init_fn_t)(bool *allow_multi_user_threads);
/**
* mpool component descriptor. Contains component version information
* and open/close/init functions.
*/
struct mca_mpool_base_component_1_0_0_t { struct mca_mpool_base_component_1_0_0_t {
mca_base_module_t mpool_version; mca_base_module_t mpool_version; /**< version */
mca_base_module_data_1_0_0_t mpool_data; mca_base_module_data_1_0_0_t mpool_data;/**< metadata */
mca_mpool_base_init_fn_t mpool_init; mca_mpool_base_init_fn_t mpool_init; /**< init function */
}; };
/**
* Convenience typedef.
*/
typedef struct mca_mpool_base_component_1_0_0_t mca_mpool_base_component_1_0_0_t; typedef struct mca_mpool_base_component_1_0_0_t mca_mpool_base_component_1_0_0_t;
/**
* Convenience typedef
*/
typedef struct mca_mpool_base_component_1_0_0_t mca_mpool_base_component_t; typedef struct mca_mpool_base_component_1_0_0_t mca_mpool_base_component_t;
/** /**
* mpool module descriptor. Contains functions exported * mpool module descriptor. Contains functions exported
* by the component. * by the component.
*/ */
struct mca_mpool_t { struct mca_mpool_t {
mca_mpool_base_component_t *mpool_component; mca_mpool_base_component_t *mpool_component; /**< component stuct */
mca_mpool_base_address_fn_t mpool_base; mca_mpool_base_address_fn_t mpool_base; /**< returns the base address */
mca_mpool_base_alloc_fn_t mpool_alloc; mca_mpool_base_alloc_fn_t mpool_alloc; /**< allocate function */
mca_mpool_base_realloc_fn_t mpool_realloc; mca_mpool_base_realloc_fn_t mpool_realloc; /**< reallocate function */
mca_mpool_base_free_fn_t mpool_free; mca_mpool_base_free_fn_t mpool_free; /**< free function */
mca_mpool_base_register_fn_t mpool_register; mca_mpool_base_register_fn_t mpool_register; /**< register memory */
mca_mpool_base_deregister_fn_t mpool_deregister; mca_mpool_base_deregister_fn_t mpool_deregister; /**< deregister memory */
mca_mpool_base_finalize_fn_t mpool_finalize; mca_mpool_base_finalize_fn_t mpool_finalize; /**< finalize */
}; };
/**
* Convenience typedef
*/
typedef struct mca_mpool_t mca_mpool_t; typedef struct mca_mpool_t mca_mpool_t;
/* /**
* Macro for use in modules that are of type ptl v1.0.0 * Macro for use in modules that are of type mpool v1.0.0
*/ */
#define MCA_MPOOL_BASE_VERSION_1_0_0 \ #define MCA_MPOOL_BASE_VERSION_1_0_0 \
/* mpool v1.0 is chained to MCA v1.0 */ \ /* mpool v1.0 is chained to MCA v1.0 */ \