fix a bug, so that the fifo size is rounded up to a power of 2.
Add some support code to determine nearest power of 2. This commit was SVN r2170.
Этот коммит содержится в:
родитель
2db94bb016
Коммит
f75b88faa5
@ -9,6 +9,7 @@
|
|||||||
#include "include/sys/cache.h"
|
#include "include/sys/cache.h"
|
||||||
#include "os/atomic.h"
|
#include "os/atomic.h"
|
||||||
#include "mca/mpool/mpool.h"
|
#include "mca/mpool/mpool.h"
|
||||||
|
#include "util/pow2.h"
|
||||||
|
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
@ -102,22 +103,21 @@ static inline int ompi_cb_fifo_init(int size_of_fifo, int lazy_free_freq,
|
|||||||
mca_mpool_base_module_t *memory_allocator)
|
mca_mpool_base_module_t *memory_allocator)
|
||||||
{
|
{
|
||||||
|
|
||||||
int tmp_size, errorCode = OMPI_SUCCESS;
|
int errorCode = OMPI_SUCCESS,i;
|
||||||
size_t len_to_allocate,i;
|
size_t len_to_allocate;
|
||||||
|
|
||||||
/* verify that size is power of 2, and greatter that 0 - if not,
|
/* verify that size is power of 2, and greatter that 0 - if not,
|
||||||
* round up */
|
* round up */
|
||||||
if ( 0 >= size_of_fifo) {
|
if ( 0 >= size_of_fifo) {
|
||||||
return OMPI_ERROR;
|
return OMPI_ERROR;
|
||||||
}
|
}
|
||||||
tmp_size/=2;
|
|
||||||
tmp_size*=2;
|
|
||||||
if( tmp_size != size_of_fifo ) {
|
|
||||||
size_of_fifo=2*tmp_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set fifo size */
|
/* set fifo size */
|
||||||
fifo->size = size_of_fifo;
|
fifo->size = ompi_round_up_to_nearest_pow2(size_of_fifo);
|
||||||
|
/* debug */
|
||||||
|
fprintf(stderr," BBB lazy %d size %d\n",lazy_free_freq,fifo->size);
|
||||||
|
fflush(stderr);
|
||||||
|
/* end debug */
|
||||||
|
|
||||||
/* set lazy free frequence */
|
/* set lazy free frequence */
|
||||||
if( ( 0 >= lazy_free_freq ) ||
|
if( ( 0 >= lazy_free_freq ) ||
|
||||||
@ -130,6 +130,10 @@ static inline int ompi_cb_fifo_init(int size_of_fifo, int lazy_free_freq,
|
|||||||
* and use the & operator for the wrap-around */
|
* and use the & operator for the wrap-around */
|
||||||
fifo->mask = (size_of_fifo - 1);
|
fifo->mask = (size_of_fifo - 1);
|
||||||
|
|
||||||
|
/* debug */
|
||||||
|
fprintf(stderr," AAA \n");
|
||||||
|
fflush(stderr);
|
||||||
|
/* end debug */
|
||||||
/* allocate fifo array */
|
/* allocate fifo array */
|
||||||
len_to_allocate = sizeof(void *) * size_of_fifo;
|
len_to_allocate = sizeof(void *) * size_of_fifo;
|
||||||
fifo->queue=memory_allocator->mpool_alloc(len_to_allocate,CACHE_LINE_SIZE);
|
fifo->queue=memory_allocator->mpool_alloc(len_to_allocate,CACHE_LINE_SIZE);
|
||||||
@ -170,6 +174,45 @@ static inline int ompi_cb_fifo_init(int size_of_fifo, int lazy_free_freq,
|
|||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function to cleanup the fifo
|
||||||
|
*
|
||||||
|
* @param fifo Pointer to data structure defining this fifo (IN)
|
||||||
|
*
|
||||||
|
* @param memory_allocator Pointer to the memory allocator to use
|
||||||
|
* to allocate memory for this fifo. (IN)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static inline int ompi_cb_fifo_free( ompi_cb_fifo_t *fifo,
|
||||||
|
mca_mpool_base_module_t *memory_allocator)
|
||||||
|
{
|
||||||
|
|
||||||
|
int errorCode = OMPI_SUCCESS;
|
||||||
|
|
||||||
|
/* make sure null fifo is not passed in */
|
||||||
|
if ( NULL == fifo) {
|
||||||
|
return OMPI_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free fifo array */
|
||||||
|
if( NULL != fifo->queue){
|
||||||
|
memory_allocator->mpool_free(fifo->queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free head control structure */
|
||||||
|
if( NULL != fifo->head) {
|
||||||
|
memory_allocator->mpool_free(fifo->head);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free tail control structure */
|
||||||
|
if( NULL != fifo->tail) {
|
||||||
|
memory_allocator->mpool_free(fifo->tail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* return */
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write pointer to the specified slot
|
* Write pointer to the specified slot
|
||||||
|
@ -79,8 +79,9 @@ 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_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 the interface functions exported
|
||||||
* by the component.
|
* by the component. This does not expose memory management
|
||||||
|
* details.
|
||||||
*/
|
*/
|
||||||
struct mca_mpool_base_module_t {
|
struct mca_mpool_base_module_t {
|
||||||
mca_mpool_base_component_t *mpool_component; /**< component stuct */
|
mca_mpool_base_component_t *mpool_component; /**< component stuct */
|
||||||
|
@ -26,6 +26,7 @@ headers = \
|
|||||||
proc_info.h \
|
proc_info.h \
|
||||||
os_path.h \
|
os_path.h \
|
||||||
os_create_dirpath.h \
|
os_create_dirpath.h \
|
||||||
|
pow2.h \
|
||||||
session_dir.h \
|
session_dir.h \
|
||||||
strncpy.h
|
strncpy.h
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ libutil_la_SOURCES = \
|
|||||||
sys_info.c \
|
sys_info.c \
|
||||||
os_path.c \
|
os_path.c \
|
||||||
os_create_dirpath.c \
|
os_create_dirpath.c \
|
||||||
|
pow2.c \
|
||||||
session_dir.c \
|
session_dir.c \
|
||||||
strncpy.c
|
strncpy.c
|
||||||
|
|
||||||
|
42
src/util/pow2.c
Обычный файл
42
src/util/pow2.c
Обычный файл
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* $HEADER$
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine takes in an interger, and returns the nearest
|
||||||
|
* power of 2 integer, same or greater than the input.
|
||||||
|
*
|
||||||
|
* @param input_integer input value
|
||||||
|
*
|
||||||
|
* @returnvalue power of 2 integer same or greater than the input
|
||||||
|
* parameter.
|
||||||
|
*/
|
||||||
|
int ompi_round_up_to_nearest_pow2(int input_integer)
|
||||||
|
{
|
||||||
|
int pop_count, highest_used_bit, tmp_input_integer, cnt,
|
||||||
|
return_value;
|
||||||
|
|
||||||
|
/* init counters */
|
||||||
|
pop_count=0;
|
||||||
|
highest_used_bit=-1;
|
||||||
|
|
||||||
|
/* get population count, and highest non-zero bit */
|
||||||
|
tmp_input_integer=input_integer;
|
||||||
|
while ( tmp_input_integer > 0 ){
|
||||||
|
pop_count+=(tmp_input_integer&1);
|
||||||
|
highest_used_bit++;
|
||||||
|
tmp_input_integer>>=1;
|
||||||
|
};
|
||||||
|
if( 1 < pop_count ) {
|
||||||
|
/* "round" up */
|
||||||
|
highest_used_bit++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* generate return value */
|
||||||
|
return_value=1<<highest_used_bit;
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
19
src/util/pow2.h
Обычный файл
19
src/util/pow2.h
Обычный файл
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* $HEADER$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OMPI_POW2_H
|
||||||
|
#define OMPI_POW2_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine takes in an interger, and returns the nearest
|
||||||
|
* power of 2 integer, same or greater than the input.
|
||||||
|
*
|
||||||
|
* @param input_integer input value
|
||||||
|
*
|
||||||
|
* @returnvalue power of 2 integer same or greater than the input
|
||||||
|
* parameter.
|
||||||
|
*/
|
||||||
|
int ompi_round_up_to_nearest_pow2(int input_integer);
|
||||||
|
|
||||||
|
#endif /* OMPI_POW2_H */
|
Загрузка…
Ссылка в новой задаче
Block a user