1
1

Change the ORTE datatype service in 2 ways:

1. Remove a unneeded field, bytes_avail, from orte_buffer_t. It is a calcualed value, and updating it everywhere is worse then just calculating it in the one place it is acutally used.
2. Change it so the default size of a orte_buffer is 128 bytes instead of 1024 bytes. We then double the size of the buffer up to 1024 bytes, then we additively increase the size by 1024 bytes at a time as was done before.

This commit was SVN r14252.
Этот коммит содержится в:
Tim Prins 2007-04-06 19:40:29 +00:00
родитель f0e6a28a1f
Коммит e058266c96
6 изменённых файлов: 41 добавлений и 39 удалений

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

@ -39,10 +39,14 @@ extern "C" {
#endif
/*
* DEFINE THE DEFAULT PAGE SIZE FOR THE DSS BUFFERS - IN KILOBYTES
* The default starting chunk size
*/
#define ORTE_DSS_DEFAULT_PAGE_SIZE 1
#define ORTE_DSS_DEFAULT_INITIAL_SIZE 128
/*
* The default threshold size when we switch from doubling the
* buffer size to addatively increasing it
*/
#define ORTE_DSS_DEFAULT_THRESHOLD_SIZE 1024
/*
* Internal type corresponding to size_t. Do not use this in
@ -199,7 +203,8 @@ ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_dss_type_info_t);
extern bool orte_dss_initialized;
extern bool orte_dss_debug;
extern int orte_dss_verbose;
extern int orte_dss_page_size;
extern int orte_dss_initial_size;
extern int orte_dss_threshold_size;
extern orte_pointer_array_t *orte_dss_types;
extern orte_data_type_t orte_dss_num_reg_types;

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

@ -39,34 +39,39 @@
*/
char* orte_dss_buffer_extend(orte_buffer_t *buffer, size_t bytes_to_add)
{
size_t required, num_pages;
size_t required, to_alloc;
size_t pack_offset, unpack_offset;
/* Check to see if we have enough space already */
if (buffer->bytes_avail >= bytes_to_add) {
if ((buffer->bytes_allocated - buffer->bytes_used) >= bytes_to_add) {
return buffer->pack_ptr;
}
/* If we don't, see how many pages will be required and alloc
that */
required = buffer->bytes_used + bytes_to_add;
num_pages = required / orte_dss_page_size;
if (0 != required % orte_dss_page_size) {
++num_pages;
if(required >= (size_t)orte_dss_threshold_size) {
to_alloc = ((required + orte_dss_threshold_size - 1)
/ orte_dss_threshold_size) * orte_dss_threshold_size;
} else {
to_alloc = buffer->bytes_allocated;
if(0 == to_alloc) {
to_alloc = orte_dss_initial_size;
}
while(to_alloc < required) {
to_alloc <<= 1;
}
}
if (NULL != buffer->base_ptr) {
pack_offset = ((char*) buffer->pack_ptr) - ((char*) buffer->base_ptr);
unpack_offset = ((char*) buffer->unpack_ptr) -
((char*) buffer->base_ptr);
buffer->base_ptr = (char*)realloc(buffer->base_ptr,
num_pages * orte_dss_page_size);
buffer->base_ptr = (char*)realloc(buffer->base_ptr, to_alloc);
} else {
pack_offset = 0;
unpack_offset = 0;
buffer->bytes_used = 0;
buffer->base_ptr = (char*)malloc(num_pages * orte_dss_page_size);
buffer->base_ptr = (char*)malloc(to_alloc);
}
if (NULL == buffer->base_ptr) {
@ -75,8 +80,7 @@ char* orte_dss_buffer_extend(orte_buffer_t *buffer, size_t bytes_to_add)
}
buffer->pack_ptr = ((char*) buffer->base_ptr) + pack_offset;
buffer->unpack_ptr = ((char*) buffer->base_ptr) + unpack_offset;
buffer->bytes_allocated = num_pages * orte_dss_page_size;
buffer->bytes_avail = buffer->bytes_allocated - buffer->bytes_used;
buffer->bytes_allocated = to_alloc;
/* All done */

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

@ -78,7 +78,7 @@ int orte_dss_unload(orte_buffer_t *buffer, void **payload,
/* dereference everything in buffer */
buffer->base_ptr = NULL;
buffer->pack_ptr = buffer->unpack_ptr = NULL;
buffer->bytes_allocated = buffer->bytes_used = buffer->bytes_avail = 0;
buffer->bytes_allocated = buffer->bytes_used = 0;
/* All done */
@ -123,7 +123,6 @@ int orte_dss_load(orte_buffer_t *buffer, void *payload,
/* set counts for size and space */
buffer->bytes_allocated = buffer->bytes_used = bytes_used;
buffer->bytes_avail = 0;
/* All done */

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

@ -34,7 +34,8 @@
bool orte_dss_initialized = false;
bool orte_dss_debug = false;
int orte_dss_verbose = -1; /* by default disabled */
int orte_dss_page_size;
int orte_dss_initial_size;
int orte_dss_threshold_size;
orte_pointer_array_t *orte_dss_types;
orte_data_type_t orte_dss_num_reg_types;
orte_dss_buffer_type_t default_buf_type;
@ -96,7 +97,7 @@ static void orte_buffer_construct (orte_buffer_t* buffer)
/* Make everything NULL to begin with */
buffer->base_ptr = buffer->pack_ptr = buffer->unpack_ptr = NULL;
buffer->bytes_allocated = buffer->bytes_used = buffer->bytes_avail = 0;
buffer->bytes_allocated = buffer->bytes_used = 0;
}
static void orte_buffer_destruct (orte_buffer_t* buffer)
@ -142,7 +143,7 @@ OBJ_CLASS_INSTANCE(orte_dss_type_info_t, opal_object_t,
int orte_dss_open(void)
{
char *enviro_val;
int id, page_size, rc;
int id, rc;
orte_data_type_t tmp;
int def_type;
@ -173,13 +174,16 @@ int orte_dss_open(void)
mca_base_param_lookup_int(id, &rc);
default_buf_type = rc;
/* setup the page size -this is for use by the BUFFER system, NOT the data type
manager that keeps track of registered data types!! It must be converted to
bytes since the buffer system will allocate a "page_size" at a time.
*/
id = mca_base_param_register_int("dss", "page", "size", NULL, ORTE_DSS_DEFAULT_PAGE_SIZE);
mca_base_param_lookup_int(id, &page_size);
orte_dss_page_size = 1024*page_size;
/* setup the initial size of the buffer. */
id = mca_base_param_register_int("dss", "buffer_initial", "size", NULL,
ORTE_DSS_DEFAULT_INITIAL_SIZE);
mca_base_param_lookup_int(id, &orte_dss_initial_size);
/* the threshold as to where to stop doubling the size of the buffer
* allocated memory and start doing additive increases */
id = mca_base_param_register_int("dss", "buffer_threshold", "size", NULL,
ORTE_DSS_DEFAULT_THRESHOLD_SIZE);
mca_base_param_lookup_int(id, &orte_dss_threshold_size);
/* Setup the types array */

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

@ -228,8 +228,6 @@ int orte_dss_pack_null(orte_buffer_t *buffer, void *src,
/* update buffer pointers */
buffer->pack_ptr += num_vals;
buffer->bytes_used += num_vals;
buffer->bytes_avail -= num_vals;
return ORTE_SUCCESS;
}
@ -255,7 +253,6 @@ int orte_dss_pack_byte(orte_buffer_t *buffer, void *src,
/* update buffer pointers */
buffer->pack_ptr += num_vals;
buffer->bytes_used += num_vals;
buffer->bytes_avail -= num_vals;
return ORTE_SUCCESS;
}
@ -284,7 +281,6 @@ int orte_dss_pack_int16(orte_buffer_t *buffer, void *src,
}
buffer->pack_ptr += num_vals * sizeof(tmp);
buffer->bytes_used += num_vals * sizeof(tmp);
buffer->bytes_avail -= num_vals * sizeof(tmp);
return ORTE_SUCCESS;
}
@ -313,7 +309,6 @@ int orte_dss_pack_int32(orte_buffer_t *buffer, void *src,
}
buffer->pack_ptr += num_vals * sizeof(tmp);
buffer->bytes_used += num_vals * sizeof(tmp);
buffer->bytes_avail -= num_vals * sizeof(tmp);
return ORTE_SUCCESS;
}
@ -343,7 +338,6 @@ int orte_dss_pack_int64(orte_buffer_t *buffer, void *src,
}
buffer->pack_ptr += bytes_packed;
buffer->bytes_used += bytes_packed;
buffer->bytes_avail -= bytes_packed;
return ORTE_SUCCESS;
}

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

@ -93,10 +93,6 @@ typedef uint8_t orte_dss_buffer_type_t;
/** Number of bytes used by the buffer (i.e., amount of data --
including overhead -- packed in the buffer) */
size_t bytes_used;
/** How many bytes are available in the allocated buffer -- kept
here for convenience rather than recalculating it all the
time */
size_t bytes_avail;
};
/**
* Convenience typedef